如何创建Google Pay链接以发送或请求付款?

时间:2020-05-21 13:14:39

标签: flutter dart google-api deep-linking google-pay

在网上浏览了一段时间(谷歌搜索)后,我什么都找不到可以创建Google Pay请求链接的东西。

在我的Flutter应用中,我想创建一个链接以使用我的电话号码接受付款,点击该链接将启动Google Pay应用,并为我的电话号码设置付款。但是,该金额将由用户从Google Pay应用中输入。

类似这样的东西:

String googlePayUrl = "https://pay.google.com?phone=XXXXXXXXXX";

对于印度的Google付费版本

4 个答案:

答案 0 :(得分:2)

免责声明:我不居住在印度,也无法访问UPI进行自我验证。

请考虑使用UPI linking specification (upi://)创建用于UPI兼容应用程序的UPI链接。您也可以参考Google Pay文档,了解如何integrate with in-app payments

String GOOGLE_PAY_PACKAGE_NAME = "com.google.android.apps.nbu.paisa.user";
int GOOGLE_PAY_REQUEST_CODE = 123;

Uri uri =
    new Uri.Builder()
        .scheme("upi")
        .authority("pay")
        .appendQueryParameter("pa", "your-merchant-vpa@xxx")
        .appendQueryParameter("pn", "your-merchant-name")
        .appendQueryParameter("mc", "your-merchant-code")
        .appendQueryParameter("tr", "your-transaction-ref-id")
        .appendQueryParameter("tn", "your-transaction-note")
        .appendQueryParameter("am", "your-order-amount")
        .appendQueryParameter("cu", "INR")
        .appendQueryParameter("url", "your-transaction-url")
        .build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_PAY_PACKAGE_NAME);
activity.startActivityForResult(intent, GOOGLE_PAY_REQUEST_CODE);

我相信您要使用的参数名称为pa

答案 1 :(得分:0)

谢谢@Soc。这篇帖子只是上面@Soc帖子的解释答案。 pdf document是一个巨大的帮助。我的要求是在 Flutter 中,我为此创建了一个链接并使用url_launcher打开该链接。打开链接将显示手机中与UPI兼容的应用程序的列表。

链接示例:

String upi_url = 'upi://pay?pa=address@okhdfcbank&pn=Payee Name&tn=Payment Message&cu=INR';

// pa : Payee address, usually found in GooglePay app profile page
// pn : Payee name
// tn : Txn note, basically your message for the payee
// cu : Currency

注意:为了成功付款,必填所有上述字段。

答案 2 :(得分:0)

以上答案可以解决问题,下面是一个例子

  void sendPayment() async {
   String upiurl = 'upi://pay?pa=user@hdfgbank&pn=SenderName&tn=TestingGpay&am=100&cu=INR';    
   await launchurl(upiurl);
  }

pa = user @ hdfgbank //每个人的gpay用户个人资料页面上都提供该功能,您需要在此处提供 收件人的ID而不是发件人的ID:

am = 100 //您要发送的金额

cu = INR //货币印度卢比

答案 3 :(得分:0)

如果您正在使用颤振,则可以这样做。 您需要在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.

此方法的一个主要问题是,它不会回叫检查付款是否成功。

如果您进行测试付款,则付款将记入我的Google付款帐户。前进!!! :D

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. You can get this code from where you have created UPI business id. For eg: I created the upi id 'rpy.payto000006621197825@icici' through razorpay and I received this code somewhere from their window. But this code is similar for all the payment services like, paypal, stripe, Citibank etc: Below are few links:
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: Transaction id.
I couldn't find any use for this, this transaction id is not showing either in Google pay transaction details or in the Razorpay transaction window. But the Google pay is not working when this is not used.
URL: The URL which shows the details of the transaction. When you go to Google pay and open the transaction details, then on the same page at the bottom you will see a button 'More details'. The value of URL parameter defines the target for the more details button. You can use this URL so that the customer can find more information about the transactions been made.

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';
相关问题