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

fix(wcs): expire manual subscriptions after on-hold duration #3681

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

chickenn00dle
Copy link
Contributor

@chickenn00dle chickenn00dle commented Jan 16, 2025

All Submissions:

Changes proposed in this Pull Request:

Part of https://app.asana.com/0/1200550061930446/1209066781737999/f

This PR adds a new scheduled action to expire manual subscriptions after the specified on-hold duration:

Screenshot 2025-01-16 at 17 19 11

How to test the changes in this Pull Request:

  1. Set at least two active subscriptions to manual, either as the reader via my-account or as admin via the edit subscriptions page in the edit billing menu.
  2. Manually process renewals for both subscriptions via the edit subscriptions page.
  3. In WPAdmin, WooCommerce > Status > Scheduled Actions, look for two pending newspack_expire_manual_subscription events that are scheduled to run X days after the next payment date, where X is what you have set as your site's on-hold duration (WooCommerce > Settings > Subscriptions > On-hold Duration) plus 7 days
  4. As a reader, renew one of the on-hold subscriptions via my-account
  5. Verify the subscription is now active as admin, and the matching scheduled action is no longer pending.
  6. As admin, manually trigger the other newspack_expire_manual_subscription action
  7. Verify the matching subscription is now expired

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?

@chickenn00dle chickenn00dle requested a review from a team as a code owner January 16, 2025 22:24
@chickenn00dle chickenn00dle force-pushed the fix/on-hold-duration-manual-subscriptions branch from cd01202 to 5ad8924 Compare January 16, 2025 22:31
@chickenn00dle chickenn00dle added [Status] Needs Review The issue or pull request needs to be reviewed Work In Progress and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Jan 16, 2025
@chickenn00dle chickenn00dle force-pushed the fix/on-hold-duration-manual-subscriptions branch from 2e0a4a7 to 3e0061b Compare January 17, 2025 14:55
@chickenn00dle chickenn00dle added [Status] Needs Review The issue or pull request needs to be reviewed and removed Work In Progress labels Jan 17, 2025
Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

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

Works as described.

I tested one other thing I'm not sure if there's an issue there or not.

While the subscription is on hold, and there's a scheduled action to expire it, if an admin manually sets the subscription as Active again it won't delete the scheduled action.

However, when that action runs, it won't expire the subscription because it's active, so no idea if it's a problem or not. thoughts? But if it goes to on hold again, then it will be expired...

Also, the expiration date is set to 7 days + on hold duration + the next payment date. So if I process a renewal but they still have 15 paid days, there will be an extra 15 days there... All good, just highlighting because it was different from the testing instructions

@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 Jan 20, 2025
@chickenn00dle
Copy link
Contributor Author

Thanks for the review on this one as well @leogermani!

While the subscription is on hold, and there's a scheduled action to expire it, if an admin manually sets the subscription as Active again it won't delete the scheduled action.

However, when that action runs, it won't expire the subscription because it's active, so no idea if it's a problem or not. thoughts? But if it goes to on hold again, then it will be expired...

Yeah. I purposefully made the scheduled action do nothing if the subscription is not on-hold to account for any scenarios where the admin wants to handle a subscription manually. I also am only removing the scheduled action only when a successful payment is made to account for any strange situations where an admin changes a subscriptions status multiple times with the final change being on-hold. My assumption here is, if a payment isn't made and the subscription is on-hold by the time we reach the end of the total grace period, we should expire. WDYT?

Also, the expiration date is set to 7 days + on hold duration + the next payment date. So if I process a renewal but they still have 15 paid days, there will be an extra 15 days there... All good, just highlighting because it was different from the testing instructions

Ah. I think what you've written here is the expected behavior. My bad. The reader should not lose any time on their subscription when it is renewed early.

@leogermani
Copy link
Contributor

LGTM

@chickenn00dle chickenn00dle merged commit 658416c into trunk Jan 20, 2025
9 checks passed
@chickenn00dle chickenn00dle deleted the fix/on-hold-duration-manual-subscriptions branch January 20, 2025 21:22
Copy link

Hey @chickenn00dle, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Jan 23, 2025
# [5.13.0-alpha.1](v5.12.2...v5.13.0-alpha.1) (2025-01-23)

### Bug Fixes

* add supported gateways check ([#3650](#3650)) ([74f7773](74f7773))
* **corrections:** replace deprecated sanitize method ([#3694](#3694)) ([ce50e24](ce50e24))
* remove support for legacy form checkout ([#3691](#3691)) ([46a3c16](46a3c16))
* **wcs:** expire manual subscriptions after on-hold duration ([#3681](#3681)) ([658416c](658416c))

### Features

* add custom bylines ([#3667](#3667)) ([3f45a6f](3f45a6f))
* rate limit checkout attempts ([#3678](#3678)) ([d275524](d275524))
@matticbot
Copy link
Contributor

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

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 [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