← Retour à mes contributions
Mode modification
Modifier le contexte « fedapay-transactions »
Modifiez le contenu du contexte selon la Spec. Vos changements sont vérifiés en direct et mis à jour immédiatement.
›
Appel API FedaPay - Transactions et jeton de paiement
1const BASE = process.env.FEDAPAY_ENV === "live" ? "https://api.fedapay.com/v1" : "https://sandbox-api.fedapay.com/v1";2 3type FedaTransaction = { id: number; reference: string; status: string };4 5export async function createFedaPayLink(amount: number, description: string): Promise<string> {6 const headers = { Authorization: "Bearer " + process.env.FEDAPAY_SECRET_KEY, "Content-Type": "application/json" };7 const created = await fetch(BASE + "/transactions", {8 method: "POST",9 headers,10 body: JSON.stringify({ description, amount, currency: { iso: "XOF" }, callback_url: process.env.APP_URL + "/paiement/retour" }),11 });12 const tx = ((await created.json()) as Record<string, FedaTransaction>)["v1/transaction"];13 const tokenRes = await fetch(BASE + "/transactions/" + tx.id + "/token", { method: "POST", headers });14 const { url } = (await tokenRes.json()) as { token: string; url: string };15 return url;16}Appel d'API vérifiable
Langage : ts · 16 lignes
💡 Conseil : Les développeurs peuvent vérifier et corriger ici chaque appel d'API. Le reste de la Spec (webhooks, erreurs, idempotence) s'édite dans l'onglet Markdown complet.