#Elian Braja

1 messages · Page 1 of 1 (latest)

dawn novaBOT
tough viper
#

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

raven zealot
#

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

tough viper
#

Is this on a custom webpage that you are writing or is this on a Stripe hosted page like Checkout?

raven zealot
#

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"

tough viper
#

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.

raven zealot
#

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?

tough viper
#

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

raven zealot
#

that was what I was saying, so seems imposible to solve that way

tough viper
#

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

raven zealot
#

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

tough viper
#

So that is possible but will take some custom code from you here. Here are the basic steps for that

  1. Make the change with a proration_behavior of create_prorations, that will create pending invoice items rather than an invoice
  2. Create an invoice, passing in a pending_invoice_item_behavior of include, this will create a draft invoice for the proration items that you just created.
  3. Apply discounts to the invoice
  4. Finalize the invoice, this will create the payment intent client secret that you can pass to your customers
raven zealot
#

Thank you, I will try that

raven zealot
#

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?

#

?

modern summit
#

Hello 👋
Pompey had to step away
Give me a moment to catch up and I'll respond as soon as I can

raven zealot
#

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

modern summit
#

can you share the subscription ID so that I can dig deeper?

raven zealot
#

sure

#

sub_1LmHq5EMyoEBRsWZH5SKQqRi

#

any reason why it acts like so?

modern summit
#

hmm i'm not super sure
Asking a colleague to see if they can provide more context

raven zealot
#

ok

modern summit
#

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

raven zealot
#

these are the arguments I pass to create the draft invoice

modern summit
#

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

raven zealot
#

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?

modern summit
#

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

raven zealot
#

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

modern summit
#

Gotcha, in that case you'd want to go with option 1.

raven zealot
#

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

modern summit
#

Yeah you can't really modify finalized invoices.
You can only edit draft invoices.

raven zealot
#

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

#

?

brittle leaf
#

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