mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
👔 Add short delay before redirecting
This commit is contained in:
parent
12b5fe8082
commit
dc90a73f81
1 changed files with 17 additions and 13 deletions
|
@ -1,3 +1,18 @@
|
||||||
|
const initiateRedirect = ( successUrl ) => {
|
||||||
|
/**
|
||||||
|
* Notice how this step initiates a redirect to a new page using a plain
|
||||||
|
* URL as new location. This process does not send any details about the
|
||||||
|
* approved order or billed customer.
|
||||||
|
*
|
||||||
|
* The redirect will start after a short delay, giving the calling method
|
||||||
|
* time to process the return value of the `await onApprove()` call.
|
||||||
|
*/
|
||||||
|
|
||||||
|
setTimeout( () => {
|
||||||
|
window.location.href = successUrl;
|
||||||
|
}, 200 );
|
||||||
|
};
|
||||||
|
|
||||||
const onApprove = ( context, errorHandler ) => {
|
const onApprove = ( context, errorHandler ) => {
|
||||||
return ( data, actions ) => {
|
return ( data, actions ) => {
|
||||||
const canCreateOrder =
|
const canCreateOrder =
|
||||||
|
@ -28,24 +43,13 @@ const onApprove = ( context, errorHandler ) => {
|
||||||
.then( ( approveData ) => {
|
.then( ( approveData ) => {
|
||||||
if ( ! approveData.success ) {
|
if ( ! approveData.success ) {
|
||||||
errorHandler.genericError();
|
errorHandler.genericError();
|
||||||
return actions.restart().catch( ( err ) => {
|
return actions.restart().catch( () => {
|
||||||
errorHandler.genericError();
|
errorHandler.genericError();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderReceivedUrl = approveData.data?.order_received_url;
|
const orderReceivedUrl = approveData.data?.order_received_url;
|
||||||
|
initiateRedirect( orderReceivedUrl || context.config.redirect );
|
||||||
/**
|
|
||||||
* Notice how this step initiates a redirect to a new page using a plain
|
|
||||||
* URL as new location. This process does not send any details about the
|
|
||||||
* approved order or billed customer.
|
|
||||||
* Also, due to the redirect starting _instantly_ there should be no other
|
|
||||||
* logic scheduled after calling `await onApprove()`;
|
|
||||||
*/
|
|
||||||
|
|
||||||
window.location.href = orderReceivedUrl
|
|
||||||
? orderReceivedUrl
|
|
||||||
: context.config.redirect;
|
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue