#Elian Braja
1 messages · Page 1 of 1 (latest)
I'm honestly not 100% certain on why we designed the system that way. That being said, as a quick workaround, you can start your subscriptions with a short (couple second long) trial. If you do that, the first paid invoice will be in a draft state for an hour just like the subsequent ones
but I don't have a trial option
users subscribe immediately. The problem is that after I create the subscription I want to apply a coupon code but since the invoice is finalized I cannot update it and this is a problem for my design flow
please tell me if you can suggest me any workaround
Is this on a custom webpage that you are writing or is this on a Stripe hosted page like Checkout?
is a custom webpage
so after I create a subscription and send the client_secret to frontend, the customer can also apply a coupon code before providing his payment details
but since the first_invoice was already finalized I receive an error from stripe that tells: "Finalized invoices can't be updated in this way"
Gotcha, so that three second trial would still be the suggestion. You would create the subscription on the backend, on the Stripe side it would be in trial mode for three seconds but the user would never see that, after three seconds, the subscription would cycle and create a draft invoice for the first paid cycle and you can use that invoice to apply discounts and such.
but since I will create the subscription in trial model, what client_secret can I pass to frontend since there is no invoice created yet?
can you please explain me more in details the flow?
You aren't going to have an payment intent until the invoice is finalized anyway. So you need to wait on your finalize call either way
that was what I was saying, so seems imposible to solve that way
Yes. And now that I think about it there is a way easier way to do this. One sec while I find the doc
Basically, we have a "preview an upcoming invoice" API. It lets you generate invoices for a hypothetical new subscription on the fly. So you can preview the amount they would pay and then once they click the button to confirm that that is what they want you can actually create the subscription
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I understand, thank you
May I ask you for another problem I faced?
relating to this topic
So after a customer is already subscribed to a certain plan I want to add another item to that subscription
I am providing payment_behavior: "always_invoice"
so that the customer can immediately pay the invoice of the item he added without waiting for the billing cycle date of the subscription
The problem is that I cannot apply a coupon or promotion code to that single invoice
how can I achieve this?
For clarification, I don't want to apply a coupon to the subscription but only that particular invoice that was created by the new subscription item added
So that is possible but will take some custom code from you here. Here are the basic steps for that
- Make the change with a
proration_behaviorofcreate_prorations, that will create pending invoice items rather than an invoice - Create an invoice, passing in a
pending_invoice_item_behaviorofinclude, this will create a draft invoice for the proration items that you just created. - Apply discounts to the invoice
- Finalize the invoice, this will create the payment intent client secret that you can pass to your customers
Thank you, I will try that
Hi Pompey. I tried this solution and it worked but I am not understanding why my applied coupon does not take effect
here is 20% off but is reflected as $0.00
why?
?
Hello 👋
Pompey had to step away
Give me a moment to catch up and I'll respond as soon as I can
ah ok, thank you. I resolved the issue. Just want to know why my coupon is reflected as $0.00 instead it should subsctract an amount
the coupon is active
can you share the subscription ID so that I can dig deeper?
hmm i'm not super sure
Asking a colleague to see if they can provide more context
ok
Since the invoice items are all for prorations and the proration is calculated inclusive of the discounts, it must have something to do with prorations.
But trying to see if there's more context that we can share
thanks for your patience
So it is due to prorations
When you make changes to a subscription, any existing discounts are applied when proration is calculated. You can’t discount proration line items further on the invoice that’s generated.
https://stripe.com/docs/billing/subscriptions/coupons
but how can I make a discount than if I want to apply a coupon code to an invoice created when I add a new subscription item
I did this flow just for that as your colleague proposed
Then which flow is correct to follow?
There are two options
1/ You could call the upcoming invoice API endpoint, see the total amount of that preview invoice that contains the proration, then when you go ahead and create the invoice you can add an invoice item with a negative amount you calculate as 20% of the total amount.
2/ Add the coupon to the sub before making the proration change
but I don't want to apply that coupon to the subscription. I just want to apply for that particular invoice created after adding a new subscription item
Gotcha, in that case you'd want to go with option 1.
what if I don't do the flow proposed before and add an invoice_item to a finalized invoice?
can that be done?
or is imossible for a finalized one?
to be modified
Yeah you can't really modify finalized invoices.
You can only edit draft invoices.
is there any way to add invoice items during invoice creation, like we can do with subscriptions adding items during the creation or update call
?
Hi 👋 I"m stepping in as @modern summit has to go. As long as the Invoice is in a Draft state you can create Invoice Items and include the Invoice ID to assign those items to the draft invoice: https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.