john bowlee
john bowlee

Reputation: 175

Stripe add coupon after creating the subscription

I am currently integrating Stripe but I am facing a problem with my current flow. After user selects a subscription, I create a subscription in my back-end and attach the prices. Then I return the response to front-end for completing the payment. The problem is that by the time user add his card information, he can also add e coupon but the invoice is already created and finalized by stripe (not paid yet) and I cannot add a coupon to an already finalized invoice. It looks strange to me since the customer hasn't paid the invoice yet and it is normal to add a coupon. Maybe this behavior is normal for invoices with status "paid" but the invoice in my case has not been paid yet and the status is just "finalized". I think that I can update the invoice if it is in status "draft" but Stripe updated the status from "draft" to "finalized" automatically after creating a Subscription, without letting me make updates to a draft invoice first and then finalize it on my own. How can I solve this situation, without changing the workflow of subscribing the user. So, I am interested to add a coupon code after creating a subscription but before paying the invoice. I would really appreciate if someone can help me in this scenario.

Upvotes: 5

Views: 2210

Answers (1)

hmunoz
hmunoz

Reputation: 3311

Correct, you can not attach a Coupon to a Subscription's first Invoice when that Subscription is created with the payment_behavior: 'default_incomplete' parameter as that creates and finalizes an Invoice (so as you noted, the amount on that cannot be changed).

You have two options here:

1/ You change your frontend flow so that instead of creating the Subscription with the Prices up front, you instead defer that later in your flow, when you present the card entry UI (and coupon code UI) to your end Customer. When they press the "subscribe" button on your webpage, you then create a Subscription with the Coupon Codes and then client-side, confirm the Subscription's underlying PaymentIntent with the PaymentElement (and the card details that were entered in it).

2/ The second option still has you do the same as option 1, where you create the Subscription later in your flow when the Customer presses your "subscribe" button.

But instead, you use the Upcoming Invoice endpoint https://stripe.com/docs/api/invoices/upcoming and use that to "preview" what the Prices + Coupon Code would result in as the first Invoice amount. That gives your end customer more visibility into previewing exactly what their Prices + Coupon combo results in. And then you create the Subscription with the Coupon code they entered in.

Upvotes: 4

Related Questions