India’s unique UPI implementation of Google Pay


I. Official website address (Science Online)

Official document docking https://developers.google.com/pay/india/api/android/googlepay-business official Dome – making the address https://github.com/googletez/inapp-payment-samples

Two, the main code implementation (integration is very simple)

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);
Copy the code

Corresponding interpretation

Uri uri = new Uri.Builder() .scheme("upi") .authority("pay") .appendQueryParameter("pa", AppendQueryParameter ("pn", "your business name ") // The name of the payment display.appendqueryParameter (" MC ", "Your business code ").appendQueryParameter("tr"," your transaction reference number ")// understood as order ID.appendqueryParameter ("tn", AppendQueryParameter ("am", "your order -amoun") // Transaction amount. AppendQueryParameter ("cu", "INR") // fix.appendqueryParameter (" URL ", "your transaction url").build();Copy the code

Return the data

Payment error cause Google Pay will display payment error data txnId=&responseCode=ZD&Status=FAILURE&txnRef=123456789 Payment success data txnId=ICI5749db96b6ed47f1bc469c80981f9387&responseCode=0&Status=SUCCESS&txnRef=123456789 private void googlePayResult(Intent data){ if (data ! = null) { String response = data.getStringExtra("response"); Map<String,String> payMap = new HashMap<>(); if (! TextUtils.isEmpty(response)){ String[] responses = response.split("&"); for (int i=0; i<responses.length; i++){ String[] re = responses[i].split("="); if (re.length == 2){ payMap.put(re[0],re[1]); } } } String status = payMap.get("Status"); if (! TextUtils.isEmpty(status) && TextUtils.equals("success", status.toLowerCase())) { String txnId = payMap.get("txnId"); String orderId = payMap.get("txnRef"); Logger.logE("google_pay==== success"); / / TODO to background check whether amount ToastUtils showSystemToast (R.s tring. Wallet_pay_succ_tips); } else { showFinalFailDialog(""); } } else { showFinalFailDialog(""); }}Copy the code

3. Pit encountered (most difficult card to solve)

1. Configure Google Pay for Business

Prerequisites Commercial channels must accept UPI and be certified as merchants by NPCI/Bank. Make sure you have the details you need to accept payments at your bank using your UPI ID. Make sure you have all the necessary apis provided by your bank to check payment status. Note that each transaction should use a unique transaction ID.Copy the code

Be sure to have permission to configure their own UPI ID needs to review several days ~~~~~The configuration address

2. Tests (Lessons learned in blood)

1. Be sure to download the Indian version of Google Pay~~~ India Google Pay~~


2. Use the correct Google Pay account

To use a Google Pay account in India, you must configure the following: 1. Phone with Google Pay installed 2. Google Pay account 3. India mobile phone Number 4. Bank card that can open UPI bound to this mobile phone number 5. Insert your mobile card, log in to Google Pay, bind your bank card, and activate UPICopy the code

Once the account is ready, the test will be very smooth. Wish you success


I hope I can help you with the same problem 😁😁😁😁 If you have any suggestions and comments, please contact me in time.