Commit af94398e by G

the navigation to the result screen when the orange transaction is a success is…

the navigation to the result screen when the orange transaction is a success is handled by the hook itself. this solve the issue with navigation still happening even tho the transaction was in progress or failed
parent 018283f7
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(<LoadingModal message="Vérification du statut de la transaction..." />);
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(
<InformationModal
message="Le payment est toujours en cours."
actionLabel="Rééssayer"
onPress={async () =>
await openBrowserThenCheckStatus(paymentUrl, orderId)
}
onPress={() => openBrowserThenCheckStatus(paymentUrl, orderId)}
/>,
);
} else if (error.name === "ORANGE_PAYMENT_FAILED") {
showModal(<ErrorModal message="Le paiment à échoué." />);
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(<LoadingModal message="Initialization de la transaction." />);
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
}
};
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment