#do0ks
1 messages · Page 1 of 1 (latest)
Hi, let me help you with this.
- I am not sure what you mean in this question. Manage what exactly?
- Yes, that seems to be a good approach.
1 - I mean I can use a previously created product (subscription) in Stripe itself with this method:
await stripe.checkout.sessions.create({
mode: "subscription", .... })
Or I could create the subscription with await stripe.subscriptions.create({ ... })
2 - Thank you for that, the next question is, how can I know when to query the service that returns the usage fee before the subscription charges the user to include both (suscbirption and fee)?
You can use both. The difference is whether you want to use Stripe-hosted payment page - Stripe Checkout, or your own page with e.g. Payment Element.
You can listen to invoice.created webhook event. It will fire before every monthly charge. After that you will have some time to update the upcoming Invoice with the fee, if needed.
Actually, a correction from earlier, it's better to update an individual monthly Invoice instead of the Subscription, given you make this decision every month.
Good to know, I would like to use the stripe hosted payment page, I guess to do so I can only use await stripe.checkout.sessions.create({
mode: "subscription", .... })
Nice. It only matters for the initial Payment Method collection. Afterwards, you will get the same Subscription object, regardless of whether you used Checkout or not.
I don't really understand this. You say that it is better to update an invoice, but how would be the flow after creating the subscription?
When the Subscription is active, you will receive the invoice.created event every month, before the the Subscription is renewed. You can take the ID of the newly created Invoice and create a one-time Invoice Item for your fee: https://stripe.com/docs/api/invoiceitems/create
Then, in about an hour, the new Invoice will be finalized and the customer will be charged for the normal monthly price, plus the added fee.
Next month the process repeats.
Nice. Thank you very much! I will try this approach! Thanks Vanya, very kind of you
Happy to help.