#stripe-connect-platform_api
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1387422835932401718
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there 👋 you are correct that you can't restrict a Coupon based on a Price, you can only specify Product IDs in applies_to.products when creating the Coupon.
Can you help me understand where you're stuck now, so I can try to advise how to proceed?
API call to get coupon to confirm the product id it applies_to
You would use the endpoint shown here for that:
https://docs.stripe.com/api/coupons/retrieve
coupon_id = "coupon_50_OFF_FIRST_MONTH"
coupon = Stripe::Coupon.retrieve(coupon_id)
#<Stripe::Coupon:0x1afcc id=coupon_50_OFF_FIRST_MONTH> JSON: {
"id": "coupon_50_OFF_FIRST_MONTH",
"object": "coupon",
"amount_off": null,
"created": 1750856868,
"currency": null,
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"name": "50% Off First Month",
"percent_off": 50.0,
"redeem_by": null,
"times_redeemed": 0,
"valid": true
}
?
applies_to?
I want to have the code to set and get applies to
then i need to move to promo code and create a new one that has the same product restriction. Do i ALSO need to set it on the promo code or only on the coupon?
Ah, apologies, forgot that field isn't included by default. You'll have to use expand to include the applies_to hash:
https://docs.stripe.com/api/expanding_objects
😦
Only on the Coupon. Promotion Codes don't support Product-restrictions themselves, they inherit that from the associated Coupon.
where are the docs that show the expand params on coupoins
how would anyone know this?
https://docs.stripe.com/api/coupons
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
There aren't docs specific to that, because the use of expand is the same for all API requests.
😦
expand: ['customer', 'payment_intent.customer'],
How would one know wtf to pass in?
that there is a hidden secret "applies_to" option?????
You read the section about how expand works where we tell you to put the name of the field that you want to include/expand int he response.
where do the coupon docs say there is a secret "applies_to" field????
While I agree currently do a bad job of distinguishing between includable and expandable fields (I've been complaining about this internally for a while now) the presence of the expandable tag in our API ref is a pretty good indication that you may need to use expand.
It's not secret?
write an applies to retrieve. I cannot
This is the section where we talk about setting eligible products for a Coupon, and point to using the applies_to hash for that:
https://docs.stripe.com/billing/subscriptions/coupons?dashboard-or-api=api#set-eligible-products
What do you have currently?
Stripe’s current API does not support an applies_to or product expansion on the Coupon object.
Product restrictions live only on Promotion Codes, not Coupons.
And what is the error you're seeing when you run it?
probably a hallucination
strip.value
value = value.strip # raise error for invalid byte sequences
oops hold on
3.2.2 :063 > coupon_id
=> "coupon_50_OFF_FIRST_MONTH"
3.2.2 :065 > request = Stripe::Coupon.retrieve(coupon_id, expand: ["applies_to"])
(irb):65:in <main>': undefined method strip' for ["applies_to"]:Array (NoMethodError)
OK got it. ChatGPT thinks its not supported but ok
OK to create a coupon with an applies_to via the API?
where is the doc on that?
OK, can I make an API and confirm that the promo code is restricted to a given product? Or how do i do so? chedck the promo code, then the related coupo, then the applies to field??? For an rspec test.
Q: Can you confirm that a promo code is restricted to a specifc product? If yes, how?
via API
for rspec test
Yup, exactly. You find the Coupon associated with the Promotion Code object, and check what Products are in the applies_to.products array on the Coupon.