#amit-dey_api

1 messages ยท Page 1 of 1 (latest)

upper prairieBOT
#

๐Ÿ‘‹ 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/1438119957408907304

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

serene yoke
#

Why does updating subscription item quantity remove existing coupon or promotion code?
What's the req_xxx ID where this happens?

#

I don't see discounts being unset on the example you shared

cerulean mulch
#

I started with the goal of updating only the quantity of an existing subscription item. My intent was not to change or modify anything else on the subscription โ€” especially the applied coupon or promotion code.
Initially, I used the following approach:
await stripe.subscriptionItems.update(itemId, {
quantity: newQty,
proration_behavior: 'create_prorations',
});
However, after this update, the existing coupon/promotion code disappeared from the subscription.
Then, I tried updating at the subscription level using:
await stripe.subscriptions.update(subId, {
items: [{ id: itemId, quantity: newQty }],
proration_behavior: 'create_prorations',
});
But that also removed the coupon/promotion code.
Finally, I found that the only way to preserve the discount was to fetch the existing coupon or promotion_code from the subscription first, then explicitly reapply it during the update. In other words โ€” first I update the subscription item quantity, and then I update the subscription again with the existing coupon/promotion code, and this sequence works correctly.
const sub = await stripe.subscriptions.retrieve(subId, {
expand: ['discounts', 'discounts.promotion_code', 'discounts.coupon'],
});

const promoCodeId = sub.discounts?.[0]?.promotion_code?.id;
const couponId = sub.discounts?.[0]?.coupon?.id || sub.discounts?.[0]?.source?.coupon;

await stripe.subscriptions.update(subId, {
items: [{ id: itemId, quantity: newQty }],
discounts: promoCodeId
? [{ promotion_code: promoCodeId }]
: couponId
? [{ coupon: couponId }]
: undefined,
});
This two-step workaround works โ€” the coupon remains intact โ€” but it feels unnecessary since Iโ€™m not intentionally modifying discounts.

#

Where can I find the req_id I called API via node server?

serene yoke
#

Sorry but you've yet to give us an example where discounts is actually unset. Both subscriptions you've set the property is never unset so overall confused about what you describe

serene yoke
upper prairieBOT
serene yoke
cerulean mulch
#

req_ozE3s10veggOR9

cerulean inlet
#

hey there ๐Ÿ‘‹ I'm taking over for ynnoj

just reviewing this thread and the example you shared - thanks!

#

hmm yeah this example seemingly does remove the discount after existing the item quantity for some reason

#

I don't think this is expected, but just running some tests to see if I can reproduce

cerulean inlet
#

hmm, ok I haven't been able to reproduce so I think this may be a bug on our end

#

we'll need you to open a support case with us so we can investigate further with our product team

upper prairieBOT
#

Hello @cerulean mulch, we have sent you a direct message, please check it at https://discord.com/channels/@me/1438133365160149032

  • ๐Ÿ”—The message has instructions on how to open a direct support case with our Developer Support team, in order to help you more effectively.