Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
165 stars 67 forks source link

Duplicate saving of 3DS card entry after checkout #8997

Open timur27 opened 1 week ago

timur27 commented 1 week ago

Describe the bug

After using a saved 3DS card during checkout, it gets re-saved on the store.

To Reproduce

  1. Perform checkout, use a 3DS card, and save it
  2. Checkout again but use the saved 3DS this time
  3. Open the checkout page and you will see the saved 3DS entry is duplicated now

Additional context

This behavior could potentially be related to our recent fixes for saving 3DS cards in https://github.com/Automattic/woocommerce-payments/commit/0635be28ae20d5c5743b1f127ce1c66cc3a524de.

mdmoore commented 1 week ago

This issue is the result of this fix for 3DS subscriptions missing payment methods and failing renewals as a result. Previously, tokens were only added when the payment_method_id was present in the request, which is only the case when saving a payment method. This meant that 3DS payment methods were not stored in subscriptions. The solution was to get the payment_method_id from the intent. This means that now the payment_method_id is always present and 3DS tokens are saved again when paying with a saved 3DS card.

I think rather than just checking for the presence of a payment method id here, we need to check whether the payment method is intended to be saved, indicated either by the save payment method checkbox or when the order is a subscription order.