@paypal/checkout-components 5.0.256 → 5.0.258

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 +72 -76
  3. package/dist/button.js +1 -1
  4. package/globals.js +28 -30
  5. package/package.json +6 -4
  6. package/src/constants/button.js +37 -36
  7. package/src/constants/class.js +32 -30
  8. package/src/constants/index.js +3 -3
  9. package/src/constants/misc.js +14 -12
  10. package/src/declarations.js +19 -19
  11. package/src/funding/applepay/config.jsx +51 -50
  12. package/src/funding/applepay/index.js +1 -1
  13. package/src/funding/applepay/style.scoped.scss +1 -1
  14. package/src/funding/applepay/template.jsx +16 -11
  15. package/src/funding/bancontact/config.jsx +48 -37
  16. package/src/funding/bancontact/index.js +1 -2
  17. package/src/funding/blik/config.jsx +48 -37
  18. package/src/funding/blik/index.js +1 -2
  19. package/src/funding/boleto/config.jsx +50 -39
  20. package/src/funding/boleto/index.js +1 -2
  21. package/src/funding/card/amex/config.js +9 -8
  22. package/src/funding/card/amex/index.js +1 -2
  23. package/src/funding/card/config.jsx +246 -177
  24. package/src/funding/card/discover/config.js +9 -7
  25. package/src/funding/card/discover/index.js +1 -2
  26. package/src/funding/card/elo/config.js +6 -7
  27. package/src/funding/card/elo/index.js +1 -2
  28. package/src/funding/card/hiper/config.js +9 -7
  29. package/src/funding/card/hiper/index.js +1 -2
  30. package/src/funding/card/index.js +1 -1
  31. package/src/funding/card/jcb/config.js +6 -7
  32. package/src/funding/card/jcb/index.js +1 -2
  33. package/src/funding/card/mastercard/config.js +9 -7
  34. package/src/funding/card/mastercard/index.js +1 -2
  35. package/src/funding/card/visa/config.js +9 -7
  36. package/src/funding/card/visa/index.js +1 -2
  37. package/src/funding/common.jsx +242 -216
  38. package/src/funding/config.js +212 -65
  39. package/src/funding/content.jsx +1946 -337
  40. package/src/funding/credit/config.jsx +74 -57
  41. package/src/funding/credit/index.js +1 -2
  42. package/src/funding/eps/config.jsx +45 -37
  43. package/src/funding/eps/index.js +1 -2
  44. package/src/funding/funding.js +193 -100
  45. package/src/funding/giropay/config.jsx +48 -38
  46. package/src/funding/giropay/index.js +1 -2
  47. package/src/funding/ideal/config.jsx +48 -37
  48. package/src/funding/ideal/index.js +1 -2
  49. package/src/funding/index.js +2 -2
  50. package/src/funding/itau/config.jsx +41 -41
  51. package/src/funding/itau/index.js +1 -1
  52. package/src/funding/maxima/config.jsx +25 -19
  53. package/src/funding/maxima/index.js +1 -2
  54. package/src/funding/mercadopago/config.jsx +48 -37
  55. package/src/funding/mercadopago/index.js +1 -2
  56. package/src/funding/multibanco/config.jsx +50 -39
  57. package/src/funding/multibanco/index.js +1 -2
  58. package/src/funding/mybank/config.jsx +48 -37
  59. package/src/funding/mybank/index.js +1 -2
  60. package/src/funding/oxxo/config.jsx +50 -39
  61. package/src/funding/oxxo/index.js +1 -2
  62. package/src/funding/p24/config.jsx +45 -37
  63. package/src/funding/p24/index.js +1 -2
  64. package/src/funding/paidy/config.jsx +50 -39
  65. package/src/funding/paidy/index.js +1 -1
  66. package/src/funding/paylater/config.jsx +118 -111
  67. package/src/funding/paylater/index.js +1 -2
  68. package/src/funding/paypal/config.jsx +44 -46
  69. package/src/funding/paypal/index.js +1 -2
  70. package/src/funding/paypal/style.scoped.scss +80 -74
  71. package/src/funding/paypal/template.jsx +450 -354
  72. package/src/funding/payu/config.jsx +50 -39
  73. package/src/funding/payu/index.js +1 -1
  74. package/src/funding/satispay/config.jsx +50 -39
  75. package/src/funding/satispay/index.js +1 -1
  76. package/src/funding/sepa/config.jsx +19 -13
  77. package/src/funding/sepa/index.js +1 -2
  78. package/src/funding/sofort/config.jsx +48 -37
  79. package/src/funding/sofort/index.js +1 -2
  80. package/src/funding/trustly/config.jsx +50 -39
  81. package/src/funding/trustly/index.js +1 -2
  82. package/src/funding/venmo/config.jsx +80 -75
  83. package/src/funding/venmo/index.js +1 -2
  84. package/src/funding/venmo/style.scoped.scss +30 -32
  85. package/src/funding/venmo/template.jsx +56 -57
  86. package/src/funding/verkkopankki/config.jsx +50 -39
  87. package/src/funding/verkkopankki/index.js +1 -1
  88. package/src/funding/wechatpay/config.jsx +48 -37
  89. package/src/funding/wechatpay/index.js +1 -2
  90. package/src/funding/zimpler/config.jsx +19 -13
  91. package/src/funding/zimpler/index.js +1 -2
  92. package/src/interface/button.js +60 -44
  93. package/src/interface/card-fields.js +11 -8
  94. package/src/interface/fields.js +7 -4
  95. package/src/interface/marks.js +4 -4
  96. package/src/interface/payment-fields.js +7 -4
  97. package/src/interface/wallet.js +4 -4
  98. package/src/lib/errors.js +7 -7
  99. package/src/lib/index.js +5 -5
  100. package/src/lib/isRTLLanguage.js +3 -3
  101. package/src/lib/perceived-latency-instrumentation.js +54 -36
  102. package/src/lib/security.js +21 -17
  103. package/src/lib/session.js +39 -35
  104. package/src/marks/component.jsx +114 -65
  105. package/src/marks/index.js +1 -2
  106. package/src/marks/template.jsx +79 -65
  107. package/src/types.js +48 -48
  108. package/src/ui/buttons/button.jsx +311 -249
  109. package/src/ui/buttons/buttonDesigns/control.jsx +3 -5
  110. package/src/ui/buttons/buttonDesigns/divideLogoAnimation.jsx +127 -99
  111. package/src/ui/buttons/buttonDesigns/index.js +78 -75
  112. package/src/ui/buttons/buttonDesigns/inlineLogoTextDesign.jsx +102 -82
  113. package/src/ui/buttons/buttonDesigns/script.jsx +24 -18
  114. package/src/ui/buttons/buttonDesigns/types.js +6 -7
  115. package/src/ui/buttons/buttons.jsx +318 -212
  116. package/src/ui/buttons/config.js +62 -59
  117. package/src/ui/buttons/content.jsx +304 -119
  118. package/src/ui/buttons/index.js +1 -1
  119. package/src/ui/buttons/menu-button/index.js +1 -1
  120. package/src/ui/buttons/menu-button/menu-button.jsx +29 -22
  121. package/src/ui/buttons/menu-button/menu-button.scoped.scss +16 -17
  122. package/src/ui/buttons/poweredBy.jsx +23 -23
  123. package/src/ui/buttons/props.js +680 -529
  124. package/src/ui/buttons/script.jsx +182 -160
  125. package/src/ui/buttons/spinner.jsx +4 -6
  126. package/src/ui/buttons/style.jsx +15 -14
  127. package/src/ui/buttons/styles/base.js +24 -16
  128. package/src/ui/buttons/styles/button.js +24 -22
  129. package/src/ui/buttons/styles/color.js +118 -118
  130. package/src/ui/buttons/styles/custom.js +30 -24
  131. package/src/ui/buttons/styles/index.js +1 -1
  132. package/src/ui/buttons/styles/labels.js +17 -13
  133. package/src/ui/buttons/styles/page.js +3 -3
  134. package/src/ui/buttons/styles/responsive.js +226 -118
  135. package/src/ui/buttons/tagline.jsx +53 -54
  136. package/src/ui/chevron.jsx +27 -16
  137. package/src/ui/index.js +3 -3
  138. package/src/ui/loading.jsx +25 -18
  139. package/src/ui/text/index.js +1 -1
  140. package/src/ui/text/style.scoped.scss +25 -26
  141. package/src/ui/text/text.jsx +42 -20
  142. package/src/ui/tracking.jsx +18 -11
  143. package/src/zoid/buttons/component.jsx +836 -684
  144. package/src/zoid/buttons/container.jsx +140 -107
  145. package/src/zoid/buttons/index.js +1 -1
  146. package/src/zoid/buttons/prerender.jsx +84 -64
  147. package/src/zoid/buttons/util.js +355 -254
  148. package/src/zoid/card-fields/component.jsx +581 -549
  149. package/src/zoid/card-fields/index.js +1 -1
  150. package/src/zoid/card-fields/prerender.jsx +20 -17
  151. package/src/zoid/card-form/component.js +155 -141
  152. package/src/zoid/card-form/index.js +1 -1
  153. package/src/zoid/checkout/component.jsx +314 -282
  154. package/src/zoid/checkout/config.js +2 -2
  155. package/src/zoid/checkout/content.js +190 -154
  156. package/src/zoid/checkout/hacks.js +31 -28
  157. package/src/zoid/checkout/index.js +2 -2
  158. package/src/zoid/checkout/props.js +27 -33
  159. package/src/zoid/installments/component.jsx +83 -70
  160. package/src/zoid/installments/index.js +1 -1
  161. package/src/zoid/installments/props.js +1 -1
  162. package/src/zoid/menu/component.jsx +53 -48
  163. package/src/zoid/menu/index.js +1 -1
  164. package/src/zoid/menu/props.js +1 -3
  165. package/src/zoid/modal/component.jsx +119 -106
  166. package/src/zoid/modal/index.js +1 -1
  167. package/src/zoid/modal/props.js +1 -3
  168. package/src/zoid/payment-fields/component.jsx +215 -191
  169. package/src/zoid/payment-fields/container.jsx +73 -64
  170. package/src/zoid/payment-fields/index.js +1 -1
  171. package/src/zoid/payment-fields/prerender.jsx +16 -14
  172. package/src/zoid/payment-fields/props.js +6 -6
  173. package/src/zoid/qr-code/component.jsx +131 -115
  174. package/src/zoid/qr-code/container.jsx +74 -68
  175. package/src/zoid/qr-code/index.js +1 -1
  176. package/src/zoid/qr-code/prerender.jsx +17 -12
  177. package/src/zoid/qr-code/types.js +2 -2
  178. package/src/zoid/wallet/component.jsx +298 -260
  179. package/src/zoid/wallet/container.jsx +73 -64
  180. package/src/zoid/wallet/index.js +1 -1
  181. package/src/zoid/wallet/prerender.jsx +14 -14
  182. package/src/zoid/wallet/props.js +4 -4
  183. package/src/actions/save/index.js +0 -40
  184. package/src/interface/actions.js +0 -14
  185. package/src/lib/getLogoCDNExperiment.js +0 -25
