zainpay 0.0.94 copy "zainpay: ^0.0.94" to clipboard
zainpay: ^0.0.94 copied to clipboard

A flutter package to implement zainpay on your flutter application.

Zainpay Flutter Package #

The Flutter library helps you create seamless payment experiences in your flutter mobile app. By connecting to our modal, you can start collecting payment in no time.

Table of Contents #

  1. Requirements
  2. Installation
  3. Usage
  4. License

Requirements #

  1. Zainpay Account API Keys
  2. Supported Flutter version >= 1.17.0

Installation #

  1. Add the dependency to your project. In your pubspec.yaml, file add: zainpay: 0.0.5.
  2. Run flutter pub get.

Usage #

Initializing a Zainpay instance #

To create an instance, you should call the Zainpay constructor. This constructor accepts a mandatory instance of the following:

  • context
  • publicKey
  • transactionRef
  • email
  • fullName
  • mobileNumber
  • zainboxCode
  • successCallBackUrl
  • failureCallBackUrl
  • amount

It returns an instance of Zainpay which we then call the async method .charge() on.

_handlePaymentInitialization() async {
    final Zainpay zainpay = Zainpay(
        context: context,
        publicKey: getPublicKey(),
        transactionRef: getRandomString(16),
        email: emailController.text.toString(),
        fullName: nameController.text.toString(),
        mobileNumber: phoneController.text.toString(),
        zainboxCode: getZainboxCode(),
        successCallBackUrl: 'test.zainpay.ng/success',
        failureCallBackUrl: 'test.zainpay.ng/failure',
        amount: double.parse(amountController.text.toString())
    );
    final PaymentResponse? response = await zainpay.charge();
    if (response != null) {
        showLoading(response.status!);
        debugPrint("${response.toJson()}");
    } else {
        showLoading("No Response!");
    }
}

Handling the response #

To handle result all you need to do is process the result in the callback methods: whenever the user cancels, the value would be null and hasValue would be false. When the transaction is complete, hasValue would be true and value would have an instance of IswPaymentResult: an object with the below fields.

Field Type meaning
responseCode String txn response code
responseDescription String txn response code description
isSuccessful boolean flag indicates if txn is successful
transactionReference String reference for txn
amount Number txn amount
channel String channel used to make payment: one of CARD, WALLET, QR, USSD

Calling the .charge() method returns a Future of PaymentResponse? which we await for the actual response as seen above.

final PaymentResponse? response = await zainpay.charge();

if (response != null) {
    showLoading(response.status!);
    debugPrint("${response.toJson()}");
} else {
    showLoading("No Response!");
}

Note:

  1. PaymentResponse can be null if a user cancels the transaction by pressing back.
  2. You need to confirm the transaction is successful. Ensure that the txRef, amount, and status are correct and successful. Be sure to verify the transaction details before providing value.

License #

By contributing to the Flutter library, you agree that your contributions will be licensed under its MIT license.

Copyright (c) zainpay.ng