|
1 |
| - |
2 | 1 | # Chapa Flutter SDK
|
3 | 2 |
|
4 |
| -Chapa Flutter sdk for Chapa payment API. It is not official and is not supported by Chapa. It is provided as-is. The main features of this library is it supports connectivity tests, auto reroutes, parameter checks for payment options. |
5 |
| - |
6 |
| - |
| 3 | +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. |
7 | 4 |
|
8 |
| -## API Reference |
| 5 | +--- |
9 | 6 |
|
10 |
| -#### Create new transaction from mobile end point |
| 7 | +## **Features** |
11 | 8 |
|
12 |
| -Base end point |
13 |
| -https://api.chapa.co/v1 |
14 |
| - |
15 |
| -```http |
16 |
| - POST /transaction/mobile-initialize |
17 |
| -``` |
| 9 | +- 🌟 **Initiate Payment:** Easily facilitate transactions via four supported wallets telebirr,cbebirr,mpesa and ebirr. |
| 10 | +- ✅ **Validate Payment Status:** Confirm payment completion and notify users instantly. |
| 11 | +- 🌐 **Web Checkout Support:** Enable users to use the web checkout for additional payment options. |
18 | 12 |
|
19 |
| -| Parameter | Type | Description | |
20 |
| -| :-------- | :------- | :------------------------- | |
21 |
| -| `key` | `string` | **Required**. This will be your public key from Chapa. When on test mode use the test key, and when on live mode use the live key. | |
22 |
| -| `email` | `string` | A customer’s email address. | |
23 |
| -| `amount` | `string` | **Required**. The amount you will be charging your customer. | |
24 |
| -| `first_name` | `string` | A customer’s first name. | |
25 |
| -| `last_name` | `string` | A customer's last name. | |
26 |
| -| `tx_ref` | `string` | **Required**. A unique reference given to each transaction. | |
27 |
| -| `currency` | `string` | **Required**. The currency in which all the charges are made. i.e ETB, USD | |
28 |
| -| `phone` | `digit` | A customer’s phone number. | |
29 |
| -| `callback_url`| `string` | The URL to redirect the customer to after payment is done.| |
30 |
| -| `customization[title]`| `string` | The customizations field (optional) allows you to customize the look and feel of the payment modal.| |
| 13 | +--- |
31 | 14 |
|
32 |
| -#### SDK requires additional parameter for fallBack page which is named route which will help you reroute webview after payment completed, on internet disconnected and many more |
| 15 | +## **Getting Started** |
33 | 16 |
|
| 17 | +### **Installation** |
34 | 18 |
|
| 19 | +Add the following dependency to your `pubspec.yaml` file: |
35 | 20 |
|
36 |
| -| Parameter | Type | Description | |
37 |
| -| :-------- | :------- | :-------------------------------- | |
38 |
| -| `namedRouteFallBack` | `string` | **Required by the sdk**. This will accepted route name in String, After successful transaction the app will direct to this page with necessary information for flutter developers to update the backend or to regenerate new transaction reference. | |
39 |
| - |
| 21 | +```dependencies: |
| 22 | + chapasdk: ^latest_version |
| 23 | +``` |
40 | 24 |
|
| 25 | +Then, run the command: |
41 | 26 |
|
| 27 | +```flutter pub get |
| 28 | +``` |
42 | 29 |
|
43 |
| -## Installation |
| 30 | +--- |
| 31 | + |
| 32 | +## **Parameters** |
| 33 | + |
| 34 | +| Parameter | Type | Required | Description | |
| 35 | +|----------------------------|-------------------|-----------|---------------------------------------------------------------------------------------------------------------| |
| 36 | +| `context` | `BuildContext` | **Yes** | Context of the current widget. | |
| 37 | +| `publicKey` | `String` | **Yes** | Your Chapa public key (use test key for testing and live key for production). | |
| 38 | +| `currency` | `String` | **Yes** | Transaction currency (ETB for native checkout, ETB or USD for web checkout). | |
| 39 | +| `amount` | `String` | **Yes** | The amount to be charged. | |
| 40 | +| `email` | `String` | **Yes** | Customer’s email address. | |
| 41 | +| `phone` | `String` | **Yes** | Customer’s phone number. | |
| 42 | +| `firstName` | `String` | **Yes** | Customer’s first name. | |
| 43 | +| `lastName` | `String` | **Yes** | Customer’s last name. | |
| 44 | +| `txRef` | `String` | **Yes** | Unique reference for the transaction. | |
| 45 | +| `title` | `String` | **Yes** | Title of the payment modal. | |
| 46 | +| `desc` | `String` | **Yes** | Description of the payment. | |
| 47 | +| `namedRouteFallBack` | `String` | **Yes** | Named route to redirect users to after payment events (success, failure, or cancellation). | |
| 48 | +| `nativeCheckout` | `bool` | No | Whether to use native checkout (`true`) or web checkout (`false`). Default is `true`. | |
| 49 | +| `showPaymentMethodsOnGridView` | `bool` | No | Display payment methods in grid (`true`) or horizontal view (`false`). Default is `true`. | |
| 50 | +| `availablePaymentMethods` | `List<String>` | No | List of allowed payment methods (`mpesa`, `cbebirr`, `telebirr`, `ebirr`). Defaults to all methods. | |
| 51 | +| `buttonColor` | `Color` | No | Button color for native checkout. Defaults to the app’s primary theme color. | |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +## **Usage** |
| 56 | + |
| 57 | +```dart |
| 58 | +import 'package:chapasdk/chapasdk.dart'; |
44 | 59 |
|
45 |
| -Installation instructions coming soon its better if you install it from pub dev |
| 60 | +Chapa.paymentParameters( |
| 61 | + context: context, |
| 62 | + publicKey: 'CHAPUBK-@@@@', |
| 63 | + currency: 'ETB', |
| 64 | + amount: '1', |
| 65 | + email: 'user@example.com', |
| 66 | + phone: '0911223344', |
| 67 | + firstName: 'John', |
| 68 | + lastName: 'Doe', |
| 69 | + txRef: 'txn_12345', |
| 70 | + title: 'Order Payment', |
| 71 | + desc: 'Payment for order #12345', |
| 72 | + nativeCheckout: true, |
| 73 | + namedRouteFallBack: '/payment-result', |
| 74 | + showPaymentMethodsOnGridView: true, |
| 75 | + availablePaymentMethods: ['mpesa', 'cbebirr', 'telebirr', 'ebirr'], |
| 76 | +); |
| 77 | +``` |
46 | 78 |
|
| 79 | +--- |
47 | 80 |
|
| 81 | +## **Payment Responses** |
48 | 82 |
|
49 |
| -## Usage/Example |
| 83 | +### For Native Checkout: |
| 84 | +```{ |
| 85 | + "message": "Any Descriptive message regarding the payment status", |
| 86 | + "transactionReference": "txn_12345", |
| 87 | + "paidAmount": "1.00" |
| 88 | +} |
| 89 | +``` |
50 | 90 |
|
51 |
| -```flutter |
52 |
| -import 'package:chapasdk/chapasdk.dart'; |
| 91 | +### For Web Checkout: |
| 92 | +#### Payment Canceled: |
| 93 | +```{ |
| 94 | + "message": "paymentCancelled", |
| 95 | + "transactionReference": "txn_12345", |
| 96 | + "paidAmount": "0.00" |
| 97 | +} |
| 98 | +``` |
| 99 | +#### Payment Successful: |
| 100 | +```{ |
| 101 | + "message": "paymentSuccessful", |
| 102 | + "transactionReference": "txn_12345", |
| 103 | + "paidAmount": "1.00" |
| 104 | +} |
| 105 | +``` |
| 106 | +#### Payment Failed: |
| 107 | +```{ |
| 108 | + "message": "paymentFailed", |
| 109 | + "transactionReference": "txn_12345", |
| 110 | + "paidAmount": "0.00" |
| 111 | +} |
| 112 | +``` |
53 | 113 |
|
| 114 | +--- |
54 | 115 |
|
55 |
| -Chapa.paymentParameters( |
56 |
| - context: context, // context |
57 |
| - publicKey: 'CHASECK_TEST--------------', |
58 |
| - currency: 'ETB', |
59 |
| - amount: '200', |
60 |
| - email: 'xyz@gmail.com', |
61 |
| - phone: '911223344', |
62 |
| - firstName: 'fullName', |
63 |
| - lastName: 'lastName', |
64 |
| - txRef: '34TXTHHgb', |
65 |
| - title: 'title', |
66 |
| - desc:'desc', |
67 |
| - namedRouteFallBack: '/second', // fall back route name |
68 |
| - ); |
69 |
| -``` |
| 116 | +## **FAQ** |
70 | 117 |
|
| 118 | +### **1. Is the fallback route mandatory?** |
| 119 | +Yes, `namedRouteFallBack` is required to handle post-payment events such as success, failure, or cancellation. |
71 | 120 |
|
72 |
| -## FAQ |
| 121 | +### **2. What currencies are supported?** |
| 122 | +- Native Checkout: **ETB** |
| 123 | +- Web Checkout: **ETB**, **USD** |
73 | 124 |
|
74 |
| -#### Should my fallBack route should be named route? |
| 125 | +--- |
75 | 126 |
|
76 |
| -Answer Yes, the fallBackRoute comes with an information such as payment is successful, user cancelled payment and connectivity issue messages. Those information will help you to update your backend, to generate new transaction reference. |
| 127 | +## **Support** |
77 | 128 |
|
| 129 | +For any questions or issues: |
| 130 | +- **Email:** [info@chapa.co](mailto:infot@chapa.co) |
| 131 | +- **Call Center:** [+251960724272](tel:+251960724272) |
| 132 | +- **Short Code:** [tel:8911](tel:8911) |
| 133 | +- **Documentation:** [Chapa Developer Docs](https://chapa.co/documenation) |
78 | 134 |
|
| 135 | +Start building seamless payment experiences today with the **Chapa Flutter SDK**! 🚀 |
0 commit comments