Authentification
Chaque requête API doit être authentifiée par signature HMAC-SHA256.
1. En-têtes HTTP requis
| Header | Description |
|---|---|
X-NekaPay-Key | Votre API Key publique. Préfixée nk_live_ en production ou nk_test_ en sandbox. |
X-NekaPay-Timestamp | Timestamp Unix (secondes) au moment de l'envoi. Doit être dans une fenêtre de ±300 secondes de l'heure serveur. |
X-NekaPay-Signature | HMAC-SHA256 du timestamp + body brut, hexadécimal en minuscules. |
Content-Type | application/json |
2. Construction de la signature
Concatener le timestamp et le body, signer en HMAC-SHA256 avec votre API Secret.
PSEUDOsignature = HMAC-SHA256(api_secret, timestamp + body_string)
PHP
PHP$body = json_encode($payload, JSON_UNESCAPED_SLASHES);
$timestamp = (string) time();
$signature = hash_hmac('sha256', $timestamp . $body, $apiSecret);
$headers = [
'X-NekaPay-Key: ' . $apiKey,
'X-NekaPay-Timestamp: ' . $timestamp,
'X-NekaPay-Signature: ' . $signature,
'Content-Type: application/json',
];
Node.js
JSconst crypto = require('crypto');
const body = JSON.stringify(payload);
const timestamp = Math.floor(Date.now() / 1000).toString();
const signature = crypto
.createHmac('sha256', apiSecret)
.update(timestamp + body)
.digest('hex');
Python
PYTHONimport hmac, hashlib, json, time
body = json.dumps(payload, separators=(',', ':'))
timestamp = str(int(time.time()))
signature = hmac.new(
api_secret.encode(),
(timestamp + body).encode(),
hashlib.sha256
).hexdigest()
cURL
BASHBODY='{"merchant_order_id":"order_123","amount":50000,"customer_msisdn":"+22376123456","currency":"XOF"}'
TS=$(date +%s)
SIG=$(echo -n "${TS}${BODY}" | openssl dgst -sha256 -hmac "$API_SECRET" | cut -d' ' -f2)
curl -X POST https://nekapaie.com/api/v1/payments/cashin \
-H "X-NekaPay-Key: $API_KEY" \
-H "X-NekaPay-Timestamp: $TS" \
-H "X-NekaPay-Signature: $SIG" \
-H "Content-Type: application/json" \
-d "$BODY"
3. Bonnes pratiques de sécurité
- Ne jamais inclure l'
API Secretdans du code côté client (browser, mobile public). - Stocker les secrets dans un coffre (AWS Secrets Manager, Vault, GCP Secret Manager).
- Roder vos clés régulièrement via votre espace marchand.
- Synchroniser l'horloge de vos serveurs (NTP) — un décalage > 300 sec entraîne un rejet.
- Utiliser HTTPS exclusivement (TLS 1.2 minimum).
- Restreindre par IP les serveurs qui appellent l'API si possible.
4. Erreurs d'authentification
| Erreur | Cause |
|---|---|
401 AUTH_FAILED | Headers manquants, signature invalide, timestamp hors fenêtre, ou clé révoquée. |
403 MERCHANT_SUSPENDED | Compte marchand suspendu temporairement. |
429 RATE_LIMITED | Trop de requêtes (limite 300 req/s). |