#ls-sub-requests
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- lokis, 3 days ago, 4 messages
Hello! Do you have an example request I can take a look at?
@bright loom please respond here and not in the main channel
We make a series of calls to Stripe API from our backend API. Below is the relevant piece of code which is taking longer to execute:
....
if(!freeTrialKeys.includes(subscriptionData.trialPlan)) {
await this.appendInvoiceItem(subscriptionData.trialPlan, subscriptionData);
}
await this.payInvoice(); // This takes roughly 3s
const subscription = await this.createSubscription(subscriptionData); // This takes roughly 4s
...
https://dashboard.stripe.com/events?related_object=cus_PAjmm0RIdseATt - as you can see in the event logs for this customer, between the invoice item being added to the invoice and the customer being charged, it has taken about 3s.
12/12/2023, 16:32:30 - 12/12/2023, 16:32:33
Is there a reason you're creating a separate Invoice for the customer before you create the Subscription?
Yes, if the customer opted for a paid trial, we want to charge them for the trial immediately and only if it succeeds, create the subscription - this is to avoid provisioning access if their payment failed.
It'd be much faster for you if you create the trialing Subscription w/ add_invoice_items - if payment isn't successful I believe the Subscription will have a status: incomplete which you can check for
My understanding is that add_invoice_items doesn't charge the customer immediately which is why we had to change our implementation to this approach
It does charge the customer immediately
Try it out in test mode to see how it works - those invoice items are immediately added to the first invoice
another thing that'll make your flow faster - instead of creating a separate setup intent, you can rely on the payment or setup intent that is created when the Subscription is created
ls-sub-requests
Sure, I will give it a try. Will the createSubscription API call immediately return a response with the status if the invoice item payment failed?
Yeah if payment does succeed the Subscription status will be status: incomplete
another thing that'll make your flow faster - instead of creating a separate setup intent, you can rely on the payment or setup intent that is created when the Subscription is created
do you mean by fetching and passing the setup intent id already created to the createSubscription call? Any examples/docs you can point me to would be very helpful. Thanks.
👋 taking over here. No, it's to use the first ever generated PaymentIntent inside the Subscription, or using the pending_setup_intent generated inside the Subscription
Do you have any docs that you can point me to, please?
Yes a min
So here is how to add extra invoice items into the first Invoice: https://stripe.com/docs/billing/invoices/subscription#first-invoice-extra
Thanks. This doc mentions that it takes an hour for the invoice to be finalised - we want it to happen immediately so that we can avoid provisioning access if the payment for the trial failed.
Stripe waits approximately one hour before finalizing the invoice and attempting payment, or sending an email.
That's the 2nd Invoice onward. The first Invoice will always finalized immediately
ah right, thanks for that.
another thing that'll make your flow faster - instead of creating a separate setup intent, you can rely on the payment or setup intent that is created when the Subscription is created.
No, it's to use the first ever generated PaymentIntent inside the Subscription, or using the pending_setup_intent generated inside the Subscription
As far as I can tell, we don't seem to be creating a new setup intent. How do we ensure the first setup intent is used rather than a new one bring created?
Do you mean how to ensure to have pending_setup_intent?
yes
Okie let me try to find explain Doc / try on my side
Sorry we don't have a dedicated Doc, only briefly mentioned here https://stripe.com/docs/billing/subscriptions/overview#using-setupintents
Stripe automatically creates SetupIntents for subscriptions that don’t require an initial payment. The authentication and authorization process also completes at this point, if required.
But if you normally create a Subscription with these parameter for example
collection_method: "charge_automatically",
trial_period_days: 2,
expand: ['pending_setup_intent', 'latest_invoice.payment_intent'],
payment_behavior: "allow_incomplete",
you would see the pending_setup_intent