Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
paypalSdk = getPayPalSDKMock();

jest.spyOn(loader, 'loadScript').mockImplementation(() => {
(window as BigCommercePaymentsHostWindow).paypal = paypalSdk;
(window as BigCommercePaymentsHostWindow).bigCommercePaymentsPayPalSDK = paypalSdk;

return Promise.resolve();
});
Expand All @@ -31,7 +31,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
});

afterEach(() => {
(window as BigCommercePaymentsHostWindow).paypal = undefined;
(window as BigCommercePaymentsHostWindow).bigCommercePaymentsPayPalSDK = undefined;
});

it('throws an error if initializationData is missing', async () => {
Expand All @@ -55,6 +55,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -100,6 +102,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -124,6 +127,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -148,6 +152,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -172,6 +177,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -196,6 +202,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand Down Expand Up @@ -236,6 +243,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -252,6 +260,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -268,6 +277,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -292,6 +302,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand Down Expand Up @@ -321,6 +332,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -347,6 +359,7 @@ describe('BigCommercePaymentsScriptLoader', () => {
const paypalSdkAttributes = {
'data-client-token': paymentMethod.clientToken,
'data-partner-attribution-id': paymentMethod.initializationData.attributionId,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
};

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
Expand All @@ -371,7 +384,7 @@ describe('BigCommercePaymentsScriptLoader', () => {

const paypalSdkScriptSrc =
'https://www.paypal.com/sdk/js?client-id=abc&disable-funding=card%2Ccredit%2Cpaylater%2Cvenmo&commit=false&components=buttons%2Chosted-fields%2Cpayment-fields%2Clegal&currency=USD&intent=capture';
const paypalSdkAttributes = {};
const paypalSdkAttributes = { 'data-namespace': 'bigCommercePaymentsPayPalSDK' };

expect(loader.loadScript).toHaveBeenCalledWith(paypalSdkScriptSrc, {
async: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class BigCommercePaymentsScriptLoader {
paypalSdkScriptConfig: BigCommercePaymentsScriptParams,
forceLoad = false,
): Promise<PayPalSDK> {
if (!this.window.paypal || forceLoad) {
if (!this.window.bigCommercePaymentsPayPalSDK || forceLoad) {
const options = this.transformConfig<BigCommercePaymentsScriptParams['options']>(
paypalSdkScriptConfig.options,
);
Expand All @@ -57,11 +57,11 @@ export default class BigCommercePaymentsScriptLoader {
await this.scriptLoader.loadScript(scriptSrc, { async: true, attributes });
}

if (!this.window.paypal) {
if (!this.window.bigCommercePaymentsPayPalSDK) {
throw new PaymentMethodClientUnavailableError();
}

return this.window.paypal;
return this.window.bigCommercePaymentsPayPalSDK;
}

private getPayPalSdkScriptConfigOrThrow(
Expand Down Expand Up @@ -143,6 +143,7 @@ export default class BigCommercePaymentsScriptLoader {
attributes: {
'data-partner-attribution-id': attributionId,
'data-client-token': clientToken,
'data-namespace': 'bigCommercePaymentsPayPalSDK',
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export interface BigCommercePaymentsScriptParams {
'data-client-metadata-id'?: string;
'data-partner-attribution-id'?: string;
'data-user-id-token'?: string;
'data-namespace'?: string;
};
}

Expand All @@ -236,7 +237,7 @@ export type ComponentsScriptType = Array<
>;

export interface BigCommercePaymentsHostWindow extends Window {
paypal?: PayPalSDK;
bigCommercePaymentsPayPalSDK?: PayPalSDK;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('BigCommercePaymentsFastlaneUtils', () => {
});

afterEach(() => {
(window as PayPalHostWindow).paypalFastlane = undefined;
(window as PayPalHostWindow).bigCommercePaymentsFastlane = undefined;

jest.resetAllMocks();
jest.restoreAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ export default class BigCommercePaymentsFastlaneUtils {
window.localStorage.setItem('axoEnv', 'sandbox'); // TODO: remove if this key does not use on PayPal side
}

if (!this.window.paypalFastlane) {
if (!this.window.bigCommercePaymentsFastlane) {
const defaultStyles = {
root: {
backgroundColorPrimary: 'transparent',
},
};

this.window.paypalFastlane = await paypalFastlaneSdk.Fastlane({
this.window.bigCommercePaymentsFastlane = await paypalFastlaneSdk.Fastlane({
styles: styles || defaultStyles,
});
}

return this.window.paypalFastlane;
return this.window.bigCommercePaymentsFastlane;
}

getPayPalFastlaneOrThrow(): PayPalFastlane {
if (!this.window.paypalFastlane) {
if (!this.window.bigCommercePaymentsFastlane) {
throw new PaymentMethodClientUnavailableError();
}

return this.window.paypalFastlane;
return this.window.bigCommercePaymentsFastlane;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export interface BigCommercePaymentsInitializationData {
*
*/
export interface PayPalHostWindow extends Window {
paypalFastlane?: PayPalFastlane;
paypalFastlaneSdk?: PayPalFastlaneSdk;
paypalMessages?: PayPalMessagesSdk;
paypalApms?: PayPalApmSdk;
paypalGooglePay?: PayPalGooglePaySdk;
bigCommercePaymentsFastlane?: PayPalFastlane;
bigCommercePaymentsFastlaneSdk?: PayPalFastlaneSdk;
bigCommercePaymentsMessages?: PayPalMessagesSdk;
bigCommercePaymentsApms?: PayPalApmSdk;
bigCommercePaymentsGooglePay?: PayPalGooglePaySdk;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions packages/bigcommerce-payments-utils/src/paypal-sdk-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ describe('PayPalSdkHelper', () => {
subject = new PayPalSdkHelper(loader);

jest.spyOn(loader, 'loadScript').mockImplementation(() => {
(window as PayPalHostWindow).paypalFastlaneSdk = paypalFastlaneSdk;
(window as PayPalHostWindow).paypalMessages = paypalMessagesSdk;
(window as PayPalHostWindow).paypalApms = paypalApmsSdk;
(window as PayPalHostWindow).paypalGooglePay = payPalGooglePaySdk;
(window as PayPalHostWindow).bigCommercePaymentsFastlaneSdk = paypalFastlaneSdk;
(window as PayPalHostWindow).bigCommercePaymentsMessages = paypalMessagesSdk;
(window as PayPalHostWindow).bigCommercePaymentsApms = paypalApmsSdk;
(window as PayPalHostWindow).bigCommercePaymentsGooglePay = payPalGooglePaySdk;

return Promise.resolve();
});
});

afterEach(() => {
(window as PayPalHostWindow).paypalFastlaneSdk = undefined;
(window as PayPalHostWindow).paypalMessages = undefined;
(window as PayPalHostWindow).paypalApms = undefined;
(window as PayPalHostWindow).paypalGooglePay = undefined;
(window as PayPalHostWindow).bigCommercePaymentsFastlaneSdk = undefined;
(window as PayPalHostWindow).bigCommercePaymentsMessages = undefined;
(window as PayPalHostWindow).bigCommercePaymentsApms = undefined;
(window as PayPalHostWindow).bigCommercePaymentsGooglePay = undefined;

jest.clearAllMocks();
});
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('PayPalSdkHelper', () => {
async: true,
attributes: {
'data-client-metadata-id': expectedSessionId,
'data-namespace': 'paypalFastlaneSdk',
'data-namespace': 'bigCommercePaymentsFastlaneSdk',
'data-partner-attribution-id': '1123JLKJASD12',
'data-sdk-client-token': 'asdcvY7XFSQasd',
},
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('PayPalSdkHelper', () => {
async: true,
attributes: {
'data-client-metadata-id': expectedSessionId,
'data-namespace': 'paypalFastlaneSdk',
'data-namespace': 'bigCommercePaymentsFastlaneSdk',
'data-partner-attribution-id': '1123JLKJASD12',
'data-sdk-client-token': 'asdcvY7XFSQasd',
},
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('PayPalSdkHelper', () => {
{
async: true,
attributes: {
'data-namespace': 'paypalMessages',
'data-namespace': 'bigCommercePaymentsMessages',
'data-partner-attribution-id': '1123JLKJASD12',
},
},
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('PayPalSdkHelper', () => {
{
async: true,
attributes: {
'data-namespace': 'paypalGooglePay',
'data-namespace': 'bigCommercePaymentsGooglePay',
'data-client-token': 'asdcvY7XFSQasd',
'data-partner-attribution-id': '1123JLKJASD12',
},
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('PayPalSdkHelper', () => {
{
async: true,
attributes: {
'data-namespace': 'paypalApms',
'data-namespace': 'bigCommercePaymentsApms',
'data-partner-attribution-id': '1123JLKJASD12',
},
},
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('PayPalSdkHelper', () => {
{
async: true,
attributes: {
'data-namespace': 'paypalApms',
'data-namespace': 'bigCommercePaymentsApms',
'data-partner-attribution-id': '1123JLKJASD12',
},
},
Expand All @@ -351,7 +351,7 @@ describe('PayPalSdkHelper', () => {
{
async: true,
attributes: {
'data-namespace': 'paypalApms',
'data-namespace': 'bigCommercePaymentsApms',
'data-partner-attribution-id': '1123JLKJASD12',
},
},
Expand Down
Loading