woocommerce/woocommerce-gateway-stripe

Refactor process_payment_with_deferred_intent() to handle subscription change payment method requests

Opened this issue · 0 comments

Describe the bug

When a subscription changes payment method WC Subscriptions calls $gateway->process_payment() with the subscription as the param.

This generally works fine as it is now with it going through the process_payment_with_deferred_intent() function, however there are some issues with this kind of set up.

  1. There's no separation from the processing of payments and the changing of subscription payment methods (very different processes).
  2. This will eventually lead to code smell being introduced and increased logic complexity as we carve out parts for different scenarios.

For example there's currently an issue when a customer changes their subscription payment method to a 3D-Secure card or another payment method like Cash App where follow-up actions are required. If the customer abandons the process and doesn't complete the 3D-Secure challenge, the subscription would have already been updated to the new pm_ and so subsequent renewals will fail attempting to use an incomplete payment method.

Changing the process_payment_with_deferred_intent() to not update the payment method on the order/subscription until after the 3D-Secure challenge is complete is something we could look at doing but it impacts the process payment flow.

Carving out a whole separate flow for subscription payment method requests will enable us to code those different flows independently without potentially stepping on the other one.

To Reproduce
Steps to reproduce the behavior:

  1. Purchase a subscription product.
  2. Go to the My Account > Subscriptions and view your subscription.
  3. Click the Change payment button.
  4. On the change payment method page enter a 3D-Secure enabled card 4000002500003155
  5. Click the Change payment method button.
  6. When the 3D-Secure challenge modal pops up close it.
  7. If you attempt to renew this subscription it will fail with this error:
Screenshot 2024-07-30 at 10 46 37 AM

Expected behavior
The subscription's payment method shouldn't be updated until it's complete.