Skip to content

fix: sync scripts for Stripe-to-Woo migrations#2632

Merged
dkoo merged 4 commits into
masterfrom
fix/stripe-migration-scripts
Sep 11, 2023
Merged

fix: sync scripts for Stripe-to-Woo migrations#2632
dkoo merged 4 commits into
masterfrom
fix/stripe-migration-scripts

Conversation

@dkoo

@dkoo dkoo commented Sep 8, 2023

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Fixes some lingering issues with the Stripe-to-Woo migration script. Also adds a new script that allows us to trigger a resync of contact data to the connected ESP, in case the ESP's synced data has diverged from the source of truth (WooCommerce).

How to test the changes in this Pull Request:

Stripe-to-Woo migration script fix

  1. On master, set your Reader Revenue platform to Stripe and make sure your wp-config.php doesn't have the NEWSPACK_USE_WC_SUBSCRIPTIONS_WITH_STRIPE_PLATFORM constant. Also make sure that RAS is enabled and that your connected ESP is either ActiveCampaign or Mailchimp (the ESPs to which we sync RAS data).
  2. Make a recurring donation as a new reader. Confirm that the contact is synced to the connected ESP with our usual Newspack metadata. Take special note of the NP_Membership Status value: it should be something like "Monthly Donor", indicating your donor status and the recurrence period of the donation.
  3. Run the wp newspack stripe sync-stripe-subscriptions-to-wc script. This will migrate the Stripe customer and their subscription to WooCommerce and cancel the Stripe subscription.
  4. In the connected ESP, observe that the Stripe subscription cancellation has triggered a contact sync: the NP_Membership Status field will now say something like "Ex-Monthly donor", which isn't accurate because the subscription wasn't actually cancelled, it was just migrated to WooCommerce. Make note of this contact for testing the resync script, below.
  5. Check out this branch and repeat steps 2-3 with a new customer email and subscription. This time, confirm that in the connected ESP, the contact has not been updated because their migrated subscription is still active in WooCommerce.
  6. In WooCommerce > Subscriptions, find and edit the migrated subscription. In the Subscription Actions panel, process a manual renewal to trigger another charge on the subscription. In the connected ESP, confirm that the contact's metadata has been updated (e.g. the NP_Total Paid value has increased by the amount of the manual renewal), indicating that the WooCommerce subscription is now syncing to this contact in the ESP.

Note: in this test, the manual renewal will trigger a one-time donation transaction for the customer, which will change the NP_Membership Status of the contact in the ESP to "Donor" instead of e.g. "Monthly Donor". This won't happen for real automated subscription renewals.

Resync script

  1. Run the wp newspack woo resync CLI script. You can run this script without flags, which will resync all customers in the site, or with the following options:
  • --migrated-subscriptions: will only resync customers attached to subscriptions that were migrated from Stripe. This takes precedence over any other args passed.
  • --subscription-ids: will resync customers attached to the given subscription IDs (comma-delimited list).
  • --user-ids: will resync customers with the given user IDs (comma-delimited list).
  • --order-ids: will resync customers attached to the given order IDs (comma-delimited list).
  1. Look up the Stripe customer that was accidentally flagged as an "ex-" donor in step 3 above, and confirm that they were resynced with the proper active status (no "ex-" in their NP_Membership Status value).
  2. Test the script with each flag (and no flags) and confirm that in every case, only the contacts you'd expect are resynced.
  3. Confirm that when resyncing, only the contact data and metadata fields are updated, not the ESP list subscription status (so that if a contact was subscribed to any lists, they won't be unsubscribed by the resync, and vice versa).

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?

@dkoo dkoo changed the title fix: don’t try to sync Stripe subscriptions that have been migrated t… fix: sync scripts for Stripe-to-Woo migrations Sep 8, 2023
@dkoo dkoo self-assigned this Sep 8, 2023
@dkoo dkoo added the [Status] Needs Review The issue or pull request needs to be reviewed label Sep 8, 2023
@dkoo dkoo marked this pull request as ready for review September 8, 2023 23:38
@dkoo dkoo requested a review from a team as a code owner September 8, 2023 23:38
Comment thread includes/reader-revenue/woocommerce/class-woocommerce-sync.php Outdated

@claudiulodro claudiulodro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the speedy turnaround on this! It looks solid and works well in my testing.

Long-term I do think we should move these CLI commands into Custom Content Migrator, so we don't have to wait so long for them to become available, but that's far outside the scope of this PR. :)

@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 Sep 11, 2023
@dkoo dkoo merged commit 34beb15 into master Sep 11, 2023
@dkoo dkoo deleted the fix/stripe-migration-scripts branch September 11, 2023 18:37
matticbot pushed a commit that referenced this pull request Sep 11, 2023
# [2.6.0-alpha.2](v2.6.0-alpha.1...v2.6.0-alpha.2) (2023-09-11)

### Bug Fixes

* sync scripts for Stripe-to-Woo migrations ([#2632](#2632)) ([34beb15](34beb15))
@matticbot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.6.0-alpha.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Sep 13, 2023
# [2.6.0](v2.5.1...v2.6.0) (2023-09-13)

### Bug Fixes

* sync scripts for Stripe-to-Woo migrations ([#2632](#2632)) ([34beb15](34beb15))

### Features

* add anonymized email to ga4 events ([#2585](#2585)) ([9ac1c33](9ac1c33))
* add filter to the lists in the reg block ([#2611](#2611)) ([d960541](d960541))
* new option to require all membership plans for restricted content ([#2623](#2623)) ([60b361e](60b361e))
@matticbot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.6.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

released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants