diff --git a/src/hooks/useOrangeMoney.tsx b/src/hooks/useOrangeMoney.tsx
index 1c41958..76a4369 100644
--- a/src/hooks/useOrangeMoney.tsx
+++ b/src/hooks/useOrangeMoney.tsx
@@ -1,4 +1,5 @@
import { useModalsManagerContext } from "@/contexts/ModalsManagerContext";
+import type { IpaymentStackNavigator } from "@/navigations/Types";
import {
type IorangePaymentStarter,
getTransactionStatus,
@@ -8,6 +9,7 @@ import ErrorModal from "@components/modals/ErrorModal";
import InformationModal from "@components/modals/InformationModal";
import LoadingModal from "@components/modals/LoadingModal";
import { LOG } from "@logger";
+import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import * as WebBrowser from "expo-web-browser";
@@ -24,7 +26,13 @@ const paymentObjectDefault: IorangePaymentStarter = {
numero: "0707070707",
commentaire: "Un commentaire",
};
-const useOrangeMoney = () => {
+const useOrangeMoney = (
+ navigation?: NativeStackNavigationProp<
+ IpaymentStackNavigator,
+ "paymentAmountInputScreen",
+ "IpaymentStackNavigator"
+ >,
+) => {
const queryClient = useQueryClient();
const [isBrowserOpen, setIsBrowserOpen] = useState(false);
@@ -83,29 +91,28 @@ const useOrangeMoney = () => {
const openBrowserThenCheckStatus = async (paymentUrl: string, orderId: string) => {
try {
await handlePaymentUsingBrowser(paymentUrl);
- log.info("Verifying transaction status...");
+ log.info("openBrowserThenCheckStatus | Verifying transaction status...");
showModal();
await transactionsStatusMutation.mutateAsync(orderId);
+ navigation?.getParent()?.navigate("paymentResultScreen");
} catch (error) {
- log.error("handlePaymentButton |", error);
+ log.error("openBrowserThenCheckStatus |", error);
if (error instanceof Error) {
if (error.name === "ORANGE_PAYMENT_IN_PROGRESS") {
- log.warn("handlePaymentButton | ORANGE_PAYMENT_IN_PROGRESS");
+ log.warn("openBrowserThenCheckStatus | ORANGE_PAYMENT_IN_PROGRESS");
showModal(
- await openBrowserThenCheckStatus(paymentUrl, orderId)
- }
+ onPress={() => openBrowserThenCheckStatus(paymentUrl, orderId)}
/>,
);
} else if (error.name === "ORANGE_PAYMENT_FAILED") {
showModal();
- log.error("handlePaymentButton | ORANGE_PAYMENT_FAILED");
+ log.error("openBrowserThenCheckStatus | ORANGE_PAYMENT_FAILED");
}
} else {
- log.error("handlePaymentButton |", error);
+ log.error("openBrowserThenCheckStatus |", error);
closeModal();
throw error;
}
@@ -117,9 +124,14 @@ const useOrangeMoney = () => {
showModal();
const { payment_url, order_id } =
await orangeTransactionInitializerMutation.mutateAsync(amount);
+ log.info("orangePaymentTransactionHandler |", payment_url, order_id);
+ log.info("Opening browser for payment...");
await openBrowserThenCheckStatus(payment_url, order_id);
} catch (error) {
log.error("makePayment |", error);
+ throw error;
+ } finally {
+ closeModal(); // just to be ultra sure that the modal is closed
}
};
diff --git a/src/screens/PaymentAmountInputScreen.tsx b/src/screens/PaymentAmountInputScreen.tsx
index 4f7dc7b..6e6664f 100644
--- a/src/screens/PaymentAmountInputScreen.tsx
+++ b/src/screens/PaymentAmountInputScreen.tsx
@@ -32,7 +32,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
isCheckingForTransactionStatus,
transactionsStatusMutation,
orangePaymentTransactionHandler,
- } = useOrangeMoney();
+ } = useOrangeMoney(navigation);
const insets = useSafeAreaInsets();
@@ -59,7 +59,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
// await orangePaymentSequence();
try {
await orangePaymentTransactionHandler(amountToPay);
- navigation.getParent()?.navigate("paymentResultScreen");
+ // navigation.getParent()?.navigate("paymentResultScreen");
} catch (error) {
log.error("handlePaymentButton |", error);
}