Connect Ionic with PayU (payment gateway)

Yes, I think this could be the issue, is there any other way to register event. As I am using the code provide by that reference link?

Let me provide you code tonight. There are multiple ways to register but I have also registered the same way as you . I guess something is missing.will let you know tonight.

Ok, Thanks lot bro I will be waiting for your response.

payThroughoPayUMoney(){
        var pageContent = '<html><head></head><body><form id="loginForm" action="https://test.payu.in/_payment" method="post">' +
        '<input type="hidden" name="key" value="'+this.mkey+'" />'+
        '<input type="hidden" name="txnid" value="'+this.txnid+'" />'+
        '<input type="hidden" name="amount" value="'+this.amount+'" />'+
        '<input type="hidden" name="productinfo" value="'+this.productinfo+'" />'+
        '<input type="hidden" name="firstname" value="' + this.firstname + '">' +
        '<input type="hidden" name="email" value="' +this. email + '">' +
        '<input type="hidden" name="phone" value="' + this.phone + '">' +
        '<input type="hidden" name="surl" value="' + this.surl + '">' +
        '<input type="hidden" name="Furl" value="' + this.Furl + '">' +
        '<input type="hidden" name="Hash" value="' + this.Hash + '">' +

        '</form> <script type="text/javascript">document.getElementById("loginForm").submit();</script></body></html>';
        var pageContentUrl = 'data:text/html;base64,' + btoa(pageContent);
        alert(pageContentUrl);

        iabRef= cordova.InAppBrowser.open(
            pageContentUrl,
            "_blank"
            //"hidden=no,location=yes,clearsessioncache=yes,clearcache=yes"
        );
        
        iabRef.addEventListener('loadstop', (event)=>{alert(event.url);this.iabLoadStop(event)});
        iabRef.addEventListener('loadstart', (event)=>{this.iabLoadStart(event)});
        iabRef.addEventListener('loaderror', (event)=>{this.iabLoadError(event)});
        iabRef.addEventListener('exit', (event)=>{this.iabClose(event)});
}

Sunil ,Please check above function it covers everything. Let me know if you have any doubt.

Bro! Please help me with Ionic1 payu integration bro was also trying from long time could not able to find any solution.

Hi @ras1kamal I have a doubt here, the Line.

iabRef= cordova.InAppBrowser.open(
pageContentUrl,
"_blank"
//“hidden=no,location=yes,clearsessioncache=yes,clearcache=yes”
);
I have InappBrowser installed, but its not open pageContentUrl in it. How did you include cordova into the controller.js, before I was using window.open() after define it as.

// Global InAppBrowser reference
var iabRef = null;

And success and faliur url will be these 2:

https://payu.herokuapp.com/success

https://payu.herokuapp.com/failure

Right?

I am running cordova as browser using following command:

cordova run browser

Then after clicking PayNow button. Its show me alert(pageContentUrl);, then throw following error.

Error in Success callbackId: InAppBrowser903676977 : SecurityError: Blocked a frame with origin “http://192.168.10.61:8000” from accessing a cross-origin frame.

Any idea why it encounter.

At this point it won’t work with ionic serve or cordova run browser. You have to make an apk and install in smartphone and check . I did like that only.

Ok, bro let me do that as well.

One thing else After payment success which event it will call where I need to update db for the transaction status.?

loadstop event will get called

Bro haven’t implemented it on ionic 1 . If time permits will try to make a demo for ionic 1 . However following link can surely help you: https://github.com/IonicU/payuhybridappintegration

Please bro! and thanks for your response. I was trying from long time. I tried the link long time back static values its working Dynamic values its not bro. Don’t know how to proceed further Bro.

Hi bro, I have checked in on device. Not getting response,back.

function iabLoadStop(event) {

if (event.url.match("https://payu.herokuapp.com/success")) {alert("matched success url");
   
    iabRef.executeScript({
        code: "document.body.innerHTML"
    }, function(values) {
        //incase values[0] contains result string
        var a = getValue(values[0], 'mihpayid');
        var b = getValue(values[0], 'status');
        var c = getValue(values[0], 'unmappedstatus');
        console.log(a + b + c);//you can capture values from return SURL
        alert(a); alert(b);//not getting these values          
    });

//iabRef.close();
}
}
do you have any idea?

Thanks lot , bro great its working fine now on device. but we need it to work for on browser as well is that possible becasse we are creating app and web-portal as well. please let me know if you have any solution for this.

Thats great . Congrats. No bro no idea how to make it work for browser. The reason behind ,why it is not working in browser is due to Cross domain access. If you see in browser console you will find that error.

@charen
If you can paste your code and what exact error you are facing then we can check and help you.

Ok, Bro I will try to fix it in browser as well, if I will get any success I will post here the solution.

Thanks for your great guidance its relay helped me lot.

Anytime Bro.Good luck

Hi Bro I have just get success response from payUmoney. After Success i need to hit a service to server as following:

function iabLoadStop(event,$state,paymentService,$http) {    

if (event.url.match("https://payu.herokuapp.com/success")) {    
   
    iabRef.executeScript({
        code: "document.body.innerHTML"
    }, function(values) {            
        //incase values[0] contains result string
        var payId = getValue(values[0], 'mihpayid');
        var response = getValue(values[0], 'status');
        var c = getValue(values[0], 'unmappedstatus');
        
          if(response == "success") {                 
        
        var apiUrl = "http://148.251.158.141/EduboldPortalApp/eduboldportal/web/app_dev.php/api/payment";
        
       $http.post(apiUrl,{
                status : response
                
            }).then (function (res){ alert("here");            
              
            })                
        }
        else{
                  alert("Error..");
                // handle fail scenario
              }          
        });        
      iabRef.close();
     }
   }

my data is not posted to the server its showing the following error:

Uncaught TypeError: Cannot read property ‘post’ of undefined, http://192.168.10.61:8100/cordova.js, Line: 314

Any idea bro what could be the issue I did some r&d but did not get anything.