API — PHP

Intégration PHP

Intégrez XPAYE dans vos applications PHP en quelques lignes de code. Notre API REST simple et sécurisée vous permet d'initialiser des paiements en toute simplicité.

Exemple d'intégration

Code PHP

payment.php
<?php

$data = array(
    'merchantId' => "MARCHAND ID",
    'amount' => 1000,
    'description' => "Paiement via API PHP",
    'channel' => "CARD",
    'countryCurrencyCode' => "952",
    'referenceNumber' => "REF-" . time(),
    'customerEmail' => "client@example.com",
    'customerFirstName' => "Jean",
    'customerLastname' => "Dupont",
    'customerPhoneNumber' => "01234567",
    'notificationURL' => "https://votre-site.com/webhook",
    'returnURL' => "https://votre-site.com/retour",
    'returnContext' => '{"order_id":"123","user":"88"}',
);

$data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sandbox.paiementpro.net/webservice/onlinepayment/init/curl-init.php");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);

if ($result['success']) {
    header("Location: " . $result['url']);
} else {
    echo "Erreur: " . $result['message'];
}
?>
Réponses de l'API

Exemples de réponses JSON

Réponse succès

response.json
{
  "success": true,
  "message": "Initialisation effectuée avec succès",
  "url": "https://sandbox.paiementpro.net/sandbox.php?sessionid=1234567890"
}

Réponse erreur

response.json
{
  "success": false,
  "message": "Echec de l'initialisation"
}
Documentation

Paramètres de l'API

Paramètres d'envoi

ParamètreTypeDescription
merchantIdstringVotre ID Marchand (ex: PP-F324)
amountintMontant de la transaction
descriptionstringDescription du paiement (obligatoire)
channelstringMode de paiement (CARD, OMCIV2, MOMOCI, etc.)
countryCurrencyCodestringCode devise (ex: 952 pour XOF)
referenceNumberstringRéférence unique de la transaction (obligatoire)
customerEmailstringEmail du client (obligatoire)
customerFirstNamestringPrénom du client (obligatoire)
customerLastnamestringNom du client (obligatoire)
customerPhoneNumberstringTéléphone du client (obligatoire)
notificationURLstringURL de webhook pour notifications
returnURLstringURL de redirection après paiement
returnContextstringDonnées additionnelles (JSON)

Paramètres de réponse

ParamètreTypeDescription
merchantIdstringIdentifiant unique du partenaire
referenceNumberstringRéférence de la transaction
amountintMontant de la transaction
transactiondtstringDate et heure de la transaction
customerIdstringIdentifiant du client
returnContextstringDonnées transmises au partenaire
hashcodestringChaîne cryptée pour sécurité
responsecodestring0 = Réussi, -1 = Échoué