@paypal/checkout-components 5.0.329 → 5.0.330
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/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +1 -1
- package/src/funding/common.jsx +1 -0
- package/src/funding/paypal/config.jsx +7 -4
- package/src/ui/buttons/button.jsx +29 -19
- package/src/ui/buttons/buttons.jsx +25 -23
- package/src/ui/buttons/props.js +4 -0
- package/src/ui/buttons/util.js +19 -2
- package/src/zoid/card-fields/component.jsx +5 -3
package/package.json
CHANGED
package/src/funding/common.jsx
CHANGED
|
@@ -45,18 +45,21 @@ export function getPayPalConfig(): FundingSourceConfig {
|
|
|
45
45
|
|
|
46
46
|
labelText: ({ content, label, period }) => {
|
|
47
47
|
let text = `${FUNDING_BRAND_LABEL.PAYPAL}`;
|
|
48
|
+
|
|
48
49
|
if (content && label === BUTTON_LABEL.INSTALLMENT) {
|
|
49
50
|
if (period) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const rawLabel = content["label.installment.withPeriod"];
|
|
52
|
+
|
|
53
|
+
if (typeof rawLabel === "string") {
|
|
54
|
+
text = rawLabel.replace("{period}", String(period));
|
|
55
|
+
}
|
|
54
56
|
} else {
|
|
55
57
|
text = content["label.installment.withoutPeriod"];
|
|
56
58
|
}
|
|
57
59
|
} else if (content && label && content[`label.${label}`]) {
|
|
58
60
|
text = content[`label.${label}`];
|
|
59
61
|
}
|
|
62
|
+
|
|
60
63
|
return text;
|
|
61
64
|
},
|
|
62
65
|
Logo,
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
/** @jsx node */
|
|
3
3
|
|
|
4
4
|
import type { FundingEligibilityType } from "@paypal/sdk-client/src";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
COUNTRY,
|
|
7
|
+
FUNDING,
|
|
8
|
+
ENV,
|
|
9
|
+
type LocaleType,
|
|
10
|
+
} from "@paypal/sdk-constants/src";
|
|
6
11
|
import { node, type ElementNode } from "@krakenjs/jsx-pragmatic/src";
|
|
7
12
|
import { LOGO_COLOR, LOGO_CLASS } from "@paypal/sdk-logos/src";
|
|
8
13
|
import {
|
|
@@ -37,12 +42,13 @@ import type {
|
|
|
37
42
|
} from "./props";
|
|
38
43
|
import { Spinner } from "./spinner";
|
|
39
44
|
import { MenuButton } from "./menu-button";
|
|
40
|
-
import { isBorderRadiusNumber } from "./util";
|
|
45
|
+
import { isBorderRadiusNumber, checkLabelEligibility } from "./util";
|
|
41
46
|
|
|
42
47
|
type IndividualButtonProps = {|
|
|
43
48
|
style: ButtonStyle,
|
|
44
49
|
fundingSource: $Values<typeof FUNDING>,
|
|
45
50
|
multiple: boolean,
|
|
51
|
+
buyerCountry: $Values<typeof COUNTRY>,
|
|
46
52
|
locale: LocaleType,
|
|
47
53
|
onClick?: Function,
|
|
48
54
|
env: $Values<typeof ENV>,
|
|
@@ -68,26 +74,27 @@ type IndividualButtonProps = {|
|
|
|
68
74
|
|};
|
|
69
75
|
|
|
70
76
|
export function Button({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
buyerCountry,
|
|
78
|
+
commit,
|
|
79
|
+
content,
|
|
80
|
+
customerId,
|
|
75
81
|
env,
|
|
82
|
+
experiment,
|
|
83
|
+
flow,
|
|
76
84
|
fundingEligibility,
|
|
85
|
+
fundingSource,
|
|
77
86
|
i,
|
|
87
|
+
instrument,
|
|
88
|
+
locale,
|
|
89
|
+
multiple,
|
|
78
90
|
nonce,
|
|
79
|
-
flow,
|
|
80
|
-
vault,
|
|
81
|
-
userIDToken,
|
|
82
|
-
customerId,
|
|
83
|
-
personalization,
|
|
84
91
|
onClick = noop,
|
|
85
|
-
|
|
86
|
-
tagline,
|
|
87
|
-
commit,
|
|
88
|
-
experiment,
|
|
89
|
-
instrument,
|
|
92
|
+
personalization,
|
|
90
93
|
showPayLabel,
|
|
94
|
+
style,
|
|
95
|
+
tagline,
|
|
96
|
+
userIDToken,
|
|
97
|
+
vault,
|
|
91
98
|
}: IndividualButtonProps): ElementNode {
|
|
92
99
|
const { layout, shape, borderRadius } = style;
|
|
93
100
|
|
|
@@ -142,13 +149,16 @@ export function Button({
|
|
|
142
149
|
}
|
|
143
150
|
};
|
|
144
151
|
|
|
152
|
+
const eligibleLabel = checkLabelEligibility(label, buyerCountry);
|
|
153
|
+
|
|
145
154
|
function getAriaLabel(): string {
|
|
146
155
|
let labelText =
|
|
147
156
|
typeof fundingConfig.labelText === "function"
|
|
148
157
|
? fundingConfig.labelText({
|
|
158
|
+
buyerCountry,
|
|
149
159
|
content,
|
|
150
160
|
fundingEligibility,
|
|
151
|
-
label,
|
|
161
|
+
label: eligibleLabel,
|
|
152
162
|
period,
|
|
153
163
|
})
|
|
154
164
|
: fundingConfig.labelText || fundingSource;
|
|
@@ -166,7 +176,7 @@ export function Button({
|
|
|
166
176
|
|
|
167
177
|
const logoNode = (
|
|
168
178
|
<Logo
|
|
169
|
-
label={
|
|
179
|
+
label={eligibleLabel}
|
|
170
180
|
locale={locale}
|
|
171
181
|
logoColor={logoColor}
|
|
172
182
|
fundingEligibility={fundingEligibility}
|
|
@@ -182,7 +192,7 @@ export function Button({
|
|
|
182
192
|
<Label
|
|
183
193
|
i={i}
|
|
184
194
|
logo={logoNode}
|
|
185
|
-
label={
|
|
195
|
+
label={eligibleLabel}
|
|
186
196
|
nonce={nonce}
|
|
187
197
|
locale={locale}
|
|
188
198
|
logoColor={logoColor}
|
|
@@ -136,36 +136,37 @@ export function validateButtonProps(props: ButtonPropsInputs) {
|
|
|
136
136
|
export function Buttons(props: ButtonsProps): ElementNode {
|
|
137
137
|
const { onClick = noop } = props;
|
|
138
138
|
const {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
applePaySupport,
|
|
140
|
+
buyerCountry,
|
|
141
|
+
commit,
|
|
142
|
+
components,
|
|
143
|
+
content,
|
|
144
|
+
customerId,
|
|
145
|
+
displayOnly,
|
|
146
|
+
enableFunding,
|
|
144
147
|
env,
|
|
148
|
+
experiment,
|
|
149
|
+
flow,
|
|
145
150
|
fundingEligibility,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
fundingSource,
|
|
152
|
+
hasShippingCallback,
|
|
153
|
+
locale,
|
|
154
|
+
message,
|
|
155
|
+
messageMarkup,
|
|
149
156
|
nonce,
|
|
150
|
-
enableFunding,
|
|
151
|
-
components,
|
|
152
|
-
onShippingChange,
|
|
153
157
|
onShippingAddressChange,
|
|
158
|
+
onShippingChange,
|
|
154
159
|
onShippingOptionsChange,
|
|
155
|
-
hasShippingCallback,
|
|
156
160
|
personalization,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
content,
|
|
160
|
-
flow,
|
|
161
|
-
experiment,
|
|
162
|
-
applePaySupport,
|
|
163
|
-
supportsPopups,
|
|
164
|
-
supportedNativeBrowser,
|
|
161
|
+
platform,
|
|
162
|
+
remembered,
|
|
165
163
|
showPayLabel,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
style,
|
|
165
|
+
supportedNativeBrowser,
|
|
166
|
+
supportsPopups,
|
|
167
|
+
userIDToken,
|
|
168
|
+
vault,
|
|
169
|
+
wallet,
|
|
169
170
|
} = normalizeButtonProps(props);
|
|
170
171
|
const { layout, shape, tagline } = style;
|
|
171
172
|
|
|
@@ -268,6 +269,7 @@ export function Buttons(props: ButtonsProps): ElementNode {
|
|
|
268
269
|
fundingSource={source}
|
|
269
270
|
multiple={multiple}
|
|
270
271
|
env={env}
|
|
272
|
+
buyerCountry={buyerCountry}
|
|
271
273
|
locale={locale}
|
|
272
274
|
nonce={nonce}
|
|
273
275
|
fundingEligibility={fundingEligibility}
|
package/src/ui/buttons/props.js
CHANGED
|
@@ -450,6 +450,7 @@ export type ButtonMessageInputs = {|
|
|
|
450
450
|
export type RenderButtonProps = {|
|
|
451
451
|
style: ButtonStyle,
|
|
452
452
|
locale: LocaleType,
|
|
453
|
+
buyerCountry: $Values<typeof COUNTRY>,
|
|
453
454
|
commit: boolean,
|
|
454
455
|
fundingSource: ?$Values<typeof FUNDING>,
|
|
455
456
|
env: $Values<typeof ENV>,
|
|
@@ -555,6 +556,7 @@ export type ButtonPropsInputs = {
|
|
|
555
556
|
clientID: string,
|
|
556
557
|
fundingSource?: ?$Values<typeof FUNDING>,
|
|
557
558
|
style?: ButtonStyleInputs | void,
|
|
559
|
+
buyerCountry: $Values<typeof COUNTRY>,
|
|
558
560
|
locale?: $PropertyType<ButtonProps, "locale"> | void,
|
|
559
561
|
commit?: $PropertyType<ButtonProps, "commit"> | void,
|
|
560
562
|
env?: $PropertyType<ButtonProps, "env"> | void,
|
|
@@ -868,6 +870,7 @@ export function normalizeButtonProps(
|
|
|
868
870
|
);
|
|
869
871
|
|
|
870
872
|
let {
|
|
873
|
+
buyerCountry,
|
|
871
874
|
clientID,
|
|
872
875
|
fundingSource,
|
|
873
876
|
style = getDefaultStyle(),
|
|
@@ -970,6 +973,7 @@ export function normalizeButtonProps(
|
|
|
970
973
|
: undefined;
|
|
971
974
|
|
|
972
975
|
return {
|
|
976
|
+
buyerCountry,
|
|
973
977
|
clientID,
|
|
974
978
|
fundingSource,
|
|
975
979
|
style,
|
package/src/ui/buttons/util.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
import { FUNDING } from "@paypal/sdk-constants/src";
|
|
2
|
+
import { COUNTRY, FUNDING } from "@paypal/sdk-constants/src";
|
|
3
3
|
|
|
4
|
-
import { BUTTON_LAYOUT, MESSAGE_POSITION } from "../../constants";
|
|
4
|
+
import { BUTTON_LABEL, BUTTON_LAYOUT, MESSAGE_POSITION } from "../../constants";
|
|
5
5
|
import { ValidationError } from "../../lib";
|
|
6
6
|
|
|
7
7
|
export function isBorderRadiusNumber(borderRadius?: number): boolean {
|
|
@@ -39,3 +39,20 @@ export function calculateMessagePosition(
|
|
|
39
39
|
}
|
|
40
40
|
return MESSAGE_POSITION.BOTTOM;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
export function checkLabelEligibility(
|
|
44
|
+
label?: $Values<typeof BUTTON_LABEL>,
|
|
45
|
+
buyerCountry: $Values<typeof COUNTRY>
|
|
46
|
+
): $Values<typeof BUTTON_LABEL> | typeof undefined {
|
|
47
|
+
const eligibleCountriesForInstallmentLabel = ["BR", "MX"];
|
|
48
|
+
|
|
49
|
+
// Don't render the installment label if buyerCountry is not eligible for installment product
|
|
50
|
+
if (
|
|
51
|
+
label === BUTTON_LABEL.INSTALLMENT &&
|
|
52
|
+
!eligibleCountriesForInstallmentLabel.includes(buyerCountry)
|
|
53
|
+
) {
|
|
54
|
+
return BUTTON_LABEL.PAYPAL;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return label;
|
|
58
|
+
}
|
|
@@ -50,6 +50,7 @@ type CardFieldsProps = {|
|
|
|
50
50
|
clientID: string,
|
|
51
51
|
style?: {|
|
|
52
52
|
height: number,
|
|
53
|
+
input: {| height: number |},
|
|
53
54
|
|},
|
|
54
55
|
env?: string,
|
|
55
56
|
locale?: string,
|
|
@@ -128,9 +129,10 @@ const url = () =>
|
|
|
128
129
|
`${getPayPalDomain()}${__PAYPAL_CHECKOUT__.__URI__.__CARD_FIELD__}`;
|
|
129
130
|
|
|
130
131
|
const prerenderTemplate = ({ props, doc }) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const height = props.style?.height ?? props.style?.input?.height ?? null;
|
|
133
|
+
return (<CardPrerender nonce={props.nonce} height={height} />).render(
|
|
134
|
+
dom({ doc })
|
|
135
|
+
);
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
export type CardFieldsComponent = ZoidComponent<
|