From e974e58368dcb83bcdf53ee2fb1aae3bc3f322c1 Mon Sep 17 00:00:00 2001 From: Dustin Jones Date: Tue, 21 May 2024 17:18:45 -0400 Subject: [PATCH] feat: add compatibility with window alias strategy --- src/setup.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/setup.js b/src/setup.js index 5e08e62f..6323d301 100644 --- a/src/setup.js +++ b/src/setup.js @@ -4,6 +4,7 @@ import { destroyElement } from "@krakenjs/belter/src"; import { getVersion } from "./global"; import { getSDKScript, getNamespace } from "./script"; +import { getLogger } from "./logger"; export type SetupComponent = {| name: string, @@ -21,7 +22,13 @@ export function setupSDK(components: $ReadOnlyArray>) { const existingVersion = existingNamespace && existingNamespace.version; if (existingNamespace) { - if (existingNamespace[INTERNAL_DESTROY_KEY]) { + if (existingVersion.startsWith("6.")) { + getLogger().info("setup_sdk_v6_integration_found", { + v5Version: version, + v6Version: existingVersion, + }); + delete window[namespace]; + } else if (existingNamespace[INTERNAL_DESTROY_KEY]) { existingNamespace[INTERNAL_DESTROY_KEY]( new Error( `New SDK instance loaded, existing instance destroyed (${namespace} / ${version})` @@ -42,6 +49,10 @@ export function setupSDK(components: $ReadOnlyArray>) { window[namespace] = window[namespace] || {}; window[namespace].version = version; + if (namespace === "paypal" && window.__paypal_sdk__?.v6) { + window.paypal.v6 = window.__paypal_sdk__.v6; + } + const destroyers = []; for (const { name, requirer, setupHandler } of components) {