CinetPay
CinetPay - Guichet de paiement
Initialise un paiement CinetPay, redirige vers payment_url et confirme par /payment/check après la notification.
Authentification
- Pas de header d'authentification :
apikeyetsite_idsont envoyés dans le corps JSON. - Les lire depuis l'environnement côté serveur uniquement.
Endpoints
POST https://api-checkout.cinetpay.com/v2/payment- Requis :
apikey,site_id,transaction_id,amount,currency,description,notify_url,return_url,channels. - Réponse :
code: "201",data.payment_token,data.payment_url.
- Requis :
POST https://api-checkout.cinetpay.com/v2/payment/checkavecapikey,site_id,transaction_id.data.status:ACCEPTED,REFUSED,PENDING.
Erreurs
- Le champ
codeest une chaîne :"201"succès,"600"erreur de paramètre,"609"authentification. - Le statut HTTP peut être
200même en cas d'erreur : lirecode.
Webhooks
- CinetPay appelle
notify_urlenPOSTformulaire aveccpm_trans_idetcpm_site_id. - Header
x-token: HMAC de contrôle, à vérifier avec la clé secrète du compte. - Toujours confirmer avec
/v2/payment/checkavant de livrer.
Idempotence et limites
transaction_idunique par paiement.
Pièges courants
Ce que les LLMs inventent le plus souvent pour CinetPay.
amountdoit être un multiple de 5 pour le XOF.channelsvautALL,MOBILE_MONEY,CREDIT_CARDouWALLET.- Le succès est
code === "201", pasres.ok.
Exemple minimal
1export async function initCinetPay(transactionId: string, amount: number): Promise<string> {2 const res = await fetch("https://api-checkout.cinetpay.com/v2/payment", {3 method: "POST",4 headers: { "Content-Type": "application/json" },5 body: JSON.stringify({6 apikey: process.env.CINETPAY_API_KEY,7 site_id: process.env.CINETPAY_SITE_ID,8 transaction_id: transactionId,9 amount: Math.ceil(amount / 5) * 5,10 currency: "XOF",11 description: "Commande " + transactionId,12 notify_url: process.env.APP_URL + "/api/webhooks/cinetpay",13 return_url: process.env.APP_URL + "/paiement/retour",14 channels: "ALL",15 }),16 });17 const json = (await res.json()) as { code: string; data: { payment_url: string } };18 if (json.code !== "201") throw new Error("CinetPay " + json.code);19 return json.data.payment_url;20}Variables d'environnement
CINETPAY_API_KEYCINETPAY_SITE_IDCINETPAY_SECRET_KEYAPP_URL