@flopay/react 0.2.1 → 0.3.1
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/index.cjs +107 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.mjs +108 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -586,6 +586,12 @@ function SplitCardFormInner({
|
|
|
586
586
|
buttonsTheme,
|
|
587
587
|
buttonsStyles: buttonsStylesOverride,
|
|
588
588
|
onButtonClick,
|
|
589
|
+
enableAVS = false,
|
|
590
|
+
avsLayout: avsLayoutProp = "row",
|
|
591
|
+
country: countryProp,
|
|
592
|
+
zip: zipProp,
|
|
593
|
+
onCountryChange,
|
|
594
|
+
onZipChange,
|
|
589
595
|
totalAmount = 0,
|
|
590
596
|
currency = "usd",
|
|
591
597
|
innerRef
|
|
@@ -596,6 +602,10 @@ function SplitCardFormInner({
|
|
|
596
602
|
const [processing, setProcessing] = (0, import_react5.useState)(false);
|
|
597
603
|
const [error, setError] = (0, import_react5.useState)(null);
|
|
598
604
|
const [is3DSActive, setIs3DSActive] = (0, import_react5.useState)(false);
|
|
605
|
+
const [selectedCountry, setSelectedCountry] = (0, import_react5.useState)(countryProp ?? "US");
|
|
606
|
+
const [zipCode, setZipCode] = (0, import_react5.useState)(zipProp ?? "");
|
|
607
|
+
const zipCodeRef = (0, import_react5.useRef)(zipProp ?? "");
|
|
608
|
+
const selectedCountryRef = (0, import_react5.useRef)(countryProp ?? "US");
|
|
599
609
|
const [viewState, setViewState] = (0, import_react5.useState)("buttons");
|
|
600
610
|
const showCardForm = viewState === "expanding" || viewState === "card";
|
|
601
611
|
const TRANSITION_MS = 280;
|
|
@@ -683,7 +693,8 @@ function SplitCardFormInner({
|
|
|
683
693
|
userId: userId ?? "",
|
|
684
694
|
email: email ?? "",
|
|
685
695
|
firstName: firstName ?? fullName.trim().split(/\s+/)[0] ?? "",
|
|
686
|
-
lastName: lastName ?? fullName.trim().split(/\s+/).slice(1).join(" ") ?? ""
|
|
696
|
+
lastName: lastName ?? fullName.trim().split(/\s+/).slice(1).join(" ") ?? "",
|
|
697
|
+
...enableAVS ? { zip: zipCodeRef.current, country: selectedCountryRef.current } : {}
|
|
687
698
|
},
|
|
688
699
|
chv
|
|
689
700
|
})
|
|
@@ -844,13 +855,24 @@ function SplitCardFormInner({
|
|
|
844
855
|
updateError(null);
|
|
845
856
|
let handedOff = false;
|
|
846
857
|
try {
|
|
858
|
+
if (enableAVS && !zipCodeRef.current.trim()) {
|
|
859
|
+
updateError((0, import_shared3.getPostalCodeLabel)(selectedCountryRef.current) + " is required");
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
847
862
|
const submitResult = await flopay.submitElements();
|
|
848
863
|
if (submitResult.error) {
|
|
849
864
|
updateError(submitResult.error.message);
|
|
850
865
|
onError?.(submitResult.error);
|
|
851
866
|
return;
|
|
852
867
|
}
|
|
853
|
-
const
|
|
868
|
+
const billingDetails = enableAVS ? {
|
|
869
|
+
name: fullName,
|
|
870
|
+
address: {
|
|
871
|
+
country: selectedCountryRef.current,
|
|
872
|
+
postal_code: zipCodeRef.current
|
|
873
|
+
}
|
|
874
|
+
} : void 0;
|
|
875
|
+
const pmResult = await flopay.createPaymentMethod(billingDetails);
|
|
854
876
|
if (pmResult.error || !pmResult.paymentMethodId) {
|
|
855
877
|
updateError(pmResult.error?.message ?? "Failed to create payment method.");
|
|
856
878
|
return;
|
|
@@ -1032,6 +1054,83 @@ function SplitCardFormInner({
|
|
|
1032
1054
|
}
|
|
1033
1055
|
}
|
|
1034
1056
|
) }),
|
|
1057
|
+
enableAVS && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: {
|
|
1058
|
+
display: "flex",
|
|
1059
|
+
flexDirection: avsLayoutProp === "column" ? "column" : "row",
|
|
1060
|
+
gap: avsLayoutProp === "column" ? "0.5rem" : "0",
|
|
1061
|
+
marginTop: "0.5rem"
|
|
1062
|
+
}, children: [
|
|
1063
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: {
|
|
1064
|
+
flex: avsLayoutProp === "row" ? 1 : void 0,
|
|
1065
|
+
backgroundColor: cardInputBg,
|
|
1066
|
+
border: `1px solid ${resolvedBorder}`,
|
|
1067
|
+
padding: "10px",
|
|
1068
|
+
...avsLayoutProp === "row" ? { borderRadius: "0", borderTopLeftRadius: "8px", borderBottomLeftRadius: "8px", borderRight: "none" } : { borderRadius: "8px" },
|
|
1069
|
+
...isButtons && bStyles.countrySelect ? bStyles.countrySelect : {}
|
|
1070
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1071
|
+
"select",
|
|
1072
|
+
{
|
|
1073
|
+
value: selectedCountry,
|
|
1074
|
+
onChange: (e) => {
|
|
1075
|
+
selectedCountryRef.current = e.target.value;
|
|
1076
|
+
setSelectedCountry(e.target.value);
|
|
1077
|
+
onCountryChange?.(e.target.value);
|
|
1078
|
+
},
|
|
1079
|
+
disabled: isSubmitting,
|
|
1080
|
+
autoComplete: "country",
|
|
1081
|
+
"data-testid": "flopay-country",
|
|
1082
|
+
style: {
|
|
1083
|
+
width: "100%",
|
|
1084
|
+
border: "none",
|
|
1085
|
+
outline: "none",
|
|
1086
|
+
background: "transparent",
|
|
1087
|
+
fontSize: bStyles.cardInputFontSize ?? "16px",
|
|
1088
|
+
fontFamily: "Poppins, sans-serif",
|
|
1089
|
+
color: bStyles.cardInputColor ?? "#262833",
|
|
1090
|
+
cursor: "pointer",
|
|
1091
|
+
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1092
|
+
},
|
|
1093
|
+
children: import_shared3.COUNTRY_OPTIONS.map((c) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("option", { value: c.code, children: [
|
|
1094
|
+
c.flag,
|
|
1095
|
+
" ",
|
|
1096
|
+
c.name
|
|
1097
|
+
] }, c.code))
|
|
1098
|
+
}
|
|
1099
|
+
) }),
|
|
1100
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: {
|
|
1101
|
+
flex: avsLayoutProp === "row" ? 1 : void 0,
|
|
1102
|
+
backgroundColor: cardInputBg,
|
|
1103
|
+
border: `1px solid ${resolvedBorder}`,
|
|
1104
|
+
padding: "10px",
|
|
1105
|
+
...avsLayoutProp === "row" ? { borderRadius: "0", borderTopRightRadius: "8px", borderBottomRightRadius: "8px" } : { borderRadius: "8px" },
|
|
1106
|
+
...isButtons && bStyles.zipInput ? bStyles.zipInput : {}
|
|
1107
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1108
|
+
"input",
|
|
1109
|
+
{
|
|
1110
|
+
placeholder: (0, import_shared3.getPostalCodeLabel)(selectedCountry),
|
|
1111
|
+
autoComplete: "postal-code",
|
|
1112
|
+
value: zipCode,
|
|
1113
|
+
onChange: (e) => {
|
|
1114
|
+
zipCodeRef.current = e.target.value;
|
|
1115
|
+
setZipCode(e.target.value);
|
|
1116
|
+
onZipChange?.(e.target.value);
|
|
1117
|
+
},
|
|
1118
|
+
disabled: isSubmitting,
|
|
1119
|
+
required: true,
|
|
1120
|
+
"data-testid": "flopay-zip",
|
|
1121
|
+
style: {
|
|
1122
|
+
width: "100%",
|
|
1123
|
+
border: "none",
|
|
1124
|
+
outline: "none",
|
|
1125
|
+
background: "transparent",
|
|
1126
|
+
fontSize: bStyles.cardInputFontSize ?? "16px",
|
|
1127
|
+
fontFamily: "Poppins, sans-serif",
|
|
1128
|
+
color: bStyles.cardInputColor ?? "#262833",
|
|
1129
|
+
...isButtons && bStyles.nameInput ? bStyles.nameInput : {}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
) })
|
|
1133
|
+
] }),
|
|
1035
1134
|
displayError && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { role: "alert", "data-testid": "flopay-error", style: {
|
|
1036
1135
|
margin: "0.75rem 0",
|
|
1037
1136
|
padding: "0.625rem 0.875rem",
|
|
@@ -1257,6 +1356,8 @@ function FloPayCheckout({
|
|
|
1257
1356
|
buttonsTheme,
|
|
1258
1357
|
buttonsStyles,
|
|
1259
1358
|
onButtonClick,
|
|
1359
|
+
enableAVS,
|
|
1360
|
+
avsLayout,
|
|
1260
1361
|
submitLabel,
|
|
1261
1362
|
className,
|
|
1262
1363
|
children,
|
|
@@ -1798,6 +1899,10 @@ function FloPayCheckout({
|
|
|
1798
1899
|
buttonsTheme,
|
|
1799
1900
|
buttonsStyles,
|
|
1800
1901
|
onButtonClick,
|
|
1902
|
+
enableAVS,
|
|
1903
|
+
avsLayout,
|
|
1904
|
+
country: session?.customer?.country,
|
|
1905
|
+
zip: session?.customer?.zip,
|
|
1801
1906
|
submitLabel,
|
|
1802
1907
|
className
|
|
1803
1908
|
}
|