Skip to main content

API AdjeminToPay

GENERATION DE VOS CLES D'APPLICATION OAUTH2#

Pour pouvoir générer des clés d'applications,vous devriez au préalable créer un compte, ensuite créer une application. Deux clés d'API oAuth2 seront générées, ces deux deux clés permettent d'identifier votre application de manière unique dans le système. Pour générer les clés d'API de votre application, voici la démarche à suivre :

  • Vous devez crĂ©er un compte AdjeminPay, crĂ©ez-en un si ce n'est dĂ©jĂ  fait
  • Connectez-vous Ă  votre compte AdejminPay et sur l'onglet Mes Application choisissez CrĂ©er une application.
  • Remplissez le formulaire de crĂ©ation
  • Vos clĂ©s API seront automatiquement gĂ©nĂ©rĂ©es.

Les clés d'API oAuth2 sont au nombre de deux(2):

  • CLIENT_ID
  • CLIENT_SECRET

Une fois les clés générées, vous pouvez maintenant utiliser notre API.

INFO
  • L'accès aux services se fait via endpoints RESTFUL.
  • Le format d'Ă©change de donnĂ©es est JSON.
  • Toutes les chaines de caractères en majuscule dans les requetes prĂ©sentĂ©es ci dessous sont Ă  remplacer par leurs valeurs.

TOKEN D'AUTORISATION#

Pour consommer notre API, il vous faut toujours un token d'autorisation.

ENDPOINTS API

https://api-dev.adjeminpay.net/oauth/token

REQUĂŠTE POST HTTP

request.php
<?php
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('POST', 'https://api-dev.adjeminpay.net/oauth/token',
['form_params' =>
[
'grant_type' => 'client_credentials',
'client_id' => 'CLIENT_ID',
'client_secret' =>'CLIENT_SECRET',
]
]);
$accessToken = json_decode((string)$response->getBody()->getContents(),true);
return $accessToken;
?>
PHP Content
  • client_id est la clĂ© user key obtenue lors de la gĂ©nĂ©ration des clĂ©s d'API
  • client_secret est la clĂ© secret key obtenue lors de la gĂ©nĂ©ration des clĂ©s d'API
OBLIGATOIRE

N'oubliez de les remplacer par leurs valeurs.

RÉPONSE ATTENDUE

{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9zbXMucGF5ZHVueWEuY29yZVwvYXBpXC92MVwvYXV0aFwvbG9naW4iLCJpYXQiOjE1NTI2NTEwNzYsImV4cCI6MTU1MjY1NDk3NiwibmJmIjoxNTUyNjUxMDc2LCJqdGkiOiJWMjBKNk1SUFh0eldMS3VOIiwic3ViIjoyLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.xagI2zndC6ThraHFrZC9qNS_BdnmNlbN2tOHU2PKinY",
"token_type": "bearer",
"expires_in": 3600,
}

FAIRE UNE TRANSACTION#

ENDPOINTS API

https://api-dev.adjeminpay.net/v2/adjemintopay

REQUĂŠTE POST HTTP

<?php
use GuzzleHttp\Client;
$body = [
'amount' => '100',
'operator' => 'mtn', // om for orange
'client_reference' => '0544650223',
'currency_code' => 'XOF',
'designation' => 'Tee-shirt',
'notif_url' => 'http://adjeminpay.test/api/v2/hook',
'client_id' => 'CLIENT_ID',
// 'otp' => '1203', for orange
'name' => 'NOM DU PAYEUR',
'transaction_id' => 'r7ZAvlg8j35OFGeN9qxZsnvGXvvdghuHjvg' //unique
];
$option = [
'headers' => [
'Authorization' => 'Bearer TOKEN',
'Accept: application/json',
],
'json' => $body
];
$request = new Client();
$response = $request->post("https://api-dev.adjeminpay.net/v2/adjemintopay", $option);
if($response->getStatusCode() == 202 || $response->getStatusCode() == 200 ){
echo $response->getBody();
}else{
throw new \Exception("Payment Erreur", 500);
}
}
  • TOKEN est le token d'autorisation gĂ©nĂ©rĂ© Ă  partir de l'endpoint pour obtenir un token d'autorisation.
  • CLIENT_ID est la clĂ© CLIENT_ID obtenue de la gĂ©nĂ©ration des clĂ©s d'API.
OBLIGATOIRE

N'oubliez de les remplacer par leurs valeurs.

RÉPONSE ATTENDUE

