我正在创建一个示例项目以通过用户获得付款,并且我使用口袋成功转移了它,但我收到的响应是未定义的。
txnId=未定义&responseCode=未定义&状态=未定义&txnRef=未定义
我准备的网址是:upi://pay?pn=john&tr=598&am=1&cu=INR&pa=9469731359@upi
使用此示例代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Uri.Builder builder = new Uri.Builder();
builder.appendQueryParameter("pa" , "9469731359@upi")
.appendQueryParameter("pn", "john") //payee name.
.appendQueryParameter("tr", "5983") //transaction reference id.
// .appendQueryParameter("mc", "0000") //payee merchant code.
// .appendQueryParameter("tn", "transferring1rs") //transaction description.
.appendQueryParameter("am", "1") //amountPayable (hardcoded to make payment of Rupee 1)
.appendQueryParameter("cu", "INR"); //currency code.
String upiQueryString = "upi://pay" + builder.build().toString(); // virtual payment address of the payee.
Intent intent = new Intent();
intent.setData(Uri.parse(upiQueryString));
Intent chooser = Intent.createChooser(intent, "Choose respective UPI"); //Shows a list of UPI enabled PSP apps if more than one is available.
startActivityForResult(chooser, 1, null);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
try {
if (intent != null) {
String pspResonse = intent.getStringExtra("response");
String[] pspResonseArray = pspResonse.split("&");
Map<String, String> map = new HashMap<>();
for (String param : pspResonseArray) {
String key = param.split("=")[0];
String value = param.split("=")[1];
map.put(key, value);
}
TextView txnStatus = (TextView)findViewById(R.id.editText10);
TextView txnId = (TextView)findViewById(R.id.editText11);
TextView txnRef = (TextView)findViewById(R.id.editText12);
TextView amount = (TextView)findViewById(R.id.editText13);
// hide layout 1
RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout1);
RelativeLayout layout2 = (RelativeLayout) findViewById(R.id.layout2);
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
txnStatus.setText(map.get("Status"));
txnId.setText(map.get("txnId"));
txnRef.setText(map.get("txnRef"));
amount.setText("1");
} else {
Toast.makeText(this, "Null intent received", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
请帮忙。提前致谢 :)