#xolott
1 messages · Page 1 of 1 (latest)
Hi there
Hmmm no that should work to preview an upcoming one with a coupon. What coupon are you using to preview with? Does it happen to have duration: once set?
Yes, it have duration: once This customer never used this coupon before
Hmm but it is attached to the Subscription already, right? Like you are updating a Sub here
I have a subscription created without a coupon. Now, I want to update the subscription, removing an item and adding a new one, but also apply the coupon.
The discuount is applied in the invoice. But the total_discounts field is 0
Ah you are just applying the coupon when you preview.
Can you show me your code for this preview?
You are using coupon and not discounts correct?
Yep, using coupons
This is what stripe returns
Let me get the code
const params = {
subscription: subscription.stripeSubscription.id,
subscription_items: subscriptionItems,
subscription_proration_behavior: 'always_invoice',
subscription_default_tax_rates: taxes,
coupon,
// @ts-ignore
customer: subscription.stripeSubscription.customer,
};
const invoice = await this.stripe.invoices.retrieveUpcoming(params);
Here, coupon is a string with the coupon ID
Node SDK
Same code is used in both scenario, new subscription or updating an existing one. For the first case, it returns the total discount as expected
Thanks, give me a moment
Also, this is the discount field on the invoice. As you can see Stripe is using the coupon
But total_discount_amounts is null
What are you doing with subscriptionItems? Like what kind of update are you performing exactly?
It is not null. Just zero
Ah thanks
Can you give me the Sub ID that you are updating?
Do you have specific Products applied for that coupon?
Yep okay I'm seeing the same thing you are in a repro
Feels like a bug to me, let me double check with a colleague
Thanks! I hope we can solve this easily 😄
Hi there. Taking over for @boreal carbon as they have to step out. This is actually expected behavior. It is a bit strange, but what's happening here is a proration line item is created (since you remove and add a new item). Proration line items by design have discountable set to false. The discount is applied to the total, but it is applied at the Subscription level in the subscription item (si_123). The proration line item is a line item based on that already-discounted amount. In other words, we surface the discount within the Subscription item at the Subscription level, but not at the Invoice level. If you wanted to understand the actual discount amount due to adding the coupon, you'd have to do the math on your end using data from the Subscription item unfortunately.
Thanks @hollow crescent
So, I need to take the prorated discounted amount from the invoice and calculate the discount amount applied. Did I get that right?
Is there any documentation about this behaviour?
Correct
Let me see if I can find documentation
Ah there's 1 line here: https://stripe.com/docs/billing/subscriptions/change. When applying changes to existing subscriptions, discounts don’t affect the resulting proration line items.
Sorry I said correct but that's not exactly right
You'd need to get the discount from the Subscription Item
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
But If I'm adding that item to the subscription and using the retrieve upcoming, I don't have a subscription item yet. For that, I need to make the changes to the subscription, but that defeats the purpose of the preview invoice. Is this correct?
Correct that's why you'll have to do the math yourself in this instance unfortunately
Uhmm. Weird behaviour. One last question, is there a reason why it's applied like this? I may need to explain this to my team. Sorry, but English is not my first language, and sometimes I struggle to understand
No worries. I don't know that I have a good answer to that unfortunately. It's just a weird caveat
Okay. Thanks for your time! Have a nice weekend