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

Warn merchant when deactivating WCPay plugin that WCPay Subscriptions (Stripe Billing )will continue renewing #5169

Merged

Conversation

haszari
Copy link
Contributor

@haszari haszari commented Nov 24, 2022

Fixes #5090

Changes proposed in this Pull Request

This PR adds a new modal if merchant clicks deactivate link for WCPay on plugins screen. If the store has active WCPay subscriptions, the modal will be shown.

The purpose of the modal is to warn merchants that Stripe billing (off site) subscriptions will continue renewing automatically.

Screenshots

This modal is displayed if merchant clicks Deactivate for WooCommerce Payments plugin, with active WCPay built-in subscriptions.

Screenshot 2022-12-02 at 3 41 50 PM

Full wording for easy review:

Your store has active subscriptions using the built-in WooCommerce Payments functionality. Due to the [off-site billing engine](https://woocommerce.com/document/payments/subscriptions/comparison/#billing-engine) these subscriptions use, they will continue to renew even after you deactivate WooCommerce Payments. [Learn more](https://woocommerce.com/document/woocommerce-payments/built-in-subscriptions/deactivate/#existing-subscriptions).

If you do not want these subscriptions to continue to be billed, you should [cancel all subscriptions](https://woocommerce.com/document/subscriptions/store-manager-guide/#cancel-or-suspend-subscription) prior to deactivating WooCommerce Payments.
Are you sure you want to deactivate WooCommerce Payments?

Testing instructions

Basic setup

  1. Ensure your WooCommerce site is set up and the WooCommerce Subscriptions plugin is not installed or not active.
  2. Ensure WooCommerce Payments is onboarded and set up. You will need to use USA store location to enable WCPay Subscriptions. For full details refer to this flow: Set up store for WCPay Subscriptions
  3. Create a WCPay subscription product
  4. Purchase WCPay subscription as shopper

You should now have an active WCPay Subscription.

Deactivate WCPay Plugin to see the warning modal & test deactivate/cancel flow

  1. Go to Dashboard > Plugins.
  2. Scroll down to WooCommerce Payments.
  3. Click Deactivate.
    • You should see the modal above.
  4. Click Cancel
    • WCPay should still be active, zero impact on anything.
  5. Repeat step 3 - click Deactivate.
  6. Click Yes, deactivate WooCommerce Payments - you accept that subscriptions will continue renewing, you have a plan for how to handle that (e.g. reactivate plugin, this is temporary).
    • Plugin should deactivate as normal.

Repeat test with no WCPay Subscriptions active

Reactivate WCPay & ensure you have an active subscription (Basic setup above).

  1. Go to Dashboard > WooCommerce > Subscriptions.
  2. Find active subscriptions - should have green Active status.
  3. In status column, click Suspend link.
  4. Repeat Deactivate WCPay Plugin test steps. The modal should not be displayed.

I followed the test steps above. I encourage reviewers to test other flow combinations, for example:

  • Test with WooCommerce Payments active. The modal should display if there are any active WCPay subscriptions.
  • Experiment with other WCPay Subscriptions states (statuses) that might be relevant.

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply). I tested on Chrome responsive mode, to ensure the modal is readable and functions. Screenshot:

Screenshot 2022-11-28 at 9 58 28 AM

Post merge

- WCPay-specific warning message coming soon to this file
- Also added comments to clarify
@haszari haszari self-assigned this Nov 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2022

Size Change: +365 B (0%)

Total Size: 1.13 MB

Filename Size Change
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 720 B +365 B (+103%) 🆘
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 913 B
release/woocommerce-payments/assets/css/success.css 401 B
release/woocommerce-payments/dist/blocks-checkout.css 2.13 kB
release/woocommerce-payments/dist/blocks-checkout.js 36.3 kB
release/woocommerce-payments/dist/checkout.css 2.21 kB
release/woocommerce-payments/dist/checkout.js 27.6 kB
release/woocommerce-payments/dist/index.css 36.1 kB
release/woocommerce-payments/dist/index.js 307 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 771 B
release/woocommerce-payments/dist/multi-currency-switcher-block.js 56.1 kB
release/woocommerce-payments/dist/multi-currency.css 14.7 kB
release/woocommerce-payments/dist/multi-currency.js 72.5 kB
release/woocommerce-payments/dist/order.css 248 B
release/woocommerce-payments/dist/order.js 12.4 kB
release/woocommerce-payments/dist/payment-gateways.css 1.2 kB
release/woocommerce-payments/dist/payment-gateways.js 47 kB
release/woocommerce-payments/dist/payment-request.js 11.6 kB
release/woocommerce-payments/dist/platform-checkout-express-button.js 12.7 kB
release/woocommerce-payments/dist/platform-checkout.css 3.73 kB
release/woocommerce-payments/dist/platform-checkout.js 70.8 kB
release/woocommerce-payments/dist/settings.css 47.4 kB
release/woocommerce-payments/dist/settings.js 111 kB
release/woocommerce-payments/dist/subscription-edit-page.js 392 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 7.18 kB
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 12.6 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 434 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 298 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 44.1 kB
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 15.5 kB
release/woocommerce-payments/dist/upe_checkout.css 2.21 kB
release/woocommerce-payments/dist/upe_checkout.js 32.5 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 2.13 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 38.6 kB
release/woocommerce-payments/includes/platform-checkout/assets/css/platform-checkout-express-button.css 247 B
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 633 B
release/woocommerce-payments/vendor/automattic/jetpack-admin-ui/src/css/jetpack-icon.css 224 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.43 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-ajax.js 789 B
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-callables.js 925 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.43 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 8.97 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.35 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 387 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.06 kB

compressed-size-action

'fields' => 'ids',
'subscription_status' => 'active',
// Ignoring phpcs warning, we need to search meta.
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to avoid the meta_query here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's a way to avoid using meta_query here.

That said, this isn't the correct way to use the 'meta_query' param.
It needs to be a nested inside an array for it to work.

For example:

$results = wcs_get_subscriptions(
	[
		'subscriptions_per_page' => 1,
		'subscription_status'    => 'active',
		'meta_query'             => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			[
				'key'     => '_wcpay_subscription_id',
				'compare' => 'EXISTS',
			]
		],
	]
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explaining, I had no idea how this was supposed to work (I did read the docs for wcs_get_subscriptions!).

Once I've fixed up the PR I'll add something to the docblock (meta_query is not mentioned).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just retested with this logic in place. I see now the flaw in my previous testing – I needed to test with WCS / tokenised subscriptions active. Since the meta_query wasn't doing anything I was getting false positives – warning shown when merchant only has active tokenised subs. Good catch 🏀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

</div>
</div>
<div class="wc-backbone-modal-backdrop modal-close"></div>
</script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template is a copy of the other warning modal. I thought that was simpler / more robust than parameterising so we have a single modal template.

self::SUBSCRIPTION_ID_META_KEY => 'EXISTS',
],
]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally keen for feedback on this query and edge cases it might need to detect. For the modal it doesn't need to be 100% perfect; false positives are ok. But if this method gets used elsewhere later it's probably a good idea to be super clear about what this searches for, and any potential edge cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any feedback on this. I think this approach will catch 99.99999% which I'm fine with :D There will always be edge cases but the nice thing about having this code in a separate function is if we do discover edge cases we can update this query or add more queries

