使用 Android Deep Link 的 UPI 支付网关 [英] UPI Payment Gateway using Android Deep Link

查看:24
本文介绍了使用 Android Deep Link 的 UPI 支付网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何使用 Android Deep Link 集成 UPI 支付网关的工作示例.我通过了 NPCI 规范并没有成功实现它.交易未完成.

Is there any working sample to integrate UPI payment gateway using Android Deep Link. I went through NPCI specifications and implemented it with no success. Transaction is not getting completed.

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如何管理Activity结果和>意图s.

The problem in your case is not related to UPI but how Android manages Activity results and Intents.

不能使用Intent.FLAG_ACTIVITY_NEW_TASK 如果调用者(在本例中为您的 Activity)正在请求正在启动的活动的结果(UPI PSP 在此案件).[来源]

You cannot use the Intent.FLAG_ACTIVITY_NEW_TASK if the caller (in this case your Activity) is requesting a result from the activity being launched (the UPI PSP in this case). [source]

所以一个简单的解决方案是简单地创建 Uri 并启动没有标志的 Intent.在java中看起来像:

So a simple solution would be to simply create the Uri and launch the Intent without the flag. In java that would look like:

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");
    }
  }
}

请求参数而言,以下是我从UPI DeepLinking 规范页面.

  • pa:收款人(收款人)的 UPI 虚拟地址
  • pn:收款人的名称.可以是商家或商店的名称.
  • tn:交易记录.交易的简单描述,例如应用内商品的支付、账单支付等.
  • am:十进制格式的交易金额.
  • cu:交易中使用的货币.目前仅支持 INR.
  • pa: UPI Virtual address of the payee (the one who receives the payment)
  • pn: Name of the payee. Can be name of merchant or store.
  • tn: Transaction note. A simple description of the transaction, like, payment for in-app items, bill payments, etc.
  • am: Monetary amount of transaction in decimal format.
  • cu: Currency used in the transaction. Currently only INR is supported.

使用上述参数,您可以静态模式PSP应用(PayTM 或银行应用等应用)创建付款请求.

Using the above parameters, you can create a payment request static mode to the PSP app (apps like PayTM or bank applications).

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

To create a payment request in dynamic mode, you also need to add the following:

  • tr:交易参考.您对系统中交易的内部参考.

正如评论中提到的 OP,要从 PSP 应用中获取响应,例如交易 ID 等,我们可以使用传入的 IntentonActivityResult()RESULT_OK == resultCode 时.

As the OP mentioned in the comments, to get back the response from the PSP app, like, transaction id, etc. we can use the Intent passed in the onActivityResult() when RESULT_OK == resultCode.

@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");
    }
  }
}

这篇关于使用 Android Deep Link 的 UPI 支付网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