UPI App Deep linking using Intent - inconsistent and buggy behavior
Asked Answered
E

4

18

I have deeplinked UPI apps from my android native app using intent. I have tested this with various UPI apps like BHIM, PhonePe, AXIS, UnionBank, Pockets etc.

I created push payment URI. I am able to launch various UPI apps. However behaviour is quite inconsistent.

"upi://pay?pa=xxxxx@upi&pn=payee&am=5.00&tn=Test_Transaction"

  1. Most apps are responding when intent is onvoked. They get launched.
  2. few apps displayed the payment page correctly with amount. Rest apps did not display the page at all. PhonePe, Axis displayed. BHIM did not display payment page
  3. Payment completed successfully b y PhonePay and Axis ONLY
  4. After UPI payment was completed successfully, the UPI app is closed and control comes back to my app. However the response data is always NULL. NONE of the app is providing response data when payment is successful
  5. If payment fails or I cancel the payment in UPI app or I do not enter right PIN and close UPI app, most of the apps do not return response data.
  6. Only AXISPay returned response data : Intent { (has extras) }

Anyone - any comments? Why such inconsistent bahaviour?

Surprising is deeplinking not working with BHIM app.

I can share android code if someone want want to try.

Erichericha answered 8/7, 2017 at 11:52 Comment(1)
Just like Pay option, is there any deep-link for requesting money through UPI?Whiten
P
18

It really works for the BHIM application also. Use this Code it works like a charm for every PSP enabled applications.

Note: Instead of using the "%" better to use "+" to replace the white space from the URL. That works better.

private String getUPIString(String payeeAddress, String payeeName, String payeeMCC, String trxnID, String trxnRefId,
                            String trxnNote, String payeeAmount, String currencyCode, String refUrl) {
    String UPI = "upi://pay?pa=" + payeeAddress + "&pn=" + payeeName
            + "&mc=" + payeeMCC + "&tid=" + trxnID + "&tr=" + trxnRefId
            + "&tn=" + trxnNote + "&am=" + payeeAmount + "&cu=" + currencyCode
            + "&refUrl=" + refUrl;
    return UPI.replace(" ", "+");
}

Then pass the parameters in the method and pass the string to the Intent in this way:

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(UPI));
            Intent chooser = Intent.createChooser(intent, "Pay with...");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                startActivityForResult(chooser, 1, null);
            }
Pareu answered 29/9, 2017 at 6:28 Comment(6)
it works. but could u please tell me the exact use of refUrl=" + refUrl in above URIHicks
Hi, does anybody have any idea about param 'tn' character limits? and allowed special characters for an UPI intent?Okie
Min Length: 1 Max Length : 50Leyla
"your money has not been debited" how to fix this issue?Erythromycin
anyone face this issue, am implemented gpay in react native application facing this issueErythromycin
https://mcmap.net/q/747276/-payment-through-google-pay-sometimes-succeeds-sometimes-fails-using-upi-intent-in-android-studio-business-upi-id Please help if possibleNorther
A
0

For displaying payment page correctly, you have to setAction(Intent.ACTION_VIEW) on your intent.

I am getting response only from BHIM app by using getStringsExtra("response") on Intent data.

Adoration answered 10/7, 2017 at 5:2 Comment(3)
You are WelcomeAdoration
@RishabhMishra is the response also in this format "upi://pay?pa=xxxxx@upi&pn=payee&am=5.00&tn=Test_Transaction"Plenipotent
@RishabhMishra any idea how I can solve this? https://mcmap.net/q/747276/-payment-through-google-pay-sometimes-succeeds-sometimes-fails-using-upi-intent-in-android-studio-business-upi-idNorther
S
0
public void UPI()
    {
         Long tsLong = System.currentTimeMillis()/1000;
         String transaction_ref_id = tsLong.toString()+"UPI"; // This is your Transaction Ref id - Here we used as a timestamp -

         String sOrderId= tsLong +"UPI";// This is your order id - Here we used as a timestamp -

         Log.e("TR Reference ID==>",""+transaction_ref_id);
        Uri myAction = Uri.parse("upi://pay?pa="+sVPA+"&pn="+"Merchant%20Finance"+"&mc="+"&tid="+transaction_ref_id +"&tr="+transaction_ref_id +"&tn=Pay%20to%20Merchant%20Finance%20Assets&am="+"1.00"+"&mam=null&cu=INR&url=https://mystar.com/orderid="+sOrderId);


         PackageManager packageManager = getPackageManager();
         //Intent intent = packageManager.getLaunchIntentForPackage("com.mgs.induspsp"); // Comment line - if you want to open specific application then you can pass that package name For example if you want to open Bhim app then pass Bhim app package name - 
         Intent intent = new Intent();

         if (intent != null) {
             intent.setAction(Intent.ACTION_VIEW);
             intent.setData(myAction);
            // startActivity(intent);
             Intent chooser = Intent.createChooser(intent, "Pay with...");
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                 startActivityForResult(chooser, 1, null);
             }

         }
    }


// For onActivityResult -

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        try
        {
            Log.e("UPI RESULT REQUEST CODE-->",""+requestCode);
            Log.e("UPI RESULT RESULT CODE-->",""+resultCode);
            Log.e("UPI RESULT DATA-->",""+data);



            if(resultCode == -1)
            {

                // 200 Success

            }
            else
            {
                // 400 Failed
            }


            YourActivity.this.finish(); 


        }
        catch(Exception e)
        {
            Log.e("Error in UPI onActivityResult->",""+e.getMessage());
        }
    }
Sorkin answered 21/5, 2018 at 8:2 Comment(1)
Welcome to Stack Overflow! Please don't just throw your source code here. Be nice and try to give a nice description to your answer, so that others will like it and upvote it. See: How do I write a good answer?Dustydusza
M
-2

Here is how I solved it for Redmi Note 5 Pro and other MI phones:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(UPI));
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
} else {
    Toast.makeText(this, "No application available to handle this request!", Toast.LENGTH_SHORT).show();
}
Mart answered 11/10, 2019 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.