#ls-sub-requests

1 messages · Page 1 of 1 (latest)

stoic prismBOT
#

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
edgy flower
#

Hello! Do you have an example request I can take a look at?

#

@bright loom please respond here and not in the main channel

bright loom
#

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

...

stoic prismBOT
bright loom
edgy flower
#

Is there a reason you're creating a separate Invoice for the customer before you create the Subscription?

bright loom
#

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.

edgy flower
#

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

bright loom
#

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

edgy flower
#

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

stoic prismBOT
#

ls-sub-requests

bright loom
#

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?

edgy flower
#

Yeah if payment does succeed the Subscription status will be status: incomplete

bright loom
#

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.

odd glen
#

👋 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

bright loom
#

Do you have any docs that you can point me to, please?

odd glen
#

Yes a min

bright loom
#

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.

odd glen
#

That's the 2nd Invoice onward. The first Invoice will always finalized immediately

bright loom
#

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?

odd glen
#

Do you mean how to ensure to have pending_setup_intent?

bright loom
#

yes

odd glen
#

Okie let me try to find explain Doc / try on my side

#

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