@paypal/checkout-components 5.0.358 → 5.0.360

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.358",
3
+ "version": "5.0.360",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -272,7 +272,7 @@ export function WalletLabelOld(opts: WalletLabelOptions): ?ChildType {
272
272
  );
273
273
  }
274
274
 
275
- const cspNonce = getCSPNonce();
275
+ const cspNonce = __WEB__ ? getCSPNonce() : undefined;
276
276
 
277
277
  return (
278
278
  <Style nonce={cspNonce} css={css}>
@@ -475,7 +475,7 @@ export function WalletLabel(opts: WalletLabelOptions): ?ChildType {
475
475
  attrs[ATTRIBUTE.PAY_NOW] = true;
476
476
  }
477
477
 
478
- const cspNonce = getCSPNonce();
478
+ const cspNonce = __WEB__ ? getCSPNonce() : undefined;
479
479
 
480
480
  return (
481
481
  <Style nonce={cspNonce} css={css}>
@@ -33,7 +33,7 @@ export function WalletLabel({ ...props }: WalletLabelOptions): ChildType {
33
33
  label = instrument.label;
34
34
  }
35
35
 
36
- const cspNonce = getCSPNonce();
36
+ const cspNonce = __WEB__ ? getCSPNonce() : undefined;
37
37
 
38
38
  return (
39
39
  <Style nonce={cspNonce} css={css}>
package/src/types.js CHANGED
@@ -67,6 +67,7 @@ export type Experiment = {|
67
67
  isPaypalRebrandEnabled?: boolean,
68
68
  defaultBlueButtonColor?: $Values<typeof BUTTON_COLOR>,
69
69
  venmoEnableWebOnNonNativeBrowser?: boolean,
70
+ spbEagerOrderCreation?: boolean,
70
71
  |};
71
72
 
72
73
  export type Requires = {|
@@ -71,6 +71,7 @@ type IndividualButtonProps = {|
71
71
  merchantFundingSource: ?$Values<typeof FUNDING>,
72
72
  instrument: ?WalletInstrument,
73
73
  showPayLabel: boolean,
74
+ showLoadingSpinner?: boolean,
74
75
  |};
75
76
 
76
77
  export function Button({
@@ -95,6 +96,7 @@ export function Button({
95
96
  tagline,
96
97
  userIDToken,
97
98
  vault,
99
+ showLoadingSpinner = false,
98
100
  }: IndividualButtonProps): ElementNode {
99
101
  const { layout, shape, borderRadius } = style;
100
102
  const { isPaypalRebrandEnabled, defaultBlueButtonColor } = experiment;
@@ -307,6 +309,7 @@ export function Button({
307
309
  }}
308
310
  class={[
309
311
  CLASS.BUTTON,
312
+ `${showLoadingSpinner ? CLASS.LOADING : ""}`,
310
313
  `${CLASS.NUMBER}-${i}`,
311
314
  `${CLASS.LAYOUT}-${layout}`,
312
315
  `${CLASS.NUMBER}-${
@@ -127,6 +127,7 @@ function getWalletInstruments({
127
127
  type ButtonsProps = ButtonPropsInputs & {|
128
128
  onClick?: Function,
129
129
  wallet?: ?Wallet,
130
+ showLoadingSpinner?: boolean,
130
131
  |};
131
132
 
132
133
  export function validateButtonProps(props: ButtonPropsInputs) {
@@ -134,7 +135,7 @@ export function validateButtonProps(props: ButtonPropsInputs) {
134
135
  }
135
136
 
136
137
  export function Buttons(props: ButtonsProps): ElementNode {
137
- const { onClick = noop } = props;
138
+ const { onClick = noop, showLoadingSpinner = false } = props;
138
139
  const {
139
140
  applePaySupport,
140
141
  buyerCountry,
@@ -289,6 +290,7 @@ export function Buttons(props: ButtonsProps): ElementNode {
289
290
  vault={vault}
290
291
  instrument={instruments[source]}
291
292
  showPayLabel={showPayLabel}
293
+ showLoadingSpinner={showLoadingSpinner}
292
294
  />
293
295
  ))}
294
296
 
@@ -512,7 +512,7 @@ type HidePayPalAppSwitchOverlay = {|
512
512
 
513
513
  export type ButtonProps = {|
514
514
  // app switch properties
515
- appSwitchWhenAvailable: string,
515
+ appSwitchWhenAvailable: boolean,
516
516
  listenForHashChanges: () => void,
517
517
  removeListenerForHashChanges: () => void,
518
518
  // Not passed to child iframe
@@ -50,7 +50,7 @@ export function PlaceHolder({
50
50
  chars,
51
51
  color = TEXT_COLOR.WHITE,
52
52
  }: PlaceHolderProps): ChildType {
53
- const cspNonce = getCSPNonce();
53
+ const cspNonce = __WEB__ ? getCSPNonce() : undefined;
54
54
 
55
55
  return (
56
56
  <Style nonce={cspNonce} css={css}>
@@ -102,6 +102,7 @@ import {
102
102
  getButtonExperiments,
103
103
  getModal,
104
104
  sendPostRobotMessageToButtonIframe,
105
+ isEagerOrderCreationEnabled,
105
106
  } from "./util";
106
107
 
107
108
  export type ButtonsComponent = ZoidComponent<
@@ -613,6 +614,13 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
613
614
  },
614
615
  },
615
616
 
617
+ eagerOrderCreation: {
618
+ type: "boolean",
619
+ queryParam: true,
620
+ value: ({ props }) =>
621
+ isEagerOrderCreationEnabled(props.appSwitchWhenAvailable),
622
+ },
623
+
616
624
  enableFunding: {
617
625
  type: "array",
618
626
  queryParam: true,
@@ -20,6 +20,8 @@ import { DEFAULT_POPUP_SIZE } from "../checkout";
20
20
  import { Buttons } from "../../ui";
21
21
  import { type ButtonProps } from "../../ui/buttons/props";
22
22
 
23
+ import { isEagerOrderCreationEnabled } from "./util";
24
+
23
25
  type PrerenderedButtonsProps = {|
24
26
  nonce: ?string,
25
27
  props: ZoidProps<ButtonProps>,
@@ -36,6 +38,9 @@ export function PrerenderedButtons({
36
38
  onRenderCheckout,
37
39
  props,
38
40
  }: PrerenderedButtonsProps): ChildType {
41
+ const eagerOrderCreation = isEagerOrderCreationEnabled(
42
+ props.appSwitchWhenAvailable
43
+ );
39
44
  let win;
40
45
  const handleClick = (
41
46
  // eslint-disable-next-line no-undef
@@ -52,6 +57,7 @@ export function PrerenderedButtons({
52
57
  .info("paypal_js_sdk_v5_button_prerender_click", {
53
58
  fundingSource,
54
59
  card,
60
+ eagerOrderCreation: String(eagerOrderCreation),
55
61
  buttonsSessionID: props.buttonSessionID,
56
62
  })
57
63
  .track({
@@ -62,6 +68,11 @@ export function PrerenderedButtons({
62
68
  [FPTI_KEY.CHOSEN_FUNDING]: fundingSource,
63
69
  });
64
70
 
71
+ if (eagerOrderCreation) {
72
+ // Pass this click. The buttons are rendered in disabled state
73
+ return;
74
+ }
75
+
65
76
  if (fundingSource === FUNDING.VENMO || fundingSource === FUNDING.APPLEPAY) {
66
77
  // wait for button to load
67
78
  } else if (supportsPopups() && !props.merchantRequestedPopupsDisabled) {
@@ -96,7 +107,11 @@ export function PrerenderedButtons({
96
107
  <html>
97
108
  <body>
98
109
  {/* $FlowFixMe */}
99
- <Buttons {...props} onClick={handleClick} />
110
+ <Buttons
111
+ {...props}
112
+ onClick={handleClick}
113
+ showLoadingSpinner={eagerOrderCreation}
114
+ />
100
115
  </body>
101
116
  </html>
102
117
  );
@@ -8,6 +8,7 @@ import {
8
8
  isSafari,
9
9
  type Experiment,
10
10
  isDevice,
11
+ isWebView,
11
12
  isTablet,
12
13
  getElement,
13
14
  isStandAlone,
@@ -455,3 +456,15 @@ export const sendPostRobotMessageToButtonIframe = ({
455
456
  }
456
457
  }
457
458
  };
459
+
460
+ export const isEagerOrderCreationEnabled = (
461
+ appSwitchWhenAvailable: boolean
462
+ ): boolean => {
463
+ const experiment = getButtonExperiments();
464
+ return Boolean(
465
+ !isWebView() &&
466
+ isDevice() &&
467
+ appSwitchWhenAvailable &&
468
+ experiment.spbEagerOrderCreation
469
+ );
470
+ };