flutter_paystack 1.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • 87

💳 Paystack Plugin for Flutter #

pub package

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

🚀 Installation #

To use this plugin, add flutter_paystack as a dependency in your pubspec.yaml file.

Then initialize the plugin preferably in the initState of your widget.

import 'package:flutter_paystack/flutter_paystack.dart';

class _PaymentPageState extends State<PaymentPage> {
  var publicKey = '[YOUR_PAYSTACK_PUBLIC_KEY]';

  void initState() {
            publicKey: publicKey);

No other configuration required—the plugin works out of the box.

💲 Making Payments #

There are two ways of making payment with the plugin.

  1. Checkout: This is the easy way; as the plugin handles all the processes involved in making a payment (except transaction initialization and verification which should be done from your backend).
  2. Charge Card: This is a longer approach; you handle all callbacks and UI states.

You initialize a charge object with an amount, email & accessCode or reference. Pass an accessCode only when you have initialized the transaction from your backend. Otherwise, pass a reference.

 Charge charge = Charge()
       ..amount = 10000
       ..reference = _getReference()
        // or ..accessCode = _getAccessCodeFrmInitialization()
       ..email = 'customer@email.com';
     CheckoutResponse response = await PaystackPlugin.checkout(
       context context,
       charge: charge,

PaystackPlugin.checkout() returns the state and details of the payment in an instance of CheckoutResponse .

It is recommended that when PaystackPlugin.checkout() returns, the payment should be verified on your backend.

2. ⭐ Charge Card

You can choose to initialize the payment locally or via your backend.

1.a. This starts by making a HTTP POST request to paystack on your backend.

1.b If everything goes well, the initialization request returns a response with an access_code. You can then create a Charge object with the access code and card details. The charge is in turn passed to the PaystackPlugin.chargeCard() function for payment:

  PaymentCard _getCardFromUI() {
    // Using just the must-required parameters.
    return PaymentCard(
      number: cardNumber,
      cvc: cvv,
      expiryMonth: expiryMonth,
      expiryYear: expiryYear,

    // Using Cascade notation (similar to Java's builder pattern)
//    return PaymentCard(
//        number: cardNumber,
//        cvc: cvv,
//        expiryMonth: expiryMonth,
//        expiryYear: expiryYear)
//      ..name = 'Segun Chukwuma Adamu'
//      ..country = 'Nigeria'
//      ..addressLine1 = 'Ikeja, Lagos'
//      ..addressPostalCode = '100001';

    // Using optional parameters
//    return PaymentCard(
//        number: cardNumber,
//        cvc: cvv,
//        expiryMonth: expiryMonth,
//        expiryYear: expiryYear,
//        name: 'Ismail Adebola Emeka',
//        addressCountry: 'Nigeria',
//        addressLine1: '90, Nnebisi Road, Asaba, Deleta State');

  _chargeCard(String accessCode) {
    var charge = Charge()
      ..accessCode = accessCode
      ..card = _getCardFromUI();

        charge: charge,
        beforeValidate: (transaction) => handleBeforeValidate(transaction),
        onSuccess: (transaction) => handleOnSuccess(transaction),
        onError: (error, transaction) => handleOnError(error, transaction));

  handleBeforeValidate(Transaction transaction) {
    // This is called only before requesting OTP
    // Save reference so you may send to server if error occurs with OTP

  handleOnError(Object e, Transaction transaction) {
    // If an access code has expired, simply ask your server for a new one
    // and restart the charge instead of displaying error

  handleOnSuccess(Transaction transaction) {
    // This is called only after transaction is successful

2. Initialize Locally #

Just send the payment details to PaystackPlugin.chargeCard

      // Set transaction params directly in app (note that these params
      // are only used if an access_code is not set. In debug mode,
      // setting them after setting an access code would throw an error
      Charge charge = Charge();
      charge.card = _getCardFromUI();
        ..amount = 2000
        ..email = 'user@email.com'
        ..reference = _getReference()
        ..putCustomField('Charged From', 'Flutter PLUGIN');

🔧 🔩 Validating Card Details

You are expected but not required to build the UI for your users to enter their payment details. For easier validation, wrap the TextFormFields inside a Form widget. Please check this article on validating forms on Flutter if this is new to you.

NOTE: You don't have to pass a card object to Charge. The plugin will call-up a UI for the user to input their card.

You can validate the fields with these methods:

card.validNumber #

This method helps to perform a check if the card number is valid.

card.validCVC #

Method that checks if the card security code is valid.

card.validExpiryDate #

Method checks if the expiry date (combination of year and month) is valid.

card.isValid #

Method to check if the card is valid. Always do this check, before charging the card.

card.getType #

This method returns an estimate of the string representation of the card type(issuer).

✔️ Verifying Transactions #

This is quite easy. Just send a HTTP GET request to https://api.paystack.co/transaction/verify/$[TRANSACTION_REFERENCE]. Please, check the official documentaion on verifying transactions.

🚁 Testing your implementation #

Paystack provides tons of payment cards for testing.

▶️ Running Example project #

For help getting started with Flutter, view the online documentation.

An example project has been provided in this plugin. Clone this repo and navigate to the example folder. Open it with a supported IDE or execute flutter run from that folder in terminal.

:pencil: Contributing, 😞 Issues and 🐛 Bug Reports

The project is open to public contribution. Please feel very free to contribute. Experienced an issue or want to report a bug? Please, report it here. Remember to be as descriptive as possible.

🏆 Credits #

Thanks to the authors of Paystack iOS and Android SDKS. I leveraged on their work to bring this plugin to fruition.

🔥 Apps Using this plugin #

  1. EasyDispatch - Play Store | App Store

To to add your app here, just shoot me an email on faradaywilly(at)gmail.com.

1.0.0 #

  • Reintroduced and improved bank payment
  • Minor bug fixes

0.10.0 (Breaking change) #

  • Security Improvement: Removed usage of the secret key in checkout
  • Removed support for bank payment (requires secret key)
  • Transaction initialization and verification is no longer being handled by the checkout function (requires secret key)
  • Handled Gateway timeout error
  • Returning last for digits instead full card number after payment

0.9.3 #

  • Fixed failure of web OTP on iOS devices
  • Automatically closes soft keyboard when text-field entries are submitted
  • Changed date picker on iOS to CupertinoDatePicker

0.9.2 #

  • Bank account payment: fixed issue where the reference value passed to checkout is different from what is returned after transaction.
  • Increased width of checkout dialog.
  • Added flag to enable fullscreen checkout dialog.
  • Felt like doing some reorganising so I refactored some .dart files.

0.9.1+2 #

  • Fixed build failure because of difference in type of passed and expected value of encrypt function.

0.9.1+1 #

  • Updated to the latest gradle and kotlin dependencies.

0.9.1 #

  • Bumped version of dependencies.

0.9.0 #

  • Added checkout form and supported bank account payment.

0.5.2 #

  • Support for Flutter v0.5.1.

0.5.1 #

  • Exposed Paystack Exception
  • Properly formatted .dart files
  • Removed deprecated APIs

0.5.0 #

  • Initial beta release.


flutter_paystack_example #

Demonstrates how to use the flutter_paystack plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_paystack: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_paystack/flutter_paystack.dart';
Version Uploaded Documentation Archive
1.0.0 Feb 13, 2019 Go to the documentation of flutter_paystack 1.0.0 Download flutter_paystack 1.0.0 archive
0.10.0 Feb 8, 2019 Go to the documentation of flutter_paystack 0.10.0 Download flutter_paystack 0.10.0 archive
0.9.3 Dec 14, 2018 Go to the documentation of flutter_paystack 0.9.3 Download flutter_paystack 0.9.3 archive
0.9.2 Nov 24, 2018 Go to the documentation of flutter_paystack 0.9.2 Download flutter_paystack 0.9.2 archive
0.9.1+2 Nov 8, 2018 Go to the documentation of flutter_paystack 0.9.1+2 Download flutter_paystack 0.9.1+2 archive
0.9.1+1 Oct 25, 2018 Go to the documentation of flutter_paystack 0.9.1+1 Download flutter_paystack 0.9.1+1 archive
0.9.1 Oct 8, 2018 Go to the documentation of flutter_paystack 0.9.1 Download flutter_paystack 0.9.1 archive
0.9.0 Oct 3, 2018 Go to the documentation of flutter_paystack 0.9.0 Download flutter_paystack 0.9.0 archive
0.5.2 Aug 9, 2018 Go to the documentation of flutter_paystack 0.5.2 Download flutter_paystack 0.5.2 archive
0.5.1 Aug 9, 2018 Go to the documentation of flutter_paystack 0.5.1 Download flutter_paystack 0.5.1 archive

All 11 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13+1
  • Flutter: 1.2.1


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
async ^2.0.8 2.0.8
flutter 0.0.0
http ^0.12.0 0.12.0+1
intl ^0.15.7 0.15.7
meta ^1.1.6 1.1.6 1.1.7
Transitive dependencies
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
path 1.6.2
sky_engine 0.0.99
source_span 1.5.4
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8