$( this ).WCBackboneModal( {
template: 'wcpay-subscriptions-plugin-warning',
} );

return false;
},
deactivate_subscriptions: function ( event ) {
// Trigger deactivate flow for WC Subscriptions.
redirect_deactivate_wc_subscriptions: function ( event ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming these as I've taken a "duplicate the existing code" approach, rather than parameterise these functions (which IMO would be more complicated without much payoff - these functions are all one-liners).

@haszari haszari marked this pull request as ready for review November 27, 2022 20:51
@haszari
Copy link
Contributor Author

haszari commented Nov 27, 2022

Requesting a review from @Automattic/helix FYI @mattallan

Questions for reviewer:

  • Should this be covered by e2e tests (or other automated tests)? I'm not sure if this is practical / worthwhile, keen for advice.
  • Keen for advice on other ways to test this or edge cases to explore, especially around subscription statuses. I've tested with admin manual Suspend only.

Also FYI:

  • @aheckler - this links out to documentation, keen for your feedback on modal wording
  • Sourav - FYI since you are aware of this issue/helped prioritise this fix

@haszari haszari added the component: wcpay subscriptions Issues related to Stripe Billing Subscriptions label Nov 27, 2022
@haszari
Copy link
Contributor Author

haszari commented Nov 27, 2022

@elizaan36 - FYI adding a new modal when disabling WCPay, to warn merchant that WCPay (built in) subscriptions will continue renewing. Let me know if you have any feedback on the modal or how this fits into the overall UI. Thanks!

@aheckler
Copy link
Member

@haszari Can we adjust the first two paragraphs of the modal to be the following?

Your store has active subscriptions using the built-in WooCommerce Payments functionality. Due to the [off-site billing engine](https://woocommerce.com/document/payments/subscriptions-basics/comparison/#billing-engine) these subscriptions use, **they will continue to renew even after you deactivate WooCommerce Payments.**

If you do not want these subscriptions to continue to be billed, you should [cancel all subscriptions](https://woocommerce.com/document/subscriptions/store-manager-guide/#cancel-or-suspend-subscription) prior to deactivating WooCommerce Payments.

@elizaan36
Copy link

elizaan36 commented Nov 28, 2022

Thanks for the ping, @haszari !

Just a quick note on the modal component styles and CTA.

  • We usually have the primary CTA positioned on the right of the modals.
  • And on mobile, the primary CTA would be below the Cancel CTA. We also need to maintain the same padding between the buttons horizontally and vertically.

Last thing is the modal title ("Are you sure?") looks like the right size but Bold weight. This is the subtitle WordPress component and should be semi-bold.

Here's a quick sketch to illustrate the notes above.
Screen Shot 2022-11-28 at 10 31 45 AM

Copy link
Contributor

@mattallan mattallan left a comment

Choose a reason for hiding this comment

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

I've done some testing on this PR, mainly focusing on the new store_has_active_wcpay_subscriptions() function.

From my testing, this function was always returning true even when I didn't have a single subscription with _wcpay_subscription_id meta.

I've provided some feedback on how to fix this as part of my review (slight issue with how the meta query param was used)

With my suggested changes, I've tested this function will work in HPOS and CPT environments and also with older versions of WC Subscriptions and the latest version of subscriptions bundled in WC Payments.

'fields' => 'ids',
'subscription_status' => 'active',
// Ignoring phpcs warning, we need to search meta.
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's a way to avoid using meta_query here.

That said, this isn't the correct way to use the 'meta_query' param.
It needs to be a nested inside an array for it to work.

For example:

$results = wcs_get_subscriptions(
	[
		'subscriptions_per_page' => 1,
		'subscription_status'    => 'active',
		'meta_query'             => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			[
				'key'     => '_wcpay_subscription_id',
				'compare' => 'EXISTS',
			]
		],
	]
);

$results = wcs_get_subscriptions(
[
'subscriptions_per_page' => 1,
'fields' => 'ids',
Copy link
Contributor

Choose a reason for hiding this comment

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

'fields' isn't a valid param for wcs_get_subscriptions() so this can be removed. This function always returns the object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that eventually wc_get_orders was called, so assumed the args would carry through. Fixed in 14ef0a4

self::SUBSCRIPTION_ID_META_KEY => 'EXISTS',
],
]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any feedback on this. I think this approach will catch 99.99999% which I'm fine with :D There will always be edge cases but the nice thing about having this code in a separate function is if we do discover edge cases we can update this query or add more queries

@haszari
Copy link
Contributor Author

haszari commented Dec 1, 2022

Addressed reviewer feedback. @mattallan thanks for the tip about meta_query, I'm keen to document that while we're here (tbc).

@mattallan I did some more testing with WCS active and inactive, and a couple of subscriptions (one tokenised, one stripe billing). If you could retest with a couple of interesting scenarios I'd appreciate it :)

Here's the current state of the modal, incorporating new wording (@aheckler) and revised default button position (on right) (@elizaan36).

Screenshot 2022-12-02 at 11 29 09 AM


Note - I haven't fixed the other styling issues picked up by @elizaan36 - title weight, button layout on mobile.

These styles come from WooCommerce core, and as far as I can tell, our markup is correct. So if we want to improve/fix the title or button layout issues, I think that should be logged as a WC core issue. I checked a core modal and see that it also has a bold title.

Screenshot 2022-12-02 at 11 26 29 AM

@haszari haszari requested a review from mattallan December 1, 2022 23:26
@aheckler
Copy link
Member

aheckler commented Dec 2, 2022

@haszari Two minor changes:

  1. Can we move the Learn more link to be after the first paragraph, rather than the second one? I think that's a more natural place for it.
  2. In the Learn more link, the period/full stop is also part of the link. Usually, punctuation is not included in links like that. Can we move the period/full stop outside the link?

Thanks!

Rua Haszard and others added 3 commits December 2, 2022 15:42
@haszari
Copy link
Contributor Author

haszari commented Dec 2, 2022

Thanks @aheckler - good spotting! I've fixed that up now:

Screenshot 2022-12-02 at 3 41 50 PM

Your store has active subscriptions using the built-in WooCommerce Payments functionality. Due to the [off-site billing engine](https://woocommerce.com/document/payments/subscriptions/comparison/#billing-engine) these subscriptions use, they will continue to renew even after you deactivate WooCommerce Payments. [Learn more](https://woocommerce.com/document/woocommerce-payments/built-in-subscriptions/deactivate/#existing-subscriptions).

If you do not want these subscriptions to continue to be billed, you should [cancel all subscriptions](https://woocommerce.com/document/subscriptions/store-manager-guide/#cancel-or-suspend-subscription) prior to deactivating WooCommerce Payments.
Are you sure you want to deactivate WooCommerce Payments?

@haszari haszari requested a review from a team December 4, 2022 21:25
@haszari
Copy link
Contributor Author

haszari commented Dec 4, 2022

Ready for a final review @mattallan / @brucealdridge 🙇

Copy link
Contributor

@mattallan mattallan left a comment

Choose a reason for hiding this comment

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

Really nice additions coming in this PR @haszari !!

I have tested the following cases against your latest changes:

  • Store with one or many active WC Pay Subscriptions and no other payment methods. Correctly shows the message on deactivation ✅
  • Store with one or many canceled WC Pay Subscriptions. No notice is shown. ✅
  • Store with only active WC Payments (tokenized) and no stripe billing subscriptions. No notice is shown. ✅
  • Store with some active WC Payments (tokenized) and some active stripe billing subscriptions. Notice is correctly shown. ✅
  • Store with some active WC Payments (tokenized) and some cancelled stripe billing subscriptions. No notice is shown. ✅
  • Tested clicking "Yes, Deactivate WooCommerce Payments" actually does deactivate the plugin ✅

The notice/warning also looks good to me (I double checked the links as well):

image

If there are no more design changes/feedback this is good to merge :) Marking as approved.

@haszari
Copy link
Contributor Author

haszari commented Dec 5, 2022

Thanks for the thorough testing @mattallan 👌

@haszari haszari merged commit fc14a19 into develop Dec 5, 2022
@haszari haszari deleted the fix/5090-warn-deactivate-with-live-stripe-subscriptions branch December 5, 2022 22:04
cesarcosta99 pushed a commit that referenced this pull request Dec 14, 2022
… (Stripe Billing )will continue renewing (#5169)

* minor refactor to rename various functions to scope to WCS:
- WCPay-specific warning message coming soon to this file
- Also added comments to clarify

* stub modal to warn when disabling WCPay plugin

* add script data to control wcpay subs plugin deactivate warning
- hard coded true for now

* function for determining if store has active subscriptions (first cut)

* fix has_active_wcpay subs:
- convert result array to bool
- only query for ids to optimise

* use has_wcpay_subs to only show warning modal when appropriate

* polish wording & docs links in active wcpay subs warning modal

* add changelog

* clarify changelog

* fix syntax of meta_query - was not working, causing false positives for tokenised WCS subs

* Update modal wording & links as advised by @aheckler

* reorder buttons in subscriptions warning modals – primary button should be rightmost

* remove fields arg - not supported by wcs_get_subscriptions

* modal tidies: move `learn more` to first para, links should close before . full stops

Co-authored-by: Rua Haszard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: wcpay subscriptions Issues related to Stripe Billing Subscriptions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn merchant when deactivating WCPay plugin that WCPay Subscriptions will continue renewing (offboarding)
4 participants