mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Revert deleted data client token for vault v2
This commit is contained in:
parent
564eec1ea4
commit
c6a2855d3d
2 changed files with 45 additions and 0 deletions
|
@ -1,10 +1,31 @@
|
||||||
import { loadScript } from '@paypal/paypal-js';
|
import { loadScript } from '@paypal/paypal-js';
|
||||||
|
import dataClientIdAttributeHandler from '../DataClientIdAttributeHandler';
|
||||||
import widgetBuilder from '../Renderer/WidgetBuilder';
|
import widgetBuilder from '../Renderer/WidgetBuilder';
|
||||||
import { processConfig } from './ConfigProcessor';
|
import { processConfig } from './ConfigProcessor';
|
||||||
|
|
||||||
const loadedScripts = new Map();
|
const loadedScripts = new Map();
|
||||||
const scriptPromises = new Map();
|
const scriptPromises = new Map();
|
||||||
|
|
||||||
|
const handleDataClientIdAttribute = async ( scriptOptions, config ) => {
|
||||||
|
if (
|
||||||
|
config.data_client_id?.set_attribute &&
|
||||||
|
config.vault_v3_enabled !== true
|
||||||
|
) {
|
||||||
|
return new Promise( ( resolve, reject ) => {
|
||||||
|
dataClientIdAttributeHandler(
|
||||||
|
scriptOptions,
|
||||||
|
config.data_client_id,
|
||||||
|
( paypal ) => {
|
||||||
|
widgetBuilder.setPaypal( paypal );
|
||||||
|
resolve( paypal );
|
||||||
|
},
|
||||||
|
reject
|
||||||
|
);
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
export const loadPayPalScript = async ( namespace, config ) => {
|
export const loadPayPalScript = async ( namespace, config ) => {
|
||||||
if ( ! namespace ) {
|
if ( ! namespace ) {
|
||||||
throw new Error( 'Namespace is required' );
|
throw new Error( 'Namespace is required' );
|
||||||
|
@ -27,6 +48,14 @@ export const loadPayPalScript = async ( namespace, config ) => {
|
||||||
'data-namespace': namespace,
|
'data-namespace': namespace,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dataClientIdResult = await handleDataClientIdAttribute(
|
||||||
|
scriptOptions,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
if ( dataClientIdResult ) {
|
||||||
|
return dataClientIdResult;
|
||||||
|
}
|
||||||
|
|
||||||
const scriptPromise = new Promise( ( resolve, reject ) => {
|
const scriptPromise = new Promise( ( resolve, reject ) => {
|
||||||
loadScript( scriptOptions )
|
loadScript( scriptOptions )
|
||||||
.then( ( script ) => {
|
.then( ( script ) => {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
import dataClientIdAttributeHandler from '../DataClientIdAttributeHandler';
|
||||||
import { loadScript } from '@paypal/paypal-js';
|
import { loadScript } from '@paypal/paypal-js';
|
||||||
import widgetBuilder from '../Renderer/WidgetBuilder';
|
import widgetBuilder from '../Renderer/WidgetBuilder';
|
||||||
import merge from 'deepmerge';
|
import merge from 'deepmerge';
|
||||||
import { keysToCamelCase } from './Utils';
|
import { keysToCamelCase } from './Utils';
|
||||||
|
import { getCurrentPaymentMethod } from './CheckoutMethodState';
|
||||||
|
|
||||||
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
||||||
const scriptOptionsMap = {};
|
const scriptOptionsMap = {};
|
||||||
|
@ -69,6 +71,20 @@ export const loadPaypalScript = ( config, onLoaded, onError = null ) => {
|
||||||
scriptOptions = merge( scriptOptions, config.script_attributes );
|
scriptOptions = merge( scriptOptions, config.script_attributes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load PayPal script for special case with data-client-token
|
||||||
|
if (
|
||||||
|
config.data_client_id?.set_attribute &&
|
||||||
|
config.vault_v3_enabled !== '1'
|
||||||
|
) {
|
||||||
|
dataClientIdAttributeHandler(
|
||||||
|
scriptOptions,
|
||||||
|
config.data_client_id,
|
||||||
|
callback,
|
||||||
|
errorCallback
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Adds data-user-id-token to script options.
|
// Adds data-user-id-token to script options.
|
||||||
const userIdToken = config?.save_payment_methods?.id_token;
|
const userIdToken = config?.save_payment_methods?.id_token;
|
||||||
if ( userIdToken && config?.user?.is_logged === true ) {
|
if ( userIdToken && config?.user?.is_logged === true ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue