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

feat(plugins): add url redirect for wc subscription renewals #3525

Merged
merged 12 commits into from
Dec 2, 2024

Conversation

chickenn00dle
Copy link
Contributor

@chickenn00dle chickenn00dle commented Nov 5, 2024

All Submissions:

Changes proposed in this Pull Request:

Closes https://app.asana.com/0/1206274567818686/1208437232706180/f

This PR adds handling for a np_renewal param a new my-account/my-renewals endpoint to redirect readers to the first available pending renewal checkout, otherwise the subscriptions my account page:

Screenshot 2024-11-05 at 16 39 08

How to test the changes in this Pull Request:

  1. As a reader, purchase multiple subscriptions
  2. As admin, go to any subscription edit page for one of these subscriptions via WooCommerce > Subscriptions
  3. Create a renewal order for the subscription
    Screenshot 2024-11-05 at 16 41 21
  4. As the logged in reader, visit the my-account/my-renewals endpoint of your test site: site.url/my-account/my-renewals
  5. Confirm you are redirected to checkout for the renewal order in question
  6. As admin again, create another renewal order for another subscription belonging to this reader (there should now be two subscriptions that need payment)
  7. As reader again, visit the url from step 3 again
  8. This time confirm you are directed to the my account subscriptions page
    Screenshot 2024-11-06 at 18 19 15
  9. Complete checkout to re-activate the subscription. Then do the same for the second pending renewal (All subscriptions should be active).
  10. Visit the url from step 3 again.
  11. Confirm you are directed to the my account subscriptions page again
  12. Log out
  13. Visit the url from step 3 again.
  14. Confirm you are presented with a login form
  15. Login and confirm you are redirected to the my account subscriptions page once again.

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 force-pushed the feat/add-subscriptions-renewal-redirect branch from 1bd87d5 to 3492424 Compare November 6, 2024 23:17
@chickenn00dle chickenn00dle marked this pull request as ready for review November 6, 2024 23:19
@chickenn00dle chickenn00dle requested a review from a team as a code owner November 6, 2024 23:19
@chickenn00dle chickenn00dle force-pushed the feat/add-subscriptions-renewal-redirect branch from 3492424 to f70d25b Compare November 6, 2024 23:21
@@ -113,7 +113,9 @@ window.newspackRAS.push( function ( readerActivation ) {
/** If there's a pre-auth, signing in redirects to the reader account. */
if ( reader?.email && ! reader?.authenticated ) {
link.setAttribute( 'data-redirect', link.getAttribute( 'href' ) );
redirectInput.value = link.getAttribute( 'href' );
if ( ! redirectInput?.value ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should respect any pre-defined redirect values.

@@ -177,7 +179,7 @@ window.newspackRAS.push( function ( readerActivation ) {
emailInput.value = reader?.email || '';
}

if ( redirectInput && ev?.target?.getAttribute( 'data-redirect' ) ) {
if ( ev?.target?.getAttribute( 'data-redirect' ) && ! redirectInput?.value ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here re: respecting pre-defined redirect values

@chickenn00dle chickenn00dle added the [Status] Needs Review The issue or pull request needs to be reviewed label Nov 6, 2024
@chickenn00dle
Copy link
Contributor Author

Got some feedback here so removing the Needs Review label to work on this: 0-as-1208437232706180/1208702687864921/f

@chickenn00dle chickenn00dle removed the [Status] Needs Review The issue or pull request needs to be reviewed label Nov 7, 2024
@chickenn00dle chickenn00dle force-pushed the feat/add-subscriptions-renewal-redirect branch from f70d25b to e29b3a3 Compare November 13, 2024 22:42
@miguelpeixe miguelpeixe self-requested a review November 14, 2024 16:00
@chickenn00dle chickenn00dle force-pushed the feat/add-subscriptions-renewal-redirect branch from e29b3a3 to eabb518 Compare November 14, 2024 16:26
@chickenn00dle
Copy link
Contributor Author

Added some changes to make the redirect happen via a new my-account endpoint my-renewals. Also updated the testing instructions.

Just awaiting feedback to verify the expected behavior before marking this one ready for review.

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 well! Conditionally approved, with just a couple of questions:

  1. I had to refresh permalinks before the new endpoint would redirect. Is there anything we need to do to ensure this happens automatically with no downtime for live sites?
  2. Based on the discussion in feat(subscriptions): add setting to reattempt payment after final retry #3560 (comment) it sounds like we're moving to a woocommerce-subscriptions directory with smaller classes inside, so should we refactor to this structure here to avoid a future conflict? This could probably just be moved to the woocommerce-subscriptions directory since it's fairly self-contained.

@github-actions github-actions bot added the [Status] Approved The pull request has been reviewed and is ready to merge label Nov 25, 2024
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.

as per @dkoo review, we need to add a rewrite rule refresh to be execute once after this change is deployed. Also agree with his comment on the file structure.

And just to confirm that naming things is one of the hardest problems in computes science. WDYT of renew-subscription or subscription-renew (in the singular form, because that's the main intent of this link, redirect to Subscriptions is a fallback)

@chickenn00dle chickenn00dle force-pushed the feat/add-subscriptions-renewal-redirect branch 3 times, most recently from dd06a16 to fa7cdc2 Compare November 27, 2024 16:11
@chickenn00dle
Copy link
Contributor Author

chickenn00dle commented Nov 27, 2024

Thanks for the feedback @leogermani and @dkoo!

we need to add a rewrite rule refresh to be execute once after this change is deployed. Also agree with his comment on the file structure.

Flushed permalinks and reorganized in fa7cdc2

And just to confirm that naming things is one of the hardest problems in computes science. WDYT of renew-subscription or subscription-renew (in the singular form, because that's the main intent of this link, redirect to Subscriptions is a fallback)

I like renew-subscription! I went with that in fa7cdc2

@chickenn00dle chickenn00dle 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 Nov 27, 2024
@leogermani
Copy link
Contributor

This looks good and works nicely.

One question though. My expectation was - I think it would be awesome - that if I'm not logged in and visit renew-subscription, I will be redirected to the checkout page, the same thing that happens when I'm logged in. Do you think that's possible?

@chickenn00dle
Copy link
Contributor Author

that if I'm not logged in and visit renew-subscription, I will be redirected to the checkout page, the same thing that happens when I'm logged in. Do you think that's possible?

We can accomplish this by adding a redirect param with a value of the new endpoint and handling this when rendering the auth form. Added in a01a0b5

Let me know what you think!

@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 Nov 28, 2024
@chickenn00dle chickenn00dle force-pushed the feat/add-subscriptions-renewal-redirect branch from a01a0b5 to f1f7787 Compare December 2, 2024 21:34
@chickenn00dle chickenn00dle merged commit 5b14aeb into trunk Dec 2, 2024
7 checks passed
@chickenn00dle chickenn00dle deleted the feat/add-subscriptions-renewal-redirect branch December 2, 2024 21:42
Copy link

github-actions bot commented Dec 2, 2024

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! ❤️

chickenn00dle added a commit that referenced this pull request Dec 12, 2024
… renewals (#3525)

This PR adds handling for a new `my-account/renew-subscription` endpoint to redirect readers to the first available pending renewal checkout, otherwise the subscriptions my account page.
matticbot pushed a commit that referenced this pull request Dec 12, 2024
# [5.10.0-alpha.1](v5.9.1...v5.10.0-alpha.1) (2024-12-12)

### Bug Fixes

* duplicate orders save on cron ([#3604](#3604)) ([ec69167](ec69167))
* **ras-acc:** re-add recaptcha to the WooCommerce checkout ([#3605](#3605)) ([f42a75b](f42a75b))
* **ras:** do not require Woo plugins if using NRH ([#3614](#3614)) ([363a834](363a834))
* **wcs:** remove subscriptions expiration feature flag ([#3618](#3618)) ([7c175d9](7c175d9))
* **wcs:** update subscription expiration feature ([#3613](#3613)) ([ebf6e6d](ebf6e6d))
* **wcs:** update subscriptions expiration cli behavior ([#3617](#3617)) ([07e768c](07e768c))

### Features

* **subscriptions:** add cancellation reason metadata ([#3568](#3568)) ([de83e02](de83e02))
* **wc:** duplicate orders admin notice ([#3555](#3555)) ([cb764e3](cb764e3))
* **wcs:** add expired subscription cli tool ([#3593](#3593)) ([5d39398](5d39398))
* **webhooks:** filter request priority ([#3587](#3587)) ([1928a6a](1928a6a))
* **woocommerce-subscriptions:** add url redirect for wc subscription renewals ([#3525](#3525)) ([5b14aeb](5b14aeb))

### Reverts

* Revert "feat: command to initialize cron job to slowly backfill CAP term data (#3425)" (#3620) ([c9a9d45](c9a9d45)), closes [#3425](#3425) [#3620](#3620)
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Dec 16, 2024
# [5.10.0](v5.9.2...v5.10.0) (2024-12-16)

### Bug Fixes

* dont load textdomain too early ([#3629](#3629)) ([76c1f97](76c1f97))
* duplicate orders save on cron ([#3604](#3604)) ([ec69167](ec69167))
* hide duplicate notices if all was dismissed ([#3630](#3630)) ([cf48188](cf48188))
* **ras-acc:** re-add recaptcha to the WooCommerce checkout ([#3605](#3605)) ([f42a75b](f42a75b))
* **ras:** do not require Woo plugins if using NRH ([#3614](#3614)) ([363a834](363a834))
* **wcs:** remove subscriptions expiration feature flag ([#3618](#3618)) ([7c175d9](7c175d9))
* **wcs:** update subscription expiration feature ([#3613](#3613)) ([ebf6e6d](ebf6e6d))
* **wcs:** update subscriptions expiration cli behavior ([#3617](#3617)) ([07e768c](07e768c))

### Features

* **subscriptions:** add cancellation reason metadata ([#3568](#3568)) ([de83e02](de83e02))
* **wc:** duplicate orders admin notice ([#3555](#3555)) ([cb764e3](cb764e3))
* **wcs:** add expired subscription cli tool ([#3593](#3593)) ([5d39398](5d39398))
* **webhooks:** filter request priority ([#3587](#3587)) ([1928a6a](1928a6a))
* **woocommerce-subscriptions:** add url redirect for wc subscription renewals ([#3525](#3525)) ([5b14aeb](5b14aeb))

### Reverts

* Revert "feat: command to initialize cron job to slowly backfill CAP term data (#3425)" (#3620) ([c9a9d45](c9a9d45)), closes [#3425](#3425) [#3620](#3620)
@matticbot
Copy link
Contributor

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

4 participants