@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,8 +1,11 @@
1
1
  /* @flow */
2
2
 
3
- import type { LazyExport } from '../types';
4
- import { getPaymentFieldsComponent, type PaymentFieldsComponent } from '../zoid/payment-fields/component';
3
+ import type { LazyExport } from "../types";
4
+ import {
5
+ getPaymentFieldsComponent,
6
+ type PaymentFieldsComponent,
7
+ } from "../zoid/payment-fields/component";
5
8
 
6
- export const PaymentFields : LazyExport<PaymentFieldsComponent> = {
7
- __get__: () => getPaymentFieldsComponent()
9
+ export const PaymentFields: LazyExport<PaymentFieldsComponent> = {
10
+ __get__: () => getPaymentFieldsComponent(),
8
11
  };
@@ -1,8 +1,8 @@
1
1
  /* @flow */
2
2
 
3
- import type { LazyExport } from '../types';
4
- import { getWalletComponent, type WalletComponent } from '../zoid/wallet';
3
+ import type { LazyExport } from "../types";
4
+ import { getWalletComponent, type WalletComponent } from "../zoid/wallet";
5
5
 
6
- export const Wallet : LazyExport<WalletComponent> = {
7
- __get__: () => getWalletComponent()
6
+ export const Wallet: LazyExport<WalletComponent> = {
7
+ __get__: () => getWalletComponent(),
8
8
  };
package/src/lib/errors.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /* @flow */
2
2
 
3
- import { ERROR_CODE } from '@paypal/sdk-constants/src';
3
+ import { ERROR_CODE } from "@paypal/sdk-constants/src";
4
4
 
5
5
  export class ValidationError extends Error {
6
- code : string;
6
+ code: string;
7
7
 
8
- constructor(message : string) {
9
- super(message);
10
- this.name = 'ValidationError';
11
- this.code = ERROR_CODE.VALIDATION_ERROR;
12
- }
8
+ constructor(message: string) {
9
+ super(message);
10
+ this.name = "ValidationError";
11
+ this.code = ERROR_CODE.VALIDATION_ERROR;
12
+ }
13
13
  }
package/src/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* @flow */
2
2
 
3
- export * from './errors';
4
- export * from './isRTLLanguage';
5
- export * from './security';
6
- export * from './session';
7
- export * from './perceived-latency-instrumentation';
3
+ export * from "./errors";
4
+ export * from "./isRTLLanguage";
5
+ export * from "./security";
6
+ export * from "./session";
7
+ export * from "./perceived-latency-instrumentation";
@@ -1,6 +1,6 @@
1
1
  /* @flow */
2
- import { LANG } from '@paypal/sdk-constants/src';
2
+ import { LANG } from "@paypal/sdk-constants/src";
3
3
 
4
- export const isRTLLanguage = (languageCode : $Values<typeof LANG>) : boolean => {
5
- return languageCode === LANG.HE || languageCode === LANG.AR;
4
+ export const isRTLLanguage = (languageCode: $Values<typeof LANG>): boolean => {
5
+ return languageCode === LANG.HE || languageCode === LANG.AR;
6
6
  };
@@ -1,32 +1,40 @@
1
1
  /* @flow */
2
2
 
3
3
  type LogLatencyInstrumentationPhaseParams = {|
4
- buttonSessionID : string,
5
- phase : string
4
+ buttonSessionID: string,
5
+ phase: string,
6
6
  |};
7
7
 
8
8
  type InstrumentationPayload = {|
9
- comp? : Object,
10
- chunk? : Object,
11
- query? : Object
9
+ comp?: Object,
10
+ chunk?: Object,
11
+ query?: Object,
12
12
  |};
13
13
 
14
- function getNavigationTimeOrigin() : number {
15
- if (window.performance) {
16
- const hrSyncPoint = performance.now();
17
- const unixSyncPoint = new Date().getTime();
18
- return window.performance.timeOrigin || window.performance.timing.navigationStart || (unixSyncPoint - hrSyncPoint);
19
- } else {
20
- throw new Error('window.performance not supported');
21
- }
14
+ function getNavigationTimeOrigin(): number {
15
+ if (window.performance) {
16
+ const hrSyncPoint = performance.now();
17
+ const unixSyncPoint = new Date().getTime();
18
+ return (
19
+ window.performance.timeOrigin ||
20
+ window.performance.timing.navigationStart ||
21
+ unixSyncPoint - hrSyncPoint
22
+ );
23
+ } else {
24
+ throw new Error("window.performance not supported");
25
+ }
22
26
  }
23
27
 
24
- function getStartTimeFromMark({ buttonSessionID, phase } : LogLatencyInstrumentationPhaseParams) : number {
25
- if (window.performance) {
26
- return performance.getEntriesByName(`${ buttonSessionID }_${ phase }`).pop().startTime;
27
- } else {
28
- throw new Error('window.performance not supported');
29
- }
28
+ function getStartTimeFromMark({
29
+ buttonSessionID,
30
+ phase,
31
+ }: LogLatencyInstrumentationPhaseParams): number {
32
+ if (window.performance) {
33
+ return performance.getEntriesByName(`${buttonSessionID}_${phase}`).pop()
34
+ .startTime;
35
+ } else {
36
+ throw new Error("window.performance not supported");
37
+ }
30
38
  }
31
39
 
32
40
  /* To Track time spent in each phase(cdn download, chunks download, etc)
@@ -39,23 +47,33 @@ function getStartTimeFromMark({ buttonSessionID, phase } : LogLatencyInstrumenta
39
47
  phase: 'html_body'
40
48
  })
41
49
  */
42
- export const logLatencyInstrumentationPhase = ({ buttonSessionID, phase } : LogLatencyInstrumentationPhaseParams) => {
43
- if (window.performance && window.performance.mark) {
44
- window.performance.mark(`${ buttonSessionID }_${ phase }`);
45
- }
50
+ export const logLatencyInstrumentationPhase = ({
51
+ buttonSessionID,
52
+ phase,
53
+ }: LogLatencyInstrumentationPhaseParams) => {
54
+ if (window.performance && window.performance.mark) {
55
+ window.performance.mark(`${buttonSessionID}_${phase}`);
56
+ }
46
57
  };
47
58
 
48
- export const prepareInstrumentationPayload = (buttonSessionID : string) : InstrumentationPayload => {
49
- const timeOrigin = getNavigationTimeOrigin();
50
- const renderStartTime = getStartTimeFromMark({ buttonSessionID, phase: 'buttons-first-render' });
51
- const renderEndTime = getStartTimeFromMark({ buttonSessionID, phase: 'buttons-first-render-end' });
52
- return {
53
- comp: {
54
- 'first-render': {
55
- start: timeOrigin + renderStartTime,
56
- tt: renderEndTime - renderStartTime
57
- }
58
- }
59
- };
59
+ export const prepareInstrumentationPayload = (
60
+ buttonSessionID: string
61
+ ): InstrumentationPayload => {
62
+ const timeOrigin = getNavigationTimeOrigin();
63
+ const renderStartTime = getStartTimeFromMark({
64
+ buttonSessionID,
65
+ phase: "buttons-first-render",
66
+ });
67
+ const renderEndTime = getStartTimeFromMark({
68
+ buttonSessionID,
69
+ phase: "buttons-first-render-end",
70
+ });
71
+ return {
72
+ comp: {
73
+ "first-render": {
74
+ start: timeOrigin + renderStartTime,
75
+ tt: renderEndTime - renderStartTime,
76
+ },
77
+ },
78
+ };
60
79
  };
61
-
@@ -1,26 +1,30 @@
1
1
  /* @flow */
2
2
 
3
- import { isSameDomain } from '@krakenjs/cross-domain-utils/src';
4
- import { supportsPopups } from '@krakenjs/belter/src';
5
- import { isPayPalDomain } from '@paypal/sdk-client/src';
3
+ import { isSameDomain } from "@krakenjs/cross-domain-utils/src";
4
+ import { supportsPopups } from "@krakenjs/belter/src";
5
+ import { isPayPalDomain } from "@paypal/sdk-client/src";
6
6
 
7
- export function allowIframe() : boolean {
7
+ export function allowIframe(): boolean {
8
+ if (!isPayPalDomain()) {
9
+ throw new Error(
10
+ `Can only determine if iframe rendering is allowed on paypal domain`
11
+ );
12
+ }
8
13
 
9
- if (!isPayPalDomain()) {
10
- throw new Error(`Can only determine if iframe rendering is allowed on paypal domain`);
11
- }
14
+ if (!supportsPopups()) {
15
+ return true;
16
+ }
12
17
 
13
- if (!supportsPopups()) {
14
- return true;
15
- }
18
+ const parentComponentWindow = window.xprops && window.xprops.getParent();
19
+ if (parentComponentWindow && isSameDomain(parentComponentWindow)) {
20
+ return true;
21
+ }
16
22
 
17
- const parentComponentWindow = window.xprops && window.xprops.getParent();
18
- if (parentComponentWindow && isSameDomain(parentComponentWindow)) {
19
- return true;
20
- }
21
-
22
- return false;
23
+ return false;
23
24
  }
24
25
 
26
+ /* eslint-disable no-confusing-arrow */
25
27
  // $FlowIssue
26
- export const protectedExport = (unprotectedExport) => (isPayPalDomain() ? unprotectedExport : undefined);
28
+ export const protectedExport = (unprotectedExport) =>
29
+ isPayPalDomain() ? unprotectedExport : undefined;
30
+ /* eslint-enable no-confusing-arrow */
@@ -1,47 +1,51 @@
1
1
  /* @flow */
2
2
 
3
- import { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
4
- import { getSessionID as getSDKSessionID, getStorageState, getSessionState } from '@paypal/sdk-client/src';
3
+ import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
4
+ import {
5
+ getSessionID as getSDKSessionID,
6
+ getStorageState,
7
+ getSessionState,
8
+ } from "@paypal/sdk-client/src";
5
9
 
6
10
  export type StateGetSet = {|
7
- // eslint-disable-next-line no-undef
8
- get : <T>(string) => ZalgoPromise<T>,
9
- // eslint-disable-next-line no-undef
10
- set : <T>(string, T) => ZalgoPromise<T>
11
+ // eslint-disable-next-line no-undef
12
+ get: <T>(string) => ZalgoPromise<T>,
13
+ // eslint-disable-next-line no-undef
14
+ set: <T>(string, T) => ZalgoPromise<T>,
11
15
  |};
12
16
 
13
- export function getSessionID() : string {
14
- if (window.xprops && window.xprops.sessionID) {
15
- return window.xprops.sessionID;
16
- }
17
+ export function getSessionID(): string {
18
+ if (window.xprops && window.xprops.sessionID) {
19
+ return window.xprops.sessionID;
20
+ }
17
21
 
18
- return getSDKSessionID();
22
+ return getSDKSessionID();
19
23
  }
20
24
 
21
- export const storageState : StateGetSet = {
22
- get: <T>(key : string) : ZalgoPromise<T> => {
23
- return getStorageState(state => {
24
- return ZalgoPromise.resolve(state[key]);
25
- });
26
- },
27
- set: <T>(key : string, value : T) : ZalgoPromise<T> => {
28
- return getStorageState(state => {
29
- state[key] = value;
30
- return ZalgoPromise.resolve(value);
31
- });
32
- }
25
+ export const storageState: StateGetSet = {
26
+ get: <T>(key: string): ZalgoPromise<T> => {
27
+ return getStorageState((state) => {
28
+ return ZalgoPromise.resolve(state[key]);
29
+ });
30
+ },
31
+ set: <T>(key: string, value: T): ZalgoPromise<T> => {
32
+ return getStorageState((state) => {
33
+ state[key] = value;
34
+ return ZalgoPromise.resolve(value);
35
+ });
36
+ },
33
37
  };
34
38
 
35
- export const sessionState : StateGetSet = {
36
- get: <T>(key : string) : ZalgoPromise<T> => {
37
- return getSessionState(state => {
38
- return ZalgoPromise.resolve(state[key]);
39
- });
40
- },
41
- set: <T>(key : string, value : T) : ZalgoPromise<T> => {
42
- return getSessionState(state => {
43
- state[key] = value;
44
- return ZalgoPromise.resolve(value);
45
- });
46
- }
39
+ export const sessionState: StateGetSet = {
40
+ get: <T>(key: string): ZalgoPromise<T> => {
41
+ return getSessionState((state) => {
42
+ return ZalgoPromise.resolve(state[key]);
43
+ });
44
+ },
45
+ set: <T>(key: string, value: T): ZalgoPromise<T> => {
46
+ return getSessionState((state) => {
47
+ state[key] = value;
48
+ return ZalgoPromise.resolve(value);
49
+ });
50
+ },
47
51
  };
@@ -1,88 +1,137 @@
1
1
  /* @flow */
2
2
  /** @jsx node */
3
3
 
4
- import { node, dom } from '@krakenjs/jsx-pragmatic/src';
5
- import { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
6
- import { getElement, isDevice, memoize, isApplePaySupported, supportsPopups as userAgentSupportsPopups } from '@krakenjs/belter/src';
7
- import { PLATFORM, FUNDING } from '@paypal/sdk-constants/src';
8
- import { getRememberedFunding } from '@paypal/funding-components/src';
9
- import { getComponents, getFundingEligibility, getEnv } from '@paypal/sdk-client/src';
4
+ import { node, dom } from "@krakenjs/jsx-pragmatic/src";
5
+ import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
6
+ import {
7
+ getElement,
8
+ isDevice,
9
+ memoize,
10
+ isApplePaySupported,
11
+ supportsPopups as userAgentSupportsPopups,
12
+ } from "@krakenjs/belter/src";
13
+ import { PLATFORM, FUNDING } from "@paypal/sdk-constants/src";
14
+ import { getRememberedFunding } from "@paypal/funding-components/src";
15
+ import {
16
+ getComponents,
17
+ getFundingEligibility,
18
+ getEnv,
19
+ } from "@paypal/sdk-client/src";
10
20
 
11
- import type { OnShippingChange, OnShippingAddressChange, OnShippingOptionsChange } from '../ui/buttons/props';
12
- import { BUTTON_LAYOUT, BUTTON_FLOW } from '../constants';
13
- import { determineEligibleFunding, isFundingEligible } from '../funding';
14
- import { isSupportedNativeBrowser, getVenmoExperiment } from '../zoid/buttons/util';
21
+ import type {
22
+ OnShippingChange,
23
+ OnShippingAddressChange,
24
+ OnShippingOptionsChange,
25
+ } from "../ui/buttons/props";
26
+ import { BUTTON_LAYOUT, BUTTON_FLOW } from "../constants";
27
+ import { determineEligibleFunding, isFundingEligible } from "../funding";
28
+ import {
29
+ isSupportedNativeBrowser,
30
+ getVenmoExperiment,
31
+ } from "../zoid/buttons/util";
15
32
 
16
- import { MarksElement } from './template';
33
+ import { MarksElement } from "./template";
17
34
 
18
35
  const DEFAULT_HEIGHT = 20;
19
36
 
20
37
  type MarksInstance = {|
21
- isEligible : () => boolean,
22
- render : (string | HTMLElement) => ZalgoPromise<void>
38
+ isEligible: () => boolean,
39
+ render: (string | HTMLElement) => ZalgoPromise<void>,
23
40
  |};
24
41
 
25
42
  type MarksProps = {|
26
- fundingSource? : ?$Values<typeof FUNDING>,
27
- onShippingChange? : OnShippingChange,
28
- onShippingAddressChange? : OnShippingAddressChange,
29
- onShippingOptionsChange? : OnShippingOptionsChange
43
+ fundingSource?: ?$Values<typeof FUNDING>,
44
+ onShippingChange?: OnShippingChange,
45
+ onShippingAddressChange?: OnShippingAddressChange,
46
+ onShippingOptionsChange?: OnShippingOptionsChange,
30
47
  |};
31
48
 
32
49
  export type MarksComponent = (MarksProps) => MarksInstance;
33
50
 
34
- export const getMarksComponent : () => MarksComponent = memoize(() => {
35
- function Marks({ fundingSource, onShippingChange, onShippingAddressChange, onShippingOptionsChange } : MarksProps = {}) : MarksInstance {
51
+ export const getMarksComponent: () => MarksComponent = memoize(() => {
52
+ function Marks({
53
+ fundingSource,
54
+ onShippingChange,
55
+ onShippingAddressChange,
56
+ onShippingOptionsChange,
57
+ }: MarksProps = {}): MarksInstance {
58
+ const height = DEFAULT_HEIGHT;
59
+ const fundingEligibility = getFundingEligibility();
60
+ const platform = isDevice() ? PLATFORM.MOBILE : PLATFORM.DESKTOP;
61
+ const remembered = getRememberedFunding();
62
+ const layout = BUTTON_LAYOUT.VERTICAL;
63
+ const components = getComponents();
64
+ const flow = BUTTON_FLOW.PURCHASE;
65
+ const applePaySupport = fundingEligibility?.applepay?.eligible
66
+ ? isApplePaySupported()
67
+ : false;
68
+ const supportsPopups = userAgentSupportsPopups();
69
+ const supportedNativeBrowser = isSupportedNativeBrowser();
70
+ const experiment = getVenmoExperiment();
71
+ const fundingSources = determineEligibleFunding({
72
+ fundingSource,
73
+ fundingEligibility,
74
+ components,
75
+ platform,
76
+ remembered,
77
+ layout,
78
+ flow,
79
+ applePaySupport,
80
+ supportsPopups,
81
+ supportedNativeBrowser,
82
+ experiment,
83
+ });
84
+ const env = getEnv();
36
85
 
37
- const height = DEFAULT_HEIGHT;
38
- const fundingEligibility = getFundingEligibility();
39
- const platform = isDevice() ? PLATFORM.MOBILE : PLATFORM.DESKTOP;
40
- const remembered = getRememberedFunding();
41
- const layout = BUTTON_LAYOUT.VERTICAL;
42
- const components = getComponents();
43
- const flow = BUTTON_FLOW.PURCHASE;
44
- const applePaySupport = fundingEligibility?.applepay?.eligible ? isApplePaySupported() : false;
45
- const supportsPopups = userAgentSupportsPopups();
46
- const supportedNativeBrowser = isSupportedNativeBrowser();
47
- const experiment = getVenmoExperiment();
48
- const fundingSources = determineEligibleFunding({ fundingSource, fundingEligibility, components, platform, remembered, layout, flow, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
49
- const env = getEnv();
86
+ const isEligible = () => {
87
+ if (!fundingSource) {
88
+ return true;
89
+ }
50
90
 
51
- const isEligible = () => {
52
- if (!fundingSource) {
53
- return true;
54
- }
91
+ return isFundingEligible(fundingSource, {
92
+ layout,
93
+ platform,
94
+ fundingSource,
95
+ fundingEligibility,
96
+ components,
97
+ onShippingChange,
98
+ onShippingAddressChange,
99
+ onShippingOptionsChange,
100
+ flow,
101
+ applePaySupport,
102
+ supportsPopups,
103
+ supportedNativeBrowser,
104
+ experiment,
105
+ });
106
+ };
55
107
 
56
- return isFundingEligible(fundingSource, { layout, platform, fundingSource, fundingEligibility, components, onShippingChange, onShippingAddressChange, onShippingOptionsChange, flow, applePaySupport, supportsPopups, supportedNativeBrowser, experiment });
57
- };
108
+ const render = (container) => {
109
+ return ZalgoPromise.try(() => {
110
+ if (!isEligible()) {
111
+ throw new Error(`${fundingSource || "marks"} not eligible`);
112
+ }
58
113
 
59
- const render = (container) => {
60
- return ZalgoPromise.try(() => {
61
- if (!isEligible()) {
62
- throw new Error(`${ fundingSource || 'marks' } not eligible`);
63
- }
114
+ getElement(container).appendChild(
115
+ (
116
+ <div>
117
+ <MarksElement
118
+ fundingEligibility={fundingEligibility}
119
+ fundingSources={fundingSources}
120
+ height={height}
121
+ experiment={experiment}
122
+ env={env}
123
+ />
124
+ </div>
125
+ ).render(dom({ doc: document }))
126
+ );
127
+ });
128
+ };
64
129
 
65
- getElement(container).appendChild(
66
- (
67
- <div>
68
- <MarksElement
69
- fundingEligibility={ fundingEligibility }
70
- fundingSources={ fundingSources }
71
- height={ height }
72
- experiment={ experiment }
73
- env={ env }
74
- />
75
- </div>
76
- ).render(dom({ doc: document }))
77
- );
78
- });
79
- };
130
+ return {
131
+ render,
132
+ isEligible,
133
+ };
134
+ }
80
135
 
81
- return {
82
- render,
83
- isEligible
84
- };
85
- }
86
-
87
- return Marks;
136
+ return Marks;
88
137
  });
@@ -1,4 +1,3 @@
1
1
  /* @flow */
2
2
 
3
- export * from './component';
4
-
3
+ export * from "./component";