UPI Payment is failing in android using deep linking

  android, deep-linking, payment-gateway, upi

I have used android deep linking to take UPI payments on the go in my e-commerce app, below is the method which I have used to start new Intent which will ask user to select any one of UPI payment apps installed on his/her device to proceed with the payment. The payment is getting failed with resultCode as -1.
Please note this code was working perfectly 5-6 months ago but suddenly stopped working.

void payUsingUpi(String upiId, String note, String amount, String tr, String beneficiaryName) {
       Log.e("main", "--up--"+upiId+"--"+ note+"--"+amount+" tr"+tr);
       Uri uri = Uri.parse("upi://pay").buildUpon()
               .appendQueryParameter("pa", upiId)
               .appendQueryParameter("pn", beneficiaryName)
               .appendQueryParameter("tr", tr)
               .appendQueryParameter("tn", note)
               .appendQueryParameter("am", amount)
               .appendQueryParameter("cu", "INR")
               .build();
       Intent upiPayIntent = new Intent(Intent.ACTION_VIEW);
       upiPayIntent.setData(uri);
       Intent chooser = Intent.createChooser(upiPayIntent, "pay with");
       if(null != chooser.resolveActivity(getPackageManager())) {
            startActivityForResult(chooser, UPI_PAYMENT);
       } else {
           Toast.makeText(getApplicationContext(), "no_UPI_app_found",Toast.LENGTH_SHORT).show();
       }
   }

Here is the onActivityResult method:

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("main ", "resultCode "+resultCode );
        Log.e("main ", "data "+data );

        switch (requestCode) {
            case UPI_PAYMENT:
                if ((RESULT_OK == resultCode) || (resultCode == 11)) {
                    if (data != null && data.getStringExtra("response").toUpperCase().contains("STATUS=SUCCESS")) {
                        Log.e("UPI", "Payment Successful");
                        String response = data.getStringExtra("response");
                        String txnId = data.getStringExtra("response").substring(response.indexOf("txnId=")+6,response.indexOf("&responseCode"));
                        String txnRef = data.getStringExtra("response").substring(response.indexOf("txnRef=")+7);
                        Log.e("main ", " "+txnId +"txnRef "+txnRef);
                    } else {
                        Log.e("UPI", "Payment failed");
                    }
                } else {
                    //when user simply back without payment
                    Log.e("UPI", "onActivityResult: " + "Return data is null");
                }
                break;
        }
    }

Source: Android Questions

LEAVE A COMMENT