首页 > 解决方案 > 如何使用 UPI Deep Link 在 IONIC 4 中仅打开部分 UPI 应用程序

问题描述

我正在使用 webintent 插件来显示已安装的 UPI 并在 IONIC 4 中使用该 UPI 进行交易。但我只想打开 PhonePe、BHIM 和 Paytm 以及 Google Pay 应用程序。如何隐藏其他 UPI 应用程序,如 CRED、AmazonPay、Whatsapp 等。下面是我的代码,请建议我。

payWithUPI() {

const packages = {
    'paytm': 'net.one97.paytm',
    'google': 'com.google.android.apps.nbu.paisa.user',    
    'bhim': 'in.org.npci.upiapp',
    'phonepe': 'com.phonepe.app'
  };
    const tid = this.getRandomString();
    const orderId = this.getRandomString();
    const totalPrice = 1.00;
    const UPI_ID = '9960777572@okbizaxis';
    const UPI_NAME = 'Adhikar Patil';
    const UPI_TXN_NOTE = 'TEST TXN';    
    let uri = `upi://pay?pa=${UPI_ID}&pn=${UPI_NAME}&tid=${tid}&am=${totalPrice}&cu=INR&tn=${UPI_TXN_NOTE}&tr=${orderId}`;
   // uri = uri.replace(' ', '+');
    (window as any).plugins.intentShim.startActivity(
      {
        action: this.webIntent.ACTION_VIEW,
        url: uri,        
        requestCode: 1
      }, intent => {
         if (intent.extras.requestCode === 1 && intent.extras.resultCode === (window as any).plugins.intentShim.RESULT_OK && intent.extras.Status && (((intent.extras.Status as string).toLowerCase()) === ('success'))) {            
              alert("Payment Success");             
        }
        else (intent.extras.requestCode === 1 && intent.extras.resultCode === (window as any).plugins.intentShim.RESULT_OK && intent.extras.Status && (((intent.extras.Status as string).toLowerCase()) === ('failed'))) {
          alert("Payment Failed ") ;    
       }      
      }, err => {
        alert('error ' + err);
      });
  } 

getRandomString() {
    const len = 10;
    const arr = '1234567890asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPZXCVBNM';
    let ans = '';
    for (let i = len; i > 0; i--) {
      ans += arr[Math.floor(Math.random() * arr.length)];
    }
    return ans;
  }

标签: ionic-frameworkdeep-linking

解决方案


推荐阅读