From 45f4e68cf93edd666a14b4f044a8ae58e34d7d96 Mon Sep 17 00:00:00 2001 From: yeul Date: Tue, 5 Sep 2023 09:10:48 -0400 Subject: [PATCH] update getPayPalDomain function --- src/utils/sdk.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils/sdk.js b/src/utils/sdk.js index c928213b6c..4bf08d3a9c 100644 --- a/src/utils/sdk.js +++ b/src/utils/sdk.js @@ -204,10 +204,20 @@ export const isScriptBeingDestroyed = () => { }; export function getPayPalDomain() { - const testEnviroment = window.__TEST_ENV__ ?? __MESSAGES__.__TEST_ENV__; - if (testEnviroment && getEnv() !== 'production' && getEnv() !== 'sandbox') { - return testEnviroment; - } else if (__MESSAGES__.__TARGET__ === 'SDK') { + if (getEnv() !== 'production' && getEnv() !== 'sandbox') { + const testEnviroment = window.__TEST_ENV__ ?? __MESSAGES__.__TEST_ENV__; + + if (testEnviroment) { + return testEnviroment; + } + + // eslint-disable-next-line security/detect-unsafe-regex + if (window.location.origin.match(/\.paypal\.com(:\d+)?$/)) { + return window.location.origin; + } + } + + if (__MESSAGES__.__TARGET__ === 'SDK') { return getSDKPayPalDomain(); } else { const domain = __MESSAGES__.__DOMAIN__[`__${getEnv().toUpperCase()}__`];