Mohsin
Mohsin

Reputation: 469

Integrating PayU with PhoneGap app

How to integrate PayU payment gateway with a PhoneGap application?

Which is the correct approach?

In case of Android

  1. After adding cordova platform for android, export it in eclipse, register the activity from payu android sdk, then call this activity from javascript
  2. As the app uses php webservice API from Webservice api call payu Rest API
  3. Use the iframe provided in github

It would be helpful if someone give some input in this.

Upvotes: 4

Views: 2655

Answers (1)

Ankit Balyan
Ankit Balyan

Reputation: 1329

Here is sample app for payu integration into phone gap you can find the html and javascript code here. This sample app is using payu without SDK.

UPDATE: if you are using angular

$scope.payuOrder = function(form) {
        $scope.payu_params = {
            key: "xx@#EX",
            salt: "Dda3dqCx",
            txnid:"qw"+Math.floor(Math.random() * 100000000000),
            amount:"1230",
            productinfo:"Product info",
            firstname:"Ankit",
            email:customer."[email protected]",
            user_credentials:"xx@#EX:unique_id",
            udf1:"",
            udf2:"",
            udf3:"",
            udf4:"",
            udf5:"",
            offer_key:"",
            card_bin:"",
            surl: encodeURI("https://payu.herokuapp.com/success"), //url needs to be encode
            furl: encodeURI("https://payu.herokuapp.com/failure") // url needs to be encode
        };

        var hash_string = $scope.payu_params.key+"|"+$scope.payu_params.txnid+"|"+$scope.payu_params.amount+"|"+
        $scope.payu_params.productinfo+"|"+$scope.payu_params.firstname+"|"+
        $scope.payu_params.email+"|"+$scope.payu_params.udf1+"|"+$scope.payu_params.udf2+"|"+
        $scope.payu_params.udf3+"|"+$scope.payu_params.udf4+"|"+$scope.payu_params.udf5+"||||||"+$scope.payu_params.salt;

        console.log("HashString = "+hash_string);

        $scope.payu_params.hash = CryptoJS.SHA512(hash_string).toString(CryptoJS.enc.Base64);

        console.log("Hash = "+$scope.payu_params.hash);

        var payu_params_string = '';
        for (var key in $scope.payu_params) {
          payu_params_string += key + "=" + $scope.payu_params[key] + "&";
        }

        payu_params_string = payu_params_string.slice(0,-1);
        console.log(payu_params_string);
        var bytes = [];
        for (var i = 0; i < payu_params_string.length; ++i) {
            bytes.push(payu_params_string.charCodeAt(i));
        }
             payu_params_string.toString().getBytes());         
             var winURL = "https://test.payu.in/_payment";
             var form = document.createElement("form");
             form.setAttribute("method", "post");
             form.setAttribute("action", winURL);
             for (var i in $scope.payu_params) {
                 if ($scope.payu_params.hasOwnProperty(i)) {
                     var input = document.createElement('input');
                     input.type = 'hidden';
                     input.name = i;
                     input.value = $scope.payu_params[i];
                     form.appendChild(input);
                 }
             }
          var options = {
              location: 'no',
              clearcache: 'yes',
              toolbar: 'no'
            };
            $cordovaInAppBrowser.open(winURL, '_blank', options)
              .then(function(event) {
                  $rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event){
                    // insert form on loaded window
                        document.body.appendChild(form);                     
                        form.submit();               
                        document.body.removeChild(form);           
                  });

              })
              .catch(function(event) {
                // error
              });
       }

Upvotes: -1

Related Questions