foloosi_plugins 1.0.8
foloosi_plugins: ^1.0.8 copied to clipboard
A Flutter plugin for making payments via Foloosi Payment Gateway. Fully supports Android and iOS.
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:foloosi_plugins/foloosi_plugins.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController amountTextField = TextEditingController();
final key = GlobalKey<ScaffoldState>();
/// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
if (amountTextField.text.trim().isNotEmpty) {
try {
await FoloosiPlugins.init("Your Merchant Key");
FoloosiPlugins.setLogVisible(true);
var res = {
"orderId": "ORDER001",
"orderDescription": "Order Description",
"orderAmount": double.parse(amountTextField.text),
"state": "Dubai",
"postalCode": "12345",
"customColor": "",
"country": "ARE",
"currencyCode": "AED",
"customerUniqueReference": "",
"customer": {
"name": "John",
"email": "john@email.com",
"mobile": "501234567",
"code": "971",
"address": "123 Dubai",
"city": "Dubai",
},
};
var result = await FoloosiPlugins.makePayment(json.encode(res));
// var referenceToken = "order_fls63571iap62c05c3665514snhIQslf";
// var result = await FoloosiPlugins.makePaymentWithReferenceToken(referenceToken);
if (kDebugMode) {
print("Payment Response: $result");
}
} on Exception catch (exception) {
exception.runtimeType;
}
} else {
WidgetsBinding.instance!.addPostFrameCallback(
(_) => key.currentState?.showSnackBar(
const SnackBar(
content: Text("Please enter amount"),
),
),
);
}
/// Platform messages may fail, so we use a try/catch PlatformException.
/// If the widget was removed from the tree while the asynchronous platform
/// message was in flight, we want to discard the reply rather than calling
/// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
key: key,
appBar: AppBar(
title: const Text('Foloosi Example'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.all(20),
child: TextField(
controller: amountTextField,
keyboardType: TextInputType.number,
decoration:
const InputDecoration(hintText: "Enter the amount"),
),
),
InkWell(
onTap: () {
initPlatformState();
},
child: Container(
margin: const EdgeInsets.all(20),
height: 50,
color: Colors.blue,
child: const Center(
child: Text(
"Proceed Payment",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
),
],
),
),
),
);
}
}