Skip to content

Commit 0680a32

Browse files
committed
Update readme and minor cleanup
1 parent c91263d commit 0680a32

File tree

3 files changed

+110
-64
lines changed

3 files changed

+110
-64
lines changed

README.md

+109-52
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,135 @@
1-
21
# Chapa Flutter SDK
32

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.
74

8-
## API Reference
5+
---
96

10-
#### Create new transaction from mobile end point
7+
## **Features**
118

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.
1812

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+
---
3114

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**
3316

17+
### **Installation**
3418

19+
Add the following dependency to your `pubspec.yaml` file:
3520

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+
```
4024

25+
Then, run the command:
4126

27+
```flutter pub get
28+
```
4229

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';
4459
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+
```
4678

79+
---
4780

81+
## **Payment Responses**
4882

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+
```
5090

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+
```
53113

114+
---
54115

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**
70117

118+
### **1. Is the fallback route mandatory?**
119+
Yes, `namedRouteFallBack` is required to handle post-payment events such as success, failure, or cancellation.
71120

72-
## FAQ
121+
### **2. What currencies are supported?**
122+
- Native Checkout: **ETB**
123+
- Web Checkout: **ETB**, **USD**
73124

74-
#### Should my fallBack route should be named route?
125+
---
75126

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**
77128

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)
78134

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

lib/chapa_payment initializer.dart

+1-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ class Chapa {
1919
String namedRouteFallBack;
2020
bool nativeCheckout;
2121

22-
final Widget? child;
2322
final Color? buttonColor;
24-
final Color? labelTextColor;
23+
2524
final bool? showPaymentMethodsOnGridView;
2625
List<String>? availablePaymentMethods;
2726

@@ -39,9 +38,7 @@ class Chapa {
3938
required this.desc,
4039
required this.namedRouteFallBack,
4140
this.nativeCheckout = false,
42-
this.child,
4341
this.buttonColor,
44-
this.labelTextColor,
4542
this.showPaymentMethodsOnGridView,
4643
this.availablePaymentMethods,
4744
}) {
@@ -93,10 +90,8 @@ class Chapa {
9390
desc: desc,
9491
txRef: txRef,
9592
buttonColor: buttonColor,
96-
labelTextColor: labelTextColor,
9793
showPaymentMethodsOnGridView: showPaymentMethodsOnGridView,
9894
availablePaymentMethods: availablePaymentMethods ?? [],
99-
child: child,
10095
),
10196
));
10297
} else {

lib/features/native-checkout/chapa_native_payment.dart

-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ class ChapaNativePayment extends StatefulWidget {
3131
final String title;
3232
final String desc;
3333
final String namedRouteFallBack;
34-
final Widget? child;
3534
final Color? buttonColor;
36-
final Color? labelTextColor;
3735
final bool? showPaymentMethodsOnGridView;
3836
List<String> availablePaymentMethods;
3937

@@ -51,9 +49,7 @@ class ChapaNativePayment extends StatefulWidget {
5149
required this.desc,
5250
required this.namedRouteFallBack,
5351
required this.currency,
54-
this.child,
5552
this.buttonColor,
56-
this.labelTextColor,
5753
this.showPaymentMethodsOnGridView,
5854
this.availablePaymentMethods = const [
5955
"telebirr",
@@ -257,7 +253,6 @@ class _ChapaNativePaymentState extends State<ChapaNativePayment> {
257253
mainAxisAlignment: MainAxisAlignment.start,
258254
crossAxisAlignment: CrossAxisAlignment.start,
259255
children: [
260-
widget.child ?? Container(),
261256
Text(
262257
"Payment Method",
263258
style: Theme.of(context).textTheme.labelMedium,
@@ -417,7 +412,6 @@ class _ChapaNativePaymentState extends State<ChapaNativePayment> {
417412
},
418413
),
419414
Spacer(),
420-
421415
],
422416
),
423417
),

0 commit comments

Comments
 (0)