#kyomen_api

1 messages ¡ Page 1 of 1 (latest)

lilac tigerBOT
#

👋 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.

spare jackalBOT
serene river
#

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?

digital kestrel
#

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

digital kestrel
#

In my db I'm storing everyones code, so I can gather the rest of the user info based on the code

serene river
digital kestrel
#

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

serene river
digital kestrel
#

What if the user doesn't pay the subscription?

spare jackalBOT
serene river
#

You can then as well do the check when you get an invoice.paid webhook event.

digital kestrel
#

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

serene river
#

What programming language are you using?

digital kestrel
#

NodeJS for the backend

#

w/ TS

serene river
serene river
digital kestrel
#

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?

serene river
digital kestrel
digital kestrel
serene river
#

Happy to help.