@paypal/checkout-components 5.0.422 → 5.0.423

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.422",
3
+ "version": "5.0.423",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -662,6 +662,7 @@ export type ButtonProps = {|
662
662
  hideSubmitButtonForCardForm?: boolean,
663
663
  userAgent: string,
664
664
  browserContext?: string,
665
+ merchantDomain?: string,
665
666
  buttonColor: ButtonColor,
666
667
  |};
667
668
 
@@ -109,6 +109,7 @@ import {
109
109
  getModal,
110
110
  sendPostRobotMessageToButtonIframe,
111
111
  isEagerOrderCreationEnabled,
112
+ resolveMerchantDomain,
112
113
  } from "./util";
113
114
 
114
115
  export type ButtonsComponent = ZoidComponent<
@@ -888,6 +889,13 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
888
889
  queryParam: true,
889
890
  },
890
891
 
892
+ merchantDomain: {
893
+ type: "string",
894
+ required: false,
895
+ sendToChild: true,
896
+ value: ({ props }) => resolveMerchantDomain(props.merchantDomain),
897
+ },
898
+
891
899
  intent: {
892
900
  type: "string",
893
901
  queryParam: true,
@@ -27,6 +27,7 @@ import {
27
27
  getFundingEligibility,
28
28
  getSDKToken,
29
29
  getIntent,
30
+ isPayPalDomain,
30
31
  } from "@paypal/sdk-client/src";
31
32
  import { FUNDING, FPTI_KEY, INTENT } from "@paypal/sdk-constants/src";
32
33
  import { getRefinedFundingEligibility } from "@paypal/funding-components/src";
@@ -426,3 +427,14 @@ export const isEagerOrderCreationEnabled = (
426
427
  experiment.spbEagerOrderCreation
427
428
  );
428
429
  };
430
+
431
+ // merchantDomain is only accepted on PayPal-hosted flows (e.g. NCPS).
432
+ // There the page origin resolves to a PayPal Domain, so the hosting service must supply
433
+ // the true merchant origin. On merchant-hosted pages browser origin is alreadyy the merchant's,
434
+ // so an explictly passed value is rejected
435
+ export function resolveMerchantDomain(merchantDomain: ?string): ?string {
436
+ if (merchantDomain && !isPayPalDomain()) {
437
+ throw new Error("merchantDomain can only be passed on PayPal-hosted flows");
438
+ }
439
+ return merchantDomain || undefined;
440
+ }
@@ -0,0 +1,40 @@
1
+ /* @flow */
2
+
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { isPayPalDomain } from "@paypal/sdk-client/src";
5
+
6
+ import { resolveMerchantDomain } from "./util";
7
+
8
+ vi.mock("@paypal/sdk-client/src", () => ({
9
+ isPayPalDomain: vi.fn(),
10
+ }));
11
+
12
+ describe("resolveMerchantDomain", () => {
13
+ it("returns the merchantDomain on a PayPal-hosted page", () => {
14
+ vi.mocked(isPayPalDomain).mockReturnValue(true);
15
+
16
+ expect(resolveMerchantDomain("https://merchant.example.com")).toBe(
17
+ "https://merchant.example.com"
18
+ );
19
+ });
20
+
21
+ it("returns undefined on a PayPal-hosted page when no merchantDomain is provided", () => {
22
+ vi.mocked(isPayPalDomain).mockReturnValue(true);
23
+
24
+ expect(resolveMerchantDomain()).toBeUndefined();
25
+ });
26
+
27
+ it("returns undefined on a merchant-hosted page when no merchantDomain is provided", () => {
28
+ vi.mocked(isPayPalDomain).mockReturnValue(false);
29
+
30
+ expect(resolveMerchantDomain()).toBeUndefined();
31
+ });
32
+
33
+ it("throws when a merchantDomain is passed on a non-PayPal (merchant-hosted) page", () => {
34
+ vi.mocked(isPayPalDomain).mockReturnValue(false);
35
+
36
+ expect(() => resolveMerchantDomain("https://merchant.example.com")).toThrow(
37
+ "merchantDomain can only be passed on PayPal-hosted flows"
38
+ );
39
+ });
40
+ });