Issues with Stripe Customer/PaymentMethod on order customer reattach

Created on 28 July 2025, 18 days ago

Problem/Motivation

Our project heavily uses user login/registration during the checkout, as well as automatic account creation at the end of checkout. All payment methods are reusable, so, for example, when anonymous user finishes checkout and then logs in, starts a new checkout and tries to re-use already stored payment method, we gen an error. This patch addresses some of the issues and edge cases we were able to find. Also, it re-uses some code from another issue already addressed.

Proposed resolution

1. Check if customer really exists by getRemoteCustomerId in attachCustomerToStripePaymentMethod. It is already covered in related issue 3326812
2. Handle edge case when updating Stripe payment method billing details fails immediately after a successful payment with 3D Secure authentication. We sometimes had an error where we received payment_intent.succeeded event from Stripe API but got an error on attachCustomerToStripePaymentMethod. Turned out, it is not always a good idea to update PaymentMethod billing_details right after 3DS, because Stripe treats some updates (like billing details) as sensitive operations and if it performed too soon after authentication, Stripe may require additional verification so it throws an error. Fixed by catching authentication_required errors, and updating the PaymentMethod later in queue.
3. We often had en error "To reuse a PaymentMethod, you must attach it to a Customer first" from stripe API. The fix is to catch this error in createPaymentIntent, find/create Stripe customer, re-attach it to PaymentMethod and then try createPaymentIntent again.

Feature request
Status

Needs review

Version

2.0

Component

Stripe Checkout

Created by

🇵🇱Poland dlevchik Poznan, Poland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024