📅  最后修改于: 2023-12-03 14:59:17.213000             🧑  作者: Mango
Unified Payments Interface(UPI)是印度国家支付公司推出的实时支付系统,旨在实现快速、安全和轻松的付款,支持从一个银行帐户转移资金到另一个银行帐户。
在Android应用程序中,可以使用UPI付款进行在线交易。以下是一些步骤和代码片段,可帮助程序员实现UPI付款集成。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
implementation 'com.google.android.gms:play-services-wallet:16.0.1'
implementation 'com.phonepe.android:UPI:1.1'
String upi = "upi://pay";
String payeeAddress = "payeeaddress@upi";
String payeeName = "payeename";
String amount = "amount";
String transactionRefId = "txn-ref-id";
String currency = "INR";
String note = "note";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(upi));
intent.setPackage("com.phonepe.app");
intent.putExtra(Intent.EXTRA_SUBJECT, payeeName);
intent.putExtra("pa", payeeAddress);
intent.putExtra("pn", payeeName);
intent.putExtra("am", amount);
intent.putExtra("tr", transactionRefId);
intent.putExtra("cu", currency);
intent.putExtra("tn", note);
startActivityForResult(intent, UPI_PAYMENT);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == UPI_PAYMENT) {
if ((RESULT_OK == resultCode) || (resultCode == 11)) {
if (data != null) {
String trxt = data.getStringExtra("response");
Log.d("UPI", "onActivityResult: "+trxt);
ArrayList<String> dataList = new ArrayList<>();
dataList.add(trxt);
upiPaymentDataOperation(dataList);
} else {
Log.d("UPI", "onActivityResult: "+ "Return data is null");
ArrayList<String> dataList = new ArrayList<>();
dataList.add("nothing");
upiPaymentDataOperation(dataList);
}
} else {
Log.d("UPI", "onActivityResult: "+ "Return data is null");
ArrayList<String> dataList = new ArrayList<>();
dataList.add("nothing");
upiPaymentDataOperation(dataList);
}
}
}
通过上述步骤, 您将能够在您的Android应用程序中集成UPI付款功能,这将帮助您的用户进行在线购买和转账。