Previously registered payment methods with Card Element not showing with Payment Element

Created on 29 November 2023, 7 months ago
Updated 4 December 2023, 7 months ago

Hello,

I would like to start using the Payment Element on my already working site. So far, we were using Card Element.
Previously used payment methods are registered on the user account and suggested to be used on any new payment.
I enabled Payment Element but it does not suggest the previously registered payment methods (card) of the user.
Is 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?
Thanks!

Nicolas

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.1

Component

Payment Element

Created by

πŸ‡«πŸ‡·France Nicolas Bouteille

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

Comments & Activities

  • 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
  • πŸ‡«πŸ‡·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.

Production build 0.69.0 2024