VipiN Negi
VipiN Negi

Reputation: 3108

How to create Google Pay link to send or request money?

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

Upvotes: 6

Views: 38726

Answers (4)

Anees Hameed
Anees Hameed

Reputation: 6544

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

Upvotes: 2

Rajesh
Rajesh

Reputation: 3998

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

Upvotes: 6

VipiN Negi
VipiN Negi

Reputation: 3108

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.

Upvotes: 1

Soc
Soc

Reputation: 7780

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.

Upvotes: 5

Related Questions