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

Stripe Subscriptions to WC subscriptions migrator #2298

Merged
merged 6 commits into from
Mar 1, 2023

Conversation

adekbadek
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

A migration script that turns Stripe Subscriptions into WooCommerce Subscriptions.

Closes 1204005426582602-as-1203870488073017

How to test the changes in this Pull Request:

  1. Set up the site to use Stripe as the Reader Revenue platform and ensure the test site is reachable for webhooks
  2. Ensure the WooCommerce suite is active, so the Stripe data will be synchronised to WC
  3. Make a recurring donation twice, observe two WC Subscriptions were created to shadow (sync) the Stripe subscriptions
  4. Delete one of the WC Subscriptions (ideally via CLI – $ wp post delete <sub-id>)
  5. Run the migration in dry-run mode – $ wp newspack stripe sync-stripe-subscriptions-to-wc --dry-run
  6. Observe the output and note that neither Stripe nor WooCommerce subscriptions were updated
  7. Now run the migration for real – $ wp newspack stripe sync-stripe-subscriptions-to-wc
  8. Observe the output, it should successfully migration both and cancel the Stripe subscriptions
  9. Verify that the Stripe subscriptions have been cancelled in the Stripe dashboard
  10. Observe that the WC Subscriptions have received helpful order notes about the process ("This subscription has been migrated…")
  11. Observe that both WC Subscriptions have cancelled-newspack-stripe-subscription-id metadata, with the Stripe subscription ID as value

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@adekbadek adekbadek added [Status] Needs Review The issue or pull request needs to be reviewed Reader Revenue Stripe WooCommerce labels Feb 20, 2023
@adekbadek adekbadek requested a review from a team as a code owner February 20, 2023 15:45
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Working really well as described on my end. Seamlessly migrates Stripe subscriptions back to Woo so that it's like all those customers subscribed via Woo in the first place. This will be great for sites that had to switch from Stripe to Woo and are currently stuck managing data in both dashboards!

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 20, 2023
Stripe Subscriptions created before the changes in
#2251 will not have a Source, but the customer will
have PaymentMethods. These changes ensure that these
customers' subscriptions can be migrated.

This also means that not all changes from #2251 are
necessary – Stripe Payment Gateway creates sources,
but will handle a PaymentMethod ID if set as the source
ID in the subscription metadata.
@adekbadek
Copy link
Member Author

adekbadek commented Feb 21, 2023

Thanks @dkoo ! I have to ask you for another look, as I've uncovered an issue and fixed it in 043e44f.

Here's the gist of it:

What this means for this PR

To test the full scope of changes, travel back in git history to 887aab6 on this repository and to 02cd767a40956aad0f1f99f558a56ea5d58b1f82 on the newspack-blocks repository, make a donation, then travel back to the present state and follow the test the migration.

What this means for #2251 (and Automattic/newspack-blocks#1359)

Switching from Sources to PaymentMethods API was not necessary, as it turns out. I haven't dived deep enough into woocommerce-gateway-stripe to see that what's stored as _stripe_source_id post meta may be a Stripe Source, PaymentMethod, or a Card. The meta name and the fact woocommerce-gateway-stripe uses Sources misled me.

@adekbadek adekbadek added [Status] Needs Review The issue or pull request needs to be reviewed and removed [Status] Approved The pull request has been reviewed and is ready to merge labels Feb 21, 2023
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Tested the migration with a subscription made with the Sources API and it worked well, so I think we're good on that. I noticed one more behavior which I think we should change, but it's a minor one, so pre-approving.

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 28, 2023
@adekbadek adekbadek merged commit 6904356 into master Mar 1, 2023
@adekbadek adekbadek deleted the feat/stripe-to-wc-migrator branch March 1, 2023 10:00
matticbot pushed a commit that referenced this pull request Mar 3, 2023
# [1.106.0-alpha.1](v1.105.0...v1.106.0-alpha.1) (2023-03-03)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Mar 14, 2023
# [1.106.0](v1.105.1...v1.106.0) (2023-03-14)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))
* show handoff to finish Newspack setup only if setup is incomplete ([#2343](#2343)) ([1173b5b](1173b5b))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants