如何解决UPI 支付在使用深层链接的 android 中失败
我已经使用 android 深度链接 在我的电子商务应用程序中随时随地进行 UPI 付款,下面是我用来启动新 Intent 的方法,它会要求用户选择任何一个安装在他/她的设备上的 UPI 支付应用程序以继续支付。付款失败,resultCode 为 -1。 请注意,此代码在 5-6 个月前运行良好,但突然停止工作。
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();
}
}
这是 onActivityResult 方法:
@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;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。