foloosi_flutter_payment 1.0.5
foloosi_flutter_payment: ^1.0.5 copied to clipboard

A Flutter plugin to integrate foloosi libraries for iOS and Android.

Foloosi Payment #

pub package

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

<div style="text-align: center">
    <table>
        <tr>
            <td style="text-align: center">
                <img src="https://raw.githubusercontent.com/FoloosiTech/foloosi_flutter_payment/master/sample.gif" width="400" />
            </td>
        </tr>
    </table>
</div>

Installation #

In the dependencies: section of your pubspec.yaml, add the following line:

foloosi_flutter_payment: ^1.0.5

Import in your project:

import 'package:foloosi_flutter_payment/foloosi_flutter_payment.dart';

Basic Usage #

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool proceedToPayment = false;
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  void _proceeedToPayment() {
    setState(() {
      proceedToPayment = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: proceedToPayment
          ? null
          : AppBar(
              title: Text('Foloosi Payment Flutter'),
            ),
      body: proceedToPayment
          ? FoloosiPayment(
              headerText: 'Foloosi Payment',
              loaderText: "Processing Request",
              merchantKey: 'YOUR_FOLOOSI_MERCHANT_KEY',
              secretKey: 'YOUR_FOLOOSI_SECRET_KEY',
              transactionAmount: 1,
              currency: 'AED',
              customerName: 'Omar Ali',
              customerEmail: 'tech@foloosi.com',
              customerMobile: '+971000000000',
              customerAddress: 'No 2, Test Street',
              customerCity: 'Dubai',
              billingState: 'Dubai',
              billingPostalCode: '000000', // For UAE, pass postal code as 000000
              billingCountry: 'ARE', // Three Digit ISO Country Code,
              optional1: '', // Optional Params 
              optional2: '', // Optional Params 
              optional3: '', // Optional Params 
              onPaymentClose: (value) {
                print("Payment Error : $value");
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(value.toString()),
                  duration: Duration(seconds: 3),
                ));
              },
              onError: (value) {
                print("Payment Error : $value");
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(value.toString()),
                  duration: Duration(seconds: 3),
                ));
              },
              onSuccess: (transactionDetails) {
                print("Payment Success : $transactionDetails");
                print(
                    json.decode(transactionDetails)['data']['transaction_no']);
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(
                      json.decode(transactionDetails)['status'].toString()),
                  duration: Duration(seconds: 3),
                ));
              },
            )
          : Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  RaisedButton(
                    onPressed: _proceeedToPayment,
                    child: new Text(
                      "Proceed to Payment",
                    ),
                  )
                ],
              ),
            ),
    );
  }
}

Sample Dart Program #

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:foloosi_flutter_payment/foloosi_flutter_payment.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Foloosi Payment Flutter',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool proceedToPayment = false;
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  void _proceeedToPayment() {
    setState(() {
      proceedToPayment = true;
    });
  }

    @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: proceedToPayment
          ? null
          : AppBar(
              title: Text('Foloosi Payment Flutter'),
            ),
      body: proceedToPayment
          ? FoloosiPayment(
              headerText: 'Foloosi Payment',
              loaderText: "Processing Request",
              merchantKey: 'YOUR_FOLOOSI_MERCHANT_KEY',
              secretKey: 'YOUR_FOLOOSI_SECRET_KEY',
              transactionAmount: 1,
              currency: 'AED',
              customerName: 'Omar Ali',
              customerEmail: 'tech@foloosi.com',
              customerMobile: '+971000000000',
              customerAddress: 'No 2, Test Street',
              customerCity: 'Dubai',
              billingState: 'Dubai',
              billingPostalCode: '000000', // For UAE, pass postal code as 000000
              billingCountry: 'ARE', // Three Digit ISO Country Code
              optional1: '', // Optional Params 
              optional2: '', // Optional Params 
              optional3: '', // Optional Params 
              onPaymentClose: (value) {
                print("Payment Error : $value");
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(value.toString()),
                  duration: Duration(seconds: 3),
                ));
              },
              onError: (value) {
                print("Payment Error : $value");
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(value.toString()),
                  duration: Duration(seconds: 3),
                ));
              },
              onSuccess: (transactionDetails) {
                print("Payment Success : $transactionDetails");
                print(
                    json.decode(transactionDetails)['data']['transaction_no']);
                setState(() {
                  proceedToPayment = false;
                });
                _scaffoldKey.currentState.showSnackBar(SnackBar(
                  content: Text(
                      json.decode(transactionDetails)['status'].toString()),
                  duration: Duration(seconds: 3),
                ));
              },
            )
          : Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  RaisedButton(
                    onPressed: _proceeedToPayment,
                    child: new Text(
                      "Proceed to Payment",
                    ),
                  )
                ],
              ),
            ),
    );
  }
}

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

merchantKey: 'YOUR_MERCHANT_KEY',
secretKey: 'YOUR_SECRET_KEY',

Properties #

Here is a list of properties available:

NameTypeRequiredDescription
headerTextStringfalsethe title of the widget's appbar
onErrorFunctiontruefunction to run on payment error
onSuccessFunctiontruefunction to run on payment success
loaderTextStringfalsetext to display under the loader
merchantKeyStringtrueyour foloosi merchant key
secretKeyStringtrueyour foloosi secret key
referenceTokenStringfalsethe reference token - generates automatically if null
redirectUrlStringfalsethe redirect url
transactionAmountString-transaction amount - required if referenceToken is null
currencyString-transaction currency - required if referenceToken is null
customerNameStringfalsecustomer name - auto render in payment popup if passed
customerEmailStringfalsecustomer email - auto render in payment popup if passed
customerMobileStringfalsecustomer mobile - auto render in payment popup if passed
customerAddressStringfalsecustomer address - auto render in payment popup if passed
customerCityStringfalsecustomer city - auto render in payment popup if passed
billingStateStringfalseBilling State - auto render in payment popup if passed
billingPostalCodeStringfalseBilling Postcode - auto render in payment popup if passed
billingCountryStringfalseBilling Country - auto render in payment popup if passed
optional1StringfalseOptional Parameter - Pass whatever you need
optional2StringfalseOptional Parameter - Pass whatever you need
optional3StringfalseOptional Parameter - Pass whatever you need
paymentCancellationMsgStringfalsemessage returned when user cancels the payment
debugModeboolfalseto enable or disable package logs

Developed by #

Foloosi

License #

Copyrights (c) 2021 Foloosi

2
likes
80
pub points
68%
popularity

A Flutter plugin to integrate foloosi libraries for iOS and Android.

Repository (GitHub)
View/report issues

Documentation

API reference

License

LICENSE

Dependencies

flutter, flutter_webview_plugin, http

More

Packages that depend on foloosi_flutter_payment