Skip to content

Commit

Permalink
Prevent WooPay opt-in checks from running when WooPayments is not ava…
Browse files Browse the repository at this point in the history
…ilable (#9943)
  • Loading branch information
leonardola authored Dec 23, 2024
1 parent 9637247 commit 952e431
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9942-no-cost-subscription
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Zero dollar subscriptions with zero dollar renewals checkout error
3 changes: 2 additions & 1 deletion client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ Object.entries( enabledPaymentMethodsConfig )
savedTokenComponent: <SavedTokenHandler api={ api } />,
canMakePayment: ( cartData ) => {
const billingCountry = cartData.billingAddress.country;
const needsPayment = cartData.cart.cartNeedsPayment;
const isRestrictedInAnyCountry = !! upeConfig.countries.length;
const isAvailableInTheCountry =
! isRestrictedInAnyCountry ||
upeConfig.countries.includes( billingCountry );
// We used to check if stripe was loaded with `getStripeForUPE`, but we can't guarantee it will be loaded synchronously.
return isAvailableInTheCountry;
return needsPayment && isAvailableInTheCountry;
},
paymentMethodId: upeMethods[ upeName ],
// see .wc-block-checkout__payment-method styles in blocks/style.scss
Expand Down
20 changes: 13 additions & 7 deletions client/components/woopay/save-user/checkout-page-save-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
const { isWCPayChosen, isNewPaymentTokenChosen } = useSelectedPaymentMethod(
isBlocksCheckout
);

// In classic checkout the saved tokens are under WCPay, so we need to check if new token is selected or not,
// under WCPay. For blocks checkout considering isWCPayChosen is enough.
const isWCPayWithNewTokenChosen = isBlocksCheckout
? isWCPayChosen
: isWCPayChosen && isNewPaymentTokenChosen;

const viewportWidth = window.document.documentElement.clientWidth;
const viewportHeight = window.document.documentElement.clientHeight;

Expand Down Expand Up @@ -193,7 +200,11 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
return;
}

if ( isSaveDetailsChecked && ! isPhoneValid ) {
if (
isSaveDetailsChecked &&
! isPhoneValid &&
isWCPayWithNewTokenChosen
) {
setValidationErrors( {
[ errorId ]: {
message: __(
Expand All @@ -212,14 +223,9 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
isSaveDetailsChecked,
sendExtensionData,
setValidationErrors,
isWCPayWithNewTokenChosen,
] );

// In classic checkout the saved tokens are under WCPay, so we need to check if new token is selected or not,
// under WCPay. For blocks checkout considering isWCPayChosen is enough.
const isWCPayWithNewTokenChosen = isBlocksCheckout
? isWCPayChosen
: isWCPayChosen && isNewPaymentTokenChosen;

const updatePhoneNumber = useCallback( () => {
if ( isPhoneNumberTouched.current ) {
return;
Expand Down

0 comments on commit 952e431

Please sign in to comment.