Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用安卓深度链接的UPI支付网关_Android_Xamarin.android_Upi - Fatal编程技术网

Android 使用安卓深度链接的UPI支付网关

Android 使用安卓深度链接的UPI支付网关,android,xamarin.android,upi,Android,Xamarin.android,Upi,是否有使用Android Deep Link集成UPI支付网关的工作示例。我仔细研究了NPCI规范,并实现了它,但没有成功。事务未完成 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); Console.WriteLin

是否有使用Android Deep Link集成UPI支付网关的工作示例。我仔细研究了NPCI规范,并实现了它,但没有成功。事务未完成

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        Console.WriteLine("Request Code:" + requestCode);
    }

    private void RunUPI(string MobileNo)
    {
        var UPIUri = Android.Net.Uri.Parse("upi://pay?pa=xxx@xxxx&pn=xxxxxx&mc=null&tid=null&tr=test101&tn=This%20is%20test%20payment&am=10&mam=null&cu=INR&url=null");
        Intent intent = new Intent();
        intent.SetAction(Intent.ActionView);
        intent.SetData(UPIUri);
        var activities = PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
        var isIntentSafe = activities.Count > 0;
        if (true == isIntentSafe)
        {
            var chooser = Intent.CreateChooser(intent, "Pay With");
            chooser.SetFlags(ActivityFlags.NewTask);
            // Verify the intent will resolve to at least one activity
            if (chooser.ResolveActivity(PackageManager) != null)
            {
                txnUPIRequestCode = 0;
                StartActivityForResult(chooser, txnUPIRequestCode);
            }
        }
    }

您案例中的问题与
UPI
无关,而是Android如何管理
活动
结果和
意图

如果调用方(在本例中为您的
活动
)正在请求正在启动的活动(在本例中为UPI PSP)的结果,则无法使用

因此,一个简单的解决方案是简单地创建
Uri
,并在不带标志的情况下启动
Intent
。在java中,它看起来像:

private void launchUPI(){
  // look below for a reference to these parameters
  Uri uri = Uri.parse("upi://pay").buildUpon()
    .appendQueryParameter("pa", "xxx@xxxxx")
    .appendQueryParameter("pn", "XYZXYZ")
    .appendQueryParameter("tn", "Pay for in-app purchase")
    .appendQueryParameter("am", "20")
    .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())) {
    Log.d(TAG, "UPI Payment resolved to activity");
    startActivityForResult(chooser, REQ_UPIPAYMENT);
  } else {
    Log.d(TAG, "No activity found to handle UPI Payment");
  }
}

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if(REQ_UPIPAYMENT == requestCode){
    if(RESULT_OK == resultCode){
      Log.d(TAG, "UPI Payment successfull");
    } else {
      Log.d(TAG, "UPI Payment failed");
    }
  }
}
就请求参数而言,下面是我从

  • pa
    :收款人(收款人)的UPI虚拟地址
  • pn
    :收款人的姓名。可以是商户或商店的名称
  • tn
    :交易记录。交易的简单描述,如应用内项目付款、账单付款等
  • am
    :十进制格式的交易金额
  • cu
    :交易中使用的货币。目前只支持INR
使用上述参数,您可以创建PSP应用程序(如PayTM或银行应用程序)的付款请求静态模式

要在动态模式下创建付款请求,您还需要添加以下内容:

  • tr
    :交易参考。您对系统中交易的内部引用

更新1 正如评论中提到的OP,要从PSP应用程序获取响应,如事务id等,我们可以在
RESULT\u OK==resultCode
时使用
ontactivityresult()中传递的
Intent

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if(REQ_UPIPAYMENT == requestCode){
    if(RESULT_OK == resultCode){
      Log.d(TAG, "UPI Payment successfull");
      String transId = data.getStringExtra("response");
    } else {
      Log.d(TAG, "UPI Payment failed");
    }
  }
}

您可以查看设备上所有UPI应用程序的列表,并使用任何应用程序启动交易

这是您可以用来获取所有UPI应用程序的函数。

private fun upiApps(context: Context): MutableList<PaymentUpiOption> {

    val upiOptions = mutableListOf<PaymentUpiOption>()

    // Set Parameters for UPI
    val payUri = Uri.Builder()

    payUri.scheme("upi").authority("pay")
    payUri.appendQueryParameter("pa", "")
    payUri.appendQueryParameter("pn", "")
    payUri.appendQueryParameter("tid", "")
    payUri.appendQueryParameter("mc", "")
    payUri.appendQueryParameter("tr", "")
    payUri.appendQueryParameter("tn", "")
    payUri.appendQueryParameter("am", "")
    payUri.appendQueryParameter("cu", "")

    val paymentIntent = Intent(Intent.ACTION_VIEW)
    paymentIntent.data = payUri.build()

    val appList = context.packageManager.queryIntentActivities(paymentIntent, 0)
    for (i in appList) {
        // this is a custom model class
        val paymentUpiOption = PaymentUpiOption(
            i.loadLabel(context.packageManager).toString(),
            i.activityInfo.packageName,
            i.loadIcon(context.packageManager),
            "upiTxn",
            "UPI"
        )
        upiOptions.add(paymentUpiOption)
    }
    return upiOptions
}
private-fun-upiApps(context:context):可变列表{
val upiOptions=mutableListOf()
//设置UPI的参数
val payUri=Uri.Builder()
payUri.方案(“upi”).管理局(“支付”)
payUri.appendQueryParameter(“pa”,即“”)
payUri.appendQueryParameter(“pn”和“”)
payUri.appendQueryParameter(“tid”,“”)
payUri.appendQueryParameter(“mc”和“”)
payUri.appendQueryParameter(“tr”,即“”)
payUri.appendQueryParameter(“tn”,“”)
payUri.appendQueryParameter(“am”,“”)
payUri.appendQueryParameter(“cu”,“”)
val paymentIntent=Intent(Intent.ACTION\u视图)
paymentIntent.data=payUri.build()
val appList=context.packageManager.queryintent活动(paymentIntent,0)
for(应用程序列表中的i){
//这是一个自定义模型类
val paymentUpiOption=paymentUpiOption(
i、 loadLabel(context.packageManager).toString(),
i、 activityInfo.packageName,
i、 loadIcon(context.packageManager),
“upiTxn”,
“万国邮联”
)
upiOptions.add(paymentUpiOption)
}
回报率上升
}

很有效。非常感谢。如何读取事务响应参数,如txnId、responseCode、txnRef(来自NPCI规范)?获取字符串var pspresense=intent.getStringExtra(“响应”);嗨,伙计们。。。我可以知道在哪里申报付款吗?