Search code examples
androidpayment-gatewaypaymentupi

Invoke PSP app with UPI url


I am trying to create a merchant app which will generate a url based on NPCI's guidelines. This url will be shared as intent and the PSP app (Any registered bank app) should be able to listen to that url and get invoked.

I have formed a url like this:-

upi://pay?pa=icici/name&pn=USER_NAME&tid=422d97c1-f0fc-4bea-b24a-511ffa85e86f&am=442.87&tn=Test%transaction

Now I am sending the intent like this :-

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, UPI);
sendIntent.setType("text/plain");
startActivity(sendIntent);

Icici bank app is not being shown in the receiver apps. Am I creating the url correctly?

UPI being released quite recently, I am unable to get good resource over the internet.

Note - In the url, the tid(transaction id) is a random uuid being generated in my app.


Solution

  • Found the correct way to do that. You need to frame the URL in the proper way as mentioned in the question. After that, this URL has to be converted to URI and sent as data to the intent.

    Intent intent = new Intent();
    intent.setData(Uri.parse(UPI));
    Intent chooser = Intent.createChooser(intent, "Pay with...");
    startActivityForResult(chooser, 1, null);
    

    After that, in your onActivityResult, check for the requestCode and id received intend data is null. If not, then the data will contain a stringExtra as response. This response will contain the status, transaction reference, transactionId and the response code.

    Also, spaces in the url should be replaced with a '+' and not with '%'.