Skip to content
Docs
FR Create an account

Track

Webhooks

On every status change, Tchin calls your callback_url. Verify the signature before trusting the content, reply fast, and handle each event only once.

When a webhook is sent

OperationkindWhenreference is
Payment(absent)completed, failed, cancelledthe payment token
Direct payoutpayoutconfirmed or failedthe disburse_token (or crypto id)
Receivepayout_linkprocessing, paid, failed, cancelledthe payout token
In-store paymentterminalpaid, declined, expired, cancelledyour reference (id: pvc_…)

The URL is the one given at creation (callback_url), otherwise your app’s. With neither, nothing is sent: read the status yourself.

Format

A POST as application/x-www-form-urlencoded with a data field: data[reference], data[status], data[customer][name]… Most frameworks put them in a data array for you. Two headers come with each call:

HeaderValue
Tchin-Signaturev1= followed by the signature (also in data[signature])
Tchin-Timestampthe send time in Unix seconds (also in data[timestamp])
The data payload (payment)
{
  "response_code": "00",
  "response_text": "Transaction completed",
  "reference": "jtkkbphr7azsn3",
  "token": "tch_9w2kq…",
  "status": "completed",
  "fail_reason": "",
  "amount": 26042,
  "fee": 1042,
  "net": 25000,
  "currency": "XOF",
  "country": "TG",
  "method": "t-money-togo",
  "method_name": "Yas",
  "mode": "live",
  "customer": { "name": "Koffi", "email": "koffi@example.com", "phone": "+22890112233" },
  "timestamp": 1795432544,
  "signature": "3f1a…"
}
FieldDescription
response_code00 if the operation succeeded, 1001 otherwise.
referenceyour key to find the operation (see the table above).
tokenthe transaction at Tchin.
statuscompleted, failed, cancelled, pending…
amount, fee, netpayment: paid by the customer, fees, received by you. Payout: left your balance, fees, received by the recipient.
method, method_namethe method used (code and name).
modelive or test: only deliver in production on live.
cryptopaid in crypto: currency, amount, credited, txid.
hashlegacy field kept for old integrations: it proves nothing. Use signature.

Verify the signature

The signature is a hex HMAC-SHA256, with your secret key, of this string (the received values, in this order, joined by dots; a missing field counts as empty):

timestamp.reference.token.status.amount.net.mode

Also reject a webhook older than 10 minutes: a message intercepted and replayed later will not pass. The kits do it for you:

With a kit
$d = $tchin->verifierWebhook($_POST['data'] ?? []);   // null si fausse ou trop ancienne
const d = tchin.verifierWebhook(req.body.data);       // null si fausse ou trop ancienne
data = {k[5:-1]: v for k, v in request.form.items() if k.startswith('data[')}
d = tchin.verifier_webhook(data)                      # None si fausse ou trop ancienne
boolean ok = tchin.verifierWebhook(data);             // data : les champs data[xxx] -> xxx
ok := c.VerifierWebhook(r.PostForm)                   // après r.ParseForm()
Without a kit
$d = $_POST['data'] ?? [];
$chaine = implode('.', [$d['timestamp'] ?? '', $d['reference'] ?? '', $d['token'] ?? '', $d['status'] ?? '',
                        $d['amount'] ?? '', $d['net'] ?? '', $d['mode'] ?? '']);
$ok = hash_equals(hash_hmac('sha256', $chaine, getenv('TCHIN_PRIVATE_KEY')), (string) ($d['signature'] ?? ''))
   && abs(time() - (int) ($d['timestamp'] ?? 0)) <= 600;
if (! $ok) { http_response_code(401); exit; }
const crypto = require('crypto');
const d = req.body.data || {};
const chaine = [d.timestamp, d.reference, d.token, d.status, d.amount, d.net, d.mode].map((v) => v ?? '').join('.');
const attendue = crypto.createHmac('sha256', process.env.TCHIN_PRIVATE_KEY).update(chaine).digest('hex');
const ok = d.signature && attendue.length === d.signature.length
  && crypto.timingSafeEqual(Buffer.from(attendue), Buffer.from(d.signature))
  && Math.abs(Date.now() / 1000 - Number(d.timestamp)) <= 600;
if (!ok) return res.sendStatus(401);
import hmac, hashlib, os, time
chaine = '.'.join(str(d.get(k, '')) for k in ['timestamp', 'reference', 'token', 'status', 'amount', 'net', 'mode'])
attendue = hmac.new(os.environ['TCHIN_PRIVATE_KEY'].encode(), chaine.encode(), hashlib.sha256).hexdigest()
ok = hmac.compare_digest(attendue, d.get('signature', '')) and abs(time.time() - int(d.get('timestamp', 0))) <= 600
f := func(k string) string { return r.PostForm.Get("data[" + k + "]") }
chaine := strings.Join([]string{f("timestamp"), f("reference"), f("token"), f("status"), f("amount"), f("net"), f("mode")}, ".")
m := hmac.New(sha256.New, []byte(os.Getenv("TCHIN_PRIVATE_KEY")))
m.Write([]byte(chaine))
ts, _ := strconv.ParseInt(f("timestamp"), 10, 64)
ok := hmac.Equal([]byte(hex.EncodeToString(m.Sum(nil))), []byte(f("signature"))) && math.Abs(float64(time.Now().Unix()-ts)) <= 600
Good to know
Rebuild the string from the values as received (as text), without converting them, and compare in constant time (hash_equals, timingSafeEqual, compare_digest).

Responding

  • Reply 200 (or any 2xx) within 10 seconds; do slow work afterwards (email, invoice…).
  • Without a timely 2xx (15 s), Tchin retries: 5 attempts in total, immediately, then after 10 s, 1 min, 5 min and 15 min.
  • A wrong signature: reply 401 and do nothing. It is a key mistake or a fraud attempt.
  • The URL must be HTTPS and public: localhost and private addresses are rejected.

Duplicates and ordering

  • The same event can arrive twice: before delivering, check whether that reference was already handled.
  • Webhooks can arrive out of order: rely on status. A completed payment never goes back to pending.
  • When in doubt, read the status: it is the source of truth.
// Livrer une seule fois (une contrainte UNIQUE sur reference suffit)
$deja = $db->prepare('SELECT 1 FROM paiements_traites WHERE reference = ?');
$deja->execute([$d['reference']]);
if ($d['status'] === 'completed' && $d['mode'] === 'live' && ! $deja->fetch()) {
    $db->prepare('INSERT INTO paiements_traites (reference, traite_le) VALUES (?, NOW())')->execute([$d['reference']]);
    livrer($d['reference']);
}
http_response_code(200);

Testing

  • In test mode, each simulated payment sends a real webhook, signed, with "mode": "test".
  • On your computer, expose your server with an HTTPS tunnel (ngrok, Cloudflare Tunnel…).
  • The playground has a webhook inbox: every webhook from your tests arrives there live, signature checked.