@flopay/react 0.1.3 → 0.1.4
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 +13 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -953,6 +953,12 @@ function FloPayCheckout({
|
|
|
953
953
|
const [confirmProcessing, setConfirmProcessing] = useState3(false);
|
|
954
954
|
const [modeError, setModeError] = useState3(null);
|
|
955
955
|
const autoCheckoutAttempted = useRef3(false);
|
|
956
|
+
const onCompleteRef = useRef3(onComplete);
|
|
957
|
+
onCompleteRef.current = onComplete;
|
|
958
|
+
const onErrorRef = useRef3(onError);
|
|
959
|
+
onErrorRef.current = onError;
|
|
960
|
+
const onSessionCompletedRef = useRef3(onSessionCompleted);
|
|
961
|
+
onSessionCompletedRef.current = onSessionCompleted;
|
|
956
962
|
const processPaymentForMode = useCallback2(
|
|
957
963
|
async (sess) => {
|
|
958
964
|
const baseUrl = resolvedBillingUrl.replace(/\/+$/, "");
|
|
@@ -974,7 +980,7 @@ function FloPayCheckout({
|
|
|
974
980
|
})
|
|
975
981
|
});
|
|
976
982
|
if (response.ok) {
|
|
977
|
-
|
|
983
|
+
onCompleteRef.current?.({ status: "succeeded" });
|
|
978
984
|
return null;
|
|
979
985
|
}
|
|
980
986
|
const json = await response.json().catch(() => null);
|
|
@@ -997,7 +1003,7 @@ function FloPayCheckout({
|
|
|
997
1003
|
"api_error"
|
|
998
1004
|
);
|
|
999
1005
|
},
|
|
1000
|
-
[resolvedBillingUrl, sessionId
|
|
1006
|
+
[resolvedBillingUrl, sessionId]
|
|
1001
1007
|
);
|
|
1002
1008
|
const handleRedirectResult = useCallback2(
|
|
1003
1009
|
async (redirectResult, sess, options) => {
|
|
@@ -1016,7 +1022,7 @@ function FloPayCheckout({
|
|
|
1016
1022
|
return false;
|
|
1017
1023
|
}
|
|
1018
1024
|
if (paymentIntent && (paymentIntent.status === "requires_capture" || paymentIntent.status === "succeeded")) {
|
|
1019
|
-
|
|
1025
|
+
onCompleteRef.current?.({ status: "succeeded", paymentIntentId: paymentIntent.id });
|
|
1020
1026
|
return true;
|
|
1021
1027
|
}
|
|
1022
1028
|
return false;
|
|
@@ -1037,12 +1043,12 @@ function FloPayCheckout({
|
|
|
1037
1043
|
setModeError(error.message ?? "PayPal authorization failed.");
|
|
1038
1044
|
return false;
|
|
1039
1045
|
}
|
|
1040
|
-
|
|
1046
|
+
onCompleteRef.current?.({ status: "succeeded" });
|
|
1041
1047
|
return true;
|
|
1042
1048
|
}
|
|
1043
1049
|
return false;
|
|
1044
1050
|
},
|
|
1045
|
-
[resolvedBillingUrl, sessionId
|
|
1051
|
+
[resolvedBillingUrl, sessionId]
|
|
1046
1052
|
);
|
|
1047
1053
|
useEffect4(() => {
|
|
1048
1054
|
let cancelled = false;
|
|
@@ -1061,7 +1067,7 @@ function FloPayCheckout({
|
|
|
1061
1067
|
}
|
|
1062
1068
|
if (sess.status === "complete") {
|
|
1063
1069
|
setIsLoading(false);
|
|
1064
|
-
|
|
1070
|
+
onSessionCompletedRef.current?.(sess.successUrl ?? "");
|
|
1065
1071
|
return;
|
|
1066
1072
|
}
|
|
1067
1073
|
const effectiveMode = checkoutModeProp ?? sess.checkoutMode ?? "full";
|
|
@@ -1129,16 +1135,7 @@ function FloPayCheckout({
|
|
|
1129
1135
|
return () => {
|
|
1130
1136
|
cancelled = true;
|
|
1131
1137
|
};
|
|
1132
|
-
}, [
|
|
1133
|
-
sessionId,
|
|
1134
|
-
resolvedBillingUrl,
|
|
1135
|
-
fallbackPublishableKey,
|
|
1136
|
-
locale,
|
|
1137
|
-
checkoutModeProp,
|
|
1138
|
-
onSessionCompleted,
|
|
1139
|
-
processPaymentForMode,
|
|
1140
|
-
handleRedirectResult
|
|
1141
|
-
]);
|
|
1138
|
+
}, [sessionId, resolvedBillingUrl, fallbackPublishableKey, locale, checkoutModeProp]);
|
|
1142
1139
|
const handleConfirmCheckout = useCallback2(async () => {
|
|
1143
1140
|
if (confirmProcessing || !session) return;
|
|
1144
1141
|
setConfirmProcessing(true);
|