如果您正在使用颤振,这就是它可以完成的方式。
您需要在 pubspec 中添加一个名为 url_launcher 的包来完成这项工作。
查看此处的文档以查看 URL 中使用的参数的详细信息。
https://developers.google.com/pay/india/api/web/create-payment-method#create-payment-method
所有参数都是必需的。
pa: UPI id of the requesting person
pn: Name of the requesting person
am: Amount
cu: Currency. I read somewhere that only INR is supported now.
这种方法的一个主要问题是,它不会返回任何回调来检查支付是成功还是失败。
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Google Pay',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
initiateTransaction() async {
String upi_url =
'upi://pay?pa=aneesshameed@oksbi&pn=Anees Hameed&am=1.27&cu=INR;
await launch(upi_url).then((value) {
print(value);
}).catchError((err) => print(err));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Google Pay'),
),
body: Center(
child: Column(
children: [
RaisedButton(
child: Text(
'Pay',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
initiateTransaction();
},
),
],
),
),
);
}
}
如果您使用的是企业 UPI id,则 upi_url 中需要更多参数。例如:我有一个 rpy.payto000006621197825@icici UPI 用于接受商业付款。然后需要添加几个参数
pa: UPI id of the requesting business account
pn: Name of the requesting business account
am: Amount
cu: Currency. I read somewhere that only INR is supported now.
mc: Merchant category code.
您可以从您创建 UPI 业务 ID 的位置获取此商家类别代码。例如:我通过 razorpay 创建了 upi id 'rpy.payto000006621197825@icici',我从他们的窗口某处收到了这个代码。但是这个代码对于所有的支付服务都是相似的,比如 paypal、stripe、Citibank 等:下面是几个链接:
https://docs.checkout.com/resources/codes/merchant-category-codes
https://www.citibank.com/tts/solutions/commercial-cards/assets/docs/govt/Merchant-Category-Codes.pdf
tr:交易ID。
我找不到任何用处,此交易 ID 既未显示在 Google 支付交易详细信息中,也未显示在 Razorpay 交易窗口中。但是当不使用时,谷歌支付不起作用。
URL:显示交易详情的 URL。当您前往 Google Pay 并打开交易详情时,您会在底部的同一页面上看到一个“更多详情”按钮。 URL 参数的值定义了更多详细信息按钮的目标。您可以使用此 URL,以便客户可以找到有关已进行交易的更多信息。
UPI 字符串示例:
String upi_url =
'upi://pay?pa=rpy.payto000006621197825@icici&pn=Elifent&mc=4900&tr=1234ABCD&url=https://elifent.tech/tr/1234&am=1.27&cu=INR';
如果您进行测试付款,则付款将记入我的 Google Pay 帐户。前进!!! :D