mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Check validation errors before submit in block
This commit is contained in:
parent
099b50728e
commit
47ad89bab9
1 changed files with 17 additions and 25 deletions
|
@ -89,6 +89,19 @@ const PayPalComponent = ({
|
|||
|
||||
const handleApprove = async (data, actions) => {
|
||||
try {
|
||||
const order = await actions.order.get();
|
||||
|
||||
if (order) {
|
||||
const addresses = paypalOrderToWcAddresses(order);
|
||||
|
||||
await wp.data.dispatch('wc/store/cart').updateCustomerData({
|
||||
billing_address: addresses.billingAddress,
|
||||
shipping_address: addresses.shippingAddress,
|
||||
});
|
||||
}
|
||||
|
||||
setPaypalOrder(order);
|
||||
|
||||
const res = await fetch(config.scriptData.ajax.approve_order.endpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
|
@ -112,20 +125,12 @@ const PayPalComponent = ({
|
|||
throw new Error(config.scriptData.labels.error.generic)
|
||||
}
|
||||
|
||||
const order = await actions.order.get();
|
||||
|
||||
setPaypalOrder(order);
|
||||
if (wp.data.select('wc/store/validation').hasValidationErrors()) {
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.finalReviewEnabled) {
|
||||
if (order) {
|
||||
const addresses = paypalOrderToWcAddresses(order);
|
||||
|
||||
await wp.data.dispatch('wc/store/cart').updateCustomerData({
|
||||
billing_address: addresses.billingAddress,
|
||||
shipping_address: addresses.shippingAddress,
|
||||
});
|
||||
}
|
||||
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
} else {
|
||||
onSubmit();
|
||||
|
@ -141,19 +146,6 @@ const PayPalComponent = ({
|
|||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = onCheckoutValidation(() => {
|
||||
if (config.scriptData.continuation) {
|
||||
return true;
|
||||
}
|
||||
if (wp.data.select('wc/store/validation').hasValidationErrors()) {
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return unsubscribe;
|
||||
}, [onCheckoutValidation] );
|
||||
|
||||
const handleClick = (data, actions) => {
|
||||
if (isEditing) {
|
||||
return actions.reject();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue