Try to fix Google Pay in the editor

This commit is contained in:
Daniel Dudzic 2024-10-09 16:38:11 +02:00
parent be6b8a39ec
commit 3171e943ba
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
12 changed files with 487 additions and 97 deletions

View file

@ -0,0 +1,26 @@
import { useState, useEffect } from '@wordpress/element';
const useGooglepayConfig = ( namespace, isGooglepayLoaded ) => {
const [ googlePayConfig, setGooglePayConfig ] = useState( null );
useEffect( () => {
const fetchConfig = async () => {
if ( ! isGooglepayLoaded ) {
return;
}
try {
const config = await window[ namespace ].Googlepay().config();
setGooglePayConfig( config );
} catch ( error ) {
console.error( 'Failed to fetch Google Pay config:', error );
}
};
fetchConfig();
}, [ namespace, isGooglepayLoaded ] );
return googlePayConfig;
};
export default useGooglepayConfig;