mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Merge remote-tracking branch 'origin/PCP-4712-appswitch-qa' into PCP-4992-cross-browser-appswitch
Some checks failed
CI / PHP 7.4 (push) Has been cancelled
CI / PHP 8.0 (push) Has been cancelled
CI / PHP 8.1 (push) Has been cancelled
CI / PHP 8.2 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
CI / PHP 8.4 (push) Has been cancelled
PR Playground Demo / prepare_version (push) Has been cancelled
PR Playground Demo / build_plugin (push) Has been cancelled
PR Playground Demo / create_archive (push) Has been cancelled
PR Playground Demo / Comment on PR with Playground details (push) Has been cancelled
Some checks failed
CI / PHP 7.4 (push) Has been cancelled
CI / PHP 8.0 (push) Has been cancelled
CI / PHP 8.1 (push) Has been cancelled
CI / PHP 8.2 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
CI / PHP 8.4 (push) Has been cancelled
PR Playground Demo / prepare_version (push) Has been cancelled
PR Playground Demo / build_plugin (push) Has been cancelled
PR Playground Demo / create_archive (push) Has been cancelled
PR Playground Demo / Comment on PR with Playground details (push) Has been cancelled
This commit is contained in:
commit
fe59ab01fb
5 changed files with 53 additions and 5 deletions
|
@ -21,6 +21,7 @@ import {
|
||||||
onApproveSavePayment,
|
onApproveSavePayment,
|
||||||
} from '../paypal-config';
|
} from '../paypal-config';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
|
import Spinner from '../../../../ppcp-button/resources/js/modules/Helper/Spinner';
|
||||||
|
|
||||||
const PAYPAL_GATEWAY_ID = 'ppcp-gateway';
|
const PAYPAL_GATEWAY_ID = 'ppcp-gateway';
|
||||||
|
|
||||||
|
@ -52,8 +53,11 @@ export const PayPalComponent = ( {
|
||||||
useState( false );
|
useState( false );
|
||||||
|
|
||||||
const [ paypalScriptLoaded, setPaypalScriptLoaded ] = useState( false );
|
const [ paypalScriptLoaded, setPaypalScriptLoaded ] = useState( false );
|
||||||
|
const [ isFullPageSpinnerActive, setIsFullPageSpinnerActive ] =
|
||||||
|
useState( false );
|
||||||
|
|
||||||
const paypalButtonRef = useRef( null );
|
const paypalButtonRef = useRef( null );
|
||||||
|
const spinnerRef = useRef( null );
|
||||||
|
|
||||||
if ( ! paypalScriptLoaded ) {
|
if ( ! paypalScriptLoaded ) {
|
||||||
if ( ! paypalScriptPromise ) {
|
if ( ! paypalScriptPromise ) {
|
||||||
|
@ -70,6 +74,18 @@ export const PayPalComponent = ( {
|
||||||
? `${ config.id }-${ fundingSource }`
|
? `${ config.id }-${ fundingSource }`
|
||||||
: config.id;
|
: config.id;
|
||||||
|
|
||||||
|
// Full-page spinner used to block UI interactions during flows like AppSwitch.
|
||||||
|
useEffect( () => {
|
||||||
|
if ( isFullPageSpinnerActive ) {
|
||||||
|
if ( ! spinnerRef.current ) {
|
||||||
|
spinnerRef.current = Spinner.fullPage();
|
||||||
|
}
|
||||||
|
spinnerRef.current.block();
|
||||||
|
} else if ( spinnerRef.current ) {
|
||||||
|
spinnerRef.current.unblock();
|
||||||
|
}
|
||||||
|
}, [ isFullPageSpinnerActive ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
// fill the form if in continuation (for product or mini-cart buttons)
|
// fill the form if in continuation (for product or mini-cart buttons)
|
||||||
if ( continuationFilled || ! config.scriptData.continuation?.order ) {
|
if ( continuationFilled || ! config.scriptData.continuation?.order ) {
|
||||||
|
@ -286,6 +302,14 @@ export const PayPalComponent = ( {
|
||||||
};
|
};
|
||||||
}, [ onPaymentSetup, paypalOrder, activePaymentMethod ] );
|
}, [ onPaymentSetup, paypalOrder, activePaymentMethod ] );
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
const unsubscribe = onCheckoutFail( () => {
|
||||||
|
setIsFullPageSpinnerActive( false );
|
||||||
|
} );
|
||||||
|
|
||||||
|
return unsubscribe;
|
||||||
|
}, [ onCheckoutFail ] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if ( activePaymentMethod !== methodId ) {
|
if ( activePaymentMethod !== methodId ) {
|
||||||
return;
|
return;
|
||||||
|
@ -336,7 +360,8 @@ export const PayPalComponent = ( {
|
||||||
setGotoContinuationOnError,
|
setGotoContinuationOnError,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onError,
|
onError,
|
||||||
onClose
|
onClose,
|
||||||
|
setIsFullPageSpinnerActive
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -491,7 +516,8 @@ export const PayPalComponent = ( {
|
||||||
setGotoContinuationOnError,
|
setGotoContinuationOnError,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onError,
|
onError,
|
||||||
onClose
|
onClose,
|
||||||
|
setIsFullPageSpinnerActive
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onShippingOptionsChange={ getOnShippingOptionsChange(
|
onShippingOptionsChange={ getOnShippingOptionsChange(
|
||||||
|
|
|
@ -64,8 +64,11 @@ export const handleApprove = async (
|
||||||
setGotoContinuationOnError,
|
setGotoContinuationOnError,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onError,
|
onError,
|
||||||
onClose
|
onClose,
|
||||||
|
setIsFullPageSpinnerActive
|
||||||
) => {
|
) => {
|
||||||
|
setIsFullPageSpinnerActive( true );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let order;
|
let order;
|
||||||
|
|
||||||
|
@ -168,6 +171,8 @@ export const handleApprove = async (
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
console.error( err );
|
console.error( err );
|
||||||
|
|
||||||
|
setIsFullPageSpinnerActive( false );
|
||||||
|
|
||||||
onError( err.message );
|
onError( err.message );
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
|
|
|
@ -8,6 +8,7 @@ import SimulateCart from '../Helper/SimulateCart';
|
||||||
import { strRemoveWord, strAddWord, throttle } from '../Helper/Utils';
|
import { strRemoveWord, strAddWord, throttle } from '../Helper/Utils';
|
||||||
import merge from 'deepmerge';
|
import merge from 'deepmerge';
|
||||||
import { debounce } from '../../../../../ppcp-blocks/resources/js/Helper/debounce';
|
import { debounce } from '../../../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||||
|
import ResumeFlowHelper from '../Helper/ResumeFlowHelper';
|
||||||
|
|
||||||
class SingleProductBootstrap {
|
class SingleProductBootstrap {
|
||||||
constructor( gateway, renderer, errorHandler ) {
|
constructor( gateway, renderer, errorHandler ) {
|
||||||
|
@ -53,7 +54,10 @@ class SingleProductBootstrap {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.render();
|
// Avoid re-rendering during the resume flow to prevent duplicate onApprove callbacks.
|
||||||
|
if ( ! ResumeFlowHelper.isResumeFlow() ) {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
this.renderer.enableSmartButtons( this.gateway.button.wrapper );
|
this.renderer.enableSmartButtons( this.gateway.button.wrapper );
|
||||||
show( this.gateway.button.wrapper );
|
show( this.gateway.button.wrapper );
|
||||||
|
|
|
@ -14,12 +14,16 @@ class Spinner {
|
||||||
background: '#fff',
|
background: '#fff',
|
||||||
opacity: 0.6,
|
opacity: 0.6,
|
||||||
},
|
},
|
||||||
|
baseZ: 10000,
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
unblock() {
|
unblock() {
|
||||||
jQuery( this.target ).unblock();
|
jQuery( this.target ).unblock();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
static fullPage() {
|
||||||
|
return new Spinner( window );
|
||||||
|
}
|
||||||
|
}
|
||||||
export default Spinner;
|
export default Spinner;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import Spinner from '../Helper/Spinner';
|
||||||
|
|
||||||
const initiateRedirect = ( successUrl ) => {
|
const initiateRedirect = ( successUrl ) => {
|
||||||
/**
|
/**
|
||||||
* Notice how this step initiates a redirect to a new page using a plain
|
* Notice how this step initiates a redirect to a new page using a plain
|
||||||
|
@ -15,6 +17,10 @@ const initiateRedirect = ( successUrl ) => {
|
||||||
|
|
||||||
const onApprove = ( context, errorHandler ) => {
|
const onApprove = ( context, errorHandler ) => {
|
||||||
return ( data, actions ) => {
|
return ( data, actions ) => {
|
||||||
|
// Block the entire page during approval process
|
||||||
|
const spinner = Spinner.fullPage();
|
||||||
|
spinner.block();
|
||||||
|
|
||||||
const canCreateOrder =
|
const canCreateOrder =
|
||||||
! context.config.vaultingEnabled || data.paymentSource !== 'venmo';
|
! context.config.vaultingEnabled || data.paymentSource !== 'venmo';
|
||||||
|
|
||||||
|
@ -50,6 +56,9 @@ const onApprove = ( context, errorHandler ) => {
|
||||||
|
|
||||||
const orderReceivedUrl = approveData.data?.order_received_url;
|
const orderReceivedUrl = approveData.data?.order_received_url;
|
||||||
initiateRedirect( orderReceivedUrl || context.config.redirect );
|
initiateRedirect( orderReceivedUrl || context.config.redirect );
|
||||||
|
} )
|
||||||
|
.finally( () => {
|
||||||
|
spinner.unblock();
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue