wunapay/Developers · Hosted checkoutDéveloppeurs · Paiement hébergé

Hosted checkout.Paiement hébergé.

Send your customer to a secure WunaPay page and get them back when they have paid. No payment screen to build.Envoyez votre client vers une page WunaPay sécurisée et récupérez-le une fois le paiement fait. Aucun écran de paiement à construire.

Hosted checkout is the fastest way to accept MTN MoMo and Orange Money on your website. You create a checkout session on your server, send the customer to its url, and WunaPay handles the rest: method choice, phone number, the prompt on the phone, waiting, errors and retries — in English or French, light or dark. When the customer has paid, they come back to your site.

How it works

  1. Your server calls POST /v1/checkout/sessions with the amount and a return_url (send an Idempotency-Key, e.g. your order number, so a retry never makes a second session).
  2. You redirect the customer to the url you receive (https://app.wunapay.com/checkout/cs_…).
  3. The customer pays on WunaPay’s page and confirms on their phone.
  4. WunaPay sends them back to return_url?session_id=cs_…&status=succeeded.
  5. Your server confirms with GET /v1/checkout/sessions/{id} (status paid) or with the payment.succeeded webhook, then marks the order as paid.

Create a session

FieldTypeDescription
amountintegerRequired. Amount in XAF, 100 to 1,000,000.
return_urlstringRequired. Where the customer goes after paying (http or https, max 500 characters).
cancel_urlstringOptional. Shown as “Cancel and return to the shop”.
referencestringOptional. Your order number (max 64). Copied onto the payment.
descriptionstringOptional. Shown to the customer under your business name (max 120).
escrow, splitsobject, arrayOptional. Hold the money until delivery, and share it on release (splits: test mode only). See the API reference.
curl https://app.wunapay.com/v1/checkout/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 15000,
    "reference": "order_1042",
    "description": "2 T-shirts",
    "return_url": "https://yourshop.cm/order/1042/thanks",
    "cancel_url": "https://yourshop.cm/cart"
  }'

Response 201 Created:

{
  "id": "cs_Qw3rT9yUiOp1",
  "object": "checkout_session",
  "amount": 15000,
  "currency": "XAF",
  "reference": "order_1042",
  "description": "2 T-shirts",
  "status": "open",
  "payment": null,
  "url": "https://app.wunapay.com/checkout/cs_Qw3rT9yUiOp1",
  "return_url": "https://yourshop.cm/order/1042/thanks",
  "cancel_url": "https://yourshop.cm/cart",
  "created_at": "2026-10-11 09:30:00",
  "expires_at": "2026-10-11 10:30:00"
}

Handle the return

After a successful payment the page shows “Payment received” and sends the customer to your return_url after about 4 seconds, adding session_id and status to the address. Anyone can type an address, so always confirm on your server before delivering:

curl https://app.wunapay.com/v1/checkout/sessions/cs_Qw3rT9yUiOp1 \
  -H "Authorization: Bearer sk_test_..."
# → "status": "paid", "payment": { "id": "pay_…", "status": "succeeded", "amount": 15000, ... }

Also check that amount matches your order total and that livemode is what you expect. The customer may close the browser before coming back — that is why a webhook is recommended: payment.succeeded includes data.checkout_session.

Full examples

// Node.js (Express) — npm install express
const express = require("express");
const app = express();
const KEY = process.env.WUNAPAY_SECRET_KEY;

app.post("/pay/:orderId", async (req, res) => {
  const order = await findOrder(req.params.orderId);        // your own code
  const r = await fetch("https://app.wunapay.com/v1/checkout/sessions", {
    method: "POST",
    headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({
      amount: order.total,
      reference: `order_${order.id}`,
      description: `Order ${order.id}`,
      return_url: `https://yourshop.cm/orders/${order.id}/thanks`,
      cancel_url: "https://yourshop.cm/cart",
    }),
  });
  const session = await r.json();
  await saveSessionId(order.id, session.id);                 // remember it
  res.redirect(303, session.url);                            // send the customer to WunaPay
});

app.get("/orders/:orderId/thanks", async (req, res) => {
  // Never trust the "status" in the address: ask WunaPay.
  const r = await fetch(`https://app.wunapay.com/v1/checkout/sessions/${req.query.session_id}`, {
    headers: { Authorization: `Bearer ${KEY}` },
  });
  const session = await r.json();
  if (session.status === "paid") await markOrderPaid(req.params.orderId, session.payment.id);
  res.send(session.status === "paid" ? "Thank you!" : "Payment not completed yet.");
});
<?php
// PHP — with the WunaPay PHP library (docs-plugins.html)
require 'WunaPay.php';
$wunapay = new WunaPay\Client(getenv('WUNAPAY_SECRET_KEY'));

$session = $wunapay->createCheckoutSession([
    'amount'      => 15000,
    'reference'   => 'order_1042',
    'description' => '2 T-shirts',
    'return_url'  => 'https://yourshop.cm/order/1042/thanks',
    'cancel_url'  => 'https://yourshop.cm/cart',
]);
header('Location: ' . $session['url'], true, 303);
exit;

Session rules

StatusMeaning
openWaiting for payment. If a try is declined, the customer can try again on the same page.
paidPaid. While one try is waiting for the customer’s PIN, a second try on the same session is refused (the page resumes the first), so the customer is not charged twice.
expiredNot paid within 60 minutes. Create a new session.

Test it with the numbers on the Testing section: 237670000000 (MTN sandbox) succeeds; an Orange number ending in 01 is declined.

Using WooCommerce? The WunaPay plugin does all of this for you.

Le paiement hébergé est le moyen le plus rapide d’accepter MTN MoMo et Orange Money sur votre site. Vous créez une session de paiement sur votre serveur, envoyez le client vers son url, et WunaPay s’occupe du reste : choix du moyen, numéro, demande sur le téléphone, attente, erreurs et nouvel essai — en français ou en anglais, en clair ou en sombre. Une fois le paiement fait, le client revient sur votre site.

Comment ça marche

  1. Votre serveur appelle POST /v1/checkout/sessions avec le montant et une return_url (envoyez une Idempotency-Key, ex. votre numéro de commande, pour qu’un nouvel essai ne crée jamais une deuxième session).
  2. Vous redirigez le client vers l’url reçue (https://app.wunapay.com/checkout/cs_…).
  3. Le client paie sur la page WunaPay et confirme sur son téléphone.
  4. WunaPay le renvoie vers return_url?session_id=cs_…&status=succeeded.
  5. Votre serveur confirme avec GET /v1/checkout/sessions/{id} (statut paid) ou avec le webhook payment.succeeded, puis marque la commande comme payée.

Créer une session

ChampTypeDescription
amountintegerObligatoire. Montant en XAF, de 100 à 1 000 000.
return_urlstringObligatoire. Où va le client après le paiement (http ou https, 500 caractères max).
cancel_urlstringFacultatif. Affiché comme « Annuler et revenir à la boutique ».
referencestringFacultatif. Votre numéro de commande (64 max). Recopié sur le paiement.
descriptionstringFacultatif. Affiché au client sous le nom de votre entreprise (120 max).
escrow, splitsobjet, tableauFacultatif. Garder l’argent jusqu’à la livraison, et le répartir à la libération (répartition : mode test uniquement). Voir la référence de l’API.
curl https://app.wunapay.com/v1/checkout/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 15000,
    "reference": "order_1042",
    "description": "2 T-shirts",
    "return_url": "https://yourshop.cm/order/1042/thanks",
    "cancel_url": "https://yourshop.cm/cart"
  }'

Réponse 201 Created :

{
  "id": "cs_Qw3rT9yUiOp1",
  "object": "checkout_session",
  "amount": 15000,
  "currency": "XAF",
  "reference": "order_1042",
  "description": "2 T-shirts",
  "status": "open",
  "payment": null,
  "url": "https://app.wunapay.com/checkout/cs_Qw3rT9yUiOp1",
  "return_url": "https://yourshop.cm/order/1042/thanks",
  "cancel_url": "https://yourshop.cm/cart",
  "created_at": "2026-10-11 09:30:00",
  "expires_at": "2026-10-11 10:30:00"
}

Gérer le retour

Après un paiement réussi, la page affiche « Paiement reçu » et renvoie le client vers votre return_url au bout d’environ 4 secondes, en ajoutant session_id et status à l’adresse. N’importe qui peut taper une adresse : confirmez toujours sur votre serveur avant de livrer :

curl https://app.wunapay.com/v1/checkout/sessions/cs_Qw3rT9yUiOp1 \
  -H "Authorization: Bearer sk_test_..."
# → "status": "paid", "payment": { "id": "pay_…", "status": "succeeded", "amount": 15000, ... }

Vérifiez aussi que amount correspond au total de la commande et que livemode est celui attendu. Le client peut fermer son navigateur avant de revenir : c’est pourquoi un webhook est recommandé — payment.succeeded contient data.checkout_session.

Exemples complets

// Node.js (Express) — npm install express
const express = require("express");
const app = express();
const KEY = process.env.WUNAPAY_SECRET_KEY;

app.post("/pay/:orderId", async (req, res) => {
  const order = await findOrder(req.params.orderId);        // your own code
  const r = await fetch("https://app.wunapay.com/v1/checkout/sessions", {
    method: "POST",
    headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({
      amount: order.total,
      reference: `order_${order.id}`,
      description: `Order ${order.id}`,
      return_url: `https://yourshop.cm/orders/${order.id}/thanks`,
      cancel_url: "https://yourshop.cm/cart",
    }),
  });
  const session = await r.json();
  await saveSessionId(order.id, session.id);                 // remember it
  res.redirect(303, session.url);                            // send the customer to WunaPay
});

app.get("/orders/:orderId/thanks", async (req, res) => {
  // Never trust the "status" in the address: ask WunaPay.
  const r = await fetch(`https://app.wunapay.com/v1/checkout/sessions/${req.query.session_id}`, {
    headers: { Authorization: `Bearer ${KEY}` },
  });
  const session = await r.json();
  if (session.status === "paid") await markOrderPaid(req.params.orderId, session.payment.id);
  res.send(session.status === "paid" ? "Thank you!" : "Payment not completed yet.");
});
<?php
// PHP — with the WunaPay PHP library (docs-plugins.html)
require 'WunaPay.php';
$wunapay = new WunaPay\Client(getenv('WUNAPAY_SECRET_KEY'));

$session = $wunapay->createCheckoutSession([
    'amount'      => 15000,
    'reference'   => 'order_1042',
    'description' => '2 T-shirts',
    'return_url'  => 'https://yourshop.cm/order/1042/thanks',
    'cancel_url'  => 'https://yourshop.cm/cart',
]);
header('Location: ' . $session['url'], true, 303);
exit;

Règles des sessions

StatutSignification
openEn attente de paiement. Si un essai est refusé, le client peut réessayer sur la même page.
paidPayée. Tant qu’un essai attend le PIN du client, un deuxième essai sur la même session est refusé (la page reprend le premier) : le client n’est pas débité deux fois.
expiredNon payée en 60 minutes. Créez une nouvelle session.

Testez avec les numéros de la section Tests : 237670000000 (sandbox MTN) réussit ; un numéro Orange se terminant par 01 est refusé.

Vous utilisez WooCommerce ? Le plugin WunaPay fait tout cela pour vous.