@flopay/react 1.3.1 → 1.3.2
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 +24 -0
- package/dist/index.cjs +51 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +51 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1337,6 +1337,9 @@ import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-run
|
|
|
1337
1337
|
var STRIPE_RESUME_KEY = "flopay_stripe_resume";
|
|
1338
1338
|
var LEGACY_WALLET_RESUME_KEY = "flopay_wallet_resume";
|
|
1339
1339
|
var PAYPAL_RESUME_KEY = "flopay_paypal_resume";
|
|
1340
|
+
function isAccountValidationError(err) {
|
|
1341
|
+
return err instanceof FloPayError3 && typeof err.statusCode === "number" && err.statusCode >= 400 && err.statusCode < 500;
|
|
1342
|
+
}
|
|
1340
1343
|
function toVaultMount(block) {
|
|
1341
1344
|
if (!block?.html) return null;
|
|
1342
1345
|
return {
|
|
@@ -2838,10 +2841,6 @@ function SplitCardFormInner({
|
|
|
2838
2841
|
},
|
|
2839
2842
|
[onErrorChange]
|
|
2840
2843
|
);
|
|
2841
|
-
useEffect5(() => {
|
|
2842
|
-
if (!vaultActive || !cardCapture) return;
|
|
2843
|
-
cardCapture.setSubmitGate?.(avsInvalid);
|
|
2844
|
-
}, [vaultActive, cardCapture, avsInvalid]);
|
|
2845
2844
|
useEffect5(() => {
|
|
2846
2845
|
if (!vaultActive || !cardCapture) return;
|
|
2847
2846
|
cardCapture.setCardFieldOrder?.(cardFieldOrder ?? null, avsConfig == null);
|
|
@@ -2922,6 +2921,46 @@ function SplitCardFormInner({
|
|
|
2922
2921
|
baseUrl
|
|
2923
2922
|
};
|
|
2924
2923
|
const vaultCompletedRef = useRef4(false);
|
|
2924
|
+
const buildVaultAccountSnapshot = useCallback(() => {
|
|
2925
|
+
const { resolvedAccount: resolvedAccount2, avsConfig: avsConfig2, fullName: fullName2, avsCheckProp: avsCheckProp2 } = vaultOutcomeRef.current;
|
|
2926
|
+
const cc = selectedCountryRef.current || resolvedAccount2.country || "US";
|
|
2927
|
+
const stateVisible = avsConfig2 ? isAVSFieldVisible(avsConfig2.state, cc) : false;
|
|
2928
|
+
const line1Visible = avsConfig2 ? isAVSFieldVisible(avsConfig2.address_line_1, cc) : false;
|
|
2929
|
+
const zipVisible = avsConfig2 ? isAVSFieldVisible(avsConfig2.postal_code, cc) : false;
|
|
2930
|
+
const cityVisible = avsConfig2 ? isAVSFieldVisible(avsConfig2.city, cc) : false;
|
|
2931
|
+
const line2Visible = avsConfig2 ? isAVSFieldVisible(avsConfig2.address_line_2, cc) : false;
|
|
2932
|
+
const derivedState = line1Visible && !stateVisible && zipVisible ? getStateFromPostalCode(cc, (zipCodeRef.current ?? "").trim()) : null;
|
|
2933
|
+
const stateValue2 = stateVisible ? stateRef.current : derivedState;
|
|
2934
|
+
return {
|
|
2935
|
+
accountData: {
|
|
2936
|
+
userId: resolvedAccount2.userId ?? "",
|
|
2937
|
+
email: resolvedAccount2.email ?? "",
|
|
2938
|
+
firstName: resolvedAccount2.firstName ?? fullName2.trim().split(/\s+/)[0] ?? "",
|
|
2939
|
+
lastName: resolvedAccount2.lastName ?? fullName2.trim().split(/\s+/).slice(1).join(" ") ?? "",
|
|
2940
|
+
...zipVisible && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
|
|
2941
|
+
...cityVisible && cityRef.current ? { city: cityRef.current } : {},
|
|
2942
|
+
...stateValue2 ? { state: stateValue2 } : {},
|
|
2943
|
+
...line1Visible && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
|
|
2944
|
+
...line2Visible && addressLine2Ref.current ? { addressLine2: addressLine2Ref.current } : {},
|
|
2945
|
+
country: cc
|
|
2946
|
+
},
|
|
2947
|
+
...avsCheckProp2 !== void 0 ? { avsCheck: avsCheckProp2 } : {},
|
|
2948
|
+
...avsConfig2 ? {
|
|
2949
|
+
avsConfig: {
|
|
2950
|
+
country: isAVSFieldVisible(avsConfig2.country, cc),
|
|
2951
|
+
postal_code: zipVisible,
|
|
2952
|
+
address_line_1: line1Visible,
|
|
2953
|
+
address_line_2: line2Visible,
|
|
2954
|
+
city: cityVisible,
|
|
2955
|
+
state: stateVisible
|
|
2956
|
+
}
|
|
2957
|
+
} : {}
|
|
2958
|
+
};
|
|
2959
|
+
}, []);
|
|
2960
|
+
useEffect5(() => {
|
|
2961
|
+
if (!vaultActive || !cardCapture) return;
|
|
2962
|
+
cardCapture.setSubmitGate?.(avsInvalid);
|
|
2963
|
+
}, [vaultActive, cardCapture, avsInvalid]);
|
|
2925
2964
|
useEffect5(() => {
|
|
2926
2965
|
if (!vaultActive || !cardCapture) return;
|
|
2927
2966
|
vaultCompletedRef.current = false;
|
|
@@ -2929,41 +2968,14 @@ function SplitCardFormInner({
|
|
|
2929
2968
|
const offSubmitting = cardCapture.on("submitting", () => {
|
|
2930
2969
|
setHasAttemptedSubmit(true);
|
|
2931
2970
|
setOverlayStatus("processing");
|
|
2932
|
-
const {
|
|
2971
|
+
const { baseUrl: baseUrl2, sessionId: sessionId2, nonce: nonce2, updateError: updateError2, onError: onError2 } = vaultOutcomeRef.current;
|
|
2933
2972
|
if (!sessionId2 || !nonce2) return;
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
const derivedState = line1Visible && !stateVisible && zipVisible ? getStateFromPostalCode(cc, zipCodeRef.current ?? "") : null;
|
|
2941
|
-
const stateValue2 = stateVisible ? stateRef.current : derivedState;
|
|
2942
|
-
void new PaymentAPI2(baseUrl2).patchAccountSnapshot(sessionId2, nonce2, {
|
|
2943
|
-
accountData: {
|
|
2944
|
-
userId: resolvedAccount2.userId ?? "",
|
|
2945
|
-
email: resolvedAccount2.email ?? "",
|
|
2946
|
-
firstName: resolvedAccount2.firstName ?? fullName2.trim().split(/\s+/)[0] ?? "",
|
|
2947
|
-
lastName: resolvedAccount2.lastName ?? fullName2.trim().split(/\s+/).slice(1).join(" ") ?? "",
|
|
2948
|
-
...zipVisible && zipCodeRef.current ? { zip: zipCodeRef.current } : {},
|
|
2949
|
-
...cityVisible && cityRef.current ? { city: cityRef.current } : {},
|
|
2950
|
-
...stateValue2 ? { state: stateValue2 } : {},
|
|
2951
|
-
...line1Visible && addressLine1Ref.current ? { addressLine1: addressLine1Ref.current } : {},
|
|
2952
|
-
...line2Visible && addressLine2Ref.current ? { addressLine2: addressLine2Ref.current } : {},
|
|
2953
|
-
country: cc
|
|
2954
|
-
},
|
|
2955
|
-
...avsCheckProp2 !== void 0 ? { avsCheck: avsCheckProp2 } : {},
|
|
2956
|
-
...avsConfig2 ? {
|
|
2957
|
-
avsConfig: {
|
|
2958
|
-
country: isAVSFieldVisible(avsConfig2.country, cc),
|
|
2959
|
-
postal_code: zipVisible,
|
|
2960
|
-
address_line_1: line1Visible,
|
|
2961
|
-
address_line_2: line2Visible,
|
|
2962
|
-
city: cityVisible,
|
|
2963
|
-
state: stateVisible
|
|
2964
|
-
}
|
|
2965
|
-
} : {}
|
|
2966
|
-
}).catch(() => {
|
|
2973
|
+
void new PaymentAPI2(baseUrl2).patchAccountSnapshot(sessionId2, nonce2, buildVaultAccountSnapshot()).catch((err) => {
|
|
2974
|
+
if (!isAccountValidationError(err)) return;
|
|
2975
|
+
const message = err instanceof Error ? err.message : "Please check your billing address and try again.";
|
|
2976
|
+
updateError2(message);
|
|
2977
|
+
setOverlayStatus(null);
|
|
2978
|
+
onError2?.(err instanceof FloPayError3 ? err : new FloPayError3(message, "api_error"));
|
|
2967
2979
|
});
|
|
2968
2980
|
});
|
|
2969
2981
|
const offComplete = cardCapture.on("complete", async (event) => {
|
|
@@ -3193,7 +3205,7 @@ function SplitCardFormInner({
|
|
|
3193
3205
|
const stateVisible = isAVSFieldVisible(avsConfig.state, c);
|
|
3194
3206
|
const line1Visible = isAVSFieldVisible(avsConfig.address_line_1, c);
|
|
3195
3207
|
const zipVisible = isAVSFieldVisible(avsConfig.postal_code, c);
|
|
3196
|
-
const derivedState = line1Visible && !stateVisible && zipVisible ? getStateFromPostalCode(c, zipCodeRef.current ?? "") : null;
|
|
3208
|
+
const derivedState = line1Visible && !stateVisible && zipVisible ? getStateFromPostalCode(c, (zipCodeRef.current ?? "").trim()) : null;
|
|
3197
3209
|
const stateValue2 = stateVisible ? stateRef.current : derivedState;
|
|
3198
3210
|
return {
|
|
3199
3211
|
country: c,
|