Skip to content

Chapa-Et/chapa-flutter

 
 

Repository files navigation

Chapa Flutter SDK

The official Chapa Flutter SDK enables Flutter developers to integrate Chapa's Payment API seamlessly into their applications. It supports both native and web checkout, providing a robust and flexible solution for initiating and validating payments.


Features

  • 🌟 Initiate Payment: Easily facilitate transactions via four supported wallets telebirr,cbebirr,mpesa and ebirr.
  • Validate Payment Status: Confirm payment completion and notify users instantly.
  • 🌐 Web Checkout Support: Enable users to use the web checkout for additional payment options.

Requirement

To accept money with Chapa in real time, a Merchant should pass all the KYC process and must be in Live mode.

If you are a developer and testing how Chapa works, you can only test using test numbers: Chapa's Test Numbers


Preview

Payment Methods in Grid View

Payment Methods in Grid View

Payment Methods in List View with Customized Button Color

Payment Methods in List View

Error

Error

Successful Payment Receipt

Successful Payment Receipt

Getting Started

Installation

Add the following dependency to your pubspec.yaml file:

dependencies:
  chapasdk: ^latest_version

Then, run the command:

flutter pub get

Parameters

Parameter Type Required Description
context BuildContext Yes Context of the current widget.
publicKey String Yes Your Chapa public key (use test key for testing and live key for production).
currency String Yes Transaction currency (ETB for native checkout, ETB or USD for web checkout NB=> You can not use USD for Naive checkout is it is only available for Web checkout.).
amount String Yes The amount to be charged.
email String Yes Customer’s email address.
phone String Yes Customer’s phone number.
firstName String Yes Customer’s first name.
lastName String Yes Customer’s last name.
txRef String Yes Unique reference for the transaction.
title String Yes Title of the payment modal.
desc String Yes Description of the payment.
namedRouteFallBack String Yes Named route to redirect users to after payment events (success, failure, or cancellation). NB: If you are using GoRoute, AutoRoute, or any custom routing package, pass this value as an empty string "" and make sure to pass a body to the onPaymentFinished function.
nativeCheckout bool No Whether to use native checkout (true) or web checkout (false). Default is true.
showPaymentMethodsOnGridView bool No Display payment methods in grid (true) or horizontal view (false). Default is true.
availablePaymentMethods List<String> No List of allowed payment methods (mpesa, cbebirr, telebirr, ebirr). Defaults to all methods.
buttonColor Color No Button color for native checkout. Defaults to the app’s primary theme color.
onPaymentFinished Function No A callback function executed when namedFallBackUrl is empty, typically used for custom navigation (e.g., AutoRoute,GoRoute).

Usage

import 'package:chapasdk/chapasdk.dart';

Chapa.paymentParameters(
  context: context,
  publicKey: 'CHAPUBK-@@@@',
  currency: 'ETB',
  amount: '1',
  email: 'fetanchapa.co',
  phone: '0911223344',
  firstName: 'Israel',
  lastName: 'Goytom',
  txRef: 'txn_12345',
  title: 'Order Payment',
  desc: 'Payment for order #12345',
  nativeCheckout: true,
  namedRouteFallBack: '/',
  showPaymentMethodsOnGridView: true,
  availablePaymentMethods: ['mpesa', 'cbebirr', 'telebirr', 'ebirr'],
  onPaymentFinished: (message, reference, amount) {
                    Navigator.pop(context);
                  },
);

Payment Responses from

For Native Checkout:

Transaction Reference Number in Native Checkout context is Chapa's Reference number for the Payment.

{
  "message": "Any Descriptive message regarding the payment status",
  "transactionReference": "CHHhvtn7xLEkZ", 
  "paidAmount": "1.00"
}

For Web Checkout:

Transaction Reference Number in Web Checkout context is The transaction reference number you generated for the payment.

Important Note: If the web checkout is initiated from the native checkout page, the Transaction Reference for the web checkout will be generated by the app itself. This is because a single transaction reference cannot be used for both native and web checkout processes. Therefore, the app will generate a separate transaction reference for the web checkout.

Payment Canceled

{
  "message": "paymentCancelled",
  "transactionReference": "txn_12345",
  "paidAmount": "1.00"
}

Payment Successful

{
  "message": "paymentSuccessful",
  "transactionReference": "txn_12345" ,
  "paidAmount": "1.00"
}

Payment Failed

{
  "message": "paymentFailed",
  "transactionReference": "txn_12345",
  "paidAmount": "0.00"
}

FAQ

1. Is the fallback route mandatory?

Yes, namedRouteFallBack is required to handle post-payment events such as success, failure, or cancellation.

2. What currencies are supported?

  • Native Checkout: ONLY ETB
  • Web Checkout: ETB, USD

Support

For any questions or issues:

Start building seamless payment experiences today with the Chapa Flutter SDK! 🚀

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 96.5%
  • HTML 2.4%
  • Other 1.1%