Créer un abonnement
curl --request POST \
--url https://api.example.com/v1/subscriptionsimport requests
url = "https://api.example.com/v1/subscriptions"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/v1/subscriptions', 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/subscriptions",
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/subscriptions"
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/subscriptions")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/subscriptions")
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_bodySubscriptions
Créer un abonnement
Créer un abonnement pour un client
POST
/
v1
/
subscriptions
Créer un abonnement
curl --request POST \
--url https://api.example.com/v1/subscriptionsimport requests
url = "https://api.example.com/v1/subscriptions"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/v1/subscriptions', 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/subscriptions",
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/subscriptions"
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/subscriptions")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/subscriptions")
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 abonnement
Crée un nouvel abonnement pour un client à un plan existant.Endpoint
POST /v1/subscriptions
Headers
| Header | Requis | Description |
|---|---|---|
Authorization | ✅ | Bearer sk_xxx |
Content-Type | ✅ | application/json |
Body
| Paramètre | Type | Requis | Description |
|---|---|---|---|
plan_id | string | ✅ | ID du plan d’abonnement |
customer_phone | string | ✅ | Numéro de téléphone du client (+223…) |
start_date | string | Date de début (ISO format, défaut: maintenant) |
Exemple
curl -X POST https://api.sahelpay.ml/v1/subscriptions \
-H "Authorization: Bearer sk_test_xxx" \
-H "Content-Type: application/json" \
-d '{
"plan_id": "plan_abc123",
"customer_phone": "+22370123456",
"start_date": "2025-01-01T00:00:00.000Z"
}'
const response = await fetch('https://api.sahelpay.ml/v1/subscriptions', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_test_xxx',
'Content-Type': 'application/json',
},
body: JSON.stringify({
plan_id: 'plan_abc123',
customer_phone: '+22370123456',
start_date: '2025-01-01T00:00:00.000Z',
}),
});
Réponse
{
"success": true,
"data": {
"id": "sub_abc123def456",
"plan_id": "plan_abc123",
"plan_name": "Premium Mensuel",
"customer_phone": "+22370123456",
"status": "ACTIVE",
"next_billing_date": "2025-01-01T00:00:00.000Z",
"retry_count": 0,
"created_at": "2025-12-18T16:45:00.000Z"
}
}
Créer un abonnement avec lien de paiement
Pour créer un abonnement ET générer immédiatement un lien de paiement :POST /v1/subscriptions/with-payment
redirect_url(optionnel) : URL de retour après paiementmetadata(optionnel) : Données personnalisées
{
"success": true,
"data": {
"subscription": { ... },
"payment_link": {
"id": "link_xxx",
"slug": "premium-mensuel-xxx",
"url": "https://pay.sahelpay.ml/premium-mensuel-xxx",
"amount": 10000
}
}
}
Erreurs
| Code | Description |
|---|---|
PLAN_NOT_FOUND | Plan non trouvé |
INVALID_PHONE | Numéro de téléphone invalide |
⌘I