Prérequis
Vous avez besoin de :- Un compte marchand AshTech Pay vérifié.
- Un accès API activé par AshTech Pay.
- Une clé API conservée dans les variables d’environnement de votre serveur.
export ASHTECH_API_KEY="YOUR_API_KEY"
Vérifier les pays disponibles
Commencez par charger le catalogue actif. Les opérateurs peuvent changer : ne codez pas la liste en dur dans votre application.- Node.js
- Python
- cURL
- PHP / Laravel
const response = await fetch("https://www.ashtechpay.com/v1/countries", {
headers: {
Authorization: `Bearer ${process.env.ASHTECH_API_KEY}`,
},
});
const countries = await response.json();
import os
import requests
response = requests.get(
"https://www.ashtechpay.com/v1/countries",
headers={"Authorization": f"Bearer {os.environ['ASHTECH_API_KEY']}"},
)
countries = response.json()
curl https://www.ashtechpay.com/v1/countries \
-H "Authorization: Bearer $ASHTECH_API_KEY"
<?php
$ch = curl_init("https://www.ashtechpay.com/v1/countries");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ASHTECH_API_KEY"),
],
]);
$countries = json_decode(curl_exec($ch), true);
curl_close($ch);
Vérifier les frais
- Node.js
- Python
- cURL
- PHP / Laravel
const response = await fetch("https://www.ashtechpay.com/v1/fees", {
headers: {
Authorization: `Bearer ${process.env.ASHTECH_API_KEY}`,
},
});
const fees = await response.json();
import os
import requests
response = requests.get(
"https://www.ashtechpay.com/v1/fees",
headers={"Authorization": f"Bearer {os.environ['ASHTECH_API_KEY']}"},
)
fees = response.json()
curl https://www.ashtechpay.com/v1/fees \
-H "Authorization: Bearer $ASHTECH_API_KEY"
<?php
$ch = curl_init("https://www.ashtechpay.com/v1/fees");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ASHTECH_API_KEY"),
],
]);
$fees = json_decode(curl_exec($ch), true);
curl_close($ch);
Créer une collecte Mobile Money
L’exemple ci-dessous utilise le Cameroun. Utilisez toujours unreference unique généré par votre serveur.
- Node.js
- Python
- cURL
- PHP / Laravel
const response = await fetch("https://www.ashtechpay.com/v1/collect", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASHTECH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: "VOTRE_USER_ID",
amount: 1000,
currency: "XAF",
country_code: "CM",
operator: "MTN",
phone: "2376XXXXXXXX",
reference: "order_12345",
notify_url: "https://example.com/webhooks/ashtechpay",
}),
});
const payment = await response.json();
import os
import requests
response = requests.post(
"https://www.ashtechpay.com/v1/collect",
headers={
"Authorization": f"Bearer {os.environ['ASHTECH_API_KEY']}",
"Content-Type": "application/json",
},
json={
"user_id": "VOTRE_USER_ID",
"amount": 1000,
"currency": "XAF",
"country_code": "CM",
"operator": "MTN",
"phone": "2376XXXXXXXX",
"reference": "order_12345",
"notify_url": "https://example.com/webhooks/ashtechpay",
},
)
payment = response.json()
curl -X POST https://www.ashtechpay.com/v1/collect \
-H "Authorization: Bearer $ASHTECH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_id": "VOTRE_USER_ID",
"amount": 1000,
"currency": "XAF",
"country_code": "CM",
"operator": "MTN",
"phone": "2376XXXXXXXX",
"reference": "order_12345",
"notify_url": "https://example.com/webhooks/ashtechpay"
}'
<?php
$payload = [
"user_id" => "VOTRE_USER_ID",
"amount" => 1000,
"currency" => "XAF",
"country_code" => "CM",
"operator" => "MTN",
"phone" => "2376XXXXXXXX",
"reference" => "order_12345",
"notify_url" => "https://example.com/webhooks/ashtechpay",
];
$ch = curl_init("https://www.ashtechpay.com/v1/collect");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ASHTECH_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$payment = json_decode(curl_exec($ch), true);
curl_close($ch);
Les noms d’opérateurs et leurs codes sont gérés par le catalogue AshTech Pay. Chargez
/v1/countries avant d’afficher votre formulaire.Vérifier le statut
Utilisez l’identifiant de transaction renvoyé par la création de collecte :- Node.js
- Python
- cURL
- PHP / Laravel
const response = await fetch(
"https://www.ashtechpay.com/v1/transaction/TRANSACTION_ID?user_id=VOTRE_USER_ID",
{
headers: {
Authorization: `Bearer ${process.env.ASHTECH_API_KEY}`,
},
},
);
const transaction = await response.json();
import os
import requests
response = requests.get(
"https://www.ashtechpay.com/v1/transaction/TRANSACTION_ID?user_id=VOTRE_USER_ID",
headers={"Authorization": f"Bearer {os.environ['ASHTECH_API_KEY']}"},
)
transaction = response.json()
curl "https://www.ashtechpay.com/v1/transaction/TRANSACTION_ID?user_id=VOTRE_USER_ID" \
-H "Authorization: Bearer $ASHTECH_API_KEY"
<?php
$ch = curl_init("https://www.ashtechpay.com/v1/transaction/TRANSACTION_ID?user_id=VOTRE_USER_ID");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("ASHTECH_API_KEY"),
],
]);
$transaction = json_decode(curl_exec($ch), true);
curl_close($ch);

