Foloosi
Search…
Flutter SDK
A Flutter plugin for making payments via Foloosi Payment Gateway. Fully supports Android and iOS.

Installation

In the dependencies: section of your pubspec.yaml, add the following line:
1
foloosi_plugins: ^1.0.3
Copied!
Import in your project:
1
import 'package:foloosi_plugins/foloosi_plugins.dart';
Copied!

Android Requirement

Set up Android build.gradle (android/app/build.gradle)

1
android {
2
defaultConfig {
3
minSdkVersion 21
4
}
5
buildTypes {
6
release {
7
// Signing with the debug keys for now, so `flutter run --release` works.
8
minifyEnabled true
9
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
10
...
11
}
12
}
13
dependencies {
14
implementation 'com.foloosi:FoloosiSDK:2.0.9'
15
implementation 'com.google.code.gson:gson:2.8.6'
16
}
17
}
18
Copied!

Proguard Rules

If you are using Proguard for your builds, modify the Proguard rule file:
1
-keepclassmembers class * {
2
@android.webkit.JavascriptInterface <methods>;
3
}
4
5
-keepattributes JavascriptInterface
6
-keepattributes *Annotation*
7
8
-dontwarn com.foloosi.**
9
-keep class com.foloosi.** {*;}
10
11
-optimizations !method/inlining/*
Copied!
*Note:-
  • settings build.gradle must be 4.1.3 or higher.
  • Kotlin version must be 1.4.30 or higher.

iOS Requirement

iOS Deployment Target 11+ (iPhone, iPad)

Sample Dart Program

1
import 'dart:convert';
2
3
import 'package:flutter/foundation.dart';
4
import 'package:flutter/material.dart';
5
import 'dart:async';
6
7
import 'package:foloosi_plugins/foloosi_plugins.dart';
8
9
void main() {
10
runApp(const MyApp());
11
}
12
13
class MyApp extends StatefulWidget {
14
const MyApp({Key? key}) : super(key: key);
15
16
@override
17
_MyAppState createState() => _MyAppState();
18
}
19
20
class _MyAppState extends State<MyApp> {
21
TextEditingController orderIdTextField = TextEditingController();
22
final key = GlobalKey<ScaffoldState>();
23
24
@override
25
void initState() {
26
super.initState();
27
}
28
29
// Platform messages are asynchronous, so we initialize in an async method.
30
Future<void> initPlatformState() async {
31
if (orderIdTextField.text.trim().isNotEmpty) {
32
try {
33
await FoloosiPlugins.init("Your Merchant Key");
34
FoloosiPlugins.setLogVisible(true);
35
var res = {
36
"orderId": "YOUR ORDER ID",
37
"orderDescription": "YOUR ORDER DESCRIPTION",
38
"orderAmount": double.parse(orderIdTextField.text),
39
"state": "Dubai",
40
"postalCode": "12345",
41
"customColor": "",
42
"country": "ARE",
43
"currencyCode": "AED",
44
"customerUniqueReference": "" //Customer Unique Reference value should be email/mobile no/uniqueCustomer id from your DB
45
"customer": {
46
"name": "John",
47
"email": "[email protected]",
48
"mobile": "501234567",
49
"code": "971",
50
"address": "123 Dubai",
51
"city": "Dubai",
52
}
53
};
54
55
var result = await FoloosiPlugins.makePayment(json.encode(res));
56
if (kDebugMode) {
57
print(result);
58
}
59
} on Exception catch (exception) {
60
exception.runtimeType;
61
}
62
} else {
63
WidgetsBinding.instance!.addPostFrameCallback(
64
(_) => key.currentState?.showSnackBar(
65
const SnackBar(
66
content: Text("Please enter amount"),
67
),
68
),
69
);
70
}
71
// Platform messages may fail, so we use a try/catch PlatformException.
72
73
// If the widget was removed from the tree while the asynchronous platform
74
// message was in flight, we want to discard the reply rather than calling
75
// setState to update our non-existent appearance.
76
if (!mounted) return;
77
78
setState(() {
79
// _platformVersion = platformVersion;
80
});
81
}
82
83
@override
84
Widget build(BuildContext context) {
85
return MaterialApp(
86
home: Scaffold(
87
key: key,
88
appBar: AppBar(
89
title: const Text('Foloosi Example'),
90
),
91
body: Center(
92
child: Column(
93
crossAxisAlignment: CrossAxisAlignment.center,
94
mainAxisAlignment: MainAxisAlignment.center,
95
children: [
96
Container(
97
margin: const EdgeInsets.all(20),
98
child: TextField(
99
controller: orderIdTextField,
100
keyboardType: TextInputType.number,
101
decoration:
102
const InputDecoration(hintText: "Enter the amount"),
103
),
104
),
105
InkWell(
106
onTap: () {
107
initPlatformState();
108
},
109
child: Container(
110
margin: const EdgeInsets.all(20),
111
height: 50,
112
color: Colors.blue,
113
child: const Center(
114
child: Text(
115
"Proceed Payment",
116
style: TextStyle(color: Colors.white, fontSize: 18),
117
),
118
),
119
),
120
),
121
],
122
),
123
),
124
),
125
);
126
}
127
}
Copied!
Note: If you're using the foloosi secret and merchant keys as a string in flutter, remember to escape the $ dollar signs although it is recommended to load these from your backend
1
merchantKey: 'Your Merchant Key'
Copied!

Properties

Here is a list of properties available:
Name
Type
Required
Description
headerText
String
false
the title of the widget's appbar
onError
Function
true
function to run on payment error
onSuccess
Function
true
function to run on payment success
loaderText
String
false
text to display under the loader
merchantKey
String
true
your foloosi merchant key
secretKey
String
true
your foloosi secret key
referenceToken
String
false
the reference token - generates automatically if null
redirectUrl
String
false
the redirect url
transactionAmount
String
true
transaction amount
currency
String
true
transaction currency
customerName
String
false
customer name - auto render in payment popup if passed
customerEmail
String
false
customer email - auto render in payment popup if passed
customerMobile
String
false
customer mobile - auto render in payment popup if passed
customerAddress
String
false
customer address - auto render in payment popup if passed
customerCity
String
false
customer city - auto render in payment popup if passed
billingState
String
false
Billing State - auto render in payment popup if passed
billingPostalCode
String
false
Billing Postcode - auto render in payment popup if passed
billingCountry
String
false
Billing Country - auto render in payment popup if passed
paymentCancellationMsg
String
false
message returned when user cancels the payment

Developed by

Foloosi

License

Copyrights (c) 2022 Foloosi