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/143: Cancelling Google Pay on checkout shows validation errors #188

Merged
merged 24 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c78c392
consistent express payment
Sidsector9 Jul 24, 2024
810ddde
working payment
Sidsector9 Jul 25, 2024
5ec93dd
remove redundancy
Sidsector9 Jul 25, 2024
497ef1f
fix bug where modal doesn't reopen after closing
Sidsector9 Jul 25, 2024
53739a0
remove redundant files
Sidsector9 Jul 25, 2024
5aa6b8d
fix eslint errors
Sidsector9 Jul 25, 2024
8e90d5f
add missing doc
Sidsector9 Jul 25, 2024
bb5fe31
use emitResponse
Sidsector9 Jul 25, 2024
4215496
fix eslint errors
Sidsector9 Jul 25, 2024
0f1d209
add missing classes on apple pay wrapper
Sidsector9 Jul 26, 2024
7b98a0c
add try/catch block
Sidsector9 Jul 26, 2024
7e01bf9
fix gpay popup in safari
Sidsector9 Jul 26, 2024
1bf478e
add early return to click handler
Sidsector9 Jul 26, 2024
3d3a553
replace onPaymentProcessing with onPaymentSetup
Sidsector9 Jul 26, 2024
4d57b4e
Merge branch 'trunk' into fix/143
Sidsector9 Jul 26, 2024
bae9495
Merge branch 'trunk' into fix/143
Sidsector9 Jul 30, 2024
343afda
Merge branch 'fix/143' of github.com:woocommerce/woocommerce-square i…
Sidsector9 Jul 30, 2024
ce66f9f
disable apple pay buttons for non-safari browsers
Sidsector9 Jul 30, 2024
b0eed44
Merge branch 'trunk' into fix/143
Sidsector9 Aug 5, 2024
33a8a84
PR review changes
Sidsector9 Aug 8, 2024
c824cae
Merge branch 'trunk' into fix/143
Sidsector9 Aug 14, 2024
9777d31
Merge branch 'fix/143' of github.com:woocommerce/woocommerce-square i…
Sidsector9 Aug 14, 2024
a2c474f
fix eslint errors
Sidsector9 Aug 14, 2024
8a0ff9d
Merge branch 'trunk' into fix/143
Sidsector9 Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/blocks/credit-card/checkout-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CheckoutHandler = ({
const square = useContext(SquareWebContext);

const {
onPaymentProcessing,
onPaymentSetup,
onCheckoutAfterProcessingWithError,
onCheckoutAfterProcessingWithSuccess,
} = eventRegistration;
Expand All @@ -42,7 +42,7 @@ export const CheckoutHandler = ({
checkoutFormHandler;

usePaymentProcessing(
onPaymentProcessing,
onPaymentSetup,
emitResponse,
square,
getPaymentMethodData,
Expand Down
8 changes: 4 additions & 4 deletions assets/blocks/credit-card/use-payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import { getSquareServerData } from '../square-utils';
* If the checkout has errors, we send `has-checkout-errors` to the server-side so that the status
* of the request can be set to 'ERROR' before gateway validation is done.
*
* @param {Function} onPaymentProcessing Callback for registering observers on the payment processing event
* @param {Function} onPaymentSetup Callback for registering observers on the payment processing event
* @param {EmitResponseProps} emitResponse Helpers for observer response objects
* @param {SquareContext} squareContext Square payment form context variable
* @param {Function} getPaymentMethodData CreateNonce function
* @param {Function} createNonce CreateNonce function
* @param {Function} verifyBuyer VerifyBuyer function
*/
export const usePaymentProcessing = (
onPaymentProcessing,
onPaymentSetup,
emitResponse,
squareContext,
getPaymentMethodData,
Expand Down Expand Up @@ -106,10 +106,10 @@ export const usePaymentProcessing = (
return response;
};

const unsubscribe = onPaymentProcessing(processCheckout);
const unsubscribe = onPaymentSetup(processCheckout);
return unsubscribe;
}, [
onPaymentProcessing,
onPaymentSetup,
emitResponse.responseTypes.SUCCESS,
emitResponse.responseTypes.ERROR,
createNonce,
Expand Down
191 changes: 0 additions & 191 deletions assets/blocks/digital-wallets/button-component.js

This file was deleted.

116 changes: 86 additions & 30 deletions assets/blocks/digital-wallets/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,104 @@ import { useEffect, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import DigitalWalletContext from './context';
import ButtonComponent from './button-component';
import { getSquareServerData } from '../square-utils';
import { tokenize } from './utils';
import { getSquareServerData } from '../square-utils/utils';
import {
useSquare,
usePaymentRequest,
useShippingContactChangeHandler,
useShippingOptionChangeHandler,
useGooglePay,
useApplePay,
usePaymentProcessing,
} from './hooks';

const Content = (props) => {
const [payments, setPayments] = useState(null);
const { onCheckoutFail } = props.eventRegistration;
const { onClose } = props;
const Content = ({
billing,
shippingData,
onClick,
onClose,
onSubmit,
setExpressPaymentError,
emitResponse,
eventRegistration: { onPaymentSetup, onCheckoutFail },
}) => {
const { needsShipping } = shippingData;
const payments = useSquare();
const paymentRequest = usePaymentRequest(payments, needsShipping);
const [googlePay, googlePayRef] = useGooglePay(payments, paymentRequest);
const [applePay, applePayRef] = useApplePay(payments, paymentRequest);
const [tokenResult, setTokenResult] = useState(false);

useShippingContactChangeHandler(paymentRequest);
useShippingOptionChangeHandler(paymentRequest);
usePaymentProcessing(
payments,
billing,
tokenResult,
emitResponse,
onPaymentSetup
);

useEffect(() => {
const applicationId = getSquareServerData().applicationId;
const locationId = getSquareServerData().locationId;
const unsubscribe = onCheckoutFail(() => {
onClose();
return true;
});
return unsubscribe;
}, [onCheckoutFail]);

const isGooglePayDisabled =
getSquareServerData().hideButtonOptions.includes('google');
const isApplePayDisabled =
getSquareServerData().hideButtonOptions.includes('apple');

if (!window.Square) {
function onClickHandler(buttonInstance) {
if (!buttonInstance) {
return;
}

try {
const __payments = window.Square.payments(
applicationId,
locationId
);
setPayments(__payments);
} catch (e) {
console.error(e);
}
}, []);
setExpressPaymentError('');
onClick();

useEffect(() => {
const unsubscribeOnCheckoutFail = onCheckoutFail(() => {
onClose();
return true;
});
(async () => {
const __tokenResult = await tokenize(buttonInstance);

if (!__tokenResult) {
onClose();
} else {
setTokenResult(__tokenResult);
onSubmit();
}
})();
}

return unsubscribeOnCheckoutFail;
}, [onCheckoutFail]); // eslint-disable-line react-hooks/exhaustive-deps
const googlePayExpressButton = !isGooglePayDisabled && (
<div // eslint-disable-line jsx-a11y/click-events-have-key-events
tabIndex={0}
role="button"
ref={googlePayRef}
onClick={() => onClickHandler(googlePay)}
></div>
);

const applePayExpressButton = !isApplePayDisabled && (
<div // eslint-disable-line jsx-a11y/click-events-have-key-events
tabIndex={0}
role="button"
ref={applePayRef}
onClick={() => onClickHandler(applePay)}
className="apple-pay-button wc-square-wallet-buttons"
>
<span className="text"></span>
<span className="logo"></span>
</div>
);

return (
<>
<DigitalWalletContext.Provider value={{ payments, props }}>
<ButtonComponent />
</DigitalWalletContext.Provider>
{applePayExpressButton}
{googlePayExpressButton}
</>
);
};
Expand Down
8 changes: 0 additions & 8 deletions assets/blocks/digital-wallets/context.js

This file was deleted.

Loading
Loading