How to create Google Pay link to send or request money?
Asked Answered
W

4

6

After looking (Googling) on the web for a while, I can find nothing that can create a link for Google Pay request.

In my Flutter app, I'd like to create a link to accept money using my Phone Number which when tapped will launch the Google Pay app with payment for my phone number already set. However the amount will be entered by the user from the Google pay app.

Something like this:

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

This if for Google pay version of India

Wideeyed answered 21/5, 2020 at 13:14 Comment(2)
FYI, there are currently two versions of Google Pay. Is this for Google Pay India or for other markets?Octuple
It is for Google Pay India. I've updated the OP. ThanksWideeyed
W
1

Thanks to @Soc for the answer. This post is just explained answer for the @Soc Post above. The pdf document was a huge help. My requirement was in Flutter for which I created a link and used url_launcher to open the link. Opening the link will show the list of UPI compatible apps in your phone.

link example:

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

Note : All the mentioned fields are required in order to make a successful payment.

Wideeyed answered 28/5, 2020 at 13:35 Comment(8)
hello, pdf link is removed, anyway I have a query , is it possible to get payment as a individual, without merchant id/code ?Debora
this is what it is.Wideeyed
please describe your experienceDebora
@MijanurRahaman For eg. if You want to transfer some amount to my account, You'll need my pa ie. Payee address, that I only can provide you. Set that in the above link and call the url using url-launcher. It will display you the relevant UPI enabled apps to select to make payment.Wideeyed
Thanks for checking things and the good answer. Small followup question, after the payment succeeds/fails what sort of codes are returned to indicate the status? Like how should the app decide whether to show to the user if their payment succeeded/failed?Abiotic
This is basically a regular URL, instead of a browser it opens installed UPI apps, hence our app doesn't expect anything in return.Wideeyed
Bro, by adding this in your app, will your app be considered as paid app?Vienna
when it comes to review, google may exempt it but if apple notices, they will surely ask to comply with their policies.Wideeyed
W
6

THe above answers are workign fine and the following is an example

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

pa=user@hdfgbank //it is available on everyone's gpay user profile page,here you need to give the receiver's id not sender's id:

am=100 // the amount you want to send

cu=INR // Currency Indian Rupees

Withershins answered 5/11, 2020 at 8:26 Comment(1)
Thanks for the answer. BTW can we generalize it?? what i mean is can we use account number directly or linked mobile number?Pichardo
O
5

Disclaimer: I don't live in India and don't have access to UPI to verify for myself.

Consider using the UPI linking specification (upi://) to create UPI links for use with UPI compatible applications. You can also refer to Google Pay documentation on how to 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);

I believe the parameter name you are after is pa.

Octuple answered 27/5, 2020 at 17:2 Comment(4)
The PDF was a huge help. Created link like this and voila. String upi_url = 'upi://pay?pa=address@okhdfcbank&pn=Payee Name&tn=Payment Message&cu=INR'; Note: All params are required!Wideeyed
Your answer is much appreciated especially since you're not in India. Small followup question, after the payment succeeds/fails what sort of codes are returned to indicate the status? Like how should the app decide whether to show to the user if their payment succeeded/failed?Abiotic
Based on Google Pay documentation, this is done by verifying the signature in the response.Octuple
tried with ``` Pay via UPI to <a href="upi://pay?pa=t6@hdfcbank&pn=Tushar Kapila&tn=payment agreed&cu=INR&a">t6@hdfcbank 3</a> ``` Any idea what a current URL looks like? when I choose paytm with above URL it says need to enter amount parm.Warmongering
H
2

If you are using flutter this is how it can be done. You need a package called url_launcher to be added in pubspec to this get work.

Check the documentation here to see the details of parameters used in the URL. https://developers.google.com/pay/india/api/web/create-payment-method#create-payment-method All parameters are required.

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.

One main problem with this method is that this doesn't give any call back to check whether the payment has been successful or failed.

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();
              },
            ),
          ],
        ),
      ),
    );
  }
}

If you are using a business UPI id then there need few more parameters in the upi_url. For eg: I have a rpy.payto000006621197825@icici UPI for accepting business payments. Then there needs to add a few more parameters

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 Merchant category 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 showing neither in Google pay transaction details nor 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 example:

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';

If you make a test payment then the payment will be credited to my google pay account. Go ahead!!! :D

Haydenhaydn answered 30/11, 2020 at 18:0 Comment(0)
W
1

Thanks to @Soc for the answer. This post is just explained answer for the @Soc Post above. The pdf document was a huge help. My requirement was in Flutter for which I created a link and used url_launcher to open the link. Opening the link will show the list of UPI compatible apps in your phone.

link example:

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

Note : All the mentioned fields are required in order to make a successful payment.

Wideeyed answered 28/5, 2020 at 13:35 Comment(8)
hello, pdf link is removed, anyway I have a query , is it possible to get payment as a individual, without merchant id/code ?Debora
this is what it is.Wideeyed
please describe your experienceDebora
@MijanurRahaman For eg. if You want to transfer some amount to my account, You'll need my pa ie. Payee address, that I only can provide you. Set that in the above link and call the url using url-launcher. It will display you the relevant UPI enabled apps to select to make payment.Wideeyed
Thanks for checking things and the good answer. Small followup question, after the payment succeeds/fails what sort of codes are returned to indicate the status? Like how should the app decide whether to show to the user if their payment succeeded/failed?Abiotic
This is basically a regular URL, instead of a browser it opens installed UPI apps, hence our app doesn't expect anything in return.Wideeyed
Bro, by adding this in your app, will your app be considered as paid app?Vienna
when it comes to review, google may exempt it but if apple notices, they will surely ask to comply with their policies.Wideeyed

© 2022 - 2024 — McMap. All rights reserved.