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

VipiN Negi picture VipiN Negi · May 21, 2020 · Viewed 9.3k times · Source

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

Answer

Soc picture Soc · May 27, 2020

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.