'Google Pay UPI Integration not working in android
GPay integration was working totally fine before 2 days but now its showing same error in gpay app. Intent calling for gpay payment is not working. I have completed transaction successfully days before. but now its not working. Any help would be appreciated! Thanks in Advance.
My Code
uriapp = new Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", getString(R.string.vpa))
.appendQueryParameter("pn", getString(R.string.payee))
.appendQueryParameter("tr", orderId)
.appendQueryParameter("tn", description)
.appendQueryParameter("am", String.valueOf(amount))
.appendQueryParameter("cu", "INR")
.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uriapp);
intent.setPackage(model.getPackageName());
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, GOOGLE_REQUEST_CODE);
} else {
Toast.makeText(this, "This payment mode is not available on your device.", Toast.LENGTH_LONG).show();
}
I am using correct vpa business Id.
GPay Error:
this transaction may be risky. for your safety it cant be completed at this time
Solution 1:[1]
Curruntly this snippet is working in test app. Let me know if its not working in yours.
private static final int TEZ_REQUEST_CODE = 123;
private static final String GOOGLE_TEZ_PACKAGE_NAME =
"com.google.android.apps.nbu.paisa.user";
Uri uri =
new Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "test@okbizaxis")
.appendQueryParameter("pn", "Test")
.appendQueryParameter("mc", "1234")
.appendQueryParameter("tr", "1234")
.appendQueryParameter("tn", "test")
.appendQueryParameter("am", "10")
.appendQueryParameter("cu", "INR")
.appendQueryParameter("url", "")
.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_TEZ_PACKAGE_NAME);
startActivityForResult(intent, TEZ_REQUEST_CODE);
Solution 2:[2]
go through this documentation and perform intent accordingly.
It clearly shows that the integration requires a signature attribute which is clearly absent in the google pay upi integration documentation.
A small Clarity why code given on the gpay upi documentation not working?
- firstly, some of the parameters are missing which are important for the Upi intent deep linking, like mode, sign, orgID.
- for mode, refer to the link.
- sign is the signature value, which is similar to checksum value, which we create while using an sdk like paytm etc.
- basically it is the rest of the string encrypted by SHA256 and RSA512. this encryption is done using the private key and public key provided by the PSP providers and the merchants bank.
- after encryption, we perform a base64 encoding.
- this is the sign value. refer documentation for more clarity.
- orgid for the intent based transaction is 000000.
as those values are not present I think, the transaction is failing.
ok a trick way to perform intent based transaction (WORKS ONLY ON TRANSACTION THROUGH GOOGLE PAY APP)
in case of phone pe and paytm qr, get the rawstring from these qr using google lens.
add the parameters into string such as 'am' and 'tn' which represents the amount and transaction note respectively. apply Uri.parse(STRING VALUE) and send this as the intent to google pay.
you will see that the transaction is happening and we get result back to our app, SUCCESS or FAILURE.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kiran |
| Solution 2 |
