#kyomen_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/1233391963869282416
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
So what's the exact concern? Checking the ID of the used discount? And ensuring the Coupon is only valid for one month?
You can limit the duration to only one month with this param: https://docs.stripe.com/api/coupons/object#coupon_object-duration_in_months
Hello! Thx for helping.
So I need to know which discount code the user used. eg:
My code is KYO123, and you use it to pay 12 months. I get a physical good on the first month
Oh actually this is done. I just forgot. Now the only concern is knowing what code was used
In my db I'm storing everyones code, so I can gather the rest of the user info based on the code
Are you using Checkout Sessions? Or creating Subscriptions directly?
I'm using the API to create the subscriptions and then presenting the payment sheet in the react native app with the payment intent client secret
Does that answer your question? I didn't know exactly how to answer
const subscription = await stripe.subscriptions.create({
customer: customerId,
promotion_code: coupon,
items: [{ price: planId }],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
})
Like this
coupon is the promotion code id actually, not the whole coupon id
You can retrieve it before creating the Subscription and check what customer it belongs to: https://docs.stripe.com/api/promotion_codes/list#list_promotion_code-code
What if the user doesn't pay the subscription?
You can then as well do the check when you get an invoice.paid webhook event.
So we're back to stage one: My problem is that in the Invoice object created w/ the constructEvent method in the webhook, there is no expand prop, and the discounts array in the Invoice is just a list of IDs. However, I can't gather the Discount object with the ID according to the docs
What programming language are you using?
Alternatively, you can always make a call to retrieve the full Invoice object by ID, as well as any expanded properties.
And as far as I know, you can expand properties in Node.js constructEvent
I'll try that and return in a bit.
Just to be sure: If the promotion code is applied only for the first month, then the discount id will only be present in the first month invoice, right?
Sorry, I think not anymore: https://docs.stripe.com/expand#with-webhooks
I am not sure, it's best to check for yourself in Test mode with test clocks: https://docs.stripe.com/billing/testing/test-clocks
oh okay thx for checking
wow I didn't knew that was possible. I'll try it out, thx a lot
Happy to help.