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