When a customer updates the payment method for one of their subscriptions, they have the option to update all their subscription payment methods.
When a customer checks this box, on a HPOS environment, its possible (depending on the payment method) that the old payment meta (tokens) will be copied to all their subscriptions, not the new one.
This is because.
When we update the subscription payment method, we call gateway->process_payment( $subscription->get_id() ).
Because only the subscription ID is passed, you can assume that all payment method changes would occur on a different instance of the subscription.
Then we call update_all_payment_methods_from_subscription() to fire off all the updates.
However, the instance passed to this function, would be a original instance which has the old payment meta.
Any plugin hooked into that process, would naturally return the old payment tokens, not the new ones.
THis all occurs in this section of the change_payment_method_via_pay_shortcode() function.
This PR fixes that by ensuring we get a fresh instance after calling process_payment() to make sure the update_all_payment_methods_from_subscription() and APIs hooked into it, get the latest version of the subscription which has the new payment method and meta (tokens.
How to test this PR
Checkout PR version of the Stripe payment gateway.
Set up Stripe if you haven't before.
Enable HPOS - sycning disabled.
Purchase two subscriptions using Stripe.
Go to one of the subscriptions from your My account page.
Click the change payment button.
Select a different payment method and check the box to "Update the payment method used for all ..."
Change payment method.
Note that all other subscriptions haven't been updated or have been updated to the old payment method, not the new one.
This video by @alefesouza, originally posted here, explains it perfectly
Description
When a customer updates the payment method for one of their subscriptions, they have the option to update all their subscription payment methods.
When a customer checks this box, on a HPOS environment, its possible (depending on the payment method) that the old payment meta (tokens) will be copied to all their subscriptions, not the new one.
This is because.
gateway->process_payment( $subscription->get_id() )
.update_all_payment_methods_from_subscription()
to fire off all the updates.THis all occurs in this section of the
change_payment_method_via_pay_shortcode()
function.This PR fixes that by ensuring we get a fresh instance after calling
process_payment()
to make sure theupdate_all_payment_methods_from_subscription()
and APIs hooked into it, get the latest version of the subscription which has the new payment method and meta (tokens.How to test this PR
This video by @alefesouza, originally posted here, explains it perfectly
https://user-images.githubusercontent.com/1025173/214762531-2cfbd27d-5104-4aa9-9b44-278964bedfb2.mov
Product impact