Search code examples
stripe-paymentsreusability

Is it okay to have a bunch of incomplete Stripe payment intents?


I am implementing the Stripe payment platform using JavaScript and the PHP SDK.

I don't have any issues with the implementation itself, but I am not sure whether I have to reuse an existing PaymentIntent or it's perfectly fine to have a bunch of them created and incomplete.

I searched for this in Stripe's documentation, but I can't seem to find anything related to this.

For example, in my test account I have this: Stripe Screenshot

It's all for the same transaction, because I was changing some visuals and refreshing the browser.

I am aware that each PaymentIntent has an ID, but is it recommended to add it as a query parameter and retrieve it on refreshing, or is it better to always generate a new Payment Intent.

My main reasoning is to avoid having a huge collection of incomplete payment intents.


Solution

  • The default integration path for Stripe today is to create a PaymentIntent first so that you get a client_secret you can use client-side to render their UI via PaymentElement. This means that if your customers decide not to pay after all, you end up with an incomplete PaymentIntent which is expected.

    This is not really a problem, other than appearing in the Payments list which can be confusing. You could also write a background job daily that would cancel any PaymentIntent via you know won't be completed because the customer left and you didn't have any data to contact them to upsell them for example but this isn't really needed.

    Stripe also has a beta (docs) right now (Feb 2023) that changes the default integration path. This simplifies the experience because you can render the PaymentElement client-side with specific options such as amount and currency. You'd then only create the PaymentIntent at the end of the flow when the customer is attempting to pay. That flow limits the number of incomplete PaymentIntents since you only create them when the customer really pays. You'd still get some, for example after a decline by the customer's bank though.