#ironbeard - subscription
1 messages ยท Page 1 of 1 (latest)
Heyo ๐ Hope you're doing well. No rush here
Let's say someone clicks my "Checkout" link I've made, which creates (or updates) a Subscription on Stripe's servers using the Prices in their cart. They don't pay it at that moment, then several hours/days later they return, add another item to their cart (which results in a Subscription update) and proceeds to insert their payment info into the Card Element (I then use subscription.latest_invoice.payment_intent to pass along the client_secret to the Card Element in the front end).
This example wouldn't result in prorations, right? Since the subscription wasn't paid on the first visit?
I don't believe this would create a proration, no
You can always test these scenarios out: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
ah yeah, good point. Thanks!
@normal heath what's up?
heyo ๐
So turns out that the situation above actually results in Request req_esxHdwEhES9Z5b: You cannot update a subscription in incomplete status in a way that results in a new invoice or invoice items.
I was using Subscription creation to get PaymentIntent and Invoice in order to show a list of InvoiceItems in the checkout page (and get the client secret from the PaymentIntent).
I suppose this is not the recommended method if people are able to add new items to the cart at any point?
Hi ๐ jumping in and catching up on context here.
no worries ๐
At first glance, there is one other piece of behavior that I think will get in the way of achieving this flow.
Subscriptions with a status of incomplete will expire if their associated Payment Intent is not confirmed within 23 hours, which puts this flow at risk if there is a potential for your customers to not come back for more than a day.
Ah, yeah.
So I guess I'm a little confused on what the flow should be
I was hoping to use InvoiceItems to display the charges before calling stripe.confirmCardPayment in the front end.
This is because my customers will only have one subscription (everything is SaaS annual prices) and if they buy an add on, it will be prorated, and so I'd want ot show the prorated amount/description from the Invoice, not just the Prices in the cart
The piece of functionality that we have that comes to mind for this, is our ability to preview an upcoming invoice.
https://stripe.com/docs/api/invoices/upcoming
This doc walks through how to leverage that to preview prorations:
https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
I believe you can also use that endpoint without providing a customer or subscription to preview what the initial invoice for a subscription would be.
Ohh, interesting.
So if 1) Customer A had no subscription and I did stripe.Invoice.upcoming(customer='cus_a', subscription_items=[<sub items>]) that would return the invoice for an initial charge to sign up.
and then 2) if Customer B already had a on going annual subscription to a single item that they made last month, Sub_Item_A, and wanted to add (another annual) Sub_item_B, then my call to stripe.Invoice.upcoming(customer='cus_b', subscription_itmes=[<sub_item_a>, <sub_item_b>]) would display prorations?
So, since I'm not creating a Subscription (which creates the PaymentIntent + Invoice), I need to create my own PaymentIntent when they load the Checkout page. Do I need to set the amount on the PaymentIntent? Would I need to get that from the Invoice.upcoming call?
For scenario 2, you would also pass in the ID of the existing subscription. You can then configure the request to either have Sub_item_B replace the existing subscription item, or be added to it, and then you will be able to see the proration calculations for those.
Thinking through the last part a bit more.
If you're using Subscription objects in Stripe, I would recommend looking for a flow that avoids using Payment Intents/Invoices that are divorced from those.
The approach that I have in mind, though I'm not exactly sure if it will map to the flow you're looking for, is roughly the following:
- Retrieve customer/subscription info to see if the customer already has a subscription
- Use the invoice preview feature to calculate what the customer will need to pay for their action, and display that amount to the user
- Either when they start the checkout process, either create the new subscription or make the necessary changes to the existing one.
- Grab the Payment Intent from the Invoice created by the new Subscription and use that to process the payment.
Clarifying question, when you add the new item to an existing Subscription, do you plan to charge the customer for that immediately?
Yeah, I think that last part gets to the crux of it.
I used to create/update the subscription and get the latest_invoice.payment_intent.client_secret when they clicked the final "pay" button.
But, now that I want to show invoice items at that part. I was creating the subscription when they loaded the Checkout page (which is bad, since they could navigate away and add more to cart).
So I think I still need to defer the actual update/create of the Subscription to when the confirm button is pressed. But I can do an Invoice.upcoming call when the Checkout page is loaded.
Alright, I think I got the flow down. Thanks ๐