mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Add docs
This commit is contained in:
parent
090a140e7e
commit
9b12abbd59
2 changed files with 24 additions and 2 deletions
|
@ -53,6 +53,11 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
|
|||
}, [ isSandbox, products, options, onboardingUrl ] );
|
||||
|
||||
useEffect( () => {
|
||||
/**
|
||||
* The partner.js script initializes all onboarding buttons in the onload event.
|
||||
* When no buttons are present, a JS error is displayed; i.e. we should load this script
|
||||
* only when the button is ready (with a valid href and data-attributes).
|
||||
*/
|
||||
if ( ! onboardingUrlState ) {
|
||||
return;
|
||||
}
|
||||
|
@ -66,6 +71,14 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
|
|||
document.body.appendChild( script );
|
||||
|
||||
return () => {
|
||||
/**
|
||||
* When the component is unmounted, remove the partner.js script, as well as the
|
||||
* dynamic scripts it loaded (signup-js and rampConfig-js)
|
||||
*
|
||||
* This is important, as the onboarding button is only initialized during the onload
|
||||
* event of those scripts; i.e. we need to load the scripts again, when the button is
|
||||
* rendered again.
|
||||
*/
|
||||
const onboardingScripts = [
|
||||
'partner-js',
|
||||
'signup-js',
|
||||
|
@ -85,6 +98,15 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
|
|||
const setCompleteHandler = useCallback(
|
||||
( environment ) => {
|
||||
const onComplete = async ( authCode, sharedId ) => {
|
||||
/**
|
||||
* Until now, the full page is blocked by PayPal's semi-transparent, black overlay.
|
||||
* But at this point, the overlay is removed, while we process the sharedId and
|
||||
* authCode via a REST call.
|
||||
*
|
||||
* Note: The REST response is irrelevant, since PayPal will most likely refresh this
|
||||
* frame before the REST endpoint returns a value. Using "withActivity" is more of a
|
||||
* visual cue to the user that something is still processing in the background.
|
||||
*/
|
||||
startActivity(
|
||||
ACTIVITIES.OAUTH_VERIFY,
|
||||
'Validating the connection details'
|
||||
|
@ -106,6 +128,7 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
|
|||
MiniBrowser.onOnboardComplete = onComplete;
|
||||
};
|
||||
|
||||
// Ensure the onComplete handler is not removed by a PayPal init script.
|
||||
timerRef.current = setInterval( addHandler, 250 );
|
||||
},
|
||||
[ authenticateWithOAuth, startActivity ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue