finapay_sdk 0.0.5
finapay_sdk: ^0.0.5 copied to clipboard
SDK pour les transactions financières. By Finasys Technologies
example/lib/main.dart
import 'package:finapay_sdk/core/models/sdk_result.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:finapay_sdk/finapay_sdk.dart';
void main() {
runApp(const MyApp());
}
// MyApp is the root widget of the application. It initializes the MaterialApp
// with the application's theme and routes.
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHome(),
);
}
}
// MyHome is the home screen of the application. It displays the platform version
// and provides buttons to perform various Finapay SDK operations such as registering
// a client's token, making a payment, deposit, withdrawal, and transfer.
class MyHome extends StatefulWidget {
const MyHome({super.key});
@override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
String _platformVersion = 'Unknown';
FinapaySdk? _finapaySdkPlugin;
SdkResult? registrationResult;
@override
void initState() {
super.initState();
_attemptSdkInstantiation();
_initPlatformState();
}
void _attemptSdkInstantiation() {
try {
_finapaySdkPlugin = FinapaySdk();
} on Exception catch (e) {
if (kDebugMode) {
debugPrint(e.toString());
}
}
}
void _initSdk() async {
try {
await FinapaySdk.init();
setState(() {
_finapaySdkPlugin = FinapaySdk();
});
} on Exception catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
}
}
}
// initPlatformState initializes the platform state by fetching the platform version
// from the Finapay SDK plugin. It handles potential errors and updates the UI
// with the fetched platform version.
Future<void> _initPlatformState() async {
if (_finapaySdkPlugin == null) return;
String platformVersion;
try {
platformVersion = await _finapaySdkPlugin?.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: _finapaySdkPlugin == null
? Column(
children: [
const Text("Le Sdk n'a pas encore été initialisé"),
ElevatedButton(
onPressed: _initSdk,
child: const Text("Initialiser le SDK"),
),
],
)
: Column(
children: [
Center(
child: Text('Running on: $_platformVersion\n'),
),
// Register client's token
ElevatedButton(
onPressed: () async {
final result = await _finapaySdkPlugin!.regsiterClientWallet(
token:
"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJaZHdYZDhVTzh0NERPQjVlYm1FdVBWVjMtSm5nMEtHNjYzOWRKcElpN1ZNIn0.eyJleHAiOjE3NDczMzc4NjEsImlhdCI6MTc0NzMzNDI2MSwianRpIjoiODVkMzY2NjYtMGQ3MS00NDI5LWIxOWItZGFmOTkwNDRmYTU5IiwiaXNzIjoiaHR0cDovLzE5Mi4xNjguODguMjE6ODA4MC9yZWFsbXMvZmluYXBheSIsImF1ZCI6WyJyZWFsbS1tYW5hZ2VtZW50IiwiYnJva2VyIiwiYWNjb3VudCJdLCJzdWIiOiI5ZjI5NDA0Yi02YjFkLTQzYTItYWU5Ni0xYzM0ZTA1YmI0MWMiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJmaW5hcGF5LWFwaSIsInNpZCI6ImQ2MjBmMTg2LTNjZDAtNGM3Yi1hZmY0LTRkODBkYjY1NWZjZiIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cDovL2xvY2FsaG9zdDo0MjAzIiwiaHR0cDovL2xvY2FsaG9zdDo0MjAxIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLWZpbmFwYXkiLCJvZmZsaW5lX2FjY2VzcyIsInVwZGF0ZV93YWxsZXQiLCJhZGRfd2FsbGV0IiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJyZWFsbS1tYW5hZ2VtZW50Ijp7InJvbGVzIjpbImNyZWF0ZS1jbGllbnQiXX0sImJyb2tlciI6eyJyb2xlcyI6WyJyZWFkLXRva2VuIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50Iiwidmlldy1hcHBsaWNhdGlvbnMiLCJ2aWV3LWNvbnNlbnQiLCJ2aWV3LWdyb3VwcyIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwiZGVsZXRlLWFjY291bnQiLCJtYW5hZ2UtY29uc2VudCIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgcGhvbmUgZW1haWwiLCJwaW5fY2hhbmdlIjpmYWxzZSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJncm91cHMiOlsiY2xpZW50Il0sInByZWZlcnJlZF91c2VybmFtZSI6IjA1NjQyNTY4NjQifQ.M3KcjdrjjnlZE2XodkB_1UNqaCbXovX9qGRc4bTlapJOw6ypGaJDnpCcFlQFIGeNOEHQ7Va8H1gYJGZj90JpASg_FIoPWei_Q-Gcnm-EmtpDPPyQvw3PFBeYMesGNHNFjVJhW5ZmxfYwzr9ATG-1LoMN07w6u6qkfxdhhRxFK6L_51Oa9Czk4-0FwYdwjtgT64NhFlozWhWBiRBGGgDh5rGKJE3etwqgnxPh_k3g5QovbH_Hn3l41O4jPfsy1FR-KPPXkMdl7Z_bVERowdoiV70NV942XVGiKeO2ev6lDkYDndoy3g0i_5o5kld36Ds91v7XRJhkJzPxM1KJEWMHcw");
setState(() {
registrationResult = result;
});
if (registrationResult?.status == RequestStatus.success) {
debugPrint(
"HOTE : Enregistrement réussi : ${registrationResult?.reference}");
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Enregistrement réussi")),
);
}
} else {
debugPrint(
"HOTE : Enregistrement échoué : ${registrationResult?.message}");
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Enregistrement échoué ")),
);
}
}
},
child: const Text("Register client with token"),
),
// Make new Payment
if (registrationResult?.status == RequestStatus.success) ...[
ElevatedButton(
onPressed: () async {
final paymentResult = await _finapaySdkPlugin!
.initPayment(context: context);
if (paymentResult.status == RequestStatus.success) {
debugPrint(
"HOTE : Paiement réussi : ${paymentResult.reference}");
} else {
debugPrint(
"HOTE : Paiement échoué : ${paymentResult.message}");
}
},
child: const Text("Make new Paiement"),
),
// Make new Deposit
ElevatedButton(
onPressed: () async {
final depositResult = await _finapaySdkPlugin!
.initDeposit(context: context);
if (depositResult.status == RequestStatus.success) {
debugPrint(
"HOTE : Dépot réussi : ${depositResult.reference}");
} else {
debugPrint(
"HOTE : Dépot échoué : ${depositResult.message}");
}
},
child: const Text("Make new Deposit"),
),
// Make new Withdraw
// Make new Transfert
ElevatedButton(
onPressed: () async {
final tranfertResult = await _finapaySdkPlugin!
.initTransfert(context: context);
if (tranfertResult.status == RequestStatus.success) {
debugPrint(
"HOTE : Transfert réussi : ${tranfertResult.reference}");
} else {
debugPrint(
"HOTE : Transfert échoué : ${tranfertResult.message}");
}
},
child: const Text("Make new Transfert"),
),
]
],
),
),
);
}
}