|
12 | 12 |
|
13 | 13 | [](https://pub.dartlang.org/packages/flutter_bkash) |
14 | 14 | [](https://opensource.org/licenses/BSD-3-Clause) |
| 15 | +[]() []() |
| 16 | +[](https://github.com/ellerbrock/open-source-badges/) |
15 | 17 |
|
16 | | -This is a Flutter package for [bKash](https://www.bkash.com/) BD Payment Gateway. This package can be used in flutter project. We created this package while working for a project and thought to made it release for all so that it helps. |
| 18 | +This is a Flutter package for [bKash](https://www.bkash.com/) BD Payment Gateway. This package can be used in flutter project. We created this package while working for a project and thought to made it release for all so that it helps. |
17 | 19 |
|
18 | | -## Features |
| 20 | +## How to use: |
19 | 21 |
|
20 | | -List what your package can do. Maybe include images, gifs, or videos. |
| 22 | +Depend on it, Run this command With Flutter: |
21 | 23 |
|
22 | | -## Getting started |
| 24 | +``` |
| 25 | +$ flutter pub add flutter_bkash |
| 26 | +``` |
23 | 27 |
|
24 | | -List prerequisites and provide or point to information on how to |
25 | | -start using the package. |
| 28 | +This will add a line like this to your package's `pubspec.yaml` (and run an implicit **`flutter pub get`**): |
26 | 29 |
|
27 | | -## Usage |
| 30 | +``` |
| 31 | +dependencies: |
| 32 | + flutter_bkash: ^0.1.0 |
| 33 | +``` |
| 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: |
28 | 39 |
|
29 | | -Include short and useful examples for package users. Add longer examples |
30 | | -to `/example` folder. |
| 40 | +` |
| 41 | +import 'package:flutter_bkash/flutter_bkash.dart'; |
| 42 | +` |
| 43 | + |
| 44 | +## Usage |
| 45 | +examples for see the `/example` folder. |
31 | 46 |
|
| 47 | +**Here is the example code** |
| 48 | +``` |
| 49 | + BkashPayment( |
| 50 | + // amount of your bkash payment |
| 51 | + amount: '20', |
| 52 | + // intent would be (sale / authorization) |
| 53 | + intent: 'sale', |
| 54 | + // accessToken: '', // if the user have own access token for verify payment |
| 55 | + // currency: 'BDT', // bkash url for create payment, when you implement on you project then it be change as your production create url createBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/create', |
| 56 | + // bkash url for execute payment, , when you implement on you project then it be change as your production create url |
| 57 | + executeBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute', |
| 58 | + // for script url, when you implement on production the set it live script js |
| 59 | + scriptUrl: 'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js', |
| 60 | + |
| 61 | + // the return value from the package |
| 62 | + // status => 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose' // data => return value of response paymentStatus: (status, data) { |
| 63 | + dev.log('return status => $status'); |
| 64 | + dev.log('return data => $data'); |
32 | 65 |
|
33 | | -## Additional information |
| 66 | + // when payment success |
| 67 | + if (status == 'paymentSuccess') { |
| 68 | + if (data['transactionStatus'] == 'Completed') { |
| 69 | + Style.basicToast('Payment Success'); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + // when payment failed |
| 74 | + else if (status == 'paymentFailed') { |
| 75 | + if (data.isEmpty) { |
| 76 | + Style.errorToast('Payment Failed'); |
| 77 | + } else if (data[0]['errorMessage'].toString() != 'null'){ |
| 78 | + Style.errorToast("Payment Failed ${data[0]['errorMessage']}"); |
| 79 | + } else { |
| 80 | + Style.errorToast("Payment Failed"); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + // when payment on error |
| 85 | + else if (status == 'paymentError') { |
| 86 | + Style.errorToast(jsonDecode(data['responseText'])['error']); |
| 87 | + } |
| 88 | + |
| 89 | + // when payment close on demand closed the windows |
| 90 | + else if (status == 'paymentClose') { |
| 91 | + if (data == 'closedWindow') { |
| 92 | + Style.errorToast('Failed to payment, closed screen'); |
| 93 | + } else if (data == 'scriptLoadedFailed') { |
| 94 | + Style.errorToast('Payment screen loading failed'); |
| 95 | + } |
| 96 | + } |
| 97 | + // back to screen to pop() |
| 98 | + Navigator.of(context).pop(); |
| 99 | + }, |
| 100 | + ) |
| 101 | +``` |
34 | 102 |
|
35 | | -Tell users more about the package: where to find more information, how to |
36 | | -contribute to the package, how to file issues, what response they can expect |
37 | | -from the package authors, and more. |
| 103 | +### Importance Notes |
| 104 | +- Read the comments in the example of code |
| 105 | +- **intent** - it would be 'sale' or 'authorization' |
| 106 | +- 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. |
0 commit comments