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