Foloosi
Search…
⌃K
Links

Sample Dart Program

import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
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 {
var initData = {
"merchantKey": "Your Merchant Key",
"customColor": "#1E8449",
};
await FoloosiPlugins.init(json.encode(initData));
FoloosiPlugins.setLogVisible(true);
var res = {
"orderId": "521",
"orderDescription": "Order Description",
"orderAmount": double.parse(amountTextField.text),
"state": "",
"postalCode": "",
"country": "ARE",
"currencyCode": "AED",
"customerUniqueReference": "",
"customer": {
"name": "Foloosi Test",
"email": "[email protected]",
"mobile": "501234567",
"code": "",
"address": "",
"city": "",
},
};
var result = await FoloosiPlugins.makePayment(json.encode(res));
// var referenceToken = "";
// var result = await FoloosiPlugins.makePaymentWithReferenceToken(referenceToken);
if (kDebugMode) {
print("Payment Response: $result");
}
} on Exception catch (exception) {
exception.runtimeType;
}
} else {
if (kDebugMode) {
print("Error: 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),
),
),
),
),
],
),
),
),
);
}
}