@@ -1,18 +1,49 @@
1
1
  /* @flow */
2
- import { supportsPopups as userAgentSupportsPopups, isAndroid, isChrome, isIos, isIOS14, isSafari, isSFVC, type Experiment, isDevice, isTablet, getElement, isLocalStorageEnabled, isStandAlone, once } from '@krakenjs/belter/src';
3
- import { CURRENCY, ENV, FUNDING } from '@paypal/sdk-constants/src';
4
- import { getEnableFunding, getLogger, createExperiment, getFundingEligibility, getPlatform, getComponents, getEnv, type FundingEligibilityType } from '@paypal/sdk-client/src';
5
- import { getRefinedFundingEligibility } from '@paypal/funding-components/src';
6
-
7
- import type { Experiment as EligibilityExperiment } from '../../types';
8
- import { BUTTON_FLOW, BUTTON_SIZE, BUTTON_LAYOUT } from '../../constants';
9
- import type { ApplePaySessionConfigRequest, CreateBillingAgreement, CreateSubscription, ButtonProps } from '../../ui/buttons/props';
10
- import { determineEligibleFunding } from '../../funding';
11
- import { BUTTON_SIZE_STYLE } from '../../ui/buttons/config';
2
+ import {
3
+ supportsPopups as userAgentSupportsPopups,
4
+ isAndroid,
5
+ isChrome,
6
+ isIos,
7
+ isIOS14,
8
+ isSafari,
9
+ isSFVC,
10
+ type Experiment,
11
+ isDevice,
12
+ isTablet,
13
+ getElement,
14
+ isLocalStorageEnabled,
15
+ isStandAlone,
16
+ once,
17
+ } from "@krakenjs/belter/src";
18
+ import { CURRENCY, ENV, FUNDING } from "@paypal/sdk-constants/src";
19
+ import {
20
+ getEnableFunding,
21
+ getLogger,
22
+ createExperiment,
23
+ getFundingEligibility,
24
+ getPlatform,
25
+ getComponents,
26
+ getEnv,
27
+ type FundingEligibilityType,
28
+ } from "@paypal/sdk-client/src";
29
+ import { getRefinedFundingEligibility } from "@paypal/funding-components/src";
30
+
31
+ import type { Experiment as EligibilityExperiment } from "../../types";
32
+ import { BUTTON_FLOW, BUTTON_SIZE, BUTTON_LAYOUT } from "../../constants";
33
+ import type {
34
+ ApplePaySessionConfigRequest,
35
+ CreateBillingAgreement,
36
+ CreateSubscription,
37
+ ButtonProps,
38
+ CreateVaultSetupToken,
39
+ } from "../../ui/buttons/props";
40
+ import { determineEligibleFunding } from "../../funding";
41
+ import { BUTTON_SIZE_STYLE } from "../../ui/buttons/config";
12
42
 
13
43
  type DetermineFlowOptions = {|
14
- createBillingAgreement : CreateBillingAgreement,
15
- createSubscription : CreateSubscription
44
+ createBillingAgreement: CreateBillingAgreement,
45
+ createSubscription: CreateSubscription,
46
+ createVaultSetupToken: CreateVaultSetupToken,
16
47
  |};
17
48
 
18
49
  /**
@@ -20,305 +51,375 @@ type DetermineFlowOptions = {|
20
51
  *
21
52
  * @param {string} key for logging
22
53
  */
23
- const logNativeScreenInformation = once((key = 'screenInformation') => {
54
+ const logNativeScreenInformation = once((key = "screenInformation") => {
24
55
  if (window) {
25
56
  const height = window.innerHeight;
26
57
  const outerHeight = window.outerHeight;
27
- const scale = Math.round(window.screen.width / window.innerWidth * 100) / 100;
58
+ const scale =
59
+ Math.round((window.screen.width / window.innerWidth) * 100) / 100;
28
60
  const computedHeight = Math.round(height * scale);
29
61
  const ios14 = isIOS14();
30
62
  const standAlone = isStandAlone();
31
63
 
32
- const screenInformation = { computedHeight, height, ios14, outerHeight, scale, standAlone };
64
+ const screenInformation = {
65
+ computedHeight,
66
+ height,
67
+ ios14,
68
+ outerHeight,
69
+ scale,
70
+ standAlone,
71
+ };
33
72
 
34
73
  getLogger()
35
74
  // $FlowFixMe - object is mixed values when this expects all of the same value types
36
- .info(key, screenInformation)
75
+ .info(key, screenInformation);
37
76
  }
38
77
  });
39
78
 
40
- export function determineFlow(props : DetermineFlowOptions) : $Values<typeof BUTTON_FLOW> {
41
-
42
- if (props.createBillingAgreement) {
43
- return BUTTON_FLOW.BILLING_SETUP;
44
- } else if (props.createSubscription) {
45
- return BUTTON_FLOW.SUBSCRIPTION_SETUP;
46
- } else {
47
- return BUTTON_FLOW.PURCHASE;
48
- }
79
+ export function determineFlow(
80
+ props: DetermineFlowOptions
81
+ ): $Values<typeof BUTTON_FLOW> {
82
+ if (props.createVaultSetupToken) {
83
+ return BUTTON_FLOW.VAULT_WITHOUT_PURCHASE;
84
+ } else if (props.createBillingAgreement) {
85
+ return BUTTON_FLOW.BILLING_SETUP;
86
+ } else if (props.createSubscription) {
87
+ return BUTTON_FLOW.SUBSCRIPTION_SETUP;
88
+ } else {
89
+ return BUTTON_FLOW.PURCHASE;
90
+ }
49
91
  }
50
92
 
51
- export function isSupportedNativeBrowser() : boolean {
52
- if (typeof window === 'undefined') {
53
- return false;
54
- }
93
+ export function isSupportedNativeBrowser(): boolean {
94
+ if (typeof window === "undefined") {
95
+ return false;
96
+ }
55
97
 
56
- if (!userAgentSupportsPopups()) {
57
- return false;
58
- }
98
+ if (!userAgentSupportsPopups()) {
99
+ return false;
100
+ }
59
101
 
60
- if (isSFVC()) {
61
- logNativeScreenInformation('sfvcScreenInformation');
62
- return false;
63
- }
102
+ if (isSFVC()) {
103
+ logNativeScreenInformation("sfvcScreenInformation");
104
+ return false;
105
+ }
64
106
 
65
- if (isTablet()) {
66
- return false;
107
+ if (isTablet()) {
108
+ return false;
109
+ }
110
+
111
+ if (isIos() && isSafari()) {
112
+ return true;
113
+ }
114
+
115
+ if (isAndroid() && isChrome()) {
116
+ return true;
117
+ }
118
+
119
+ return false;
120
+ }
121
+
122
+ export function createVenmoExperiment(): ?Experiment {
123
+ const enableFunding = getEnableFunding();
124
+ const isEnableFundingVenmo =
125
+ enableFunding && enableFunding.indexOf(FUNDING.VENMO) !== -1;
126
+
127
+ const fundingEligibility = getFundingEligibility();
128
+ const hasBasicVenmoEligibility =
129
+ fundingEligibility &&
130
+ fundingEligibility[FUNDING.VENMO] &&
131
+ fundingEligibility[FUNDING.VENMO].eligible;
132
+ const isEligibleForVenmoNative =
133
+ isSupportedNativeBrowser() && !isEnableFundingVenmo;
134
+
135
+ // basic eligibility must be true for venmo to be eligible for the experiments
136
+ if (!hasBasicVenmoEligibility) {
137
+ return;
138
+ }
139
+
140
+ if (isDevice()) {
141
+ if (!isEligibleForVenmoNative) {
142
+ return;
67
143
  }
68
144
 
69
145
  if (isIos() && isSafari()) {
70
- return true;
146
+ return createExperiment("enable_venmo_ios", 100);
71
147
  }
72
148
 
73
149
  if (isAndroid() && isChrome()) {
74
- return true;
150
+ return createExperiment("enable_venmo_android", 100);
75
151
  }
76
-
77
- return false;
152
+ } else {
153
+ return createExperiment("enable_venmo_desktop", 100);
154
+ }
78
155
  }
79
156
 
80
- export function createVenmoExperiment() : ?Experiment {
81
- const enableFunding = getEnableFunding();
82
- const isEnableFundingVenmo = enableFunding && enableFunding.indexOf(FUNDING.VENMO) !== -1;
157
+ export function getVenmoExperiment(): EligibilityExperiment {
158
+ const experiment = createVenmoExperiment();
83
159
 
84
- const fundingEligibility = getFundingEligibility();
85
- const hasBasicVenmoEligibility = fundingEligibility && fundingEligibility[FUNDING.VENMO] && fundingEligibility[FUNDING.VENMO].eligible;
86
- const isEligibleForVenmoNative = isSupportedNativeBrowser() && !isEnableFundingVenmo;
160
+ const enableFunding = getEnableFunding();
161
+ const isVenmoFundingEnabled =
162
+ enableFunding && enableFunding.indexOf(FUNDING.VENMO) !== -1;
163
+ const isNativeSupported = isSupportedNativeBrowser();
164
+ const isExperimentEnabled = experiment && experiment.isEnabled();
87
165
 
88
- // basic eligibility must be true for venmo to be eligible for the experiments
89
- if (!hasBasicVenmoEligibility) {
90
- return;
91
- }
166
+ if (isDevice()) {
167
+ return {
168
+ enableVenmo: Boolean(
169
+ (isExperimentEnabled || isVenmoFundingEnabled) && isNativeSupported
170
+ ),
171
+ };
172
+ } else {
173
+ return {
174
+ enableVenmo: Boolean(isExperimentEnabled),
175
+ };
176
+ }
177
+ }
92
178
 
93
- if (isDevice()) {
94
- if (!isEligibleForVenmoNative) {
95
- return;
96
- }
179
+ export function getVenmoAppLabelExperiment(): EligibilityExperiment {
180
+ const isEnvForTest =
181
+ getEnv() === ENV.LOCAL || getEnv() === ENV.TEST || getEnv() === ENV.STAGE;
97
182
 
98
- if (isIos() && isSafari()) {
99
- return createExperiment('enable_venmo_ios', 100);
100
- }
183
+ let isEnabledForTest = false;
101
184
 
102
- if (isAndroid() && isChrome()) {
103
- return createExperiment('enable_venmo_android', 100);
104
- }
105
- } else {
106
- return createExperiment('enable_venmo_desktop', 100);
107
- }
108
- }
185
+ if (isLocalStorageEnabled() && isEnvForTest) {
186
+ isEnabledForTest = window.localStorage.getItem("enable_venmo_app_label");
187
+ }
109
188
 
110
- export function getVenmoExperiment() : EligibilityExperiment {
111
- const experiment = createVenmoExperiment();
112
-
113
- const enableFunding = getEnableFunding();
114
- const isVenmoFundingEnabled = enableFunding && enableFunding.indexOf(FUNDING.VENMO) !== -1;
115
- const isNativeSupported = isSupportedNativeBrowser();
116
- const isExperimentEnabled = experiment && experiment.isEnabled();
117
-
118
- if (isDevice()) {
119
- return {
120
- enableVenmo: Boolean((isExperimentEnabled || isVenmoFundingEnabled) && isNativeSupported)
121
- };
122
- } else {
123
- return {
124
- enableVenmo: Boolean(isExperimentEnabled)
125
- };
126
- }
189
+ return {
190
+ enableVenmoAppLabel: isEnabledForTest,
191
+ };
127
192
  }
128
193
 
129
- export function getVenmoAppLabelExperiment() : EligibilityExperiment {
130
- const isEnvForTest = getEnv() === ENV.LOCAL || getEnv() === ENV.TEST || getEnv() === ENV.STAGE;
131
-
132
- let isEnabledForTest = false;
194
+ export function getRenderedButtons(
195
+ props: ButtonProps
196
+ ): $ReadOnlyArray<$Values<typeof FUNDING>> {
197
+ const {
198
+ fundingSource,
199
+ onShippingChange,
200
+ onShippingAddressChange,
201
+ onShippingOptionsChange,
202
+ style = {},
203
+ fundingEligibility = getRefinedFundingEligibility(),
204
+ experiment = getVenmoExperiment(),
205
+ applePaySupport,
206
+ supportsPopups = userAgentSupportsPopups(),
207
+ supportedNativeBrowser = isSupportedNativeBrowser(),
208
+ createBillingAgreement,
209
+ createSubscription,
210
+ createVaultSetupToken,
211
+ } = props;
212
+
213
+ const flow = determineFlow({
214
+ createBillingAgreement,
215
+ createSubscription,
216
+ createVaultSetupToken,
217
+ });
218
+ const { layout } = style;
219
+ const remembered = [];
220
+ const platform = getPlatform();
221
+ const components = getComponents();
222
+
223
+ const renderedButtons = determineEligibleFunding({
224
+ fundingSource,
225
+ remembered,
226
+ layout,
227
+ platform,
228
+ fundingEligibility,
229
+ components,
230
+ onShippingChange,
231
+ onShippingAddressChange,
232
+ onShippingOptionsChange,
233
+ flow,
234
+ applePaySupport,
235
+ supportsPopups,
236
+ supportedNativeBrowser,
237
+ experiment,
238
+ });
239
+ return renderedButtons;
240
+ }
133
241
 
134
- if (isLocalStorageEnabled() && isEnvForTest) {
135
- isEnabledForTest = window.localStorage.getItem('enable_venmo_app_label');
242
+ export function applePaySession(): ?ApplePaySessionConfigRequest {
243
+ try {
244
+ if (!window.ApplePaySession) {
245
+ return;
136
246
  }
137
247
 
138
- return {
139
- enableVenmoAppLabel: isEnabledForTest
248
+ const convertErrorsFromUpdate = (update) => {
249
+ return {
250
+ ...update,
251
+ errors: (update.errors || []).map(
252
+ (error) =>
253
+ new window.ApplePayError(
254
+ error.code,
255
+ error.contactField,
256
+ error.message
257
+ )
258
+ ),
259
+ };
260
+ };
261
+
262
+ return (version, request) => {
263
+ const session = new window.ApplePaySession(version, request);
264
+ const listeners = {};
265
+
266
+ session.onvalidatemerchant = ({ validationURL }) => {
267
+ listeners.validatemerchant({ validationURL });
268
+ };
269
+
270
+ session.onpaymentmethodselected = ({ paymentMethod }) => {
271
+ listeners.paymentmethodselected({ paymentMethod });
272
+ };
273
+
274
+ session.onshippingmethodselected = ({ shippingMethod }) => {
275
+ listeners.shippingmethodselected({ shippingMethod });
276
+ };
277
+
278
+ session.onshippingcontactselected = ({ shippingContact }) => {
279
+ listeners.shippingcontactselected({ shippingContact });
280
+ };
281
+
282
+ session.onpaymentauthorized = ({ payment }) => {
283
+ listeners.paymentauthorized({ payment });
284
+ };
285
+
286
+ // eslint-disable-next-line unicorn/prefer-add-event-listener
287
+ session.oncancel = () => {
288
+ listeners.oncancel();
289
+ };
290
+
291
+ return {
292
+ addEventListener: (name, handler) => {
293
+ listeners[name] = handler;
294
+ },
295
+ completeMerchantValidation: (validatedSession) => {
296
+ session.completeMerchantValidation(validatedSession);
297
+ },
298
+ completePaymentMethodSelection: (update) => {
299
+ session.completePaymentMethodSelection(update);
300
+ },
301
+ completeShippingMethodSelection: (update) => {
302
+ session.completeShippingMethodSelection(update);
303
+ },
304
+ completeShippingContactSelection: (update) => {
305
+ const newUpdate = convertErrorsFromUpdate(update);
306
+ session.completeShippingContactSelection(newUpdate);
307
+ },
308
+ completePayment: (update) => {
309
+ const newUpdate = convertErrorsFromUpdate(update);
310
+ session.completePayment(newUpdate);
311
+ },
312
+ begin: () => session.begin(),
313
+ abort: () => session.abort(),
314
+ };
140
315
  };
316
+ } catch (e) {
317
+ return undefined;
318
+ }
141
319
  }
142
320
 
143
- export function getRenderedButtons(props : ButtonProps) : $ReadOnlyArray<$Values<typeof FUNDING>> {
144
- const { fundingSource, onShippingChange, onShippingAddressChange, onShippingOptionsChange, style = {}, fundingEligibility = getRefinedFundingEligibility(),
145
- experiment = getVenmoExperiment(), applePaySupport, supportsPopups = userAgentSupportsPopups(),
146
- supportedNativeBrowser = isSupportedNativeBrowser(), createBillingAgreement, createSubscription } = props;
321
+ export function getButtonExperiments(): EligibilityExperiment {
322
+ return {
323
+ ...getVenmoExperiment(),
324
+ ...getVenmoAppLabelExperiment(),
325
+ };
326
+ }
147
327
 
148
- const flow = determineFlow({ createBillingAgreement, createSubscription });
149
- const { layout } = style;
150
- const remembered = [];
151
- const platform = getPlatform();
152
- const components = getComponents();
328
+ export function getButtonSize(
329
+ props: ButtonProps,
330
+ container: string | HTMLElement | void
331
+ ): string | void {
332
+ if (!container) {
333
+ return;
334
+ }
153
335
 
154
- const renderedButtons = determineEligibleFunding({ fundingSource, remembered, layout, platform, fundingEligibility, components, onShippingChange, onShippingAddressChange, onShippingOptionsChange, flow, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
155
- return renderedButtons;
156
- }
336
+ let containerWidth = 0;
337
+
338
+ if (typeof container === "string") {
339
+ const containerElement = document.querySelector(container);
340
+ containerWidth = containerElement?.offsetWidth || 0;
341
+ } else {
342
+ containerWidth = getElement(container)?.offsetWidth;
343
+ }
344
+
345
+ const layout = props?.style?.layout || BUTTON_LAYOUT.HORIZONTAL;
346
+ const numButtonsRendered = props?.renderedButtons?.length || 1;
347
+ const { tiny, small, medium, large, huge } = BUTTON_SIZE_STYLE;
157
348
 
158
- export function applePaySession() : ?ApplePaySessionConfigRequest {
159
- try {
160
- if (!window.ApplePaySession) {
161
- return;
162
- }
163
-
164
- const convertErrorsFromUpdate = (update) => {
165
- return {
166
- ...update,
167
- errors: (update.errors || []).map(error => new window.ApplePayError(error.code, error.contactField, error.message))
168
- };
169
- };
170
-
171
- return (version, request) => {
172
- const session = new window.ApplePaySession(version, request);
173
- const listeners = {};
174
-
175
- session.onvalidatemerchant = ({ validationURL }) => {
176
- listeners.validatemerchant({ validationURL });
177
- };
178
-
179
- session.onpaymentmethodselected = ({ paymentMethod }) => {
180
- listeners.paymentmethodselected({ paymentMethod });
181
- };
182
-
183
- session.onshippingmethodselected = ({ shippingMethod }) => {
184
- listeners.shippingmethodselected({ shippingMethod });
185
- };
186
-
187
- session.onshippingcontactselected = ({ shippingContact }) => {
188
- listeners.shippingcontactselected({ shippingContact });
189
- };
190
-
191
- session.onpaymentauthorized = ({ payment }) => {
192
- listeners.paymentauthorized({ payment });
193
- };
194
-
195
- // eslint-disable-next-line unicorn/prefer-add-event-listener
196
- session.oncancel = () => {
197
- listeners.oncancel();
198
- };
199
-
200
- return {
201
- addEventListener: (name, handler) => {
202
- listeners[name] = handler;
203
- },
204
- completeMerchantValidation: (validatedSession) => {
205
- session.completeMerchantValidation(validatedSession);
206
- },
207
- completePaymentMethodSelection: (update) => {
208
- session.completePaymentMethodSelection(update);
209
- },
210
- completeShippingMethodSelection: (update) => {
211
- session.completeShippingMethodSelection(update);
212
- },
213
- completeShippingContactSelection: (update) => {
214
- const newUpdate = convertErrorsFromUpdate(update);
215
- session.completeShippingContactSelection(newUpdate);
216
- },
217
- completePayment: (update) => {
218
- const newUpdate = convertErrorsFromUpdate(update);
219
- session.completePayment(newUpdate);
220
- },
221
- begin: () => session.begin(),
222
- abort: () => session.abort()
223
- };
224
- };
225
- } catch (e) {
226
- return undefined;
349
+ if (containerWidth) {
350
+ let buttonWidth = Math.min(containerWidth, 750);
351
+ const spaceBetweenHorizontalButtons = 8;
352
+ if (layout === BUTTON_LAYOUT.HORIZONTAL && numButtonsRendered === 2) {
353
+ buttonWidth = (buttonWidth - spaceBetweenHorizontalButtons) / 2;
227
354
  }
228
- }
229
355
 
230
- export function getButtonExperiments () : EligibilityExperiment {
231
- return {
232
- ...getVenmoExperiment(),
233
- ...getVenmoAppLabelExperiment()
234
- };
235
- }
356
+ if (tiny.minWidth <= buttonWidth && buttonWidth <= tiny.maxWidth) {
357
+ return BUTTON_SIZE.TINY;
358
+ }
236
359
 
237
- export function getButtonSize (props : ButtonProps, container : string | HTMLElement | void) : string | void {
238
- if (!container) {
239
- return;
360
+ if (small.minWidth < buttonWidth && buttonWidth <= small.maxWidth) {
361
+ return BUTTON_SIZE.SMALL;
240
362
  }
241
363
 
242
- let containerWidth = 0;
364
+ if (medium.minWidth < buttonWidth && buttonWidth <= medium.maxWidth) {
365
+ return BUTTON_SIZE.MEDIUM;
366
+ }
243
367
 
244
- if (typeof container === 'string') {
245
- const containerElement = document.querySelector(container);
246
- containerWidth = containerElement?.offsetWidth || 0;
247
- } else {
248
- containerWidth = getElement(container)?.offsetWidth;
368
+ if (large.minWidth < buttonWidth && buttonWidth <= large.maxWidth) {
369
+ return BUTTON_SIZE.LARGE;
249
370
  }
250
371
 
251
- const layout = props?.style?.layout || BUTTON_LAYOUT.HORIZONTAL;
252
- const numButtonsRendered = props?.renderedButtons?.length || 1;
253
- const {
254
- tiny,
255
- small,
256
- medium,
257
- large,
258
- huge
259
- } = BUTTON_SIZE_STYLE;
260
-
261
- if (containerWidth) {
262
- let buttonWidth = Math.min(containerWidth, 750);
263
- const spaceBetweenHorizontalButtons = 8;
264
- if (layout === BUTTON_LAYOUT.HORIZONTAL && numButtonsRendered === 2) {
265
- buttonWidth = (buttonWidth - spaceBetweenHorizontalButtons) / 2;
266
- }
267
-
268
- if (tiny.minWidth <= buttonWidth && buttonWidth <= tiny.maxWidth) {
269
- return BUTTON_SIZE.TINY;
270
- }
271
-
272
- if (small.minWidth < buttonWidth && buttonWidth <= small.maxWidth) {
273
- return BUTTON_SIZE.SMALL;
274
- }
275
-
276
- if (medium.minWidth < buttonWidth && buttonWidth <= medium.maxWidth) {
277
- return BUTTON_SIZE.MEDIUM;
278
- }
279
-
280
- if (large.minWidth < buttonWidth && buttonWidth <= large.maxWidth) {
281
- return BUTTON_SIZE.LARGE;
282
- }
283
-
284
- if (huge.minWidth < buttonWidth) {
285
- return BUTTON_SIZE.HUGE;
286
- }
372
+ if (huge.minWidth < buttonWidth) {
373
+ return BUTTON_SIZE.HUGE;
287
374
  }
375
+ }
288
376
  }
289
377
 
290
378
  type InlineCheckoutEligibilityProps = {|
291
- commit : boolean,
292
- createBillingAgreement? : Function,
293
- currency : string,
294
- disableFunding : $ReadOnlyArray<$Values<typeof FUNDING>>,
295
- fundingEligibility : FundingEligibilityType,
296
- layout : $Values<typeof BUTTON_LAYOUT>,
297
- merchantID? : $ReadOnlyArray<string>,
298
- onComplete : Function,
299
- custom? : ?{|
300
- css? : {|
301
- [string] : string
302
- |},
303
- label? : string
379
+ commit: boolean,
380
+ createBillingAgreement?: Function,
381
+ currency: string,
382
+ disableFunding: $ReadOnlyArray<$Values<typeof FUNDING>>,
383
+ fundingEligibility: FundingEligibilityType,
384
+ layout: $Values<typeof BUTTON_LAYOUT>,
385
+ merchantID?: $ReadOnlyArray<string>,
386
+ onComplete: Function,
387
+ custom?: ?{|
388
+ css?: {|
389
+ [string]: string,
304
390
  |},
305
- vault : boolean
391
+ label?: string,
392
+ |},
393
+ vault: boolean,
306
394
  |};
307
395
 
308
- export function isInlineXOEligible({ props } : {| props : InlineCheckoutEligibilityProps |}) : boolean {
309
- const { commit, currency, custom, createBillingAgreement, disableFunding, fundingEligibility, layout, onComplete, vault } = props;
310
-
311
- const isEligible = (
312
- custom?.label && custom.label.length > 0,
313
- onComplete &&
314
- commit === true &&
315
- !createBillingAgreement &&
316
- currency === CURRENCY.USD &&
317
- (disableFunding?.indexOf(FUNDING.CARD) === -1) &&
318
- (fundingEligibility?.card?.eligible || false) &&
319
- layout === BUTTON_LAYOUT.VERTICAL &&
320
- vault === false
321
- );
322
-
323
- return isEligible;
396
+ export function isInlineXOEligible({
397
+ props,
398
+ }: {|
399
+ props: InlineCheckoutEligibilityProps,
400
+ |}): boolean {
401
+ const {
402
+ commit,
403
+ currency,
404
+ custom,
405
+ createBillingAgreement,
406
+ disableFunding,
407
+ fundingEligibility,
408
+ layout,
409
+ onComplete,
410
+ vault,
411
+ } = props;
412
+
413
+ const isEligible =
414
+ (custom?.label && custom.label.length > 0,
415
+ onComplete &&
416
+ commit === true &&
417
+ !createBillingAgreement &&
418
+ currency === CURRENCY.USD &&
419
+ disableFunding?.indexOf(FUNDING.CARD) === -1 &&
420
+ (fundingEligibility?.card?.eligible || false) &&
421
+ layout === BUTTON_LAYOUT.VERTICAL &&
422
+ vault === false);
423
+
424
+ return isEligible;
324
425
  }