@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.
- package/README.md +8 -0
- package/__sdk__.js +72 -76
- package/dist/button.js +1 -1
- package/globals.js +28 -30
- package/package.json +6 -4
- package/src/constants/button.js +37 -36
- package/src/constants/class.js +32 -30
- package/src/constants/index.js +3 -3
- package/src/constants/misc.js +14 -12
- package/src/declarations.js +19 -19
- package/src/funding/applepay/config.jsx +51 -50
- package/src/funding/applepay/index.js +1 -1
- package/src/funding/applepay/style.scoped.scss +1 -1
- package/src/funding/applepay/template.jsx +16 -11
- package/src/funding/bancontact/config.jsx +48 -37
- package/src/funding/bancontact/index.js +1 -2
- package/src/funding/blik/config.jsx +48 -37
- package/src/funding/blik/index.js +1 -2
- package/src/funding/boleto/config.jsx +50 -39
- package/src/funding/boleto/index.js +1 -2
- package/src/funding/card/amex/config.js +9 -8
- package/src/funding/card/amex/index.js +1 -2
- package/src/funding/card/config.jsx +246 -177
- package/src/funding/card/discover/config.js +9 -7
- package/src/funding/card/discover/index.js +1 -2
- package/src/funding/card/elo/config.js +6 -7
- package/src/funding/card/elo/index.js +1 -2
- package/src/funding/card/hiper/config.js +9 -7
- package/src/funding/card/hiper/index.js +1 -2
- package/src/funding/card/index.js +1 -1
- package/src/funding/card/jcb/config.js +6 -7
- package/src/funding/card/jcb/index.js +1 -2
- package/src/funding/card/mastercard/config.js +9 -7
- package/src/funding/card/mastercard/index.js +1 -2
- package/src/funding/card/visa/config.js +9 -7
- package/src/funding/card/visa/index.js +1 -2
- package/src/funding/common.jsx +242 -216
- package/src/funding/config.js +212 -65
- package/src/funding/content.jsx +1946 -337
- package/src/funding/credit/config.jsx +74 -57
- package/src/funding/credit/index.js +1 -2
- package/src/funding/eps/config.jsx +45 -37
- package/src/funding/eps/index.js +1 -2
- package/src/funding/funding.js +193 -100
- package/src/funding/giropay/config.jsx +48 -38
- package/src/funding/giropay/index.js +1 -2
- package/src/funding/ideal/config.jsx +48 -37
- package/src/funding/ideal/index.js +1 -2
- package/src/funding/index.js +2 -2
- package/src/funding/itau/config.jsx +41 -41
- package/src/funding/itau/index.js +1 -1
- package/src/funding/maxima/config.jsx +25 -19
- package/src/funding/maxima/index.js +1 -2
- package/src/funding/mercadopago/config.jsx +48 -37
- package/src/funding/mercadopago/index.js +1 -2
- package/src/funding/multibanco/config.jsx +50 -39
- package/src/funding/multibanco/index.js +1 -2
- package/src/funding/mybank/config.jsx +48 -37
- package/src/funding/mybank/index.js +1 -2
- package/src/funding/oxxo/config.jsx +50 -39
- package/src/funding/oxxo/index.js +1 -2
- package/src/funding/p24/config.jsx +45 -37
- package/src/funding/p24/index.js +1 -2
- package/src/funding/paidy/config.jsx +50 -39
- package/src/funding/paidy/index.js +1 -1
- package/src/funding/paylater/config.jsx +118 -111
- package/src/funding/paylater/index.js +1 -2
- package/src/funding/paypal/config.jsx +44 -46
- package/src/funding/paypal/index.js +1 -2
- package/src/funding/paypal/style.scoped.scss +80 -74
- package/src/funding/paypal/template.jsx +450 -354
- package/src/funding/payu/config.jsx +50 -39
- package/src/funding/payu/index.js +1 -1
- package/src/funding/satispay/config.jsx +50 -39
- package/src/funding/satispay/index.js +1 -1
- package/src/funding/sepa/config.jsx +19 -13
- package/src/funding/sepa/index.js +1 -2
- package/src/funding/sofort/config.jsx +48 -37
- package/src/funding/sofort/index.js +1 -2
- package/src/funding/trustly/config.jsx +50 -39
- package/src/funding/trustly/index.js +1 -2
- package/src/funding/venmo/config.jsx +80 -75
- package/src/funding/venmo/index.js +1 -2
- package/src/funding/venmo/style.scoped.scss +30 -32
- package/src/funding/venmo/template.jsx +56 -57
- package/src/funding/verkkopankki/config.jsx +50 -39
- package/src/funding/verkkopankki/index.js +1 -1
- package/src/funding/wechatpay/config.jsx +48 -37
- package/src/funding/wechatpay/index.js +1 -2
- package/src/funding/zimpler/config.jsx +19 -13
- package/src/funding/zimpler/index.js +1 -2
- package/src/interface/button.js +60 -44
- package/src/interface/card-fields.js +11 -8
- package/src/interface/fields.js +7 -4
- package/src/interface/marks.js +4 -4
- package/src/interface/payment-fields.js +7 -4
- package/src/interface/wallet.js +4 -4
- package/src/lib/errors.js +7 -7
- package/src/lib/index.js +5 -5
- package/src/lib/isRTLLanguage.js +3 -3
- package/src/lib/perceived-latency-instrumentation.js +54 -36
- package/src/lib/security.js +21 -17
- package/src/lib/session.js +39 -35
- package/src/marks/component.jsx +114 -65
- package/src/marks/index.js +1 -2
- package/src/marks/template.jsx +79 -65
- package/src/types.js +48 -48
- package/src/ui/buttons/button.jsx +311 -249
- package/src/ui/buttons/buttonDesigns/control.jsx +3 -5
- package/src/ui/buttons/buttonDesigns/divideLogoAnimation.jsx +127 -99
- package/src/ui/buttons/buttonDesigns/index.js +78 -75
- package/src/ui/buttons/buttonDesigns/inlineLogoTextDesign.jsx +102 -82
- package/src/ui/buttons/buttonDesigns/script.jsx +24 -18
- package/src/ui/buttons/buttonDesigns/types.js +6 -7
- package/src/ui/buttons/buttons.jsx +318 -212
- package/src/ui/buttons/config.js +62 -59
- package/src/ui/buttons/content.jsx +304 -119
- package/src/ui/buttons/index.js +1 -1
- package/src/ui/buttons/menu-button/index.js +1 -1
- package/src/ui/buttons/menu-button/menu-button.jsx +29 -22
- package/src/ui/buttons/menu-button/menu-button.scoped.scss +16 -17
- package/src/ui/buttons/poweredBy.jsx +23 -23
- package/src/ui/buttons/props.js +680 -529
- package/src/ui/buttons/script.jsx +182 -160
- package/src/ui/buttons/spinner.jsx +4 -6
- package/src/ui/buttons/style.jsx +15 -14
- package/src/ui/buttons/styles/base.js +24 -16
- package/src/ui/buttons/styles/button.js +24 -22
- package/src/ui/buttons/styles/color.js +118 -118
- package/src/ui/buttons/styles/custom.js +30 -24
- package/src/ui/buttons/styles/index.js +1 -1
- package/src/ui/buttons/styles/labels.js +17 -13
- package/src/ui/buttons/styles/page.js +3 -3
- package/src/ui/buttons/styles/responsive.js +226 -118
- package/src/ui/buttons/tagline.jsx +53 -54
- package/src/ui/chevron.jsx +27 -16
- package/src/ui/index.js +3 -3
- package/src/ui/loading.jsx +25 -18
- package/src/ui/text/index.js +1 -1
- package/src/ui/text/style.scoped.scss +25 -26
- package/src/ui/text/text.jsx +42 -20
- package/src/ui/tracking.jsx +18 -11
- package/src/zoid/buttons/component.jsx +836 -684
- package/src/zoid/buttons/container.jsx +140 -107
- package/src/zoid/buttons/index.js +1 -1
- package/src/zoid/buttons/prerender.jsx +84 -64
- package/src/zoid/buttons/util.js +355 -254
- package/src/zoid/card-fields/component.jsx +581 -549
- package/src/zoid/card-fields/index.js +1 -1
- package/src/zoid/card-fields/prerender.jsx +20 -17
- package/src/zoid/card-form/component.js +155 -141
- package/src/zoid/card-form/index.js +1 -1
- package/src/zoid/checkout/component.jsx +314 -282
- package/src/zoid/checkout/config.js +2 -2
- package/src/zoid/checkout/content.js +190 -154
- package/src/zoid/checkout/hacks.js +31 -28
- package/src/zoid/checkout/index.js +2 -2
- package/src/zoid/checkout/props.js +27 -33
- package/src/zoid/installments/component.jsx +83 -70
- package/src/zoid/installments/index.js +1 -1
- package/src/zoid/installments/props.js +1 -1
- package/src/zoid/menu/component.jsx +53 -48
- package/src/zoid/menu/index.js +1 -1
- package/src/zoid/menu/props.js +1 -3
- package/src/zoid/modal/component.jsx +119 -106
- package/src/zoid/modal/index.js +1 -1
- package/src/zoid/modal/props.js +1 -3
- package/src/zoid/payment-fields/component.jsx +215 -191
- package/src/zoid/payment-fields/container.jsx +73 -64
- package/src/zoid/payment-fields/index.js +1 -1
- package/src/zoid/payment-fields/prerender.jsx +16 -14
- package/src/zoid/payment-fields/props.js +6 -6
- package/src/zoid/qr-code/component.jsx +131 -115
- package/src/zoid/qr-code/container.jsx +74 -68
- package/src/zoid/qr-code/index.js +1 -1
- package/src/zoid/qr-code/prerender.jsx +17 -12
- package/src/zoid/qr-code/types.js +2 -2
- package/src/zoid/wallet/component.jsx +298 -260
- package/src/zoid/wallet/container.jsx +73 -64
- package/src/zoid/wallet/index.js +1 -1
- package/src/zoid/wallet/prerender.jsx +14 -14
- package/src/zoid/wallet/props.js +4 -4
- package/src/actions/save/index.js +0 -40
- package/src/interface/actions.js +0 -14
- package/src/lib/getLogoCDNExperiment.js +0 -25
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
import type { LazyExport } from
|
|
4
|
-
import {
|
|
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
|
|
7
|
-
|
|
9
|
+
export const PaymentFields: LazyExport<PaymentFieldsComponent> = {
|
|
10
|
+
__get__: () => getPaymentFieldsComponent(),
|
|
8
11
|
};
|
package/src/interface/wallet.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
import type { LazyExport } from
|
|
4
|
-
import { getWalletComponent, type WalletComponent } from
|
|
3
|
+
import type { LazyExport } from "../types";
|
|
4
|
+
import { getWalletComponent, type WalletComponent } from "../zoid/wallet";
|
|
5
5
|
|
|
6
|
-
export const Wallet
|
|
7
|
-
|
|
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
|
|
3
|
+
import { ERROR_CODE } from "@paypal/sdk-constants/src";
|
|
4
4
|
|
|
5
5
|
export class ValidationError extends Error {
|
|
6
|
-
|
|
6
|
+
code: string;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
3
|
+
export * from "./errors";
|
|
4
|
+
export * from "./isRTLLanguage";
|
|
5
|
+
export * from "./security";
|
|
6
|
+
export * from "./session";
|
|
7
|
+
export * from "./perceived-latency-instrumentation";
|
package/src/lib/isRTLLanguage.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
import { LANG } from
|
|
2
|
+
import { LANG } from "@paypal/sdk-constants/src";
|
|
3
3
|
|
|
4
|
-
export const isRTLLanguage = (languageCode
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
buttonSessionID: string,
|
|
5
|
+
phase: string,
|
|
6
6
|
|};
|
|
7
7
|
|
|
8
8
|
type InstrumentationPayload = {|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
comp?: Object,
|
|
10
|
+
chunk?: Object,
|
|
11
|
+
query?: Object,
|
|
12
12
|
|};
|
|
13
13
|
|
|
14
|
-
function getNavigationTimeOrigin()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 = ({
|
|
43
|
-
|
|
44
|
-
|
|
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 = (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
package/src/lib/security.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
import { isSameDomain } from
|
|
4
|
-
import { supportsPopups } from
|
|
5
|
-
import { isPayPalDomain } from
|
|
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()
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
if (!supportsPopups()) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
const parentComponentWindow = window.xprops && window.xprops.getParent();
|
|
19
|
+
if (parentComponentWindow && isSameDomain(parentComponentWindow)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
16
22
|
|
|
17
|
-
|
|
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) =>
|
|
28
|
+
export const protectedExport = (unprotectedExport) =>
|
|
29
|
+
isPayPalDomain() ? unprotectedExport : undefined;
|
|
30
|
+
/* eslint-enable no-confusing-arrow */
|
package/src/lib/session.js
CHANGED
|
@@ -1,47 +1,51 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
import { ZalgoPromise } from
|
|
4
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
export function getSessionID(): string {
|
|
18
|
+
if (window.xprops && window.xprops.sessionID) {
|
|
19
|
+
return window.xprops.sessionID;
|
|
20
|
+
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
return getSDKSessionID();
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
export const storageState
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
};
|
package/src/marks/component.jsx
CHANGED
|
@@ -1,88 +1,137 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
/** @jsx node */
|
|
3
3
|
|
|
4
|
-
import { node, dom } from
|
|
5
|
-
import { ZalgoPromise } from
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
33
|
+
import { MarksElement } from "./template";
|
|
17
34
|
|
|
18
35
|
const DEFAULT_HEIGHT = 20;
|
|
19
36
|
|
|
20
37
|
type MarksInstance = {|
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
isEligible: () => boolean,
|
|
39
|
+
render: (string | HTMLElement) => ZalgoPromise<void>,
|
|
23
40
|
|};
|
|
24
41
|
|
|
25
42
|
type MarksProps = {|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
108
|
+
const render = (container) => {
|
|
109
|
+
return ZalgoPromise.try(() => {
|
|
110
|
+
if (!isEligible()) {
|
|
111
|
+
throw new Error(`${fundingSource || "marks"} not eligible`);
|
|
112
|
+
}
|
|
58
113
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
82
|
-
render,
|
|
83
|
-
isEligible
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return Marks;
|
|
136
|
+
return Marks;
|
|
88
137
|
});
|
package/src/marks/index.js
CHANGED