@paypal/checkout-components 5.0.409-alpha-cc8673c.0 → 5.0.411

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/globals.js CHANGED
@@ -23,6 +23,7 @@ module.exports = {
23
23
  __URI__: {
24
24
  __CHECKOUT__: "/checkoutnow",
25
25
  __BUTTONS__: "/smart/buttons",
26
+ __SAVED_PAYMENT_METHODS__: "/smart/saved-payment-methods",
26
27
  __PIXEL__: "/smart/pixel",
27
28
  __MENU__: "/smart/menu",
28
29
  __QRCODE__: "/smart/qrcode",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.409-alpha-cc8673c.0",
3
+ "version": "5.0.411",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,6 +20,7 @@ declare var __PAYPAL_CHECKOUT__: {|
20
20
  __WALLET__: string,
21
21
  __PAYMENT_FIELDS__: string,
22
22
  __MESSAGE_MODAL__: string,
23
+ __SAVED_PAYMENT_METHODS__: string,
23
24
  |},
24
25
  |};
25
26
 
@@ -0,0 +1,15 @@
1
+ /* @flow */
2
+
3
+ import type { LazyExport } from "../types";
4
+ import {
5
+ getSavedPaymentMethodsComponent,
6
+ type SavedPaymentMethodsComponent,
7
+ } from "../zoid/saved-payment-methods";
8
+
9
+ export const SavedPaymentMethods: LazyExport<SavedPaymentMethodsComponent> = {
10
+ __get__: () => getSavedPaymentMethodsComponent(),
11
+ };
12
+
13
+ export function setup() {
14
+ getSavedPaymentMethodsComponent();
15
+ }
@@ -57,16 +57,17 @@ export const logLatencyInstrumentationPhase = ({
57
57
  };
58
58
 
59
59
  export const prepareInstrumentationPayload = (
60
- buttonSessionID: string
60
+ buttonSessionID: string,
61
+ component: "buttons" | "saved-payment-methods"
61
62
  ): InstrumentationPayload => {
62
63
  const timeOrigin = getNavigationTimeOrigin();
63
64
  const renderStartTime = getStartTimeFromMark({
64
65
  buttonSessionID,
65
- phase: "buttons-first-render",
66
+ phase: `${component}-first-render`,
66
67
  });
67
68
  const renderEndTime = getStartTimeFromMark({
68
69
  buttonSessionID,
69
- phase: "buttons-first-render-end",
70
+ phase: `${component}-first-render-end`,
70
71
  });
71
72
  return {
72
73
  comp: {
@@ -31,25 +31,34 @@ export function destroy(err?: mixed) {
31
31
  export const ThreeDomainSecureClient: LazyExport<ThreeDomainSecureComponentInterface> =
32
32
  {
33
33
  __get__: () => {
34
- const accessToken = getSDKToken() || getUserIDToken();
35
- const threeDomainSecureInstance = new ThreeDomainSecureComponent({
36
- logger: getLogger(),
37
- restClient: new RestClient({ accessToken }),
38
- graphQLClient: new GraphQLClient({
39
- baseURL:
40
- getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX,
41
- accessToken,
42
- }),
43
- // $FlowIssue ZalgoPromise vs Promise
44
- sdkConfig: {
45
- authenticationToken: accessToken,
46
- paypalApiDomain: getPayPalAPIDomain(),
47
- clientID: getClientID(),
48
- },
49
- });
34
+ let threeDomainSecureInstance;
35
+ const getThreeDomainSecureInstance = () => {
36
+ if (!threeDomainSecureInstance) {
37
+ const accessToken = getSDKToken() || getUserIDToken();
38
+ threeDomainSecureInstance = new ThreeDomainSecureComponent({
39
+ logger: getLogger(),
40
+ restClient: new RestClient({ accessToken }),
41
+ graphQLClient: new GraphQLClient({
42
+ baseURL:
43
+ getEnv() === "production" ? BRAINTREE_PROD : BRAINTREE_SANDBOX,
44
+ accessToken,
45
+ }),
46
+ // $FlowIssue ZalgoPromise vs Promise
47
+ sdkConfig: {
48
+ authenticationToken: accessToken,
49
+ paypalApiDomain: getPayPalAPIDomain(),
50
+ clientID: getClientID(),
51
+ },
52
+ });
53
+ }
54
+
55
+ return threeDomainSecureInstance;
56
+ };
57
+
50
58
  return {
51
- isEligible: (payload) => threeDomainSecureInstance.isEligible(payload),
52
- show: () => threeDomainSecureInstance.show(),
59
+ isEligible: (payload) =>
60
+ getThreeDomainSecureInstance().isEligible(payload),
61
+ show: () => getThreeDomainSecureInstance().show(),
53
62
  };
54
63
  },
55
64
  };
@@ -4,9 +4,10 @@ import {
4
4
  getLogger,
5
5
  getPayPalAPIDomain,
6
6
  getSDKToken,
7
+ getUserIDToken,
7
8
  getClientID,
8
9
  } from "@paypal/sdk-client/src";
9
- import { describe, expect, vi } from "vitest";
10
+ import { beforeEach, describe, expect, vi } from "vitest";
10
11
  import { destroy as zoidDestroy } from "@krakenjs/zoid/src";
11
12
 
12
13
  import { ThreeDomainSecureComponent } from "./component";
@@ -21,6 +22,10 @@ vi.mock("./api");
21
22
  vi.mock("./utils");
22
23
 
23
24
  describe("ThreeDomainSecure interface", () => {
25
+ beforeEach(() => {
26
+ vi.clearAllMocks();
27
+ });
28
+
24
29
  it("should setup and destroy", () => {
25
30
  setup();
26
31
  expect(getThreeDS).toHaveBeenCalledTimes(1);
@@ -34,6 +39,7 @@ describe("ThreeDomainSecure interface", () => {
34
39
  it("should create and return instance of ThreeDomainSecureClient only on dev environment", async () => {
35
40
  vi.mocked(getEnv).mockReturnValue("stage");
36
41
  vi.mocked(getSDKToken).mockReturnValue("test-token");
42
+ vi.mocked(getUserIDToken).mockReturnValue(undefined);
37
43
  vi.mocked(getPayPalAPIDomain).mockReturnValue("test-domain");
38
44
  vi.mocked(getClientID).mockReturnValue("test-client-id");
39
45
 
@@ -85,4 +91,15 @@ describe("ThreeDomainSecure interface", () => {
85
91
  },
86
92
  });
87
93
  });
94
+
95
+ it("should not throw during __get__ when sdk token is missing", () => {
96
+ vi.mocked(getEnv).mockReturnValue("stage");
97
+ vi.mocked(getSDKToken).mockReturnValue(undefined);
98
+ vi.mocked(getUserIDToken).mockReturnValue(undefined);
99
+ vi.mocked(getPayPalAPIDomain).mockReturnValue("test-domain");
100
+ vi.mocked(getClientID).mockReturnValue("test-client-id");
101
+
102
+ expect(() => ThreeDomainSecureClient.__get__()).not.toThrow();
103
+ expect(ThreeDomainSecureComponent).not.toHaveBeenCalled();
104
+ });
88
105
  });
package/src/types.js CHANGED
@@ -70,7 +70,6 @@ export type Experiment = {|
70
70
  paypalCreditButtonCreateVaultSetupTokenExists?: boolean,
71
71
  isPaylaterCobrandedLabelEnabled?: boolean,
72
72
  isPaylaterCobrandedLabelRandomizationEnabled?: boolean,
73
- isBfcacheEnabled?: boolean,
74
73
  |};
75
74
 
76
75
  export type Requires = {|
@@ -513,12 +513,12 @@ export type ButtonExtensions = {|
513
513
  resume: () => void,
514
514
  |};
515
515
 
516
- type ShowPayPalAppSwitchOverlay = {|
516
+ export type ShowPayPalAppSwitchOverlay = {|
517
517
  focus: () => void,
518
518
  close: () => void,
519
519
  |};
520
520
 
521
- type HidePayPalAppSwitchOverlay = {|
521
+ export type HidePayPalAppSwitchOverlay = {|
522
522
  close: () => void,
523
523
  |};
524
524
 
@@ -589,7 +589,9 @@ export type ButtonProps = {|
589
589
  hashChangeHandler: (event: any) => void,
590
590
  listenForVisibilityChange: () => void,
591
591
  removeListenerForVisibilityChanges: () => void,
592
+ // Not passed to child iframe
592
593
  visibilityChangeHandler: () => void,
594
+
593
595
  showPayPalAppSwitchOverlay: (args: ShowPayPalAppSwitchOverlay) => void,
594
596
  hidePayPalAppSwitchOverlay: (args: HidePayPalAppSwitchOverlay) => void,
595
597
 
@@ -497,8 +497,8 @@ const generateRebrandedDisableMaxHeightStyles = (): string => {
497
497
  .${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT},
498
498
  .${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.SPACE} {
499
499
  font-size: ${fontSize}px;
500
- position: relative;
501
500
  }
501
+ }
502
502
  `;
503
503
  })
504
504
  .join("\n");
@@ -572,7 +572,6 @@ const generateRebrandedButtonSizeStyles = ({
572
572
  BUTTON_NUMBER.MULTIPLE
573
573
  } .${CLASS.SPACE} {
574
574
  font-size: ${fontSize}px;
575
- position: relative;
576
575
  }
577
576
 
578
577
  .${CLASS.BUTTON_ROW}.${CLASS.NUMBER}-${BUTTON_NUMBER.MULTIPLE} .${
@@ -681,7 +680,6 @@ const generateRebrandedButtonSizeStyles = ({
681
680
  .${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT},
682
681
  .${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.SPACE} {
683
682
  font-size: ${fontSize}px;
684
- position: relative;
685
683
  }
686
684
 
687
685
  .${CLASS.BUTTON_ROW} .${CLASS.BUTTON_REBRAND} .${CLASS.TEXT} {
@@ -107,8 +107,8 @@ import {
107
107
  getButtonSize,
108
108
  getButtonExperiments,
109
109
  getModal,
110
- isEagerOrderCreationEnabled,
111
110
  sendPostRobotMessageToButtonIframe,
111
+ isEagerOrderCreationEnabled,
112
112
  } from "./util";
113
113
 
114
114
  export type ButtonsComponent = ZoidComponent<
@@ -128,8 +128,6 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
128
128
  url: () => `${getPayPalDomain()}${__PAYPAL_CHECKOUT__.__URI__.__BUTTONS__}`,
129
129
 
130
130
  domain: getPayPalDomainRegex(),
131
- enableBfcache: Boolean(getButtonExperiments()?.isBfcacheEnabled),
132
-
133
131
  getExtensions: (parent) => {
134
132
  return {
135
133
  hasReturned: () => {
@@ -192,7 +190,10 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
192
190
  phase: "buttons-first-render-end",
193
191
  });
194
192
  try {
195
- const cplPhases = prepareInstrumentationPayload(buttonSessionID);
193
+ const cplPhases = prepareInstrumentationPayload(
194
+ buttonSessionID,
195
+ "buttons"
196
+ );
196
197
  const cplLatencyMetrics = {
197
198
  [FPTI_KEY.STATE]: "CPL_LATENCY_METRICS",
198
199
  [FPTI_KEY.TRANSITION]: "process_client_metrics",
@@ -460,20 +461,6 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
460
461
  },
461
462
  },
462
463
 
463
- onBfcacheRestore: {
464
- type: "function",
465
- sendToChild: false,
466
- queryParam: false,
467
- value:
468
- () =>
469
- ({ cachedDurationMs } = {}) => {
470
- sendPostRobotMessageToButtonIframe({
471
- eventName: "bfcache_restore",
472
- payload: { cachedDurationMs },
473
- });
474
- },
475
- },
476
-
477
464
  // allowBillingPayments prop is used by Honey Extension to render the one-click button
478
465
  // with payment methods & to use the payment methods instead of the Billing Agreement
479
466
  allowBillingPayments: {
@@ -410,7 +410,6 @@ export const sendPostRobotMessageToButtonIframe = ({
410
410
  if (iframes[i].name.includes("zoid__paypal_buttons")) {
411
411
  postRobotSend(iframes[i].contentWindow, eventName, payload, {
412
412
  domain: getPayPalDomain(),
413
- fireAndForget: true,
414
413
  });
415
414
  }
416
415
  }
@@ -55,8 +55,6 @@ export function getCheckoutComponent(): CheckoutComponent {
55
55
  },
56
56
  },
57
57
 
58
- enableBfcache: false,
59
-
60
58
  defaultContext: supportsPopups() ? CONTEXT.POPUP : CONTEXT.IFRAME,
61
59
 
62
60
  domain: getPayPalDomainRegex(),