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-to-Stripe Migrator #2032

Merged
merged 3 commits into from
Sep 26, 2022
Merged

Stripe-to-Stripe Migrator #2032

merged 3 commits into from
Sep 26, 2022

Conversation

claudiulodro
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This PR adds a Stripe-to-Stripe migrator which can migrate Stripe subscriptions (even Connect ones) to Newspack Simplified Donate Block Stripe subscriptions. We'll want to figure out how to merge this and #1984, because merge conflicts are gonna happen as soon as one of these is merged.

How to test the changes in this Pull Request:

  1. Generate some Stripe Connect orders using this PR: Experimental Stripe Connect test #2031 Make sure after you're done and this branch is checked out, you reset the Stripe keys in the Reader Revenue settings to use the child connected account keys, not the parent account which would be e.g. Pico's Stripe keys.
  2. Run wp newspack stripe sync-stripe-connect-to-stripe --dry-run. You should see output similar to the following:
Processing customer: typescripting@example.com
  - Processing subscription: [redacted subscription id]
    * Found subscription item: $15/month
    * Would have created subscription with next renewal at 2022-10-22
Processing customer: refactorconnect1@example.com
  - Processing subscription: [redacted subscription id]
    * Found subscription item: $41.5/month
    * Would have created subscription with next renewal at 2022-10-22
Processing customer: testconnectedacc@example.com
  - Processing subscription: [redacted subscription id]
    * Found subscription item: $20.91/month
    * Would have created subscription with next renewal at 2022-10-22
...
  1. Run wp newspack stripe sync-stripe-connect-to-stripe. You should see output similar to the following:
Processing customer: typescripting@example.com
  - Processing subscription: [redacted existing subscription id]
    * Found subscription item: $15/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription: [redacted existing subscription id]
Processing customer: refactorconnect1@example.com
  - Processing subscription: [redacted existing subscription id]
    * Found subscription item: $41.5/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription: [redacted existing subscription id]
Processing customer: testconnectedacc@example.com
  - Processing subscription: [redacted existing subscription id]
    * Found subscription item: $20.91/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription: [redacted existing subscription id]
...

In Stripe, you should see the new subscriptions created with correct next renewal date:

Screen Shot 2022-09-22 at 1 13 12 PM

In the cancelled subscriptions section, you should see the old ones cancelled:

Screen Shot 2022-09-22 at 1 13 30 PM

  1. Run wp newspack stripe sync-stripe-connect-to-stripe again. You should see output similar to the following:
Processing customer: typescripting@example.com
  - Processing subscription: [redacted new subscription id]
  - Subscription already migrated to Newspack on 2022-09-22T19:43:15+00:00. Skipping.
Processing customer: refactorconnect1@example.com
  - Processing subscription: [redacted new subscription id]
  - Subscription already migrated to Newspack on 2022-09-22T19:43:19+00:00. Skipping.
Processing customer: testconnectedacc@example.com
  - Processing subscription: [redacted new subscription id]
  - Subscription already migrated to Newspack on 2022-09-22T19:43:23+00:00. Skipping.
...
  1. Run wp newspack stripe sync-stripe-connect-to-stripe --force. This will re-build all subscriptions, even migrated ones. You should see output similar to the following:
Processing customer: typescripting@example.com
  - Processing subscription:  [redacted existing subscription id]
    * Found subscription item: $15/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription:  [redacted existing subscription id]
Processing customer: refactorconnect1@example.com
  - Processing subscription:  [redacted existing subscription id]
    * Found subscription item: $41.5/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription: [redacted existing subscription id]
Processing customer: testconnectedacc@example.com
  - Processing subscription:  [redacted existing subscription id]
    * Found subscription item: $20.91/month
    * Created subscription: [redacted new subscription id] with next renewal at 2022-10-22
    * Cancelled old subscription:  [redacted existing subscription id]
...

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?

@claudiulodro claudiulodro added the [Status] Needs Review The issue or pull request needs to be reviewed label Sep 22, 2022
@claudiulodro claudiulodro requested a review from a team as a code owner September 22, 2022 20:22
@claudiulodro
Copy link
Contributor Author

Just realized after opening this, I should probably add a check for existing Woo and Simplified Donate Block payments in Stripe, so we don't override those.

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

Pushed two changes:

  • e09d57d changes the methods to static, since they're called statically. As it was before the code errored out, perhaps because I ran it on PHP 8.
  • 0537941 adds trial_end, to avoid charging the customer twice. When a subscriptions is created, the customer is charged. Putting the subscription on trial period until next invoice seems like the only way to create a subscription without the initial charge.

@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 23, 2022
@claudiulodro
Copy link
Contributor Author

Good catch! Thanks for fixing those. I switched to a different local environment recently, and clearly I need to make sure PHP notices are working correctly 🤔 I'll hold off on merging this until #1984 is merged, so I can resolve merge conflicts in this one

@claudiulodro claudiulodro merged commit a82f326 into master Sep 26, 2022
@claudiulodro claudiulodro deleted the feat/stripe-to-stripe-sync branch September 26, 2022 16:04
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.92.0-alpha.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

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