#ll_best-practices

1 messages ยท Page 1 of 1 (latest)

tough compassBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1351137098392145940

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

gleaming dagger
#

๐Ÿ‘‹

The docs say that you cannot modify invoices attached to subscriptions after finalisation but I'm curious to know if there's any sort of work around or if I have to recreate the subscription object whenever I want to add a discount.
Nope there is no workaround, you should use the grace period (1h) between the creation of the invoice and finalizing it

#

During that interval, you can make updates on the invoice

pallid cypress
#

Immediately upon creating the subscription on the API it says I cannot make any updates

#

okay,

#

i'll take a look ty

gleaming dagger
#

In that case you should pass the discount with the Subscription creation object

#

First when creating a Subscription, its invoice is immediatly finalized

#

The grace period is for the upcoming invoice

pallid cypress
#

ah so it's not for the initial invoice?

#

as in; i cannot modify the initial invoice of the subscription object?

gleaming dagger
#

Why you want to modify it ?

pallid cypress
#

in case the user chooses to add a discount after creation

gleaming dagger
#

you should modify the Subscription directly, as it's still increation phase

#

You can add the discount at the Subscription level directly

pallid cypress
#

can i show you my code?

gleaming dagger
#

Yes sure

#

But you should pass the discount here

pallid cypress
#

okay so, i do have the code to apply a discount to my line item. however, if a user first enters the page without a discount it would be the item without the discount

#

in the same way that i can modify the payment intent of a one time item

#

is there a way i can do this with subscriptions or can i only do it upon creation, i.e. having to create a new subscription object every time?

gleaming dagger
#

Actually, you need to create the Subscription only, when you are sure that the customer won't enter any thing else

#

You should make the call at the latest moment possible

pallid cypress
#

the way the page is designed it's set to add the subscription to the cart immediately as that's the default option for the checkout page

#

and it has a radio toggle to toggle between either the subscription + one-time payment or the one-time payment alone

#

and i pass the intent to an Elements component

#

unless there's a way for me to render the checkout form and create the intent after the user has already submitted their details?

#

that way i'm only creating it upon submit?

#

i'm looking at this page in the docs

#

which seems like it might work

#

but it's talking about including the price and currency in the options object

#

i can't tell if that's fully required or not? currency would be fine to include but if the price is determined after discounts are applied would that be an issue? or could i perhaps just perform my calculations on the price in the backend and return that value to my options object and also to the checkoutform?

gleaming dagger
#

that way i'm only creating it upon submit?
You need to update your code, to not creating the Subscription Object at stripe side, you can track that in your database if you want

#

but you should defer the creation of the Subscriprion via Stripe APIuntill the last moment

pallid cypress
#

so within my handleSubmit for my checkoutForm element for example?

gleaming dagger
#

Yes you can or whatever other location in your code

#

But the idea is to create the Subscriprion with all the possible option at once

pallid cypress
#

I see okay, thank you

#

i'll figure something out

#

i've appreciated your help

gleaming dagger
#

Welcome! Happy to help!