Skip to content

Commit a491a00

Browse files
authored
Merge pull request #6 from dev-masum/feature/support-new-tokenized-api
Feature as new tokenized api based bkash implementation on flutter
2 parents c773a42 + 0089958 commit a491a00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2386
-3772
lines changed

.github/workflows/dart.yml

-42
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.project
2222
.settings/
2323
.vscode/
24+
.fvm/
2425

2526
# Flutter repo-specific
2627
/bin/cache/

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
## 0.1.3
1717
* Modified the README.md
1818
* Flutter formats the code [flutter format .]
19+
## 0.1.3
20+
* Modified the README.md
21+
* Added Tokenized API feature
22+
* Changed API of flutter Bkash

README.md

+107-78
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
12
<p align="center" >
2-
<img src="https://www.bkash.com/sites/all/themes/bkash/logo.png?87980">
3+
<img src="https://www.bkash.com/images/favicon.png">
34
</p>
45

56
<h1 align="center">bKash(BD) Mobile Finance Payment Gateway Flutter Package</h1>
@@ -18,107 +19,135 @@ This is a [Flutter package](https://pub.dartlang.org/packages/flutter_bkash) for
1819
1920
Check the package in <a target="_blank" href="https://github.com/codeboxrcodehub/flutter-bkash" rel="noopener">github</a> and also available in <a href="https://pub.dartlang.org/packages/flutter_bkash" rel="noopener nofollow" target="_blank">flutter/dart package</a>
2021
## How to use:
21-
2222
Depend on it, Run this command With Flutter:
23-
2423
```
2524
$ flutter pub add flutter_bkash
2625
```
27-
2826
This will add a line like this to your package's `pubspec.yaml` (and run an implicit **`flutter pub get`**):
29-
3027
```
3128
dependencies:
32-
flutter_bkash: ^0.1.3
29+
flutter_bkash: ^0.2.0
30+
```
31+
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more. Import it, Now in your Dart code, you can use:
3332
```
34-
35-
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
36-
Import it
37-
38-
Now in your Dart code, you can use:
39-
40-
`
4133
import 'package:flutter_bkash/flutter_bkash.dart';
42-
`
34+
```
35+
## Features
36+
- Pay using bKash without an agreement
37+
- Create a bKash agreement for future payments
38+
- Pay using bKash with an agreement
4339

4440
## Usage
45-
4641
Official Link for API documentation and demo checkout
4742
- [bKash API Specifications](https://developer.bka.sh/v1.2.0-beta/reference)
4843
- [bKash Payment Checkout Demo](https://merchantdemo.sandbox.bka.sh/frontend/checkout)
4944

50-
Examples for see the `/example` folder.
45+
### Initialize the `FlutterBkash` instance:
46+
47+
***Sandbox***
48+
```
49+
final flutterBkash = FlutterBkash();
50+
```
51+
***Production***
52+
```
53+
final flutterBkash = FlutterBkash(
54+
credentials: BkashCredentials(
55+
username: "app_username",
56+
password: "app_password",
57+
appKey: "app_key",
58+
appSecret: "app_secret",
59+
isSandbox: false,
60+
),
61+
);
62+
```
63+
> Make sure to replace the provided credentials with your own bKash sandbox or production credentials depending on your development environment.
64+
65+
### Pay without Agreement
66+
To make a payment without an agreement, use the `pay` method:
67+
68+
***Request***
69+
```
70+
final result = await flutterBkash.pay(
71+
context: context, // BuildContext context
72+
amount: 100.0, // amount as double
73+
merchantInvoiceNumber: "invoice123",
74+
);
75+
```
76+
***Response***
77+
```
78+
BkashPaymentResponse(
79+
trxId: AFI60BAC94,
80+
payerReference: ,
81+
paymentId: TR0011fd4uZMS1687062024354,
82+
customerMsisdn: 01877722345,
83+
merchantInvoiceNumber: tranId,
84+
_executeTime: 2023-06-18T10:22:31:623 GMT+0600
85+
)
86+
```
87+
### Create Agreement
88+
To create a new agreement, use the `createAgreement` method:
5189

52-
**Here is the example code**
53-
```
54-
BkashPayment(
55-
// depend isSandbox (true/false)
56-
isSandbox: true,
57-
// amount of your bkash payment
58-
amount: '20',
59-
/// intent would be (sale / authorization)
60-
intent: 'sale',
61-
// accessToken: '', /// if the user have own access token for verify payment
62-
// currency: 'BDT',
63-
/// bkash url for create payment, when you implement on you project then it be change as your production create url, [when you send it on sandbox mode, send it as empty string '' or anything]
64-
createBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/create',
65-
/// bkash url for execute payment, , when you implement on you project then it be change as your production create url, [when you send it on sandbox mode, send it as empty string '' or anything]
66-
executeBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute',
67-
/// for script url, when you implement on production the set it live script js (https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-pay.js)
68-
scriptUrl: 'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js',
69-
/// the return value from the package
70-
/// status => 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose'
71-
/// data => return value of response
72-
73-
paymentStatus: (status, data) {
74-
dev.log('return status => $status');
75-
dev.log('return data => $data');
76-
77-
/// when payment success
78-
if (status == 'paymentSuccess') {
79-
if (data['transactionStatus'] == 'Completed') {
80-
Style.basicToast('Payment Success');
81-
}
82-
}
83-
84-
/// when payment failed
85-
else if (status == 'paymentFailed') {
86-
if (data.isEmpty) {
87-
Style.errorToast('Payment Failed');
88-
} else if (data[0]['errorMessage'].toString() != 'null'){
89-
Style.errorToast("Payment Failed ${data[0]['errorMessage']}");
90-
} else {
91-
Style.errorToast("Payment Failed");
92-
}
93-
}
94-
95-
/// when payment on error
96-
else if (status == 'paymentError') {
97-
Style.errorToast(jsonDecode(data['responseText'])['error']);
98-
}
99-
100-
/// when payment close on demand closed the windows
101-
else if (status == 'paymentClose') {
102-
if (data == 'closedWindow') {
103-
Style.errorToast('Failed to payment, closed screen');
104-
} else if (data == 'scriptLoadedFailed') {
105-
Style.errorToast('Payment screen loading failed');
106-
}
107-
}
108-
/// back to screen to pop()
109-
Navigator.of(context).pop();
110-
},
90+
***Request***
91+
```
92+
final result = await flutterBkash.createAgreement(context: context);
93+
```
94+
***Response***
95+
```
96+
BkashAgreementResponse(
97+
payerReference: ,
98+
paymentId: TR0000RCHQGmX1687063332607,
99+
customerMsisdn: 01877722345,
100+
agreementId: TokenizedMerchant02P1AIJ7G1687063381235,
101+
_executeTime: 2023-06-18T10:43:01:235 GMT+0600
111102
)
112103
```
104+
### Pay with Agreement
105+
To make a payment with an existing agreement, use the `payWithAgreement` method:
106+
107+
***Request***
108+
```
109+
final result = await flutterBkash.payWithAgreement(
110+
context: context, // BuildContext context
111+
amount: 100.0, // type as double
112+
agreementId: "agreement123",
113+
merchantInvoiceNumber: "invoice123",
114+
);
115+
```
116+
***Response***
117+
```
118+
BkashPaymentResponse(
119+
trxId: AFI60BAC94,
120+
payerReference: ,
121+
paymentId: TR0011fd4uZMS1687062024354,
122+
customerMsisdn: 01877722345,
123+
merchantInvoiceNumber: tranId,
124+
_executeTime: 2023-06-18T10:22:31:623 GMT+0600
125+
)
126+
```
127+
### Error Handling
128+
The methods mentioned above may throw a `BkashFailure` exception in case of an error. You can catch and handle the exception using a try-catch block:
129+
```
130+
try {
131+
// Make a payment or create an agreement
132+
} on BkashFailure catch (e) {
133+
// Handle the error
134+
print(e.message);
135+
}
136+
```
137+
138+
Examples for see the `/example` folder.
139+
140+
**Here is the example code** [link](https://github.com/codeboxrcodehub/flutter-bkash/blob/master/example/lib/main.dart)
113141

114142
### Importance Notes
115143
- Read the comments in the example of code
116144
- See the documents and demo checkout [bKash API Specifications](https://developer.bka.sh/v1.2.0-beta/reference), [bKash Payment Checkout Demo](https://merchantdemo.sandbox.bka.sh/frontend/checkout)
117-
- **intent** - it would be 'sale' or 'authorization'
118-
- Payment status return as 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose', find on this keyword of the payment status, then you get the data of response on specific status.
119145

120146

121147
## Contributing
148+
**Core Maintainer**
149+
- [Md Riadul Islam](https://github.com/rdnasim)
150+
- [ABDULLAH AL MASUM](https://github.com/dev-masum)
122151

123152
Contributions to the **flutter_bkash** package are welcome. Please note the following guidelines before submitting your pull request.
124153

@@ -129,4 +158,4 @@ Contributions to the **flutter_bkash** package are welcome. Please note the foll
129158

130159
flutter_bkash package is licensed under the [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause).
131160

132-
Copyright 2022 [Codeboxr.com Team](https://codeboxr.com/team-codeboxr/). We are not affiliated with bKash and don't give any guarantee.
161+
Copyright 2023 [Codeboxr.com Team](https://codeboxr.com/team-codeboxr/). We are not affiliated with bKash and don't give any guarantee.

0 commit comments

Comments
 (0)