woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
234 stars 206 forks source link

[Non-UPE] Recently saved payment method not saved to DB when it can't be retrieved but was already attached #2677

Open a-danae opened 1 year ago

a-danae commented 1 year ago

Describe the bug (Probably not a bug but a UX that could be improved)

A payment method can be attached to the Stripe customer but not show up in the Payment methods page right away under certain circumstances.

To Reproduce Steps to reproduce the behavior:

  1. Make sure UPE is disabled. Do this by going to Stripe settings {site url}/wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings -> Advanced settings -> Uncheck "Enable the updated checkout experience"
  2. In the Stripe dashboard, go to the customer's page that belongs to the shopper you'll be testing with https://dashboard.stripe.com/test/customers/< customer ID starting with cus_xxx >
  3. Notice the number of attached payment methods
  4. Add return ''; early in WC_Stripe_Payment_Gateway::get_source_object
  5. As a shopper, go to My account -> Payment methods -> Add payment method
  6. Add a card
  7. Notice you get an error message
  8. Go to My account -> Payment methods {site url}/my-account/payment-methods/. Notice the payment method you added doesn't show up
  9. Go to the Stripe dashboard -> Customer overview
  10. Under Payment methods, notice that the payment method you just added does show up
  11. Go to the Checkout page. Notice the payment method you added does show up (Probably. If the transient expired)

Expected behavior

I'd expect the payment method to show up under My account -> Payment methods if it was attached to the Stripe customer and can be used during checkout.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

Spotted by @mattallan in https://github.com/woocommerce/woocommerce-gateway-stripe/pull/2659#pullrequestreview-1544583474.

The payment method gets attached to the Stripe customer before WC_Stripe_Payment_Gateway::add_payment_method() is called. It happens in: -> WC_Stripe_Intent_Controller's wc_ajax_wc_stripe_create_setup_intent action -> WC_Stripe_Intent_Controller's::create_setup_intent() -> WC_Stripe_Customer::attach_source() -> WC_Stripe_API::attach_payment_method_to_customer()

The payment method is attached to the Stripe customer, but the token isn't stored in the DB, so it doesn't show up in My account -> Payment methods. The customer's payment methods are retrieved when visiting the checkout page, and I assume they get stored in the DB then.

So, the -> WC_Stripe_Payment_Gateway::add_payment_method -> WC_Stripe_Customer::add_source method saves the payment token to the DB. The payment method was already attached to the Stripe customer at this point.

github-actions[bot] commented 1 month ago

Hi, This issue has gone 150 days (5 months) without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest version, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.

github-actions[bot] commented 5 days ago

This issue has gone 180 days (6 months) without any activity.