mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge pull request #2464 from woocommerce/PCP-3374-google-pay-button-not-displayed-in-the-word-press-editor
Fix the Google Pay button in the block Checkout in the editor (3374)
This commit is contained in:
commit
8592213b9a
5 changed files with 100 additions and 10 deletions
|
@ -7,15 +7,25 @@ import { getCurrentPaymentMethod } from './CheckoutMethodState';
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
||||
const options = ( window.ppcpWidgetBuilder = window.ppcpWidgetBuilder || {
|
||||
isLoading: false,
|
||||
onLoadedCallbacks: [],
|
||||
onErrorCallbacks: [],
|
||||
} );
|
||||
const scriptOptionsMap = {};
|
||||
|
||||
const getNamespaceOptions = ( namespace ) => {
|
||||
if ( ! scriptOptionsMap[ namespace ] ) {
|
||||
scriptOptionsMap[ namespace ] = {
|
||||
isLoading: false,
|
||||
onLoadedCallbacks: [],
|
||||
onErrorCallbacks: [],
|
||||
};
|
||||
}
|
||||
return scriptOptionsMap[ namespace ];
|
||||
};
|
||||
|
||||
export const loadPaypalScript = ( config, onLoaded, onError = null ) => {
|
||||
// If PayPal is already loaded call the onLoaded callback and return.
|
||||
if ( typeof paypal !== 'undefined' ) {
|
||||
const dataNamespace = config?.data_namespace || '';
|
||||
const options = getNamespaceOptions( dataNamespace );
|
||||
|
||||
// If PayPal is already loaded for this namespace, call the onLoaded callback and return.
|
||||
if ( typeof window.paypal !== 'undefined' && ! dataNamespace ) {
|
||||
onLoaded();
|
||||
return;
|
||||
}
|
||||
|
@ -90,6 +100,11 @@ export const loadPaypalScript = ( config, onLoaded, onError = null ) => {
|
|||
scriptOptions[ 'data-user-id-token' ] = userIdToken;
|
||||
}
|
||||
|
||||
// Adds data-namespace to script options.
|
||||
if ( dataNamespace ) {
|
||||
scriptOptions.dataNamespace = dataNamespace;
|
||||
}
|
||||
|
||||
// Load PayPal script
|
||||
loadScript( scriptOptions ).then( callback ).catch( errorCallback );
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue