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

Don't load Apple/Google Pay for synced subscriptions that don't have payment due today and also require shipping #7582

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from

Conversation

mattallan
Copy link
Contributor

Fixes #3742

Changes proposed in this Pull Request

When customers attempt to use Apple Pay or Google Pay to purchase a synchronized subscription product that has no upfront costs (i.e. trial period or delayed initial payment due to product being synced) and also requires shipping, they're met with an error on the page:

image

Inside our WC_Payments_Payment_Request_Button_Handler class, we have code that prevents non-virtual (physical) products with free trials from being purchased with Apple/Google Pay, however there isn't any code to handle products that imitate a free trial period like what we do to handle synchronised subscription purchased outside of the synced date with no initial payment.

In this PR, I've introduced a new function to check if the product is a subscription product and has a free trial period (either trial set on the product or is a synced product), and requires shipping, and if so, prevent loading the Apple Pay/Google Pay buttons on the page.

Testing instructions

  1. Enable Apple Pay and Google Pay payment methods
  2. Install and active Woo Subscriptions
  3. Enable synchronised subscriptions in WooCommerce > Settings > Subscriptions > Synchronise renewals
    image
  4. Create a synced product that is not virtual and is not synced to today:
    image
  5. While on the develop branch, view the product page and note the Payment Request buttons (PRB) are loaded. If you attempt to purchase this product with PRB, you will see the above error.
  6. Check out this branch and confirm the PRB are no longer loaded on product pages for physical synced subscription products that

Other test cases to run:

  • Physical (non-virtual) variable synced subscriptions. The PRB shouldn't show on the product page if any variation isn't supported.
  • Virtual synced subscriptions. The PRB should show.
  • Physical synced products with a sync date set to today. The PRB should show
  • Physical synced subscription that is synced to another day but proration is enabled in WC > Settings > Subscriptions

  • 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)

Post merge

@mattallan mattallan requested a review from a team October 31, 2023 07:02
@botwoo
Copy link
Collaborator

botwoo commented Oct 31, 2023

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 7582 or branch name fix/3742-synced-subscriptions-payment-requests in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: d9cc561
  • Build time: 2024-02-06 05:40:08 UTC

Note: the build is updated when a new commit is pushed to this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2023

Size Change: +38 B (0%)

Total Size: 1.27 MB

Filename Size Change
release/woocommerce-payments/dist/payment-request.js 12.2 kB +38 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.06 kB
release/woocommerce-payments/assets/css/success.css 158 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 1.81 kB
release/woocommerce-payments/dist/blocks-checkout.css 1.81 kB
release/woocommerce-payments/dist/blocks-checkout.js 83.7 kB
release/woocommerce-payments/dist/checkout-rtl.css 318 B
release/woocommerce-payments/dist/checkout.css 319 B
release/woocommerce-payments/dist/checkout.js 35.9 kB
release/woocommerce-payments/dist/index-rtl.css 37 kB
release/woocommerce-payments/dist/index.css 37 kB
release/woocommerce-payments/dist/index.js 291 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.4 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 61.2 kB
release/woocommerce-payments/dist/multi-currency.css 3.4 kB
release/woocommerce-payments/dist/multi-currency.js 56.6 kB
release/woocommerce-payments/dist/order-rtl.css 693 B
release/woocommerce-payments/dist/order.css 696 B
release/woocommerce-payments/dist/order.js 42.6 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.31 kB
release/woocommerce-payments/dist/payment-gateways.css 1.31 kB
release/woocommerce-payments/dist/payment-gateways.js 40.2 kB
release/woocommerce-payments/dist/payment-request-rtl.css 153 B
release/woocommerce-payments/dist/payment-request.css 153 B
release/woocommerce-payments/dist/product-details.js 919 B
release/woocommerce-payments/dist/settings-rtl.css 10.3 kB
release/woocommerce-payments/dist/settings.css 10.3 kB
release/woocommerce-payments/dist/settings.js 235 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.4 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 710 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.4 kB
release/woocommerce-payments/dist/tos-rtl.css 230 B
release/woocommerce-payments/dist/tos.css 231 B
release/woocommerce-payments/dist/tos.js 20.9 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 2.06 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 153 B
release/woocommerce-payments/dist/woopay-express-button.css 153 B
release/woocommerce-payments/dist/woopay-express-button.js 51.3 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.18 kB
release/woocommerce-payments/dist/woopay.css 4.19 kB
release/woocommerce-payments/dist/woopay.js 70.9 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 812 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-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
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.37 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.37 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.03 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
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.6 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 9.4 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.52 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 781 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.05 kB

compressed-size-action

@diegocurbelo diegocurbelo requested a review from Mayisha November 1, 2023 19:39
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

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

Thanks @mattallan. The fix is working as described 🎉

@Mayisha
Copy link
Contributor

Mayisha commented Nov 2, 2023

@mattallan I have reviewed the changes and approved the PR as things are fixed. But you may need to consider the scenario @james-allan raised about variations.

@mattallan
Copy link
Contributor Author

Thanks @Mayisha and @james-allan. I've refactored the product_has_trial_and_needs_shipping() function so that if this function is passed a variable subscription, it will only return true if all the variations have a trial and require shipping.

This means if you have a subscription that has one variation that is valid for express payment methods and another that is not, the button will still appear on the product page for it and only show for variations that are supported, here's a quick screencast showcasing this:

Screen Capture on 2023-11-03 at 12-48-54

@james-allan james-allan force-pushed the fix/3742-synced-subscriptions-payment-requests branch from 65c5d02 to 4bbfc67 Compare November 6, 2023 04:52
Copy link
Contributor

@james-allan james-allan left a comment

Choose a reason for hiding this comment

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

Hey @mattallan.

Changes look good and works. I left a comment suggesting that we can remove the is_today() check. I believe that isn't necessary given the is_payment_upfront() function includes an equivalent check. :)

@mattallan
Copy link
Contributor Author

mattallan commented Nov 7, 2023

Thanks for the suggestion @james-allan. I had to fix the psalm issues and unit tests but this is good for a final review

Edit: I've ran through the standard tests on the latest changes

@mattallan
Copy link
Contributor Author

While copying these changes over to our Stripe gateway, I found a few more issues over there that are also issues in WooPayments.

Here are the individual fixes I've pushed up to this PR:

  • Don't display the PRB on the product page for virtual synced subscriptions that have no upfront payment. This is to prevent incorrect totals that don't account for things like a trial period or a prorated initial payment. Fixed by de80fb0
  • If a variation is already selected on page load (i.e. using /?attribute_{name}=value in URL), don't show the PRBs on page load if that variation isn't supported. Fixed by b9d2ba5
  • After adding a variation to the cart that doesn't support PRBs, don't show PRBs on the page load that occurs while the unsupported variation is still selected. Fixed by 47374a0

@james-allan did you mind taking this PR for another spin? 🙏 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronized Subscriptions Requiring Shipping Can't Be Purchased with Apple Pay
9 participants