@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,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";