#xolott

1 messages · Page 1 of 1 (latest)

zenith walrusBOT
boreal carbon
#

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?

lost gorge
#

Yes, it have duration: once This customer never used this coupon before

boreal carbon
#

Hmm but it is attached to the Subscription already, right? Like you are updating a Sub here

lost gorge
#

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

boreal carbon
#

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?

lost gorge
#

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

boreal carbon
#

Thanks, give me a moment

lost gorge
#

Also, this is the discount field on the invoice. As you can see Stripe is using the coupon

boreal carbon
#

But total_discount_amounts is null

#

What are you doing with subscriptionItems? Like what kind of update are you performing exactly?

lost gorge
#

It is not null. Just zero

boreal carbon
#

Ah thanks

#

Can you give me the Sub ID that you are updating?

#

Do you have specific Products applied for that coupon?

lost gorge
#

Subscription ID: sub_1MANKKIcCLTQY54L3EvHkRqI
The coupon is for all the products

boreal carbon
#

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

lost gorge
#

Thanks! I hope we can solve this easily 😄

hollow crescent
#

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.

lost gorge
#

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?

hollow crescent
#

Correct

#

Let me see if I can find documentation

#

Sorry I said correct but that's not exactly right

#

You'd need to get the discount from the Subscription Item

lost gorge
#

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?

hollow crescent
#

Correct that's why you'll have to do the math yourself in this instance unfortunately

lost gorge
#

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

hollow crescent
#

No worries. I don't know that I have a good answer to that unfortunately. It's just a weird caveat

lost gorge
#

Okay. Thanks for your time! Have a nice weekend