zainpay 0.1.11 zainpay: ^0.1.11 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 #
Requirements #
- Zainpay Account API Keys
- Supported Flutter version >= 1.17.0
Installation #
- Add the dependency to your project. In your
pubspec.yaml
, file add:zainpay: 0.1.11
. - 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
fullName
email
publicKey
callBackUrl
mobileNumber
zainboxCode
transactionRef
amount
isTest
It returns an instance of Zainpay which we then call the async method .charge()
on.
_handlePaymentInitialization() async {
final Zainpay zainpay = Zainpay(
context: context,
fullName: fullNameController.text,
email: emailController.text,
publicKey: getPublicKey(),
callBackUrl: "https://localhost:8080/success",
mobileNumber: phoneController.text,
zainboxCode: getZainBoxCode(),
transactionRef: getRandomString(12),
amount: amountController.text,
isTest: true
);
final PaymentResponse? response = await zainpay.charge();
if (response != null) {
debugPrint("${response.toJson()}");
} else {
debugPrint("No Response");
}
}
Handling the response #
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:
PaymentResponse
can be null if a user cancels the transaction by pressing back.- 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