Skip to content

Commit

Permalink
Merge pull request #465 from paypal/DTPPCPSDK-1482
Browse files Browse the repository at this point in the history
Set data-js-sdk-library default value
  • Loading branch information
nbierdeman authored Mar 19, 2024
2 parents f829b81 + 9d90088 commit 199e978
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brown-elephants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@paypal/paypal-js": patch
---

Set default data-js-sdk-library value
2 changes: 1 addition & 1 deletion packages/paypal-js/src/load-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("loadScript()", () => {

// simulate the script already being loaded
document.head.innerHTML =
'<script src="https://www.paypal.com/sdk/js?client-id=test"></script>';
'<script src="https://www.paypal.com/sdk/js?client-id=test" data-js-sdk-library="paypal-js"></script>';
vi.stubGlobal("paypal", { version: "5" });

const response = await loadScript({ clientId: "test" });
Expand Down
4 changes: 4 additions & 0 deletions packages/paypal-js/src/load-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function loadScript(
const namespace = attributes["data-namespace"] || "paypal";
const existingWindowNamespace = getPayPalWindowNamespace(namespace);

if (!attributes["data-js-sdk-library"]) {
attributes["data-js-sdk-library"] = "paypal-js";
}

// resolve with the existing global paypal namespace when a script with the same params already exists
if (findScript(url, attributes) && existingWindowNamespace) {
return PromisePonyfill.resolve(existingWindowNamespace);
Expand Down

0 comments on commit 199e978

Please sign in to comment.