Skip to content

Commit

Permalink
Update 'payment-flow' param for web-sdk bridge to be optional (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjopa authored Oct 22, 2024
1 parent 1bd5666 commit fb121b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions server/meta.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ const sdkMetaList = [
},
},
],
[
{
url: "https://www.paypal.com/web-sdk/v6/bridge?",
origin: "https://www.whiterabbitvintagemarket.com",
version: "6.4.1",
"payment-flow": "popup",
debug: "false",
},
// no attributes
{},
],
];

// $FlowIgnore[prop-missing] missing each property for test
Expand Down
4 changes: 2 additions & 2 deletions server/meta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function validateWebSDKUrl({ pathname, query }) {
);
}

// validate the payment-flow parameter
// validate the optional payment-flow parameter
const validPaymentFlows = ["popup", "modal", "payment-handler"];
if (
query["payment-flow"] === undefined ||
query["payment-flow"] &&
!validPaymentFlows.includes(query["payment-flow"])
) {
throw new Error(
Expand Down
29 changes: 29 additions & 0 deletions server/meta.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,35 @@ test("should not error when the optional debug parameter is missing", () => {
}
});

test("should not error when the optional payment-flow parameter is missing", () => {
const sdkUrl =
"https://www.paypal.com/web-sdk/v6/bridge?version=1.2.3&origin=https%3A%2F%2Fwww.example.com%3A8000&debug=false";
const sdkUID = "abc123";

const { getSDKLoader } = unpackSDKMeta(
Buffer.from(
JSON.stringify({
url: sdkUrl,
attrs: {
"data-uid": sdkUID,
},
})
).toString("base64")
);

const $ = cheerio.load(getSDKLoader());
const script = $("script");
const src = script.attr("src");
const uid = script.attr("data-uid");

if (src !== sdkUrl) {
throw new Error(`Expected script url to be ${sdkUrl} - got ${src}`);
}
if (uid !== sdkUID) {
throw new Error(`Expected data UID be ${sdkUID} - got ${uid}`);
}
});

test("should error when the version parameter is missing", () => {
const sdkUrl =
"https://www.paypal.com/web-sdk/v6/bridge?origin=https%3A%2F%2Fwww.example.com%3A8000&payment-flow=payment-handler";
Expand Down

0 comments on commit fb121b1

Please sign in to comment.