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
| Operation | kind | When | reference is |
|---|---|---|---|
| Payment | (absent) | completed, failed, cancelled | the payment token |
| Direct payout | payout | confirmed or failed | the disburse_token (or crypto id) |
| Receive | payout_link | processing, paid, failed, cancelled | the payout token |
| In-store payment | terminal | paid, declined, expired, cancelled | your 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:
| Header | Value |
|---|---|
Tchin-Signature | v1= followed by the signature (also in data[signature]) |
Tchin-Timestamp | the send time in Unix seconds (also in data[timestamp]) |
{
"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…"
}| Field | Description |
|---|---|
response_code | 00 if the operation succeeded, 1001 otherwise. |
reference | your key to find the operation (see the table above). |
token | the transaction at Tchin. |
status | completed, failed, cancelled, pending… |
amount, fee, net | payment: paid by the customer, fees, received by you. Payout: left your balance, fees, received by the recipient. |
method, method_name | the method used (code and name). |
mode | live or test: only deliver in production on live. |
crypto | paid in crypto: currency, amount, credited, txid. |
hash | legacy 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.modeAlso reject a webhook older than 10 minutes: a message intercepted and replayed later will not pass. The kits do it for you:
$d = $tchin->verifierWebhook($_POST['data'] ?? []); // null si fausse ou trop ancienneconst d = tchin.verifierWebhook(req.body.data); // null si fausse ou trop anciennedata = {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 ancienneboolean ok = tchin.verifierWebhook(data); // data : les champs data[xxx] -> xxxok := c.VerifierWebhook(r.PostForm) // après r.ParseForm()$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))) <= 600f := 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)) <= 600hash_equals, timingSafeEqual, compare_digest).Responding
- Reply
200(or any2xx) 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
401and do nothing. It is a key mistake or a fraud attempt. - The URL must be HTTPS and public:
localhostand private addresses are rejected.
Duplicates and ordering
- The same event can arrive twice: before delivering, check whether that
referencewas already handled. - Webhooks can arrive out of order: rely on
status. Acompletedpayment never goes back topending. - 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.