Le SDK Flutter Digitalpaye permet aux développeurs d'intégrer facilement les paiements via Digitalpaye dans leurs applications Flutter. Il fournit une interface simple pour configurer et initier des transactions de paiement.
flutter pub add digitalpaye_sdk_flutter
Avant d'utiliser le SDK, configurez-le avec vos informations d'API. Vous devez fournir une clé API, un secret API, et d'autres paramètres de configuration.
final config = DigitalpayeConfig(
apiKey: 'live_digitalpaye931',
apiSecret: 'f511e4f4-d932-928cd-a804-51539700d60c',
isSandbox: false,
color: AppColors.orange,
);
// Constructeur de DigitalpayeConfig
DigitalpayeConfig({required String apiKey, required String apiSecret, required bool isSandbox, Color ? color, String ?logo});
Configuration de paiement
Définissez les paramètres de votre transaction de paiement.
final payment = DigitalpayePaymentConfig(
codeCountry: DigitalpayeEnumCountries.ivoryCoast,
amount: 10000.0,
transactionId: paymentId,
designation: "Vente de télévision",
currency: DigitalpayeEnumCurrencies.xof,
emailUser: "elieguei225@gmail.com",
nameUser: "HELIE GUEI",
customerId: "0777101308",
urlError: "https://digitalpaye.com",
urlSuccess: "https://digitalpaye.com",
);
DigitalpayeFlutterSDK(
config: config,
payment: payment,
errorBuilder: (error) {
return Container();
},
successBuilder: (success) {
return Container();
},
pendingBuilder: (pending) {
return Container();
},
Voici un exemple complet de l'utilisation du SDK dans une application Flutter.
import 'dart:math';
import 'package:digitalpaye_sdk_flutter/digitalpaye_sdk_flutter.dart';
import 'package:digitalpaye_sdk_flutter/enum/digitalpaye_enum_countries.dart';
import 'package:digitalpaye_sdk_flutter/enum/digitalpaye_enum_currencies.dart';
import 'package:digitalpaye_sdk_flutter/models/digitalpaye_config.dart';
import 'package:digitalpaye_sdk_flutter/models/digitalpaye_payment_config.dart';
import 'package:digitalpaye_sdk_flutter/utils/app_color.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
String generatePaymentId({int length = 20}) {
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
final random = Random();
return String.fromCharCodes(Iterable.generate(
length,
(_) => characters.codeUnitAt(random.nextInt(characters.length)),
));
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
final config = DigitalpayeConfig(
apiKey: 'live_digitalpaye961',
apiSecret: 'f511e4f4-d932-8299-a804-51539700d60c',
isSandbox: false,
color: AppColors.orange,
);
return Scaffold(
appBar: AppBar(title: const Text('Digitalpaye Flutter SDK Example')),
body: Center(
child: ElevatedButton(
onPressed: () async {
final paymentId = generatePaymentId();
final payment = DigitalpayePaymentConfig(
codeCountry: DigitalpayeEnumCountries.ivoryCoast,
amount: 10000.0,
transactionId: paymentId,
designation: "Vente de télévision",
currency: DigitalpayeEnumCurrencies.xof,
emailUser: "elieguei225@gmail.com",
nameUser: "HELIE GUEI",
customerId: "0777101308",
urlError: "https://digitalpaye.com",
urlSuccess: "https://digitalpaye.com",
);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DigitalpayeFlutterSDK(
config: config,
payment: payment,
errorBuilder: (error) {
return Column(
children: [
const Text("Paiment échoué"),
Row(
children: [
const Text("Référence"),
Text("${error.transactionId}")
],
),
Row(
children: [
const Text("Montant"),
Text("${error.amount}")
],
),
],
);
},
successBuilder: (success) {
return Column(
children: [
const Text("Paiment effectué avec succès"),
Row(
children: [
const Text("Référence"),
Text("${success.transactionId}")
],
),
],
);
},
pendingBuilder: (pending) {
return Column(
children: [
const Text("Paiment en attente"),
Row(
children: [
const Text("Référence"),
Text("${pending.transactionId}")
],
),
Row(
children: [
const Text("Montant"),
Text("${pending.amount}")
],
),
],
);
},
),
),
);
},
child: const Text('Make Payment'),
),
),
);
}
}