import { LOG } from "@logger"; import axiosRequest from "../axios-request"; export interface IorangePaymentStarter { type_paiement : number, marchand : "1", service : "1", montant : number, commentaire : string, numero : string } export interface IOrangeResponse { status : number, message : string, pay_token : string, payment_url : string, notif_token : string, order_id : string, } type OrangeStatus = "INITIATED" | "SUCCESS" | "FAILED"; export interface IorangePaymentStatus { status : OrangeStatus, code : number, message : { status : OrangeStatus, 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}); let response = await axiosRequest({ url: `/api/TransactionCheckStatus/${orderId}/`, method: "GET", }) log.http("getTransactionStatus |", JSON.stringify(response, null, 2)); if (response.status === "INITIATED"){ log.http("Payment is still in progress, throwing error for mutation to catch"); throw new Error("Payment is still in progress"); } else { log.http("getTransactionStatus |", JSON.stringify(response, null, 2)); return response } }