@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,35 +1,41 @@
1
1
  /* @flow */
2
2
  /** @jsx node */
3
3
 
4
- import { node, type ElementNode } from '@krakenjs/jsx-pragmatic/src';
4
+ import { node, type ElementNode } from "@krakenjs/jsx-pragmatic/src";
5
5
 
6
- import { getComponentScript } from '../script';
6
+ import { getComponentScript } from "../script";
7
7
 
8
8
  type ScriptProps = {|
9
- nonce : ?string,
10
- buttonDesignScript : string
9
+ nonce: ?string,
10
+ buttonDesignScript: string,
11
11
  |};
12
12
 
13
- export function ButtonDesignExperimentScriptWrapper({ nonce, buttonDesignScript } : ScriptProps) : ElementNode {
14
-
15
- const scripts = `
16
- const scriptFns = ${ getComponentScript().toString() };
13
+ export function ButtonDesignExperimentScriptWrapper({
14
+ nonce,
15
+ buttonDesignScript,
16
+ }: ScriptProps): ElementNode {
17
+ const scripts = `
18
+ const scriptFns = ${getComponentScript().toString()};
17
19
  scriptFns();
18
- function onDomLoad(){ ${ buttonDesignScript } };
20
+ function onDomLoad(){ ${buttonDesignScript} };
19
21
  document.addEventListener('DOMContentLoaded', onDomLoad);
20
22
  `;
21
- return (
22
- <script nonce={ nonce } innerHTML={ `(function(){ ${ scripts }})()` } />
23
- );
23
+ return <script nonce={nonce} innerHTML={`(function(){ ${scripts}})()`} />;
24
24
  }
25
25
 
26
- export function getDesignScript(designFn : Function, getValidDesignProps : Function, designConfig : Object) : string {
27
- const buttonDesignScript = `
28
- const designProps = ${ getValidDesignProps.toString() }( document, ${ JSON.stringify(designConfig) })
26
+ export function getDesignScript(
27
+ designFn: Function,
28
+ getValidDesignProps: Function,
29
+ designConfig: Object
30
+ ): string {
31
+ const buttonDesignScript = `
32
+ const designProps = ${getValidDesignProps.toString()}( document, ${JSON.stringify(
33
+ designConfig
34
+ )})
29
35
  if (designProps) {
30
- const applyDesign = ${ designFn.toString() }
31
- applyDesign(designProps, ${ JSON.stringify(designConfig) })
36
+ const applyDesign = ${designFn.toString()}
37
+ applyDesign(designProps, ${JSON.stringify(designConfig)})
32
38
  }
33
39
  `;
34
- return buttonDesignScript;
40
+ return buttonDesignScript;
35
41
  }
@@ -1,13 +1,12 @@
1
1
  /* @flow */
2
- import { type ChildType } from '@krakenjs/jsx-pragmatic/src';
3
-
4
- export type ButtonDesignOutputParams ={|
5
- buttonDesignContainerClass : string,
6
- buttonDesignScript : string,
7
- buttonDesignComponent : ChildType
2
+ import { type ChildType } from "@krakenjs/jsx-pragmatic/src";
8
3
 
4
+ export type ButtonDesignOutputParams = {|
5
+ buttonDesignContainerClass: string,
6
+ buttonDesignScript: string,
7
+ buttonDesignComponent: ChildType,
9
8
  |};
10
9
 
11
10
  export type ContentOptions = {|
12
- designLabelText : string
11
+ designLabelText: string,
13
12
  |};
@@ -1,246 +1,352 @@
1
1
  /* @flow */
2
2
  /** @jsx node */
3
3
 
4
- import { node, type ElementNode } from '@krakenjs/jsx-pragmatic/src';
5
- import { FUNDING, WALLET_INSTRUMENT, APM_LIST } from '@paypal/sdk-constants/src';
6
- import { noop } from '@krakenjs/belter/src';
7
-
8
- import type { Wallet, WalletInstrument } from '../../types';
9
- import { CLASS, BUTTON_NUMBER, BUTTON_LAYOUT, BUTTON_FLOW, EXPERIENCE } from '../../constants';
10
- import { determineEligibleFunding, isWalletFundingEligible } from '../../funding';
11
- import { ValidationError } from '../../lib';
12
-
13
- import { getButtonDesign } from './buttonDesigns';
14
- import { ButtonDesignExperimentScriptWrapper } from './buttonDesigns/script';
15
- import { normalizeButtonProps, type ButtonPropsInputs, type OnShippingChange, type OnShippingAddressChange, type OnShippingOptionsChange } from './props';
16
- import { Style } from './style';
17
- import { Button } from './button';
18
- import { TagLine } from './tagline';
19
- import { Script } from './script';
20
- import { PoweredByPayPal } from './poweredBy';
4
+ import { node, type ElementNode } from "@krakenjs/jsx-pragmatic/src";
5
+ import {
6
+ FUNDING,
7
+ WALLET_INSTRUMENT,
8
+ APM_LIST,
9
+ } from "@paypal/sdk-constants/src";
10
+ import { noop } from "@krakenjs/belter/src";
11
+
12
+ import type { Wallet, WalletInstrument } from "../../types";
13
+ import {
14
+ CLASS,
15
+ BUTTON_NUMBER,
16
+ BUTTON_LAYOUT,
17
+ BUTTON_FLOW,
18
+ EXPERIENCE,
19
+ } from "../../constants";
20
+ import {
21
+ determineEligibleFunding,
22
+ isWalletFundingEligible,
23
+ } from "../../funding";
24
+ import { ValidationError } from "../../lib";
25
+
26
+ import { getButtonDesign } from "./buttonDesigns";
27
+ import { ButtonDesignExperimentScriptWrapper } from "./buttonDesigns/script";
28
+ import {
29
+ normalizeButtonProps,
30
+ type ButtonPropsInputs,
31
+ type OnShippingChange,
32
+ type OnShippingAddressChange,
33
+ type OnShippingOptionsChange,
34
+ } from "./props";
35
+ import { Style } from "./style";
36
+ import { Button } from "./button";
37
+ import { TagLine } from "./tagline";
38
+ import { Script } from "./script";
39
+ import { PoweredByPayPal } from "./poweredBy";
21
40
 
22
41
  type GetWalletInstrumentOptions = {|
23
- wallet : ?Wallet,
24
- fundingSource : $Values<typeof FUNDING>,
25
- onShippingChange : ?OnShippingChange,
26
- onShippingAddressChange : ?OnShippingAddressChange,
27
- onShippingOptionsChange : ?OnShippingOptionsChange
42
+ wallet: ?Wallet,
43
+ fundingSource: $Values<typeof FUNDING>,
44
+ onShippingChange: ?OnShippingChange,
45
+ onShippingAddressChange: ?OnShippingAddressChange,
46
+ onShippingOptionsChange: ?OnShippingOptionsChange,
28
47
  |};
29
48
 
30
- function getWalletInstrument({ wallet, fundingSource, onShippingChange, onShippingAddressChange, onShippingOptionsChange } : GetWalletInstrumentOptions) : ?WalletInstrument {
31
- if (!isWalletFundingEligible({ wallet, onShippingChange, onShippingAddressChange, onShippingOptionsChange })) {
32
- return;
33
- }
34
-
35
- const walletFunding = wallet && wallet[fundingSource.toString()];
36
- const instruments = walletFunding && walletFunding.instruments;
37
-
38
- if (!instruments || !instruments.length) {
39
- return;
40
- }
41
-
42
- return instruments[0];
49
+ function getWalletInstrument({
50
+ wallet,
51
+ fundingSource,
52
+ onShippingChange,
53
+ onShippingAddressChange,
54
+ onShippingOptionsChange,
55
+ }: GetWalletInstrumentOptions): ?WalletInstrument {
56
+ if (
57
+ !isWalletFundingEligible({
58
+ wallet,
59
+ onShippingChange,
60
+ onShippingAddressChange,
61
+ onShippingOptionsChange,
62
+ })
63
+ ) {
64
+ return;
65
+ }
66
+
67
+ const walletFunding = wallet && wallet[fundingSource.toString()];
68
+ const instruments = walletFunding && walletFunding.instruments;
69
+
70
+ if (!instruments || !instruments.length) {
71
+ return;
72
+ }
73
+
74
+ return instruments[0];
43
75
  }
44
76
 
45
77
  const FUNDING_TO_INSTRUMENT = {
46
- [ FUNDING.CREDIT ]: WALLET_INSTRUMENT.CREDIT
78
+ [FUNDING.CREDIT]: WALLET_INSTRUMENT.CREDIT,
47
79
  };
48
80
 
49
81
  type GetWalletInstrumentsOptions = {|
50
- wallet : ?Wallet,
51
- fundingSources : $ReadOnlyArray<$Values<typeof FUNDING>>,
52
- onShippingChange : ?OnShippingChange,
53
- onShippingAddressChange : ?OnShippingAddressChange,
54
- onShippingOptionsChange : ?OnShippingOptionsChange,
55
- layout : $Values<typeof BUTTON_LAYOUT>
82
+ wallet: ?Wallet,
83
+ fundingSources: $ReadOnlyArray<$Values<typeof FUNDING>>,
84
+ onShippingChange: ?OnShippingChange,
85
+ onShippingAddressChange: ?OnShippingAddressChange,
86
+ onShippingOptionsChange: ?OnShippingOptionsChange,
87
+ layout: $Values<typeof BUTTON_LAYOUT>,
56
88
  |};
57
89
 
58
- function getWalletInstruments({ wallet, layout, fundingSources, onShippingChange, onShippingAddressChange, onShippingOptionsChange } : GetWalletInstrumentsOptions) : {| [$Values<typeof FUNDING>] : WalletInstrument |} {
59
-
60
- const instruments = {};
61
- for (const source of fundingSources) {
62
- const instrument = getWalletInstrument({ wallet, fundingSource: source, onShippingChange, onShippingAddressChange, onShippingOptionsChange });
90
+ function getWalletInstruments({
91
+ wallet,
92
+ layout,
93
+ fundingSources,
94
+ onShippingChange,
95
+ onShippingAddressChange,
96
+ onShippingOptionsChange,
97
+ }: GetWalletInstrumentsOptions): {|
98
+ [$Values<typeof FUNDING>]: WalletInstrument,
99
+ |} {
100
+ const instruments = {};
101
+ for (const source of fundingSources) {
102
+ const instrument = getWalletInstrument({
103
+ wallet,
104
+ fundingSource: source,
105
+ onShippingChange,
106
+ onShippingAddressChange,
107
+ onShippingOptionsChange,
108
+ });
63
109
 
64
- if (instrument) {
65
- instruments[source] = instrument;
66
- }
110
+ if (instrument) {
111
+ instruments[source] = instrument;
67
112
  }
68
-
69
- for (const source of Object.keys(instruments)) {
70
- for (const mapSource of Object.keys(FUNDING_TO_INSTRUMENT)) {
71
- if (source !== mapSource && fundingSources.indexOf(mapSource) !== -1 && instruments[source] && instruments[source].type === FUNDING_TO_INSTRUMENT[mapSource]) {
72
- delete instruments[source];
73
- }
74
- }
113
+ }
114
+
115
+ for (const source of Object.keys(instruments)) {
116
+ for (const mapSource of Object.keys(FUNDING_TO_INSTRUMENT)) {
117
+ if (
118
+ source !== mapSource &&
119
+ fundingSources.indexOf(mapSource) !== -1 &&
120
+ instruments[source] &&
121
+ instruments[source].type === FUNDING_TO_INSTRUMENT[mapSource]
122
+ ) {
123
+ delete instruments[source];
124
+ }
75
125
  }
126
+ }
76
127
 
77
- if (layout === BUTTON_LAYOUT.HORIZONTAL) {
78
- let found = false;
79
- for (const source of fundingSources) {
80
- if (instruments[source]) {
81
- if (found) {
82
- delete instruments[source];
83
- } else {
84
- found = true;
85
- }
86
- }
128
+ if (layout === BUTTON_LAYOUT.HORIZONTAL) {
129
+ let found = false;
130
+ for (const source of fundingSources) {
131
+ if (instruments[source]) {
132
+ if (found) {
133
+ delete instruments[source];
134
+ } else {
135
+ found = true;
87
136
  }
137
+ }
88
138
  }
139
+ }
89
140
 
90
- // $FlowFixMe[incompatible-return]
91
- return instruments;
141
+ // $FlowFixMe[incompatible-return]
142
+ return instruments;
92
143
  }
93
144
 
94
145
  type ButtonsProps = ButtonPropsInputs & {|
95
- onClick? : Function,
96
- wallet? : ?Wallet
146
+ onClick?: Function,
147
+ wallet?: ?Wallet,
97
148
  |};
98
149
 
99
- export function validateButtonProps(props : ButtonPropsInputs) {
100
- normalizeButtonProps(props);
150
+ export function validateButtonProps(props: ButtonPropsInputs) {
151
+ normalizeButtonProps(props);
101
152
  }
102
153
 
103
- export function Buttons(props : ButtonsProps) : ElementNode {
104
- const { onClick = noop } = props;
105
- const { wallet, fundingSource, style, locale, remembered, env, fundingEligibility, platform, commit, vault,
106
- nonce, components, onShippingChange, onShippingAddressChange, onShippingOptionsChange, personalization, userIDToken, content, flow, experiment, applePaySupport,
107
- supportsPopups, supportedNativeBrowser, experience, showPayLabel } = normalizeButtonProps(props);
108
- const { custom, layout, shape, tagline } = style;
109
-
110
- const inlineExperience = experience === EXPERIENCE.INLINE && custom && custom.label && custom.label.length !== 0;
111
-
112
- let fundingSources = determineEligibleFunding({ fundingSource, layout, remembered, platform, fundingEligibility, components, onShippingChange, flow, wallet, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
113
- const multiple = fundingSources.length > 1;
114
-
115
- if (!fundingSources.length) {
116
- throw new ValidationError(`No eligible funding fundingSources found to render buttons:\n\n${ JSON.stringify(fundingEligibility, null, 4) }`);
154
+ export function Buttons(props: ButtonsProps): ElementNode {
155
+ const { onClick = noop } = props;
156
+ const {
157
+ wallet,
158
+ fundingSource,
159
+ style,
160
+ locale,
161
+ remembered,
162
+ env,
163
+ fundingEligibility,
164
+ platform,
165
+ commit,
166
+ vault,
167
+ nonce,
168
+ components,
169
+ onShippingChange,
170
+ onShippingAddressChange,
171
+ onShippingOptionsChange,
172
+ personalization,
173
+ userIDToken,
174
+ content,
175
+ flow,
176
+ experiment,
177
+ applePaySupport,
178
+ supportsPopups,
179
+ supportedNativeBrowser,
180
+ experience,
181
+ showPayLabel,
182
+ } = normalizeButtonProps(props);
183
+ const { custom, layout, shape, tagline } = style;
184
+
185
+ const inlineExperience =
186
+ experience === EXPERIENCE.INLINE &&
187
+ custom &&
188
+ custom.label &&
189
+ custom.label.length !== 0;
190
+
191
+ let fundingSources = determineEligibleFunding({
192
+ fundingSource,
193
+ layout,
194
+ remembered,
195
+ platform,
196
+ fundingEligibility,
197
+ components,
198
+ onShippingChange,
199
+ flow,
200
+ wallet,
201
+ applePaySupport,
202
+ supportsPopups,
203
+ supportedNativeBrowser,
204
+ experiment,
205
+ });
206
+ const multiple = fundingSources.length > 1;
207
+
208
+ if (!fundingSources.length) {
209
+ throw new ValidationError(
210
+ `No eligible funding fundingSources found to render buttons:\n\n${JSON.stringify(
211
+ fundingEligibility,
212
+ null,
213
+ 4
214
+ )}`
215
+ );
216
+ }
217
+
218
+ if (fundingSources.indexOf(FUNDING.CARD) !== -1) {
219
+ if (inlineExperience) {
220
+ fundingSources = [
221
+ FUNDING.CARD,
222
+ ...fundingSources.filter((src) => src !== FUNDING.CARD),
223
+ ];
224
+ } else {
225
+ fundingSources = [
226
+ ...fundingSources.filter((src) => src !== FUNDING.CARD),
227
+ FUNDING.CARD,
228
+ ];
117
229
  }
118
-
119
- if (fundingSources.indexOf(FUNDING.CARD) !== -1) {
120
- if (inlineExperience) {
121
- fundingSources = [ FUNDING.CARD, ...fundingSources.filter(src => src !== FUNDING.CARD) ];
122
- } else {
123
- fundingSources = [ ...fundingSources.filter(src => src !== FUNDING.CARD), FUNDING.CARD ];
124
- }
230
+ }
231
+
232
+ const isAPM = fundingSources.some((src) => {
233
+ return APM_LIST.includes(src);
234
+ });
235
+
236
+ const instruments = getWalletInstruments({
237
+ wallet,
238
+ fundingSources,
239
+ layout,
240
+ onShippingChange,
241
+ onShippingAddressChange,
242
+ onShippingOptionsChange,
243
+ });
244
+
245
+ const isWallet =
246
+ flow === BUTTON_FLOW.PURCHASE &&
247
+ ((__WEB__ && userIDToken) || Object.keys(instruments).length);
248
+
249
+ const { buttonDesignScript = "" } = getButtonDesign(personalization);
250
+ const index = (i) => {
251
+ if (!inlineExperience) {
252
+ return i;
125
253
  }
126
254
 
127
- const isAPM = fundingSources.some(src => {
128
- return APM_LIST.includes(src);
129
- });
130
-
131
- const instruments = getWalletInstruments({ wallet, fundingSources, layout, onShippingChange, onShippingAddressChange, onShippingOptionsChange });
132
-
133
- const isWallet = (
134
- flow === BUTTON_FLOW.PURCHASE &&
135
- ((__WEB__ && userIDToken) || Object.keys(instruments).length)
136
- );
137
-
138
- const { buttonDesignScript = '' } = getButtonDesign(personalization);
139
- const index = (i) => {
140
- if (!inlineExperience) {
141
- return i;
142
- }
143
-
144
- // InlineXO: Need to change color indexing because we bring Cards to the top
145
- if (i === 0) {
146
- return fundingSources.length - 1;
147
- } else {
148
- return i - 1;
149
- }
150
- };
151
-
152
- return (
153
- <div class={ [
154
- CLASS.CONTAINER,
155
- `${ CLASS.LAYOUT }-${ layout }`,
156
- `${ CLASS.SHAPE }-${ shape }`,
157
- `${ CLASS.NUMBER }-${ multiple ? BUTTON_NUMBER.MULTIPLE : BUTTON_NUMBER.SINGLE }`,
158
- `${ CLASS.ENV }-${ env }`,
159
- `${ isWallet ? CLASS.WALLET : '' }`
160
- ].join(' ') }>
161
-
162
- <Style
163
- nonce={ nonce }
164
- style={ style }
165
- fundingEligibility={ fundingEligibility }
166
- />
167
-
168
- {
169
- fundingSources.map((source, i) => (
170
- <Button
171
- content={ content }
172
- i={ index(i) }
173
- style={ style }
174
- merchantFundingSource={ fundingSource }
175
- fundingSource={ source }
176
- multiple={ multiple }
177
- env={ env }
178
- locale={ locale }
179
- nonce={ nonce }
180
- fundingEligibility={ fundingEligibility }
181
- wallet={ wallet }
182
- onShippingChange={ onShippingChange }
183
- onShippingAddressChange={ onShippingAddressChange }
184
- onShippingOptionsChange={ onShippingOptionsChange }
185
- onClick={ onClick }
186
- userIDToken={ userIDToken }
187
- personalization={ personalization }
188
- tagline={ tagline }
189
- commit={ commit }
190
- experiment={ experiment }
191
- flow={ flow }
192
- vault={ vault }
193
- instrument={ instruments[source] }
194
- experience={ experience }
195
- showPayLabel={ showPayLabel }
196
- />
197
- ))
198
- }
199
-
200
- {
201
- (tagline && layout === BUTTON_LAYOUT.HORIZONTAL && !fundingSource)
202
- ? <TagLine
203
- fundingSource={ fundingSources[0] }
204
- style={ style }
205
- locale={ locale }
206
- multiple={ multiple }
207
- nonce={ nonce }
208
- personalization={ personalization }
209
- /> : null
210
- }
211
-
212
- {
213
- (fundingSources.indexOf(FUNDING.CARD) !== -1)
214
- ? <div id="card-fields-container" class="card-fields-container" />
215
- : null
216
- }
217
-
218
- {
219
- (isAPM)
220
- ? <div id="payment-fields-container" className="payment-fields-container"/>
221
- : null
222
- }
223
-
224
- {
225
- (layout === BUTTON_LAYOUT.VERTICAL && fundingSources.indexOf(FUNDING.CARD) !== -1 && !inlineExperience)
226
- ? <PoweredByPayPal
227
- locale={ locale }
228
- nonce={ nonce }
229
- /> : null
230
- }
231
-
232
- {
233
- buttonDesignScript
234
- ? <ButtonDesignExperimentScriptWrapper
235
- nonce={ nonce }
236
- buttonDesignScript={ buttonDesignScript }
237
- />
238
- : <Script
239
- nonce={ nonce }
240
- />
241
- }
242
- </div>
243
- );
255
+ // InlineXO: Need to change color indexing because we bring Cards to the top
256
+ if (i === 0) {
257
+ return fundingSources.length - 1;
258
+ } else {
259
+ return i - 1;
260
+ }
261
+ };
262
+
263
+ return (
264
+ <div
265
+ class={[
266
+ CLASS.CONTAINER,
267
+ `${CLASS.LAYOUT}-${layout}`,
268
+ `${CLASS.SHAPE}-${shape}`,
269
+ `${CLASS.NUMBER}-${
270
+ multiple ? BUTTON_NUMBER.MULTIPLE : BUTTON_NUMBER.SINGLE
271
+ }`,
272
+ `${CLASS.ENV}-${env}`,
273
+ `${isWallet ? CLASS.WALLET : ""}`,
274
+ ].join(" ")}
275
+ >
276
+ <Style
277
+ nonce={nonce}
278
+ style={style}
279
+ fundingEligibility={fundingEligibility}
280
+ />
281
+
282
+ {fundingSources.map((source, i) => (
283
+ <Button
284
+ content={content}
285
+ i={index(i)}
286
+ style={style}
287
+ merchantFundingSource={fundingSource}
288
+ fundingSource={source}
289
+ multiple={multiple}
290
+ env={env}
291
+ locale={locale}
292
+ nonce={nonce}
293
+ fundingEligibility={fundingEligibility}
294
+ wallet={wallet}
295
+ onShippingChange={onShippingChange}
296
+ onShippingAddressChange={onShippingAddressChange}
297
+ onShippingOptionsChange={onShippingOptionsChange}
298
+ onClick={onClick}
299
+ userIDToken={userIDToken}
300
+ personalization={personalization}
301
+ tagline={tagline}
302
+ commit={commit}
303
+ experiment={experiment}
304
+ flow={flow}
305
+ vault={vault}
306
+ instrument={instruments[source]}
307
+ experience={experience}
308
+ showPayLabel={showPayLabel}
309
+ />
310
+ ))}
311
+
312
+ {tagline && layout === BUTTON_LAYOUT.HORIZONTAL && !fundingSource ? (
313
+ <TagLine
314
+ fundingSource={fundingSources[0]}
315
+ style={style}
316
+ locale={locale}
317
+ multiple={multiple}
318
+ nonce={nonce}
319
+ personalization={personalization}
320
+ />
321
+ ) : null}
322
+
323
+ {fundingSources.indexOf(FUNDING.CARD) !== -1 ? (
324
+ <div id="card-fields-container" class="card-fields-container" />
325
+ ) : null}
326
+
327
+ {isAPM ? (
328
+ <div
329
+ id="payment-fields-container"
330
+ className="payment-fields-container"
331
+ />
332
+ ) : null}
333
+
334
+ {layout === BUTTON_LAYOUT.VERTICAL &&
335
+ fundingSources.indexOf(FUNDING.CARD) !== -1 &&
336
+ !inlineExperience ? (
337
+ <PoweredByPayPal locale={locale} nonce={nonce} />
338
+ ) : null}
339
+
340
+ {buttonDesignScript ? (
341
+ <ButtonDesignExperimentScriptWrapper
342
+ nonce={nonce}
343
+ buttonDesignScript={buttonDesignScript}
344
+ />
345
+ ) : (
346
+ <Script nonce={nonce} />
347
+ )}
348
+ </div>
349
+ );
244
350
  }
245
351
 
246
- export { DEFAULT_PROPS } from './props';
352
+ export { DEFAULT_PROPS } from "./props";