API — Dart

Intégration Dart

Intégrez XPAYE dans vos applications Dart et Flutter. Une solution native pour initialiser des paiements depuis vos applications mobiles et web.

Classe PaiementPro

Définition de la classe

paiement-pro.dart
import 'package:http/http.dart' as http;
import 'dart:convert';

class PaiementPro {
    String merchantId = '';
    int amount = 0; /* Montant à payer */
    String description = ''; /* Description pour le paiement obligatoire */
    String channel = ''; /* Mode paiement consulter l'espace XPAYE pour les différents providers */
    String countryCurrencyCode = '952'; /* Code de la devise: FCFA par défaut */
    String referenceNumber = ''; /* Référence de la transaction obligatoire et unique */
    String customerEmail = ''; /* Email de l'utilisateur obligatoire */
    String customerFirstName = ''; /* Prénom de l'utilisateur obligatoire */
    String customerLastname = ''; /* Nom de l'utilisateur obligatoire */
    String customerPhoneNumber = ''; /* Contact de l'utilisateur obligatoire */
    String notificationURL = ''; /* URL de notification dans le cas où vous enregistrez les données sur votre espace */
    String returnURL = ''; /* URL de retour après paiement: Il est conseillé d'utiliser le même que notificationURL */
    String returnContext = ''; /* Données présentes dans returnURL Ex: {utilisateur_id:1,data:true} */
    String url = ''; /* URL de paiement */
    String message = ''; /* Message */
    bool success = false; /* Initialisation du paiement */

    PaiementPro(this.merchantId);

    getUrlPayment() async {
        var url = Uri.https('paiementpro.net', 'webservice/onlinepayment/init/curl-init.php');
        var response = await http.post(url, body: jsonEncode({
            "merchantId": this.merchantId,
            "amount": this.amount,
            "description": this.description,
            "channel": this.channel,
            "countryCurrencyCode": this.countryCurrencyCode,
            "referenceNumber": this.referenceNumber,
            "customerEmail": this.customerEmail,
            "customerFirstName": this.customerFirstName,
            "customerLastname": this.customerLastname,
            "customerPhoneNumber": this.customerPhoneNumber,
            "notificationURL": this.notificationURL,
            "returnURL": this.returnURL,
            "returnContext": this.returnContext,
        }));
        
        var data = jsonDecode(response.body);
        
        if(data['url'] != null){
            this.url = data['url'];
            this.success = data['success'];
        } else {
            this.message = data['message'];
            this.success = data['success'];
        }
    }
}
Exemple d'intégration

Utilisation avec Flutter

main.dart
import 'package:flutter/material.dart';
import 'package:ppro/class/paiement-pro.dart';
import 'package:url_launcher/url_launcher.dart';

function_paiement() async {
    PaiementPro paiement_pro = new PaiementPro('ID MARCHAND');
    
    paiement_pro.amount = 1000;
    paiement_pro.channel = 'WAVECI';
    paiement_pro.referenceNumber = '0123456789';
    paiement_pro.customerEmail = 'client@example.com';
    paiement_pro.customerFirstName = 'Jean';
    paiement_pro.customerLastname = 'Dupont';
    paiement_pro.customerPhoneNumber = '0123456789';
    paiement_pro.description = 'Paiement via API Dart';
    
    await paiement_pro.getUrlPayment();
    
    if(paiement_pro.success){
        print(paiement_pro.url);
        
        final Uri _url = Uri.parse(paiement_pro.url);
        
        Future<void> _launchUrl() async {
            if (!await launchUrl(_url)) {
                throw 'Could not launch $_url';
            }
        }
        
        // Succès: ouvrir dans le navigateur
        _launchUrl();
    } else {
        // Erreur d'initialisation
        print(paiement_pro.message);
    }
}
Réponses de l'API

Propriétés de l'objet PaiementPro

Succès

response.dart
paiement_pro.success = true;
paiement_pro.url = "https://sandbox.paiementpro.net/sandbox.php?sessionid=...";

Erreur

response.dart
paiement_pro.success = false;
paiement_pro.message = "Message d'erreur";
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, WAVECI, 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é