import ApiConnect3 from "../ApiConfig"; // import ApiConnect3 from "./ApiConfig"; import { encode as base64Encode } from 'base-64'; //Get All User payments export const get_payments = async (data) => { // console.log(data) try { if (!data.id) { throw new Error("data.id is empty or undefined"); } const result = await ApiConnect3(`payments/user/${data.id}`, { method: "GET", headers: { Authorization: `Bearer ${data.token}`, }, }); return result; } catch (error) { console.log(error); console.log(error + "failed get user payment api"); return error; } }; //Get a payment export const get_payment = async (data) => { // console.log(data) try { if (!data.ref) { throw new Error("data.id is empty or undefined"); } const result = await ApiConnect3(`payment/get/ref/${data.ref}`, { method: "GET", // headers: { // Authorization: `Bearer ${data.token}`, // }, }); return result; } catch (error) { console.log(error); console.log(error + "failed get payment api"); return error; } }; //CREATE payment export const create_payment = async (data) => { // console.log(data) try { const username = "hey"; // Replace with your actual username const password = "heytoo"; // Replace with your actual password // Encode the credentials in Base64 const base64Credentials = base64Encode(`${username}:${password}`); const result = await ApiConnect3(`payment/links`, { method: "POST", data: data.body, headers: { Authorization: `Basic ${base64Credentials}`, }, }); return result; } catch (error) { console.log(error); console.log(error + "failed create user payment link api"); return error; } }; export const update_payment = async (data) => { try { const username = "hey"; // Replace with your actual username const password = "heytoo"; // Replace with your actual password // Encode the credentials in Base64 const base64Credentials = base64Encode(`${username}:${password}`); const result = await ApiConnect3(`/payment/links/update/${data.id}`, { method: "PATCH", data: data.body, headers: { Authorization: `Basic ${base64Credentials}`, }, }); return result; } catch (error) { console.log(error); return error; } }; export const update_payment_att = async (data) => { try { const username = "hey"; // Replace with your actual username const password = "heytoo"; // Replace with your actual password // Encode the credentials in Base64 const base64Credentials = base64Encode(`${username}:${password}`); const result = await ApiConnect3( `payment/links/update-payment/${data.refId}/${data.id}`, { method: "PATCH", data: data.body, headers: { Authorization: `Basic ${base64Credentials}`, }, } ); return result; } catch (error) { console.log(error); return error; } };