mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Try to fix Google Pay in the editor
This commit is contained in:
parent
be6b8a39ec
commit
3171e943ba
12 changed files with 487 additions and 97 deletions
|
@ -0,0 +1,32 @@
|
|||
import { useState, useEffect } from '@wordpress/element';
|
||||
import { loadCustomScript } from '@paypal/paypal-js';
|
||||
|
||||
const useGooglepayScript = ( buttonConfig, isPayPalLoaded ) => {
|
||||
const [ isGooglepayLoaded, setIsGooglepayLoaded ] = useState( false );
|
||||
|
||||
useEffect( () => {
|
||||
const loadGooglepayScript = async () => {
|
||||
if ( ! isPayPalLoaded ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! buttonConfig || ! buttonConfig.sdk_url ) {
|
||||
console.error( 'Invalid buttonConfig or missing sdk_url' );
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await loadCustomScript( { url: buttonConfig.sdk_url } );
|
||||
setIsGooglepayLoaded( true );
|
||||
} catch ( error ) {
|
||||
console.error( 'Failed to load Googlepay script:', error );
|
||||
}
|
||||
};
|
||||
|
||||
loadGooglepayScript();
|
||||
}, [ buttonConfig, isPayPalLoaded ] );
|
||||
|
||||
return isGooglepayLoaded;
|
||||
};
|
||||
|
||||
export default useGooglepayScript;
|
Loading…
Add table
Add a link
Reference in a new issue