Documentation SDK Flutter

SDK Flutter / Dart

mypaie_flutter: ^1.0.0

Télécharger le SDK

Installation

# pubspec.yaml
dependencies:
  mypaie_flutter: ^1.0.0
  url_launcher: ^6.2.1
flutter pub get

Initialisation

import 'package:mypaie_flutter/mypaie_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

final mypaie = MyPaieClient(apiKey: 'pk_test_votre_cle');

Checkout hébergé

Future<void> createCheckout() async {
  try {
    final session = await mypaie.checkout.create(
      amount: 5000,
      currency: 'XOF',
      description: 'Commande #123',
      successUrl: 'https://votresite.com/success',
      cancelUrl: 'https://votresite.com/cancel',
      customerEmail: 'client@email.com',
    );

    // Ouvrir la page de paiement
    await launchUrl(Uri.parse(session.checkoutUrl));
  } on MyPaieException catch (e) {
    print('Erreur: ${e.message}');
  }
}

Orange Money

Future<void> payWithOrangeMoney() async {
  final payment = await mypaie.payments.orangeMoney(
    amount: 5000,
    currency: 'XOF',
    phone: '+22370123456',
    description: 'Achat produit',
  );

  // Ouvrir Orange Money
  await launchUrl(Uri.parse(payment.paymentUrl));
}

Carte bancaire

Future<void> payWithCard() async {
  final payment = await mypaie.payments.card(
    amount: 10000,
    currency: 'XOF',
    customerEmail: 'client@email.com',
    customerName: 'Amadou Diallo',
    description: 'Abonnement Premium',
  );

  await launchUrl(Uri.parse(payment.paymentUrl));
}

Vérifier le statut

Future<void> checkStatus(String reference) async {
  final status = await mypaie.payments.retrieve(reference);

  print('Statut: ${status.status}');  // completed, pending, failed
  print('Montant: ${status.amount}');
  print('Méthode: ${status.paymentMethod}');

  if (status.status == 'completed') {
    // Paiement réussi !
  }
}

Transactions

// Lister les transactions
final transactions = await mypaie.transactions.list(
  page: 1,
  limit: 20,
  status: 'completed',
);

for (var tx in transactions.data) {
  print('${tx['reference']}: ${tx['amount']} ${tx['currency']}');
}

// Statistiques
final stats = await mypaie.transactions.stats();
print('Volume total: ${stats.totalVolume} XOF');
print('Taux de succès: ${stats.successRate}%');

Exemple Widget complet

class PaymentButton extends StatefulWidget {
  final int amount;
  final String description;

  const PaymentButton({
    required this.amount,
    required this.description,
  });

  @override
  _PaymentButtonState createState() => _PaymentButtonState();
}

class _PaymentButtonState extends State<PaymentButton> {
  final mypaie = MyPaieClient(apiKey: 'pk_test_xxx');
  bool isLoading = false;

  Future<void> _pay() async {
    setState(() => isLoading = true);
    
    try {
      final session = await mypaie.checkout.create(
        amount: widget.amount,
        currency: 'XOF',
        description: widget.description,
      );
      
      await launchUrl(Uri.parse(session.checkoutUrl));
    } on MyPaieException catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Erreur: ${e.message}')),
      );
    } finally {
      setState(() => isLoading = false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: isLoading ? null : _pay,
      child: isLoading
          ? CircularProgressIndicator(color: Colors.white)
          : Text('Payer ${widget.amount} XOF'),
    );
  }
}

Gestion des erreurs

try {
  await mypaie.payments.orangeMoney(...);
} on MyPaieException catch (e) {
  print(e.message);    // Message d'erreur
  print(e.errorCode);  // VALIDATION_ERROR, etc.
  print(e.httpCode);   // 400, 401, etc.
}
Retour à la documentation