Créer un paiement
curl --request POST \
--url https://api.example.com/v1/paymentsimport requests
url = "https://api.example.com/v1/payments"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/v1/payments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/payments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/payments"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/payments")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/payments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyPayments
Créer un paiement
Créer une intention de paiement
POST
/
v1
/
payments
Créer un paiement
curl --request POST \
--url https://api.example.com/v1/paymentsimport requests
url = "https://api.example.com/v1/payments"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/v1/payments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/payments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/payments"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/payments")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/payments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyCréer un paiement
Crée une nouvelle intention de paiement et retourne une URL de redirection vers le checkout.Endpoint
POST /v1/payments
Headers
| Header | Requis | Description |
|---|---|---|
Authorization | ✅ | Bearer sk_xxx |
Content-Type | ✅ | application/json |
X-Idempotency-Key | Recommandé | Clé unique pour éviter les doublons |
Body
| Paramètre | Type | Requis | Description |
|---|---|---|---|
amount | integer | ✅ | Montant en FCFA (min: 100) |
currency | string | Devise (défaut: XOF) | |
payment_method | string | ✅ | ORANGE_MONEY, WAVE, MOOV, CARD, VISA, MASTERCARD, GIM_UEMOA |
country | string | Code pays: ML, SN, CI | |
customer_phone | string | ✅ | Numéro de téléphone (+223…) |
customer_name | string | ✅ pour CARD | Nom du client (requis pour cartes) |
customer_email | string | ✅ pour CARD | Email du client (requis pour cartes) |
return_url | string | ✅ | URL de retour après paiement |
client_reference | string | Votre référence (order_id) | |
metadata | object | Données personnalisées |
Exemple
curl -X POST https://api.sahelpay.ml/v1/payments \
-H "Authorization: Bearer sk_test_xxx" \
-H "Content-Type: application/json" \
-H "X-Idempotency-Key: order-123" \
-d '{
"amount": 5000,
"currency": "XOF",
"payment_method": "ORANGE_MONEY",
"country": "ML",
"customer_phone": "+22370123456",
"customer_name": "Amadou Diallo",
"return_url": "https://votre-site.com/checkout/return",
"client_reference": "order_123",
"metadata": {
"order_id": "order_123"
}
}'
const response = await fetch('https://api.sahelpay.ml/v1/payments', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_xxx',
'Content-Type': 'application/json',
'X-Idempotency-Key': 'order-123',
},
body: JSON.stringify({
amount: 5000,
currency: 'XOF',
payment_method: 'ORANGE_MONEY',
country: 'ML',
customer_phone: '+22370123456',
customer_name: 'Amadou Diallo',
return_url: 'https://votre-site.com/checkout/return',
client_reference: 'order_123',
}),
});
Réponse
{
"success": true,
"data": {
"id": "txn_abc123def456",
"status": "PENDING",
"amount": 5000,
"currency": "XOF",
"payment_method": "ORANGE_MONEY",
"redirect_url": "https://pay.sahelpay.ml/checkout/txn_abc123def456",
"gateway_used": "internal_gateway_id",
"routing_reason": "Routing optimisé pour coût et disponibilité",
"expires_at": "2025-12-18T17:00:00.000Z",
"created_at": "2025-12-18T16:45:00.000Z"
}
}
Champs de routing
| Champ | Description |
|---|---|
gateway_used | Identifiant technique interne (pour monitoring uniquement) |
routing_reason | Explication du routing choisi par SahelPay |
Ces champs sont informatifs. SahelPay choisit automatiquement le meilleur gateway selon le coût et la disponibilité. Voir le guide Smart Routing pour plus de détails.
## Erreurs
| Code | Description |
|------|-------------|
| `INVALID_AMOUNT` | Montant invalide (< 100 ou > 5M) |
| `MISSING_PHONE` | Numéro de téléphone requis |
| `MISSING_RETURN_URL` | URL de retour requise |
| `DUPLICATE_PAYMENT` | Paiement déjà créé (idempotence) |
⌘I