MTN RESPONSE
{
"code": "01",
"message": "Paiement en attente",
"status": "PENDING",
"mtnResponse": {
"financialTransactionId": "2295790230",
"externalId": "c8937f14-d69d-49ca-baa3-1778e63e2b89",
"amount": "1",
"currency": "XOF",
"payer": {
"partyIdType": "MSISDN",
"partyId": "2250544650223"
},
"payerMessage": "Tee-shirt",
"payeeNote": "note",
"status": "PENDING"
},
"transaction": {
"amount": "1",
"designation": "Tee-shirt",
"reference": "ADJEMIN_ORDER_050815_004263",
"client_reference": "r7ZAvlg8j35OFGeN9qxZsnvGXvvdg",
"phone_number": "0544650223",
"notif_url": "http://adjeminpay.test/api/v2/hook",
"currency_code": "XOF",
"buyer_name": "nelly",
"status": "PENDING",
"payment_method_code": "MTN-CI",
"type": 0,
"updated_at": "2021-04-09T15:33:56.000000Z",
"created_at": "2021-04-09T15:33:56.000000Z",
}
}
ORANGE RESPONSE
{
"code": 11,
"message": null,
"input": {
"amount": "100",
"operator": "om",
"client_reference": "0778487321",
"currency_code": "XOF",
"designation": "ehhhh",
"notif_url": "http://adjeminpay.test/api/v2/hook",
"client_id": "9",
"otp": "5605",
"name": "nelly",
"transaction_id": "r7ZAvlg8j35OFGeN9qxZsnvGXvvdgqrd"
},
"data": {
"status": "SUCCESS",
"accesslayer": "",
"txnid": "MP210409.1637.C94532",
"message": "Votre paiement est confirmé",
"reason": ""
},
"transaction": {
"amount": "100",
"designation": "Tee-shirt",
"reference": "ADJEMIN_ORDER_035169_008350",
"client_reference": "r7ZAvlg8j35OFGeN9qxZsnvGXvvdgqrd",
"phone_number": "0778487321",
"notif_url": "http://adjeminpay.test/api/v2/hook",
"currency_code": "XOF",
"buyer_name": "nelly",
"status": "SUCCESSFUL",
"type": 0,
"payment_method_code": "ORANGE-CI",
"updated_at": "2021-04-09T16:37:55.000000Z",
"created_at": "2021-04-09T16:37:52.000000Z",
"orange_payment_url": "https://webpayment.orange-money.com/ci/mpayment/abstract/v1r6iahyjgxq9biw25ykrmwsiiuu3jv1hgdwtro8ybn2mabo8p7o700i3hvxj7mw",
"is_initiated": 0,
"is_approuved": 1,
"approuved_at": "2021-04-09T16:37:55.667795Z"
}
}
Solde insuffisant
{
"code": -11,
"message": "Solde Insuffisant",
"status": "FAILED",
"data": "0544650223"
}
{
"code": -11,
"message": "Votre solde Orange Money est insuffisant. Veuillez recharger votre compte Orange Money et recommencer.",
"status": "FAILED",
"data": "0778487321"
}

ENDPOINTS POUR RECUPÉRER LES STATUS MTN

https://api-dev.adjeminpay.net/v2/get/status/mtn/<externalId>
<?php
use GuzzleHttp\Client;
$option = [
'headers' => [
'Authorization' => 'Bearer TOKEN',
'Accept: application/json',
]
];
$externalId = EXTERNAL_ID;
$request = new Client();
$response = $request->get("https://api-dev.adjeminpay.net/v2/get/status/mtn/$extenerId");
if($response->getStatusCode() == 202 || $response->getStatusCode() == 200 ){
echo $response->getBody();
}else{
throw new \Exception("Erreur", 500);
}
}

RÉPONSE ATTENDUE

{
"mtnResponse": {
"financialTransactionId": "2264615632",
"externalId": "d63c4c03-19da-4bea-a4bf-8ee53a422456",
"amount": "10",
"currency": "XOF",
"payer": {
"partyIdType": "MSISDN",
"partyId": "2250544650223"
},
"payerMessage": "test",
"status": "FAILED", // SUCCESSFUL
"reason": "COULD_NOT_PERFORM_TRANSACTION" // if failed
}
}

WEBHOOK#

hook.json
{
"status":"FAILED",
"designation":"Marmite",
"transaction_id":"ADP_016700_004602",
"client_reference":"8DyMmQuv0NZKIgjL0jzTf1wYD0Z3vH8c",
"amount":"10.00",
"phone_number":"0778487321",
"buyer_name":"Kouyate Karim",
"currency_code":"CFA",
"cancelled_at":null,
"approuved_at":null,
"transaction_type":"ORANGE-CI"
}
Json content

Code PHP#

hook.php
<?php
$status = $_POST['status'];
$designation = $_POST['designation'];
$transaction_id = $_POST['transaction_id'];
$client_reference = $_POST['client_reference'];
$amount = $_POST['amount'];
$currency_code = $_POST['currency_code'];
$buyer_name = $_POST['buyer_name'] ? $_POST['buyer_name'] : 'null';
$cancelled_at = $_POST['cancelled_at'] ? $_POST['cancelled_at'] : 'null' ;
$approuved_at = $_POST['approuved_at'] ?? 'null' ;
$transaction_type = $_POST['transaction_type'] ?? 'null' ;
$notification = $db->prepare("INSERT INTO notifications(status,designation,transaction_id,client_reference,amount,
phone_number, buyer_name, currency_code, cancelled_at, approuved_at, transaction_type)
VALUES (?,?,?,?,?,?,?,?,?,?,?)");
$notification->execute(array($status,$designation,$transaction_id, $client_reference,
$amount, $phone_number, $buyer_name, $currency_code, $cancelled_at,
$approuved_at, $transaction_type));
?>

AUTRES REPONSES POSSIBLES#

CODEMESSAGEDESRIPTION
-11solde insuffisantVotre solde Orange Money est insuffisant. Veuillez recharger votre compte Orange Money et recommencer.
401UnauthenticatedLe token est mauvais ou vide