import { LOG } from "@logger"; import axiosRequest from "../axios-request"; export interface IorangePaymentStarter { // biome-ignore lint/style/useNamingConvention: type_paiement: number; marchand: "1"; service: "1"; montant: number; commentaire: string; numero: string; } export interface IorangeResponse { status: number; message: string; // biome-ignore lint/style/useNamingConvention: pay_token: string; // biome-ignore lint/style/useNamingConvention: payment_url: string; // biome-ignore lint/style/useNamingConvention: notif_token: string; // biome-ignore lint/style/useNamingConvention: order_id: string; } type OrangeStatus = "INITIATED" | "SUCCESS" | "FAILED"; export interface IorangePaymentStatus { status: OrangeStatus; code: number; message: { status: OrangeStatus; // biome-ignore lint/style/useNamingConvention: order_id: string; txnid?: string; }; } const log = LOG.extend("orangePayment"); export const getTransactionsData = async (payload: IorangePaymentStarter) => { log.http("getTransactionsData", payload); // const basictoken = base64.encode("admin:admin"); const response = await axiosRequest({ url: "/transactions/", method: "POST", data: payload, }); log.http("getTransactionsData |", JSON.stringify(response, null, 2)); return response; }; export const getTransactionStatus = async (orderId: string) => { log.http("getTransactionStatus |", { orderId }); try { const response = await axiosRequest({ url: `/api/TransactionCheckStatus/${orderId}/`, method: "GET", }); log.http("getTransactionStatus |", JSON.stringify(response, null, 2)); if (response.status === "INITIATED") { log.warn("Payment is still in progress, throwing error for mutation to catch"); const error = new Error("Payment is still in progress"); error.name = "PaymentInProgress"; throw error; } if (response.status === "FAILED") { log.warn("Payment failed, throwing error for mutation to catch"); const error = new Error("Payment failed"); error.name = "PaymentFailed"; throw error; } log.http("getTransactionStatus |", JSON.stringify(response, null, 2)); return response; } catch (error) { log.error("getTransactionStatus |", error); throw error; } };