mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +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) => {
|
const handleApprove = async (data, actions) => {
|
||||||
try {
|
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, {
|
const res = await fetch(config.scriptData.ajax.approve_order.endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
|
@ -112,20 +125,12 @@ const PayPalComponent = ({
|
||||||
throw new Error(config.scriptData.labels.error.generic)
|
throw new Error(config.scriptData.labels.error.generic)
|
||||||
}
|
}
|
||||||
|
|
||||||
const order = await actions.order.get();
|
if (wp.data.select('wc/store/validation').hasValidationErrors()) {
|
||||||
|
location.href = getCheckoutRedirectUrl();
|
||||||
setPaypalOrder(order);
|
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,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.finalReviewEnabled) {
|
||||||
location.href = getCheckoutRedirectUrl();
|
location.href = getCheckoutRedirectUrl();
|
||||||
} else {
|
} else {
|
||||||
onSubmit();
|
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) => {
|
const handleClick = (data, actions) => {
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
return actions.reject();
|
return actions.reject();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue