@paypal/checkout-components 5.0.256 → 5.0.257

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.
Files changed (185) hide show
  1. package/README.md +8 -0
  2. package/__sdk__.js +76 -76
  3. package/dist/button.js +1 -1
  4. package/globals.js +28 -30
  5. package/package.json +6 -4
  6. package/src/actions/save/index.js +17 -12
  7. package/src/constants/button.js +36 -36
  8. package/src/constants/class.js +32 -30
  9. package/src/constants/index.js +3 -3
  10. package/src/constants/misc.js +14 -12
  11. package/src/declarations.js +19 -19
  12. package/src/funding/applepay/config.jsx +51 -50
  13. package/src/funding/applepay/index.js +1 -1
  14. package/src/funding/applepay/style.scoped.scss +1 -1
  15. package/src/funding/applepay/template.jsx +16 -11
  16. package/src/funding/bancontact/config.jsx +48 -37
  17. package/src/funding/bancontact/index.js +1 -2
  18. package/src/funding/blik/config.jsx +48 -37
  19. package/src/funding/blik/index.js +1 -2
  20. package/src/funding/boleto/config.jsx +50 -39
  21. package/src/funding/boleto/index.js +1 -2
  22. package/src/funding/card/amex/config.js +9 -8
  23. package/src/funding/card/amex/index.js +1 -2
  24. package/src/funding/card/config.jsx +246 -177
  25. package/src/funding/card/discover/config.js +9 -7
  26. package/src/funding/card/discover/index.js +1 -2
  27. package/src/funding/card/elo/config.js +6 -7
  28. package/src/funding/card/elo/index.js +1 -2
  29. package/src/funding/card/hiper/config.js +9 -7
  30. package/src/funding/card/hiper/index.js +1 -2
  31. package/src/funding/card/index.js +1 -1
  32. package/src/funding/card/jcb/config.js +6 -7
  33. package/src/funding/card/jcb/index.js +1 -2
  34. package/src/funding/card/mastercard/config.js +9 -7
  35. package/src/funding/card/mastercard/index.js +1 -2
  36. package/src/funding/card/visa/config.js +9 -7
  37. package/src/funding/card/visa/index.js +1 -2
  38. package/src/funding/common.jsx +242 -216
  39. package/src/funding/config.js +212 -65
  40. package/src/funding/content.jsx +1946 -337
  41. package/src/funding/credit/config.jsx +74 -57
  42. package/src/funding/credit/index.js +1 -2
  43. package/src/funding/eps/config.jsx +45 -37
  44. package/src/funding/eps/index.js +1 -2
  45. package/src/funding/funding.js +193 -100
  46. package/src/funding/giropay/config.jsx +48 -38
  47. package/src/funding/giropay/index.js +1 -2
  48. package/src/funding/ideal/config.jsx +48 -37
  49. package/src/funding/ideal/index.js +1 -2
  50. package/src/funding/index.js +2 -2
  51. package/src/funding/itau/config.jsx +41 -41
  52. package/src/funding/itau/index.js +1 -1
  53. package/src/funding/maxima/config.jsx +25 -19
  54. package/src/funding/maxima/index.js +1 -2
  55. package/src/funding/mercadopago/config.jsx +48 -37
  56. package/src/funding/mercadopago/index.js +1 -2
  57. package/src/funding/multibanco/config.jsx +50 -39
  58. package/src/funding/multibanco/index.js +1 -2
  59. package/src/funding/mybank/config.jsx +48 -37
  60. package/src/funding/mybank/index.js +1 -2
  61. package/src/funding/oxxo/config.jsx +50 -39
  62. package/src/funding/oxxo/index.js +1 -2
  63. package/src/funding/p24/config.jsx +45 -37
  64. package/src/funding/p24/index.js +1 -2
  65. package/src/funding/paidy/config.jsx +50 -39
  66. package/src/funding/paidy/index.js +1 -1
  67. package/src/funding/paylater/config.jsx +118 -111
  68. package/src/funding/paylater/index.js +1 -2
  69. package/src/funding/paypal/config.jsx +43 -46
  70. package/src/funding/paypal/index.js +1 -2
  71. package/src/funding/paypal/style.scoped.scss +80 -74
  72. package/src/funding/paypal/template.jsx +450 -354
  73. package/src/funding/payu/config.jsx +50 -39
  74. package/src/funding/payu/index.js +1 -1
  75. package/src/funding/satispay/config.jsx +50 -39
  76. package/src/funding/satispay/index.js +1 -1
  77. package/src/funding/sepa/config.jsx +19 -13
  78. package/src/funding/sepa/index.js +1 -2
  79. package/src/funding/sofort/config.jsx +48 -37
  80. package/src/funding/sofort/index.js +1 -2
  81. package/src/funding/trustly/config.jsx +50 -39
  82. package/src/funding/trustly/index.js +1 -2
  83. package/src/funding/venmo/config.jsx +80 -75
  84. package/src/funding/venmo/index.js +1 -2
  85. package/src/funding/venmo/style.scoped.scss +30 -32
  86. package/src/funding/venmo/template.jsx +56 -57
  87. package/src/funding/verkkopankki/config.jsx +50 -39
  88. package/src/funding/verkkopankki/index.js +1 -1
  89. package/src/funding/wechatpay/config.jsx +48 -37
  90. package/src/funding/wechatpay/index.js +1 -2
  91. package/src/funding/zimpler/config.jsx +19 -13
  92. package/src/funding/zimpler/index.js +1 -2
  93. package/src/interface/actions.js +1 -1
  94. package/src/interface/button.js +60 -44
  95. package/src/interface/card-fields.js +11 -8
  96. package/src/interface/fields.js +7 -4
  97. package/src/interface/marks.js +4 -4
  98. package/src/interface/payment-fields.js +7 -4
  99. package/src/interface/wallet.js +4 -4
  100. package/src/lib/errors.js +7 -7
  101. package/src/lib/index.js +5 -5
  102. package/src/lib/isRTLLanguage.js +3 -3
  103. package/src/lib/perceived-latency-instrumentation.js +54 -36
  104. package/src/lib/security.js +21 -17
  105. package/src/lib/session.js +39 -35
  106. package/src/marks/component.jsx +114 -65
  107. package/src/marks/index.js +1 -2
  108. package/src/marks/template.jsx +79 -65
  109. package/src/types.js +48 -48
  110. package/src/ui/buttons/button.jsx +311 -249
  111. package/src/ui/buttons/buttonDesigns/control.jsx +3 -5
  112. package/src/ui/buttons/buttonDesigns/divideLogoAnimation.jsx +127 -99
  113. package/src/ui/buttons/buttonDesigns/index.js +78 -75
  114. package/src/ui/buttons/buttonDesigns/inlineLogoTextDesign.jsx +102 -82
  115. package/src/ui/buttons/buttonDesigns/script.jsx +24 -18
  116. package/src/ui/buttons/buttonDesigns/types.js +6 -7
  117. package/src/ui/buttons/buttons.jsx +318 -212
  118. package/src/ui/buttons/config.js +62 -59
  119. package/src/ui/buttons/content.jsx +304 -119
  120. package/src/ui/buttons/index.js +1 -1
  121. package/src/ui/buttons/menu-button/index.js +1 -1
  122. package/src/ui/buttons/menu-button/menu-button.jsx +29 -22
  123. package/src/ui/buttons/menu-button/menu-button.scoped.scss +16 -17
  124. package/src/ui/buttons/poweredBy.jsx +23 -23
  125. package/src/ui/buttons/props.js +677 -529
  126. package/src/ui/buttons/script.jsx +182 -160
  127. package/src/ui/buttons/spinner.jsx +4 -6
  128. package/src/ui/buttons/style.jsx +15 -14
  129. package/src/ui/buttons/styles/base.js +24 -16
  130. package/src/ui/buttons/styles/button.js +24 -22
  131. package/src/ui/buttons/styles/color.js +118 -118
  132. package/src/ui/buttons/styles/custom.js +30 -24
  133. package/src/ui/buttons/styles/index.js +1 -1
  134. package/src/ui/buttons/styles/labels.js +17 -13
  135. package/src/ui/buttons/styles/page.js +3 -3
  136. package/src/ui/buttons/styles/responsive.js +226 -118
  137. package/src/ui/buttons/tagline.jsx +53 -54
  138. package/src/ui/chevron.jsx +27 -16
  139. package/src/ui/index.js +3 -3
  140. package/src/ui/loading.jsx +25 -18
  141. package/src/ui/text/index.js +1 -1
  142. package/src/ui/text/style.scoped.scss +25 -26
  143. package/src/ui/text/text.jsx +42 -20
  144. package/src/ui/tracking.jsx +18 -11
  145. package/src/zoid/buttons/component.jsx +820 -684
  146. package/src/zoid/buttons/container.jsx +140 -107
  147. package/src/zoid/buttons/index.js +1 -1
  148. package/src/zoid/buttons/prerender.jsx +84 -64
  149. package/src/zoid/buttons/util.js +346 -254
  150. package/src/zoid/card-fields/component.jsx +581 -549
  151. package/src/zoid/card-fields/index.js +1 -1
  152. package/src/zoid/card-fields/prerender.jsx +20 -17
  153. package/src/zoid/card-form/component.js +155 -141
  154. package/src/zoid/card-form/index.js +1 -1
  155. package/src/zoid/checkout/component.jsx +314 -282
  156. package/src/zoid/checkout/config.js +2 -2
  157. package/src/zoid/checkout/content.js +190 -154
  158. package/src/zoid/checkout/hacks.js +31 -28
  159. package/src/zoid/checkout/index.js +2 -2
  160. package/src/zoid/checkout/props.js +27 -33
  161. package/src/zoid/installments/component.jsx +83 -70
  162. package/src/zoid/installments/index.js +1 -1
  163. package/src/zoid/installments/props.js +1 -1
  164. package/src/zoid/menu/component.jsx +53 -48
  165. package/src/zoid/menu/index.js +1 -1
  166. package/src/zoid/menu/props.js +1 -3
  167. package/src/zoid/modal/component.jsx +119 -106
  168. package/src/zoid/modal/index.js +1 -1
  169. package/src/zoid/modal/props.js +1 -3
  170. package/src/zoid/payment-fields/component.jsx +215 -191
  171. package/src/zoid/payment-fields/container.jsx +73 -64
  172. package/src/zoid/payment-fields/index.js +1 -1
  173. package/src/zoid/payment-fields/prerender.jsx +16 -14
  174. package/src/zoid/payment-fields/props.js +6 -6
  175. package/src/zoid/qr-code/component.jsx +131 -115
  176. package/src/zoid/qr-code/container.jsx +74 -68
  177. package/src/zoid/qr-code/index.js +1 -1
  178. package/src/zoid/qr-code/prerender.jsx +17 -12
  179. package/src/zoid/qr-code/types.js +2 -2
  180. package/src/zoid/wallet/component.jsx +298 -260
  181. package/src/zoid/wallet/container.jsx +73 -64
  182. package/src/zoid/wallet/index.js +1 -1
  183. package/src/zoid/wallet/prerender.jsx +14 -14
  184. package/src/zoid/wallet/props.js +4 -4
  185. package/src/lib/getLogoCDNExperiment.js +0 -25
@@ -1,109 +1,138 @@
1
1
  /* @flow */
2
2
  /** @jsx node */
3
3
 
4
- import { values, destroyElement, toCSS } from '@krakenjs/belter/src';
5
- import { node, dom } from '@krakenjs/jsx-pragmatic/src';
6
- import { EVENT, type RenderOptionsType } from '@krakenjs/zoid/src';
7
- import { getVersion } from '@paypal/sdk-client/src';
8
-
9
- import { BUTTON_SIZE, ATTRIBUTE, MENU_PLACEMENT } from '../../constants';
10
- import { BUTTON_SIZE_STYLE, MINIMUM_SIZE, MAXIMUM_SIZE } from '../../ui/buttons/config';
11
- import { type ButtonProps } from '../../ui/buttons/props';
4
+ import { values, destroyElement, toCSS } from "@krakenjs/belter/src";
5
+ import { node, dom } from "@krakenjs/jsx-pragmatic/src";
6
+ import { EVENT, type RenderOptionsType } from "@krakenjs/zoid/src";
7
+ import { getVersion } from "@paypal/sdk-client/src";
8
+
9
+ import { BUTTON_SIZE, ATTRIBUTE, MENU_PLACEMENT } from "../../constants";
10
+ import {
11
+ BUTTON_SIZE_STYLE,
12
+ MINIMUM_SIZE,
13
+ MAXIMUM_SIZE,
14
+ } from "../../ui/buttons/config";
15
+ import { type ButtonProps } from "../../ui/buttons/props";
12
16
 
13
17
  const CLASS = {
14
- VISIBLE: 'visible',
15
- INVISIBLE: 'invisible',
16
- COMPONENT_FRAME: 'component-frame',
17
- PRERENDER_FRAME: 'prerender-frame',
18
- SMART_MENU: 'smart-menu',
19
- INSTALLMENTS_MODAL: 'installments-modal'
18
+ VISIBLE: "visible",
19
+ INVISIBLE: "invisible",
20
+ COMPONENT_FRAME: "component-frame",
21
+ PRERENDER_FRAME: "prerender-frame",
22
+ SMART_MENU: "smart-menu",
23
+ INSTALLMENTS_MODAL: "installments-modal",
20
24
  };
21
25
 
22
26
  const ID = {
23
- SMART_MENU: 'smart-menu',
24
- INSTALLMENTS_MODAL: 'installments-modal'
27
+ SMART_MENU: "smart-menu",
28
+ INSTALLMENTS_MODAL: "installments-modal",
25
29
  };
26
30
 
27
- export function containerTemplate({ uid, props, tag, context, frame, prerenderFrame, doc, container, event } : RenderOptionsType<ButtonProps>) : ?HTMLElement {
28
-
29
- if (!frame || !prerenderFrame) {
30
- return;
31
- }
32
-
33
- if (container && container.tagName.toLowerCase() === 'button') {
34
- throw new Error(`Do not render the PayPal button into a button element`);
35
- }
36
-
37
- frame.classList.add(CLASS.COMPONENT_FRAME);
38
- prerenderFrame.classList.add(CLASS.PRERENDER_FRAME);
39
-
40
- frame.classList.add(CLASS.INVISIBLE);
41
- prerenderFrame.classList.add(CLASS.VISIBLE);
42
-
43
- event.on(EVENT.RENDERED, () => {
44
- prerenderFrame.classList.remove(CLASS.VISIBLE);
45
- prerenderFrame.classList.add(CLASS.INVISIBLE);
46
-
47
- frame.classList.remove(CLASS.INVISIBLE);
48
- frame.classList.add(CLASS.VISIBLE);
49
-
50
- setTimeout(() => {
51
- destroyElement(prerenderFrame);
52
- }, 1000);
31
+ export function containerTemplate({
32
+ uid,
33
+ props,
34
+ tag,
35
+ context,
36
+ frame,
37
+ prerenderFrame,
38
+ doc,
39
+ container,
40
+ event,
41
+ }: RenderOptionsType<ButtonProps>): ?HTMLElement {
42
+ if (!frame || !prerenderFrame) {
43
+ return;
44
+ }
45
+
46
+ if (container && container.tagName.toLowerCase() === "button") {
47
+ throw new Error(`Do not render the PayPal button into a button element`);
48
+ }
49
+
50
+ frame.classList.add(CLASS.COMPONENT_FRAME);
51
+ prerenderFrame.classList.add(CLASS.PRERENDER_FRAME);
52
+
53
+ frame.classList.add(CLASS.INVISIBLE);
54
+ prerenderFrame.classList.add(CLASS.VISIBLE);
55
+
56
+ event.on(EVENT.RENDERED, () => {
57
+ prerenderFrame.classList.remove(CLASS.VISIBLE);
58
+ prerenderFrame.classList.add(CLASS.INVISIBLE);
59
+
60
+ frame.classList.remove(CLASS.INVISIBLE);
61
+ frame.classList.add(CLASS.VISIBLE);
62
+
63
+ setTimeout(() => {
64
+ destroyElement(prerenderFrame);
65
+ }, 1000);
66
+ });
67
+
68
+ // $FlowFixMe
69
+ const { style, nonce } = props;
70
+ const { label, layout, height: buttonHeight, menuPlacement } = style;
71
+
72
+ let minimumSize = MINIMUM_SIZE[layout];
73
+ const maximumSize = MAXIMUM_SIZE[layout];
74
+
75
+ if (buttonHeight) {
76
+ const possibleSizes = values(BUTTON_SIZE).filter((possibleSize) => {
77
+ return (
78
+ BUTTON_SIZE_STYLE[possibleSize] &&
79
+ buttonHeight &&
80
+ BUTTON_SIZE_STYLE[possibleSize].minHeight <= buttonHeight &&
81
+ BUTTON_SIZE_STYLE[possibleSize].maxHeight >= buttonHeight
82
+ );
53
83
  });
54
84
 
55
- // $FlowFixMe
56
- const { style, nonce } = props;
57
- const { label, layout, height: buttonHeight, menuPlacement } = style;
58
-
59
- let minimumSize = MINIMUM_SIZE[layout];
60
- const maximumSize = MAXIMUM_SIZE[layout];
61
-
62
- if (buttonHeight) {
63
- const possibleSizes = values(BUTTON_SIZE).filter(possibleSize => {
64
- return BUTTON_SIZE_STYLE[possibleSize] && buttonHeight &&
65
- BUTTON_SIZE_STYLE[possibleSize].minHeight <= buttonHeight && BUTTON_SIZE_STYLE[possibleSize].maxHeight >= buttonHeight;
66
- });
67
-
68
- possibleSizes.sort((sizeA : $Values<typeof BUTTON_SIZE>, sizeB : $Values<typeof BUTTON_SIZE>) : number => {
69
- return BUTTON_SIZE_STYLE[sizeA].defaultWidth - BUTTON_SIZE_STYLE[sizeB].defaultWidth;
70
- });
71
-
72
- minimumSize = possibleSizes[0];
73
- }
74
-
75
- const setupAutoResize = (el) => {
76
- event.on(EVENT.RESIZE, ({ width: newWidth, height: newHeight }) => {
77
- if (typeof newWidth === 'number') {
78
- el.style.width = toCSS(newWidth);
79
- }
80
-
81
- if (typeof newHeight === 'number') {
82
- el.style.height = toCSS(newHeight);
83
- }
84
- });
85
- };
86
-
87
- const element = (
88
- <div
89
- id={ uid }
90
- class={ `${ tag } ${ tag }-context-${ context } ${ tag }-label-${ label || 'unknown' } ${ tag }-layout-${ layout }` }
91
- { ...({ [ATTRIBUTE.VERSION]: `${ getVersion() }` }) }
92
- onRender={ setupAutoResize } >
93
-
94
- <style nonce={ nonce }>
95
- {`
96
- #${ uid } {
85
+ possibleSizes.sort(
86
+ (
87
+ sizeA: $Values<typeof BUTTON_SIZE>,
88
+ sizeB: $Values<typeof BUTTON_SIZE>
89
+ ): number => {
90
+ return (
91
+ BUTTON_SIZE_STYLE[sizeA].defaultWidth -
92
+ BUTTON_SIZE_STYLE[sizeB].defaultWidth
93
+ );
94
+ }
95
+ );
96
+
97
+ minimumSize = possibleSizes[0];
98
+ }
99
+
100
+ const setupAutoResize = (el) => {
101
+ event.on(EVENT.RESIZE, ({ width: newWidth, height: newHeight }) => {
102
+ if (typeof newWidth === "number") {
103
+ el.style.width = toCSS(newWidth);
104
+ }
105
+
106
+ if (typeof newHeight === "number") {
107
+ el.style.height = toCSS(newHeight);
108
+ }
109
+ });
110
+ };
111
+
112
+ const element = (
113
+ <div
114
+ id={uid}
115
+ class={`${tag} ${tag}-context-${context} ${tag}-label-${
116
+ label || "unknown"
117
+ } ${tag}-layout-${layout}`}
118
+ {...{ [ATTRIBUTE.VERSION]: `${getVersion()}` }}
119
+ onRender={setupAutoResize}
120
+ >
121
+ <style nonce={nonce}>
122
+ {`
123
+ #${uid} {
97
124
  position: relative;
98
125
  display: inline-block;
99
126
  width: 100%;
100
- min-height: ${ BUTTON_SIZE_STYLE[minimumSize].minHeight }px;
101
- min-width: ${ BUTTON_SIZE_STYLE[minimumSize].minWidth }px;
102
- max-width: ${ BUTTON_SIZE_STYLE[maximumSize].maxWidth }px;
127
+ min-height: ${
128
+ BUTTON_SIZE_STYLE[minimumSize].minHeight
129
+ }px;
130
+ min-width: ${BUTTON_SIZE_STYLE[minimumSize].minWidth}px;
131
+ max-width: ${BUTTON_SIZE_STYLE[maximumSize].maxWidth}px;
103
132
  font-size: 0;
104
133
  }
105
134
 
106
- #${ uid } > iframe {
135
+ #${uid} > iframe {
107
136
  position: absolute;
108
137
  top: 0;
109
138
  left: 0;
@@ -111,48 +140,52 @@ export function containerTemplate({ uid, props, tag, context, frame, prerenderFr
111
140
  height: 100%;
112
141
  }
113
142
 
114
- #${ uid } > iframe.${ CLASS.COMPONENT_FRAME } {
143
+ #${uid} > iframe.${CLASS.COMPONENT_FRAME} {
115
144
  z-index: 100;
116
145
  }
117
146
 
118
- #${ uid } > iframe.${ CLASS.PRERENDER_FRAME } {
147
+ #${uid} > iframe.${CLASS.PRERENDER_FRAME} {
119
148
  transition: opacity .2s linear;
120
149
  z-index: 200;
121
150
  }
122
151
 
123
- #${ uid } > iframe.${ CLASS.VISIBLE } {
152
+ #${uid} > iframe.${CLASS.VISIBLE} {
124
153
  opacity: 1;
125
154
  }
126
155
 
127
- #${ uid } > iframe.${ CLASS.INVISIBLE } {
156
+ #${uid} > iframe.${CLASS.INVISIBLE} {
128
157
  opacity: 0;
129
158
  pointer-events: none;
130
159
  }
131
160
 
132
- #${ uid } > .${ CLASS.SMART_MENU } {
161
+ #${uid} > .${CLASS.SMART_MENU} {
133
162
  position: absolute;
134
163
  z-index: 300;
135
- ${ menuPlacement === MENU_PLACEMENT.ABOVE ? 'bottom: 100%;' : 'top: 0;' }
164
+ ${
165
+ menuPlacement === MENU_PLACEMENT.ABOVE
166
+ ? "bottom: 100%;"
167
+ : "top: 0;"
168
+ }
136
169
  left: 0;
137
170
  width: 100%;
138
171
  }
139
172
  `}
140
- </style>
173
+ </style>
141
174
 
142
- <node el={ frame } />
143
- <node el={ prerenderFrame } />
175
+ <node el={frame} />
176
+ <node el={prerenderFrame} />
144
177
 
145
- <div id={ ID.SMART_MENU } class={ CLASS.SMART_MENU } />
178
+ <div id={ID.SMART_MENU} class={CLASS.SMART_MENU} />
146
179
 
147
- <div id={ ID.INSTALLMENTS_MODAL } class={ CLASS.INSTALLMENTS_MODAL } />
148
- </div>
149
- ).render(dom({ doc }));
180
+ <div id={ID.INSTALLMENTS_MODAL} class={CLASS.INSTALLMENTS_MODAL} />
181
+ </div>
182
+ ).render(dom({ doc }));
150
183
 
151
- event.on(EVENT.RENDERED, () => {
152
- setTimeout(() => {
153
- element.style.transition = 'all 0.2s ease-in-out';
154
- }, 1000);
155
- });
184
+ event.on(EVENT.RENDERED, () => {
185
+ setTimeout(() => {
186
+ element.style.transition = "all 0.2s ease-in-out";
187
+ }, 1000);
188
+ });
156
189
 
157
- return element;
190
+ return element;
158
191
  }
@@ -1,3 +1,3 @@
1
1
  /* @flow */
2
2
 
3
- export * from './component';
3
+ export * from "./component";
@@ -1,79 +1,99 @@
1
1
  /* @flow */
2
2
  /** @jsx node */
3
3
 
4
- import { node, dom, type ChildType } from '@krakenjs/jsx-pragmatic/src';
5
- import { FUNDING, CARD, FPTI_KEY } from '@paypal/sdk-constants/src';
6
- import { popup, supportsPopups, writeElementToWindow } from '@krakenjs/belter/src';
7
- import { assertSameDomain, type CrossDomainWindowType } from '@krakenjs/cross-domain-utils/src';
8
- import { SpinnerPage } from '@paypal/common-components/src';
9
- import { getLogger } from '@paypal/sdk-client/src';
10
- import type { ZoidProps } from '@krakenjs/zoid/src';
4
+ import { node, dom, type ChildType } from "@krakenjs/jsx-pragmatic/src";
5
+ import { FUNDING, CARD, FPTI_KEY } from "@paypal/sdk-constants/src";
6
+ import {
7
+ popup,
8
+ supportsPopups,
9
+ writeElementToWindow,
10
+ } from "@krakenjs/belter/src";
11
+ import {
12
+ assertSameDomain,
13
+ type CrossDomainWindowType,
14
+ } from "@krakenjs/cross-domain-utils/src";
15
+ import { SpinnerPage } from "@paypal/common-components/src";
16
+ import { getLogger } from "@paypal/sdk-client/src";
17
+ import type { ZoidProps } from "@krakenjs/zoid/src";
11
18
 
12
- import { DEFAULT_POPUP_SIZE } from '../checkout';
13
- import { EXPERIENCE } from '../../constants';
14
- import { Buttons } from '../../ui';
15
- import { type ButtonProps } from '../../ui/buttons/props';
19
+ import { DEFAULT_POPUP_SIZE } from "../checkout";
20
+ import { EXPERIENCE } from "../../constants";
21
+ import { Buttons } from "../../ui";
22
+ import { type ButtonProps } from "../../ui/buttons/props";
16
23
 
17
24
  type PrerenderedButtonsProps = {|
18
- nonce : ?string,
19
- props : ZoidProps<ButtonProps>,
20
- onRenderCheckout : ({|
21
- win? : CrossDomainWindowType,
22
- fundingSource : $Values<typeof FUNDING>,
23
- card : ?$Values<typeof CARD>
24
- |}) => void
25
+ nonce: ?string,
26
+ props: ZoidProps<ButtonProps>,
27
+ onRenderCheckout: ({|
28
+ win?: CrossDomainWindowType,
29
+ fundingSource: $Values<typeof FUNDING>,
30
+ card: ?$Values<typeof CARD>,
31
+ |}) => void,
25
32
  |};
26
33
 
27
- export function PrerenderedButtons({ nonce, onRenderCheckout, props } : PrerenderedButtonsProps) : ChildType {
28
- let win;
29
- const handleClick = (
30
- // eslint-disable-next-line no-undef
31
- event : SyntheticInputEvent<HTMLInputElement>,
32
- { fundingSource, card } : {|
33
- fundingSource : $Values<typeof FUNDING>,
34
- card : ?$Values<typeof CARD>
35
- |}
36
- ) => {
37
- getLogger().info('button_prerender_click').track({
38
- [ FPTI_KEY.BUTTON_SESSION_UID ]: props.buttonSessionID,
39
- [ FPTI_KEY.CONTEXT_TYPE ]: 'button_session_id',
40
- [ FPTI_KEY.CONTEXT_ID ]: props.buttonSessionID,
41
- [ FPTI_KEY.TRANSITION ]: 'process_button_prerender_click',
42
- [ FPTI_KEY.CHOSEN_FUNDING]: fundingSource
43
- }).flush();
34
+ export function PrerenderedButtons({
35
+ nonce,
36
+ onRenderCheckout,
37
+ props,
38
+ }: PrerenderedButtonsProps): ChildType {
39
+ let win;
40
+ const handleClick = (
41
+ // eslint-disable-next-line no-undef
42
+ event: SyntheticInputEvent<HTMLInputElement>,
43
+ {
44
+ fundingSource,
45
+ card,
46
+ }: {|
47
+ fundingSource: $Values<typeof FUNDING>,
48
+ card: ?$Values<typeof CARD>,
49
+ |}
50
+ ) => {
51
+ getLogger()
52
+ .info("button_prerender_click")
53
+ .track({
54
+ [FPTI_KEY.BUTTON_SESSION_UID]: props.buttonSessionID,
55
+ [FPTI_KEY.CONTEXT_TYPE]: "button_session_id",
56
+ [FPTI_KEY.CONTEXT_ID]: props.buttonSessionID,
57
+ [FPTI_KEY.TRANSITION]: "process_button_prerender_click",
58
+ [FPTI_KEY.CHOSEN_FUNDING]: fundingSource,
59
+ })
60
+ .flush();
44
61
 
45
- if (fundingSource === FUNDING.VENMO || fundingSource === FUNDING.APPLEPAY || (fundingSource === FUNDING.CARD && props.experience === EXPERIENCE.INLINE)) {
46
- // wait for button to load
47
- } else if (supportsPopups() && !props.merchantRequestedPopupsDisabled) {
48
- // remember the popup window to prevent showing a new popup window on every click in the prerender state
49
- if (!win || win.closed) {
50
- win = assertSameDomain(popup('', {
51
- width: DEFAULT_POPUP_SIZE.WIDTH,
52
- height: DEFAULT_POPUP_SIZE.HEIGHT
53
- }));
54
- }
62
+ if (
63
+ fundingSource === FUNDING.VENMO ||
64
+ fundingSource === FUNDING.APPLEPAY ||
65
+ (fundingSource === FUNDING.CARD && props.experience === EXPERIENCE.INLINE)
66
+ ) {
67
+ // wait for button to load
68
+ } else if (supportsPopups() && !props.merchantRequestedPopupsDisabled) {
69
+ // remember the popup window to prevent showing a new popup window on every click in the prerender state
70
+ if (!win || win.closed) {
71
+ win = assertSameDomain(
72
+ popup("", {
73
+ width: DEFAULT_POPUP_SIZE.WIDTH,
74
+ height: DEFAULT_POPUP_SIZE.HEIGHT,
75
+ })
76
+ );
77
+ }
55
78
 
56
- const doc = window.document;
79
+ const doc = window.document;
57
80
 
58
- const spinner = (
59
- <SpinnerPage nonce={ nonce } />
60
- ).render(dom({ doc }));
81
+ const spinner = (<SpinnerPage nonce={nonce} />).render(dom({ doc }));
61
82
 
62
- writeElementToWindow(win, spinner);
83
+ writeElementToWindow(win, spinner);
63
84
 
64
- onRenderCheckout({ win, fundingSource, card });
85
+ onRenderCheckout({ win, fundingSource, card });
86
+ } else {
87
+ onRenderCheckout({ fundingSource, card });
88
+ }
89
+ };
65
90
 
66
- } else {
67
- onRenderCheckout({ fundingSource, card });
68
- }
69
- };
70
-
71
- return (
72
- <html>
73
- <body>
74
- {/* $FlowFixMe */}
75
- <Buttons { ...props } onClick={ handleClick } />
76
- </body>
77
- </html>
78
- );
91
+ return (
92
+ <html>
93
+ <body>
94
+ {/* $FlowFixMe */}
95
+ <Buttons {...props} onClick={handleClick} />
96
+ </body>
97
+ </html>
98
+ );
79
99
  }