Flutter支付集成插件lazerpay_flutter的使用
Flutter支付集成插件lazerpay_flutter的使用
该插件使得在Flutter项目中使用Lazerpay变得简单。
📸 屏幕截图
🚀 如何使用插件
添加Material支持
在android/build.gradle
文件中添加以下依赖:
dependencies {
// ...
implementation 'com.google.android.material:material:<version>'
// ...
}
使用LazerPay插件
启动LazerSendView作为底部弹窗
import 'package:lazerpay_flutter/lazerpay_flutter.dart';
void launch() async {
await LazerPayView(
data: LazerPayData(
publicKey: "pk_live_...", // 替换为你的公钥
reference: 'YOUR_REFERENCE', // 替换为你生成的引用
name: "Chizo Ozioma",
email: "test@gmail.com",
amount: 1000,
currency: LazerPayCurency.USD,
acceptPartialPayment: true, // 默认为false
metadata: {
'product_id': '324324324324',
}, // 元数据是可选参数
),
showLogs: true,
onInitialize: (data) {
print('initialized');
},
onClosed: () {
print('closed');
Navigator.pop(context);
},
onSuccess: (data) {
print(data);
Navigator.pop(context);
},
onError: print,
).show(context);
}
使用LazerPayView小部件
import 'package:lazerpay_flutter/lazerpay_flutter.dart';
// ...
LazerPayView(
data: LazerPayData(
publicKey: "pk_live_...", // 替换为你的公钥
reference: 'YOUR_REFERENCE', // 替换为你生成的引用
name: "Package Free",
email: "test@gmail.com",
amount: 1000,
currency: LazerPayCurency.NGN,
acceptPartialPayment: true, // 默认为false
),
onClosed: () {
Navigator.pop(context);
print('Widget closed');
},
onSuccess: (data) {
print(data);
Navigator.pop(context);
},
onError: print,
error: Text('Error'),
)
成功事件返回的交易JSON示例:
{
"event": "successful",
"data": {
"id": "12896b32-0d7d-4744-bc15-5960af40d519",
"reference": "aa6KlHy88D",
"senderAddress": "0x0B4d358D349809037003F96A3593ff9015E89efA",
"recipientAddress": "0x785F44E779cfEeDeBf7aA7CFde19DaA3312fd19e",
"actualAmount": 10,
"amountPaid": 10,
"fiatAmount": 10,
"feeInCrypto": 0.17,
"coin": "BUSD",
"currency": "USD",
"hash": "0x3332d7b046d53e90dc0337c715252f210386c2a471c5025c953a0b1d9bc90593",
"blockNumber": 14160827,
"type": "received",
"status": "confirmed",
"network": "mainnet",
"acceptPartialPayment": true,
"blockchain": "Binance Smart Chain",
"customer": {
"id": "b847dbbd-e5a4-4afc-ba26-b292707dc391",
"customerName": "Njoku Emmanuel",
"customerEmail": "kalunjoku123@gmail.com",
"customerPhone": null,
"network": "mainnet"
}
}
}
更多关于Flutter支付集成插件lazerpay_flutter的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复