bKash(BD) 适用于Flutter的移动金融支付网关
这是一个适用于bKash BD支付网关的Flutter包。该包可用于Flutter项目。我们在项目中创建了这个包,并决定将其发布给所有人,以便它能有所帮助。
如何使用
依赖它,使用Flutter运行此命令
$ flutter pub add flutter_bkash
这将在您的包的pubspec.yaml文件中添加类似此行的内容(并运行隐式的flutter pub get)
dependencies:
flutter_bkash: ^0.1.0
或者,您的编辑器可能支持flutter pub get。请查阅您编辑器的文档以了解更多信息。导入它
现在,在您的 Dart 代码中,您可以使用
import 'package:flutter_bkash/flutter_bkash.dart';
用法
示例可在/example文件夹中查看。
这是示例代码
BkashPayment(
// amount of your bkash payment
amount: '20',
// intent would be (sale / authorization)
intent: 'sale',
// accessToken: '', // if the user have own access token for verify payment
// 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',
// bkash url for execute payment, , when you implement on you project then it be change as your production create url
executeBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute',
// for script url, when you implement on production the set it live script js
scriptUrl: 'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js',
// the return value from the package
// status => 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose' // data => return value of response paymentStatus: (status, data) {
dev.log('return status => $status');
dev.log('return data => $data');
// when payment success
if (status == 'paymentSuccess') {
if (data['transactionStatus'] == 'Completed') {
Style.basicToast('Payment Success');
}
}
// when payment failed
else if (status == 'paymentFailed') {
if (data.isEmpty) {
Style.errorToast('Payment Failed');
} else if (data[0]['errorMessage'].toString() != 'null'){
Style.errorToast("Payment Failed ${data[0]['errorMessage']}");
} else {
Style.errorToast("Payment Failed");
}
}
// when payment on error
else if (status == 'paymentError') {
Style.errorToast(jsonDecode(data['responseText'])['error']);
}
// when payment close on demand closed the windows
else if (status == 'paymentClose') {
if (data == 'closedWindow') {
Style.errorToast('Failed to payment, closed screen');
} else if (data == 'scriptLoadedFailed') {
Style.errorToast('Payment screen loading failed');
}
}
// back to screen to pop()
Navigator.of(context).pop();
},
)
重要说明
- 请阅读示例代码中的注释
- intent – 应该是‘sale’或‘authorization’
- 付款状态将返回“paymentSuccess”、“paymentFailed”、“paymentError”、“paymentClose”,请查找付款状态的关键字,然后您将获得特定状态下的响应数据。
