Merge branch 'trunk' into PCP-1874-block-validation

This commit is contained in:
Alex P 2023-09-21 08:12:51 +03:00
commit d86b315229
No known key found for this signature in database
GPG key ID: 54487A734A204D71
218 changed files with 18423 additions and 1807 deletions

View file

@ -2,6 +2,7 @@ import {useEffect, useState} from '@wordpress/element';
import {registerExpressPaymentMethod, registerPaymentMethod} from '@woocommerce/blocks-registry';
import {paypalAddressToWc, paypalOrderToWcAddresses} from "./Helper/Address";
import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
const config = wc.wcSettings.getSetting('ppcp-gateway_data');
@ -28,6 +29,15 @@ const PayPalComponent = ({
if (!loaded) {
loadPaypalScript(config.scriptData, () => {
setLoaded(true);
buttonModuleWatcher.registerContextBootstrap(config.scriptData.context, {
createOrder: () => {
return createOrder();
},
onApprove: (data, actions) => {
return handleApprove(data, actions);
},
});
});
}
}, [loaded]);
@ -107,12 +117,18 @@ const PayPalComponent = ({
setPaypalOrder(order);
if (config.finalReviewEnabled) {
const addresses = paypalOrderToWcAddresses(order);
if (order) {
const addresses = paypalOrderToWcAddresses(order);
await wp.data.dispatch('wc/store/cart').updateCustomerData({
billing_address: addresses.billingAddress,
shipping_address: addresses.shippingAddress,
});
await wp.data.dispatch('wc/store/cart').updateCustomerData({
billing_address: addresses.billingAddress,
shipping_address: addresses.shippingAddress,
});
}
const checkoutUrl = new URL(config.scriptData.redirect);
// sometimes some browsers may load some kind of cached version of the page,
// so adding a parameter to avoid that
checkoutUrl.searchParams.append('ppcp-continuation-redirect', (new Date()).getTime().toString());
location.href = getCheckoutRedirectUrl();
} else {