finapay_sdk 0.0.3
finapay_sdk: ^0.0.3 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:finapay_sdk_example/core/theme.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 MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
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 {
@override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
String _platformVersion = 'Unknown';
FinapaySdk? _finapaySdkPlugin;
@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 registrationResult = await _finapaySdkPlugin!
.regsiterClientWallet(
token:
"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJaZHdYZDhVTzh0NERPQjVlYm1FdVBWVjMtSm5nMEtHNjYzOWRKcElpN1ZNIn0.eyJleHAiOjE3NDY3NDg3OTEsImlhdCI6MTc0NjcxMjc5MSwianRpIjoiZTkxYmQ4MzQtZDM2Ni00YTkxLTllN2EtYWIxNmU2M2MxOWVjIiwiaXNzIjoiaHR0cDovLzE5Mi4xNjguODguMjE6ODA4MC9yZWFsbXMvZmluYXBheSIsImF1ZCI6WyJyZWFsbS1tYW5hZ2VtZW50IiwiYnJva2VyIiwiYWNjb3VudCJdLCJzdWIiOiJlZWMzMTYyMC0xNTVjLTQxMDAtOWZhZC1iOWQxYWZmN2M0MDgiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJmaW5hcGF5LWFwaSIsInNpZCI6IjA1OTA3MjM4LWE4MTYtNDE4NC1iNTI0LTEyYTNkZWIwNTU2OCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cDovL2xvY2FsaG9zdDo0MjAzIiwiaHR0cDovL2xvY2FsaG9zdDo0MjAxIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLWZpbmFwYXkiLCJvZmZsaW5lX2FjY2VzcyIsInVwZGF0ZV93YWxsZXQiLCJhZGRfd2FsbGV0IiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJyZWFsbS1tYW5hZ2VtZW50Ijp7InJvbGVzIjpbImNyZWF0ZS1jbGllbnQiXX0sImJyb2tlciI6eyJyb2xlcyI6WyJyZWFkLXRva2VuIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50Iiwidmlldy1hcHBsaWNhdGlvbnMiLCJ2aWV3LWNvbnNlbnQiLCJ2aWV3LWdyb3VwcyIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwiZGVsZXRlLWFjY291bnQiLCJtYW5hZ2UtY29uc2VudCIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgcGhvbmUgZW1haWwiLCJwaW5fY2hhbmdlIjpmYWxzZSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJncm91cHMiOlsiY2xpZW50Il0sInByZWZlcnJlZF91c2VybmFtZSI6IjA3NzcxNjg4NDkifQ.bEl7XA_MiX29Eg3rDbPfJTc_pBKoPumXo-bvCQwip9lAGnT6inzrny_1HVE9A9HU942M7R-BAwl8VgyjNZ1dbdSHtiXrnikB4boshvK2S7_dTrB6FeVRx9ncHtb-b4LA5g-mep4Fq-H-aiebJ6xiT7SA8KfVUKn8KwgZ8DFhk7vqwYMC6N60c0TTkuhmrJdru9MjqPSk4aigSb78ohoiwxtGFDi8t6x_W9mkBpT3Qm2jbFTwJRtdK9TwhlHYrdeNH8TZLwJNDwYC0Tm9PQLmF8iIY-luM4tqCzCvEHoqd8ZOMS7kIPUSWHIVV_wIrfR7iStJzbXIdDGn_HqJlYZW2A");
if (registrationResult.status == RequestStatus.success) {
debugPrint(
"Enregistrement réussi : ${registrationResult.reference}");
} else {
debugPrint(
"Enregistrement échoué : ${registrationResult.message}");
}
},
child: const Text("Register client with token"),
),
// Make new Payment
ElevatedButton(
onPressed: () async {
final paymentResult = await _finapaySdkPlugin!
.initPayment(context: context);
if (paymentResult.status == RequestStatus.success) {
debugPrint(
"Paiement réussi : ${paymentResult.reference}");
} else {
debugPrint(
"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("Dépot réussi : ${depositResult.reference}");
} else {
debugPrint("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(
"Transfert réussi : ${tranfertResult.reference}");
} else {
debugPrint(
"Transfert échoué : ${tranfertResult.message}");
}
},
child: const Text("Make new Transfert"),
),
],
),
),
);
}
}