- Issue created by @Nicolas Bouteille
- πΊπ¦Ukraine marchuk.vitaliy Rivne, UA
s it something you have not had time to implement yet? Something you did not think about? Something not possible (Payment methods created via Card Element not compatible inside Payment Element?) ? Something I need to configure?
This is expected behavior because the payment methods created with the Stripe Card element belong to the payment gateway you disabled (see what data we have in the commerce_payment_method table). In theory, you could migrate payment methods to a new payment gateway (by changing some data in the commerce_payment_method table) that uses the Stripe Payment Element, and I hope that works (but never actually tested it).
- π«π·France Nicolas Bouteille
Ok thanks for the quick reply. I will have a look at it.
In my tests, I have also noticed that when paying with Payment Element, with an already existing user that had made some payments in the past using Card Element, not only the stored payment methods (Card Element) are not suggested to be reused, but any new Credit Card created through Payment Element are not associated to the existing Stripe "Customer". A new Stripe Customer is created by the transaction, so I have two Stripe Customers with the same email. I noticed in Stripe developer logs that during Payment Intent request, the "customer" parameter is null when using Payment Element. So I will dig deeper in that direction for now. Because I believe that maybe if we give the proper Customer ID to Stripe when creating the Payment Intent, maybe Stripe will suggest already stored payment methods inside Payment Element. - π«π·France Nicolas Bouteille
Here is an error I get when I manage to select a previously stored payment method yet choosing Payment Element as the gateway:
Stripe\Exception\InvalidRequestException: The `payment_method` parameter supplied pm_1OHps9LaAQrxbmc9xxxxxxxx belongs to the Customer cus_P61wxxxxxxx. Please include the Customer in the `customer` parameter on the PaymentIntent. in Stripe\Exception\ApiErrorException::factory() (line 38 of β¦/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php).
I need to check if the empty customer parameter is due to some custom stuff or not. - π«π·France Nicolas Bouteille
Ok I was able to understand how to reproduce this use case / error. As soon as you chose a payment gateway / payment method, a Payment Intent is created based on this payment gateway. Method createPaymentIntent() is called either in Stripe.php or StripePaymentElement.php.
If you empty the cart, the checkout_step db column is emptied for the order which allows you to chose another payment gateway / payment method. But, the Payment Intent is not created again. The same Payment Intent created earlier based on a different payment gateway is used.
So in my case I can chose Payment Element the first time, so the Payment Intent is created based on Payment Element (which has customer : null btw - might be a bugβ¦). Then I empty the cart, fill it back again, chose a previously stored Credit Card, based on the lagacy stripe payment gateway. So an update Payment Intent request is sent based on Payment Element, trying to add a specific payment method that belongs to a Stripe customer, but the customer param is null so does not match the customer of the card.I think we should check if the chosen payment gateway still matches the one configured in the Payment Intent. If not, create a new Payment Intent. This is worth a separate issue as this one is just about being able to offer previously stored payment methods inside Payment Element.
Also, once I figure out why customer is null when creating Payment Intent with PaymentElement, I might create another separate issue for that matter.
- π«π·France Nicolas Bouteille
I contacted Stripe Developers on Discord and they told me that displaying / suggesting previously stored payment methods directly inside the Payment Element JS component is not available yet, but this is being worked on.
"work is being done to build and offer that functionality, but I don't think it is generally available yet. It's being worked on, but I'm always hesitant to guarantee things being worked on will launch. I strongly believe this one will, but I'm not comfortable guaranteeing that π "
So in the mean time we shall keep manually suggesting stored payment methods and use Payment Element only if the customer needs to add a new payment method.
- Status changed to Closed: works as designed
7 months ago 9:36am 4 December 2023 - π«π·France Nicolas Bouteille
The initial question of this issue was to know if it was possible to suggest previously strored cards (with Card Element) directly inside the Payment Element JS component.
Now I know that this is not possible, that Payment Element can only be used to add new payment methods (except when using Link btw) and that we need to manually suggest stored cards during the checkout process.
I have also noticed that this is actually already working. But, as mentionned in #2, cards previously stored in the past with Card Element don't show up anymore if I replace Card Element with Payment Element. This is due to the fact that technically the way Commerce Stripe has been handling this is that Card Element and Payment Element are considered as two completely different payment gateways, not sharing remote customer IDs and not sharing stored payment methods either. Making it hard to switch from one another on an existing site.
So I am closing this issue as works as designed and opening a new one about sharing Stripe payment methods between Card Element and Payment Element.