@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.cjs
CHANGED
|
@@ -997,6 +997,12 @@ function FloPayCheckout({
|
|
|
997
997
|
const [confirmProcessing, setConfirmProcessing] = (0, import_react6.useState)(false);
|
|
998
998
|
const [modeError, setModeError] = (0, import_react6.useState)(null);
|
|
999
999
|
const autoCheckoutAttempted = (0, import_react6.useRef)(false);
|
|
1000
|
+
const onCompleteRef = (0, import_react6.useRef)(onComplete);
|
|
1001
|
+
onCompleteRef.current = onComplete;
|
|
1002
|
+
const onErrorRef = (0, import_react6.useRef)(onError);
|
|
1003
|
+
onErrorRef.current = onError;
|
|
1004
|
+
const onSessionCompletedRef = (0, import_react6.useRef)(onSessionCompleted);
|
|
1005
|
+
onSessionCompletedRef.current = onSessionCompleted;
|
|
1000
1006
|
const processPaymentForMode = (0, import_react6.useCallback)(
|
|
1001
1007
|
async (sess) => {
|
|
1002
1008
|
const baseUrl = resolvedBillingUrl.replace(/\/+$/, "");
|
|
@@ -1018,7 +1024,7 @@ function FloPayCheckout({
|
|
|
1018
1024
|
})
|
|
1019
1025
|
});
|
|
1020
1026
|
if (response.ok) {
|
|
1021
|
-
|
|
1027
|
+
onCompleteRef.current?.({ status: "succeeded" });
|
|
1022
1028
|
return null;
|
|
1023
1029
|
}
|
|
1024
1030
|
const json = await response.json().catch(() => null);
|
|
@@ -1041,7 +1047,7 @@ function FloPayCheckout({
|
|
|
1041
1047
|
"api_error"
|
|
1042
1048
|
);
|
|
1043
1049
|
},
|
|
1044
|
-
[resolvedBillingUrl, sessionId
|
|
1050
|
+
[resolvedBillingUrl, sessionId]
|
|
1045
1051
|
);
|
|
1046
1052
|
const handleRedirectResult = (0, import_react6.useCallback)(
|
|
1047
1053
|
async (redirectResult, sess, options) => {
|
|
@@ -1060,7 +1066,7 @@ function FloPayCheckout({
|
|
|
1060
1066
|
return false;
|
|
1061
1067
|
}
|
|
1062
1068
|
if (paymentIntent && (paymentIntent.status === "requires_capture" || paymentIntent.status === "succeeded")) {
|
|
1063
|
-
|
|
1069
|
+
onCompleteRef.current?.({ status: "succeeded", paymentIntentId: paymentIntent.id });
|
|
1064
1070
|
return true;
|
|
1065
1071
|
}
|
|
1066
1072
|
return false;
|
|
@@ -1081,12 +1087,12 @@ function FloPayCheckout({
|
|
|
1081
1087
|
setModeError(error.message ?? "PayPal authorization failed.");
|
|
1082
1088
|
return false;
|
|
1083
1089
|
}
|
|
1084
|
-
|
|
1090
|
+
onCompleteRef.current?.({ status: "succeeded" });
|
|
1085
1091
|
return true;
|
|
1086
1092
|
}
|
|
1087
1093
|
return false;
|
|
1088
1094
|
},
|
|
1089
|
-
[resolvedBillingUrl, sessionId
|
|
1095
|
+
[resolvedBillingUrl, sessionId]
|
|
1090
1096
|
);
|
|
1091
1097
|
(0, import_react6.useEffect)(() => {
|
|
1092
1098
|
let cancelled = false;
|
|
@@ -1105,7 +1111,7 @@ function FloPayCheckout({
|
|
|
1105
1111
|
}
|
|
1106
1112
|
if (sess.status === "complete") {
|
|
1107
1113
|
setIsLoading(false);
|
|
1108
|
-
|
|
1114
|
+
onSessionCompletedRef.current?.(sess.successUrl ?? "");
|
|
1109
1115
|
return;
|
|
1110
1116
|
}
|
|
1111
1117
|
const effectiveMode = checkoutModeProp ?? sess.checkoutMode ?? "full";
|
|
@@ -1173,16 +1179,7 @@ function FloPayCheckout({
|
|
|
1173
1179
|
return () => {
|
|
1174
1180
|
cancelled = true;
|
|
1175
1181
|
};
|
|
1176
|
-
}, [
|
|
1177
|
-
sessionId,
|
|
1178
|
-
resolvedBillingUrl,
|
|
1179
|
-
fallbackPublishableKey,
|
|
1180
|
-
locale,
|
|
1181
|
-
checkoutModeProp,
|
|
1182
|
-
onSessionCompleted,
|
|
1183
|
-
processPaymentForMode,
|
|
1184
|
-
handleRedirectResult
|
|
1185
|
-
]);
|
|
1182
|
+
}, [sessionId, resolvedBillingUrl, fallbackPublishableKey, locale, checkoutModeProp]);
|
|
1186
1183
|
const handleConfirmCheckout = (0, import_react6.useCallback)(async () => {
|
|
1187
1184
|
if (confirmProcessing || !session) return;
|
|
1188
1185
|
setConfirmProcessing(true);
|