Initialiser un Paiement
Pour initialiser un paiement dans le système NoWallet, utilisez le point de terminaison suivant :
{baseUrl}/init/paymentParamètres du Corps de la Requête
Lors de l'initialisation d'un paiement, le corps de la requête doit inclure les paramètres suivants au format JSON :
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| body | body | InitPaymentModelDTO | true | none |
Exemple de Corps de Requête
{
"transaction_id": "ca3a65bb-9008-443d-8d4b-61c3b0006438",
"additional_infos": {
"customer_email": "[email protected]",
"customer_lastname": "Doe",
"customer_firstname": "John",
"customer_phone": "691234567"
},
"amount": 200,
"callback_url": "https://example.com/callback",
"return_url": "https://example.com/return",
"country_code": "CM",
"operators_code": ["OM"],
"method": "MERCHANT",
"tunnel": "CHECKOUTPAGE",
"operator_otp": "123456"
}
Exemples de Code dans Plusieurs Langages
Pour vous aider à intégrer l'API NoWallet facilement, nous fournissons des exemples de code dans divers langages de programmation. Ces exemples montrent comment effectuer une requête au point de terminaison de l'API et gérer la réponse.
- Shell (cURL) : Pour des tests rapides et une utilisation en ligne de commande.
- HTTP : Format brut de la requête HTTP pour comprendre la structure.
- JavaScript : En utilisant
fetchpour les environnements de navigateur ou Node.js. - Ruby : En utilisant la bibliothèque
rest-clientpour les applications Ruby. - Python : En utilisant la bibliothèque
requestspour les projets Python. - PHP : En utilisant
GuzzleHttppour les intégrations PHP. - Java : En utilisant
HttpURLConnectionpour les applications Java. - Go : En utilisant le package
net/httppour les projets Go.
Exemple de Requête
Voici un exemple de la façon d'initialiser un lien de paiement en utilisant différents langages. Sélectionnez l'onglet correspondant à votre langage préféré pour voir l'implémentation.
Assurez-vous de remplacer {access-token} par votre véritable jeton d'API et de fournir les paramètres requis dans la requête.
- cURL
- HTTP
- JavaScript
- Ruby
- Python
- PHP
- Java
- Go
# Example of initializing a payment link using cURL
curl -X POST {baseUrl}/init/payment \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {access-token}'
POST {baseUrl}/init/payment HTTP/1.1
Content-Type: application/json
Accept: application/json
const inputBody = {
transaction_id: "ca3a65bb-9008-443d-8d4b-61c3b0006438",
additional_infos: {
customer_email: "[email protected]",
customer_lastname: "Doe",
customer_firstname: "John",
customer_phone: "691234567",
},
amount: 200,
callback_url: "https://example.com/callback",
return_url: "https://example.com/return",
country_code: "CM",
operators_code: ["OM"],
method: "MERCHANT",
tunnel: "CHECKOUTPAGE",
operator_otp: "123456",
};
const headers = {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: "Bearer {access-token}",
};
fetch("{baseUrl}/init/payment", {
method: "POST",
body: inputBody,
headers: headers,
})
.then(function (res) {
return res.json();
})
.then(function (body) {
console.log(body);
});
require 'rest-client'
require 'json'
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer {access-token}'
}
result = RestClient.post '{baseUrl}/init/payment',
params: {
}, headers: headers
p JSON.parse(result)
import requests
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer {access-token}'
}
r = requests.post('{baseUrl}/init/payment', headers = headers)
print(r.json())
<?php
require 'vendor/autoload.php';
$headers = array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer {access-token}',
);
$client = new \GuzzleHttp\Client();
// Define array of request body.
$request_body = array();
try {
$response = $client->request('POST','{baseUrl}/init/payment', array(
'headers' => $headers,
'json' => $request_body,
)
);
print_r($response->getBody()->getContents());
}
catch (\GuzzleHttp\Exception\BadResponseException $e) {
// handle exception or api errors.
print_r($e->getMessage());
}
// ...
URL obj = new URL("{baseUrl}/init/payment");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main
import (
"bytes"
"net/http"
)
func main() {
headers := map[string][]string{
"Content-Type": []string{"application/json"},
"Accept": []string{"application/json"},
"Authorization": []string{"Bearer {access-token}"},
}
data := bytes.NewBuffer([]byte{jsonReq})
req, err := http.NewRequest("POST", "{baseUrl}/init/payment", data)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
// ...
}
Paramètres de la Réponse
La réponse du serveur inclura les paramètres suivants au format JSON :
| Statut | Signification | Description | Schéma |
|---|---|---|---|
| 200 | OK | Réponse de succès pour l'initialisation du paiement | InitPaymentResponseModelDto |
| 400 | Bad Request | Erreurs possibles dans la requête | Aucun |
Types de Réponse
La réponse du serveur inclura l'URL de l'initialisation du paiement et toute information pertinente. La réponse sera au format JSON.
Réponse de Succès (200 OK)
Réponse de succès pour l'initialisation du paiement
{
"country": "CM",
"currency": "XAF",
"signature": "EXAMPLE-XXXXX-XXXXX",
"available_operator": ["MTN", "OM"],
"authorized_operator": ["MTN", "OM"],
"payment_url": "https://example.com/payment"
}
Réponse d'Erreur (400 Bad Request)
Erreurs possibles dans la requête
{
"statusCode": 400,
"error": "ERROR_COUNTRY_CODE_NOT_FOUND",
"message": "It seems that this country code does not exist"
}
{
"statusCode": 400,
"error": "NOT_ALLOWED_TUNNEL_WITHOUT_PHONENUMBER",
"message": "API tunnel is allowed only if there is a customer_phone"
}
{
"statusCode": 400,
"error": "NOT_ALLOWED_TUNNEL_OPERATORS_CODE",
"message": "API tunnel is allowed only for single operators_code e.g. ['OM']"
}
{
"statusCode": 400,
"error": "ERROR_PHONE_NUMBER_LENGTH_IS_TOO_SHORT",
"message": "phone number invalid, the length of this phone number is too short"
}
{
"statusCode": 400,
"error": "ERROR_PHONE_NUMBER_OPERATOR_COUNTRY",
"message": "It seems that this number is not a valid phone number, the phone number is not valid for this operator or country"
}
{
"statusCode": 400,
"error": "ERROR_FEE_NOT_FOUND",
"message": "You cannot generate a signature, please contact administrator to get help."
}
{
"statusCode": 400,
"error": "ERROR_GENERATE_SIGNATURE",
"message": "Something went wrong during signature generation, please contact support to get help or try again."
}
{
"statusCode": 400,
"error": "ERROR_BALANCE_DEFICIT",
"message": "An error has occurred, the transaction signature could not be generated. Your balance is deficit. Please contact administrator to get help."
}
Cette page vous a-t-elle été utile ?