1

I have a requirement that i need to send form data with window.open(). am going to integrate PayU money to Ionic and AngularJS application at that scenario i need to send some form data from window.ope() using InAppBrowser Cordova plugin but am not able to send form data.

following code written in my app.js

    var example = angular.module('starter', ['ionic', 'ngSanitize']);
    example.run(function($ionicPlatform, $timeout) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
    });
    example.controller("ExampleController", ['$scope', '$interval', function($scope, $interval) {
    $scope.myHTML = 'Check out my programming <a href="https://www.thepolyglotdeveloper.com">blog</a> while you are here';
    $scope.testmethod = function() {
        onDeviceReadyEWEWE();
    }
    }]);
    // Global InAppBrowser reference
     var iabRef = null;

    function iabLoadStart(event) {
    var winName = 'MyWindow';
    //var winURL='https://test.payu.in/_payment.php';
    var winURL = 'https://test.payu.in/_payment';
    // var winURL='https://test.payu.in/merchant/postservice.php?form=2';
    var windowoption = 'resizable=yes,height=600,width=800,location=0,menubar=0,scrollbars=1';
    //var params = { 'param1' : '1','param2' :'2'};  
    var params = {
        'key': 'gtKFFx',
        'txnid': 'mdd0sss9023',
        'amount': '100',
        'productinfo': 'oxygenconcentrator',
        'firstname': 'test',
        'email': 'test@gmail.com',
        'phone': '9000024100',
        'surl': 'https://payu.herokuapp.com/success',
        /*  'Furl' :'https://www.payumoney.com/mobileapp/payumoney/failure.php', */
        'Furl': 'https://payu.herokuapp.com/failure',
        'Hash': '9feaefa45b5b68c7091f7f1ff513183f3fca5b23b47d47d760c285c8ad2d5f9fd1ec9514f2bad5d3672b6cb9138af5dd5350a5cf1e87c6f20ca26817ee02ae77'
    };
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", winURL);
    form.setAttribute("target", winName);
    for (var i in params) {
        if (params.hasOwnProperty(i)) {
            var input = document.createElement('input');
            input.type = 'hidden';
            input.name = i;
            input.value = params[i];
            form.appendChild(input);
        }
     }
    document.body.appendChild(form);
    // window.open('', winName,windowoption);
    form.target = winName;
    console.log(form.action);
    form.submit();
    alert(event.type + ' - ' + event.url);
    }

    function iabLoadStop(event) {
    alert(event.type + ' - ' + event.url);
    }

    function iabLoadError(event) {
    alert(event.type + ' - ' + event.message);
    }

    function iabClose(event) {
    alert(event.type);
    iabRef.removeEventListener('loadstart', iabLoadStart);
    iabRef.removeEventListener('loadstop', iabLoadStop);
    iabRef.removeEventListener('loaderror', iabLoadError);
    iabRef.removeEventListener('exit', iabClose);
    }
    // device APIs are available

    function onDeviceReadyEWEWE() {
    //form.submit();   
    var options = {
        location: 'yes',
        clearcache: 'yes',
        toolbar: 'yes',
        closebuttoncaption: 'DONE?'
    };
    iabRef = window.open('https://test.payu.in/_payment', '_blank', options);
    iabRef.addEventListener('loadstart', iabLoadStart);
    iabRef.addEventListener('loadstop', iabLoadStop);
    iabRef.addEventListener('loaderror', iabLoadError);
    iabRef.addEventListener('exit', iabClose);
     }

and in my index.html

    <!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>

        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">

        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->

        <!-- ionic/angularjs js -->
        <script src="lib/ionic/js/ionic.bundle.js"></script>

        <!-- cordova script (this will be a 404 during development) -->
        <script src="cordova.js"></script>

        <!-- your app's js -->
        <script src="js/app.js"></script>

    </head>
    <body ng-app="starter">
        <ion-pane>
            <ion-header-bar class="bar-stable">
                <h1 class="title">Ionic Blank Starter</h1>
            </ion-header-bar>
            <ion-content ng-controller="ExampleController">
            <a href="http://www.google.com">Testing</a>
            <p ng-bind-html="myHTML"></p>

            <button ng-click="testmethod()">button</button>

        </ion-content>
        </ion-pane>
    </body>
</html>

so please help me out how to send form data with URL in window.open();

After Edit:

finally Integrated Inappbrowser to My Ionic app and cracked a solution.please find the URL for PayU Money Integration for Hybrid appsPayUmoneyIntegartion

Sai
  • 311
  • 1
  • 3
  • 18
  • To what URL are you trying to send the data and why can't you use Ajax for it ? – 11thdimension Apr 18 '16 at 04:59
  • HI @11thdimension am going to send data to https://test.payu.in/_payment but when it opening at that moment i need to send some input paramaetrs to that URL – Sai Apr 18 '16 at 05:03
  • I would suggest looking at this post: http://stackoverflow.com/questions/10472927/add-content-to-a-new-open-window – Conrad Lotz Apr 18 '16 at 05:19
  • try using `query parameters` like `test.payu.in/_payment?param1=val1&param2=val2`, that would be easier – 11thdimension Apr 18 '16 at 05:37
  • but no luck...still it not accepting any Params from URL `var URI='https://test.payu.in/_payment?key=gtKFFx&txnid=msaasda12&amount=100&productinfo=oxygenconcentrator&firstname=test&email=test@gmail.com&phone=9000120123&surl=https://payu.herokuapp.com/success1&Furl=https://payu.herokuapp.com/failure&Hash=7f82f251a2130cf69e22e17b62a990382a731877cb2c8f2584c5b7a0bed3f1567d166d3bb47b9ff10db43456d9dc2f907e456cdecea10493201dbc830d26899f'; iabRef = window.open(encodeURI(URI), '_blank', 'location=yes');` – Sai Apr 18 '16 at 06:37

0 Answers0