Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the subscriptions sources to payment methods if they were migrated #3249

Merged
merged 11 commits into from
Jul 8, 2024

Conversation

a-danae
Copy link
Contributor

@a-danae a-danae commented Jul 5, 2024

Changes proposed in this Pull Request:

Stripe accounts will undergo a migration to move their Sources to PaymentMethods. This PR updates the payment method associated with subscriptions from src_ to the migrated pm_, if the migration already took place in the account.

  • Update the payment method associated with a subscription when it's a src_ and it was already migrated to pm_
  • Run this update during the Repairer job that also updates the associated gateway ID
  • Also, run this during subsequent renewals because it's possible that the Stripe account hasn't been migrated at the time we repair all subscriptions

Testing instructions

Setup

  1. Ensure webhooks are set up on the testing site and that the site is publicly accessible
  2. Set EUR as the store currency
  3. Enable the Legacy checkout experience
  4. Enable SEPA under the Stripe payment methods
  5. Find a Stripe account that can use Sources and that has at least one customer with Sources migrated to PaymentMethods. DM me if yours hasn't been migrated 🙂

Testing the migration and subsequent renewals

  1. Log in with a shopper that has at least one payment method migrated from Sources to PaymentMethods.
    If you use my account, use customer cus_PuO841WftotzWl
    On the usermeta of a shopper, set wp__stripe_customer_id to cus_PuO841WftotzWl
    There are two SEPA payment methods that end in 3201. One of them is a src_ src_1PEHjXGwE7I87pM0KSAsG4If , and the other is a pm_ created by the migration pm_1PG2BmGwE7I87pM0FaxCi8UN
  2. Purchase a subscription using this Source as the payment method
  3. As the merchant, renew this subscription
  4. Notice it gets processed successfully, all good
  5. Disable the Legacy checkout experience to start using the PaymentMethods API
  6. As the merchant, go edit this subscription
  7. Notice that under "Payment method", it says "Manual Renewal" and that the renewal was processed successfully
  8. On the sidebar at the right, run "Process renewal"
  9. Confirm that:
  • The renewal is processed successfully
  • Under "Payment method", it now says "SEPA debit"
  • Under Billing > Edit (The pencil icon) > Stripe Source ID, it now has a pm_
  1. Process another renewal
  2. Confirm it's successfully processed

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

a-danae added 6 commits July 5, 2024 13:30
…scription

The renewal will use the payment method ID stored in the subscription metadata, no token is needed. The token will be created from the payment methods in the Stripe account when we list the tokens for the shopper.
@a-danae a-danae marked this pull request as ready for review July 7, 2024 17:10
@a-danae a-danae requested a review from james-allan July 7, 2024 17:11
@james-allan
Copy link
Contributor

Nice work @a-danae! I left some comments. Some are minor typos comments but the others are critical that we fix. :)

I confirmed that signing up to the Subscription using the 3201 token uses the legacy src and renewing the subscription while still in legacy mode uses the src.

Initial order Renewal order

Screenshot 2024-07-08 at 1 32 14 PM

Screenshot 2024-07-08 at 1 42 56 PM

I then disabled Legacy checkout mode - as you mentioned the subscription temporarily changes to manual. After processing a renewal again, the payment is successful using the new token and the subscription has migrated to the new pm_ 🕺 🥳

WooCommerce Stripe
Screenshot 2024-07-08 at 1 59 29 PMScreenshot 2024-07-08 at 2 05 32 PM Screenshot 2024-07-08 at 2 00 53 PM

As part of reviewing this PR I also tested 2 other scenarios:

  1. A subscription purchased with a src that hasn't been migrated to a pm (0154 - src_1PZKXpGwE7I87pM061ChSWmz). When the repair scheduled action runs or the we attempt to renew it, it updates the payment method ID, and the subscription keeps its src. There's the following subscription note added:
Screenshot 2024-07-08 at 2 37 42 PM

Each time the subscription renews it will continue adding this note (screenshot). Some may consider that overkill but it's good that it records that we've at least attempted to migrate it.

  1. The steps above outline how to test via renewals. I just double checked that this also works when the subscription is repaired via the Action Scheduler job.

Once again some really good work @a-danae!

@james-allan james-allan self-requested a review July 8, 2024 04:45
Copy link
Contributor

@james-allan james-allan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To streamline the review I'm going to approve the PR. I've made some suggested code changes which are important that we fix.

@a-danae a-danae changed the base branch from develop to release/8.5.0 July 8, 2024 18:15
@a-danae a-danae changed the base branch from release/8.5.0 to develop July 8, 2024 18:44
@a-danae
Copy link
Contributor Author

a-danae commented Jul 8, 2024

Some are minor typos comments but the others are critical that we fix. :)

Critical indeed, great catch on the str_starts_with PHP compatibility! Changes committed ✅

Each time the subscription renews it will continue adding this note (screenshot). Some may consider that overkill but it's good that it records that we've at least attempted to migrate it.

Ah yeah, I thought it might be overkill, but exactly. Thinking it'd be good to debug the potential scenario of renewals failing due to Stripe deprecating the use of Sources. Glad to update it if a different approach would be better 🙂

Thanks for the thorough review, as always @james-allan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants