Adhikar Patil

Adhikar Patil

  • NA
  • 481
  • 128.9k

How to do the person to merchant transaction in ionic 4 using UPI

Jul 15 2021 5:43 PM

Hello All,
I am using webintent plugin for showing the installed UPI and doing the transaction with that UPI in IONIC 4. But PhonePe and Paytm working fine as well as it gives proper response. But when i am trying with Whatsapp Payment and CRED Payment it gives me response like that {"extras":{"resultCode":0,"requestCode":1},"flags":0}. What should i do for proper response? Below is my code in IONIC 4. Please provide me the proper solution.

payWithUPI() {
    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;
  }