mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Apply the Venmo + vaulting functionality on block pages
This commit is contained in:
parent
84616d07da
commit
2cb76ed8f2
1 changed files with 35 additions and 12 deletions
|
@ -23,6 +23,9 @@ import {
|
|||
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
|
||||
import BlockCheckoutMessagesBootstrap from "./Bootstrap/BlockCheckoutMessagesBootstrap";
|
||||
import {keysToCamelCase} from "../../../ppcp-button/resources/js/modules/Helper/Utils";
|
||||
import {
|
||||
handleShippingOptionsChange
|
||||
} from "../../../ppcp-button/resources/js/modules/Helper/ShippingHandler";
|
||||
const config = wc.wcSettings.getSetting('ppcp-gateway_data');
|
||||
|
||||
window.ppcpFundingSource = config.fundingSource;
|
||||
|
@ -146,7 +149,7 @@ const PayPalComponent = ({
|
|||
shipping_address: addresses.shippingAddress,
|
||||
}),
|
||||
];
|
||||
if (!config.finalReviewEnabled) {
|
||||
if (shouldHandleShippingInPayPal()) {
|
||||
// set address in UI
|
||||
promises.push(wp.data.dispatch('wc/store/cart').setBillingAddress(addresses.billingAddress));
|
||||
if (shippingData.needsShipping) {
|
||||
|
@ -181,7 +184,7 @@ const PayPalComponent = ({
|
|||
throw new Error(config.scriptData.labels.error.generic)
|
||||
}
|
||||
|
||||
if (config.finalReviewEnabled) {
|
||||
if (!shouldHandleShippingInPayPal()) {
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
} else {
|
||||
setGotoContinuationOnError(true);
|
||||
|
@ -220,7 +223,7 @@ const PayPalComponent = ({
|
|||
shipping_address: addresses.shippingAddress,
|
||||
}),
|
||||
];
|
||||
if (!config.finalReviewEnabled) {
|
||||
if (shouldHandleShippingInPayPal()) {
|
||||
// set address in UI
|
||||
promises.push(wp.data.dispatch('wc/store/cart').setBillingAddress(addresses.billingAddress));
|
||||
if (shippingData.needsShipping) {
|
||||
|
@ -255,7 +258,7 @@ const PayPalComponent = ({
|
|||
throw new Error(config.scriptData.labels.error.generic)
|
||||
}
|
||||
|
||||
if (config.finalReviewEnabled) {
|
||||
if (!shouldHandleShippingInPayPal()) {
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
} else {
|
||||
setGotoContinuationOnError(true);
|
||||
|
@ -297,8 +300,12 @@ const PayPalComponent = ({
|
|||
onClick();
|
||||
};
|
||||
|
||||
const isVenmoAndVaultingEnabled = () => {
|
||||
return window.ppcpFundingSource === 'venmo' && config.scriptData.vaultingEnabled;
|
||||
const shouldHandleShippingInPayPal = () => {
|
||||
if (config.finalReviewEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return window.ppcpFundingSource !== 'venmo' || !config.scriptData.vaultingEnabled;
|
||||
}
|
||||
|
||||
let handleShippingOptionsChange = null;
|
||||
|
@ -306,7 +313,7 @@ const PayPalComponent = ({
|
|||
let handleSubscriptionShippingOptionsChange = null;
|
||||
let handleSubscriptionShippingAddressChange = null;
|
||||
|
||||
if (shippingData.needsShipping && !config.finalReviewEnabled) {
|
||||
if (shippingData.needsShipping && shouldHandleShippingInPayPal()) {
|
||||
handleShippingOptionsChange = async (data, actions) => {
|
||||
try {
|
||||
const shippingOptionId = data.selectedShippingOption?.id;
|
||||
|
@ -447,7 +454,7 @@ const PayPalComponent = ({
|
|||
if (config.scriptData.continuation) {
|
||||
return true;
|
||||
}
|
||||
if (!config.finalReviewEnabled) {
|
||||
if (shouldHandleShippingInPayPal()) {
|
||||
location.href = getCheckoutRedirectUrl();
|
||||
}
|
||||
return true;
|
||||
|
@ -493,8 +500,16 @@ const PayPalComponent = ({
|
|||
onError={onClose}
|
||||
createSubscription={createSubscription}
|
||||
onApprove={handleApproveSubscription}
|
||||
onShippingOptionsChange={handleSubscriptionShippingOptionsChange}
|
||||
onShippingAddressChange={handleSubscriptionShippingAddressChange}
|
||||
onShippingOptionsChange={(data, actions) => {
|
||||
shouldHandleShippingInPayPal()
|
||||
? handleSubscriptionShippingOptionsChange(data, actions)
|
||||
: null;
|
||||
}}
|
||||
onShippingAddressChange={(data, actions) => {
|
||||
shouldHandleShippingInPayPal()
|
||||
? handleSubscriptionShippingAddressChange(data, actions)
|
||||
: null;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -508,8 +523,16 @@ const PayPalComponent = ({
|
|||
onError={onClose}
|
||||
createOrder={createOrder}
|
||||
onApprove={handleApprove}
|
||||
onShippingOptionsChange={handleShippingOptionsChange}
|
||||
onShippingAddressChange={handleShippingAddressChange}
|
||||
onShippingOptionsChange={(data, actions) => {
|
||||
shouldHandleShippingInPayPal()
|
||||
? handleShippingOptionsChange(data, actions)
|
||||
: null;
|
||||
}}
|
||||
onShippingAddressChange={(data, actions) => {
|
||||
shouldHandleShippingInPayPal()
|
||||
? handleShippingAddressChange(data, actions)
|
||||
: null;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue