将PayU资金整合到Ionic + Cordova混合应用程序中

时间:2016-04-01 11:55:03

标签: cordova ionic-framework payu payumoney

请帮助我如何设置或呈现成功网址到我的离子应用程序。 当我将PayU资金整合到Ionic应用程序时,它需要在完成付款后成功Url和Failure Url才能成功,但它不会回到Ionic App。

<form name="sendParam" method="post"    action="https://test.payu.in/_payment.php">
    <input type="text" name="key" value="P3kHif" />
    <input type="text" name="txnid" value="mdd0123" />
    <input type="text" name="amount" value="100" />
    <input type="text" name="productinfo" value="oxygenconcentrator" />
    <input type="text" name="firstname" value="test" />
    <input type="text" name="email" value="test@gmail.com" />
    <input type="text" name="phone" value="9999999999" />
    <input type="text" name="surl" value="http://example.com" />
    <input type="text" name="Furl" value="http://example.com/about-us/" />
    <input type="text" name="Hash" value="9a4c95b065ae294414e6a5b0b6e8e5d1a2ebf26074228eac6ff7c7d739c9cd4d021a9f70af8860ac369b1ccecfdaa60ba5839ee9dc1fd41e2848a3813677d520"/>
    <input type="submit" value="enter"/>
 </form >

响应来自PayUmoney仅采用HTML格式,它没有任何JSON对象格式。我只是按照以下链接PayU Money Rest API

4 个答案:

答案 0 :(得分:3)

Payumoney没有混合应用程序的sdk。我们需要使用Cordova inapp浏览器来实现这一目标。

第1步:创建Payumoney帐户并获取沙箱详细信息。

第2步:安装Cordova inapp浏览器

第3步:创建付款网址

第4步:在服务器中创建成功和失败网址,并在付款页面中添加这些网址

第5步:在您的inapp浏览器中运行您的付款网址。

多数民众赞成。它将执行付款流程并将状态发送给给定的成功和失败URL。

Here您可以找到离子中支付网关集成的代码。

答案 1 :(得分:1)

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContextOver) throws JSONException {

    Intent intentScan = new Intent(this.cordova.getActivity().getBaseContext(), com.timepay.payu.activity.MainActivity.class);

    intentScan.putExtra("amount", "1000");

    intentScan.setPackage(this.cordova.getActivity().getApplicationContext().getPackageName());
    callbackContext = callbackContextOver;

    this.cordova.startActivityForResult(this, intentScan, 11);


    return true;
}

答案 2 :(得分:0)

我一直在寻找同样但没有运气。因此,最终需要做很多解决方法才能使用IONIC 1 App。

我的方法可能不完美,但我可以为我的离子应用程序付款。

首先,我想与你分享我的应用程序,但是我用它包装的凭证很少,所以在这里分享它是不安全的。 是的,我的应用程序在Playstore中存在,有超过100个活跃用户(我上次检查)

任何方式让我告诉你我是如何在我的应用程序中做到的。 以下是我的代码。请查看是否有人有更好的方法请分享..     `$ scope.pay = function(address){

        sharedUtils.showLoading("Processing Payment...");
        // sending data from app to server for preprocessing 
        var req = {
            method: 'POST',
            url: 'https://xyx.com/payment/getmobilepaymentdata',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
            // below data contains all info collected form device page transitions like user address , order details etc. 
            data: data
        }
        var serverRes = {};
        if (datatobeshared !== undefined)
        //Note: response data will have all the required info we need to send it to payumoney
            $http(req).then(function (response) {
                serverRes = response.data;
                var data = 'key=' + serverRes.key
                    + '&txnid=' + serverRes.txnid
                    + '&amount=' + serverRes.amount
                    + '&productinfo=' + serverRes.productinfo
                    + '&firstname=' + serverRes.firstname
                    + '&email=' + serverRes.email
                    + '&phone=' + serverRes.phone
                    + '&surl=' + serverRes.surl
                    + '&furl=' + serverRes.furl
                    + '&hash=' + serverRes.hash
                    + '&service_provider='+serverRes.service_provider
                    + '&udf3=' + serverRes.udf3
                    + '&udf1=' + serverRes.udf1;

               // Note: check below option.This will be set in browser
                var options = {
                    "location": "no",
                    "toolbar": "no",
                    "hardwareback": "no",
                    "clearcache": "no"
                };
                $rootScope.paymentwindow = window.open('templates/payuBiz.html?' + data, '_blank', 'location=no');
                sharedUtils.hideLoading();



// here I am updating a status flag i.e -1 on server side which my server will update to 0(on failure) or 1(on Success)                   fireBaseData.refOrderStatus().child(serverRes.txnid).update({
                    status: -1,
                });
         // once window with payumoney will open in our app we will keep checking status flag that we have set above and put a timeout for session incase user let device and didn't perform any action on payment page
                $rootScope.timesRun = 0;
                $rootScope.interval = setInterval(function () {
                    console.log($rootScope.timesRun);
                    $rootScope.timesRun += 1;

                    if ($rootScope.timesRun >= 50) {
                        clearInterval($rootScope.interval);
                        clearInterval($rootScope.interval);
                        $rootScope.paymentwindow.close();
                        sharedUtils.showAlert('Payment Session Time out', 'Payment gateway session got time out.');

                        $ionicHistory.nextViewOptions({
                            historyRoot: true
                        });
                        $state.go('lastOrders', {}, {location: "replace", reload: true});
                        return;
                    }

                    if ($rootScope.paymentwindow.closed) {
                        clearInterval($rootScope.interval);
                        sharedUtils.showAlert('Payment error', 'Payment got interrupted unexpectedly. Please try again.');
                        $ionicHistory.nextViewOptions({
                            historyRoot: true
                        });
                        $state.go('lastOrders', {}, {location: "replace", reload: true});
                        return;
                    }


                    fireBaseData.refOrderStatus().child($rootScope.txnid).child('status').once("value", function (snapshot) {


                        if (snapshot.val() != -1) {
                            $rootScope.paymentwindow.close();

                            if (snapshot.val() == 1) {
                                clearInterval($rootScope.interval);

                                $scope.orderSuccess(address, $rootScope.txnid);

                                return;
                            } else {
                                clearInterval($rootScope.interval);
                                $scope.orderFailure(address);
                                return;

                            }
                        }
                    });
                }, 5000);


            }, function (error) {
                $ionicPopup.alert({
                    title: 'Error',
                    template: 'This is some error in processing your order Please retry ' + JSON.stringify(error.data)
                });
                return;

            });
        sharedUtils.hideLoading();

    }`

其余代码是不言自明的。

希望这会有所帮助。

这是我的payumoney templet`

    

<h2 style="text-align: center">Your will be taken to paytment gateway </br> Please dont use back button or move app in background</h2>
<div align="center">
<div class="loader" ></div></div>

<form id = "payuForm" name="payuForm" method="post" action="https://secure.payu.in/_payment">
  <!--<form id = "payuForm" name="payuForm" method="post" action="https://test.payu.in/_payment">-->

  <input type="hidden" name="key" value=""/>
  <input type="hidden" name="txnid" value=""/>
  <input type="hidden" name="amount" value=""/>
  <input type="hidden" name="productinfo" value=""/>
  <input type="hidden" name="firstname" value=""/>
  <input type="hidden" name="email" value=""/>
  <input type="hidden" name="phone" value=""/>
  <input type="hidden" name="surl" value=""/>
  <input type="hidden" name="furl" value=""/>
  <input type="hidden" name="hash" value=""/>
  <input type="hidden" name="udf3" value=""/>
  <input type="hidden" name="udf1" value=""/>
  <input type="hidden" name="service_provider" value=""/>
  <input type="hidden" name="productinfo" value=""/>
  <input type="submit" value="enter" style="position: absolute; left: -9999px"/>
</form>

<script>

  function findGetParameter(parameterName) {
    var result = null,
      tmp = [];
    location.search
      .substr(1)
      .split("&")
      .forEach(function (item) {
        tmp = item.split("=");
        if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
      });
    return result;
  }

  try {
    $('form[name="payuForm"] input[name="firstname"]').val(findGetParameter('firstname'));
    $('form[name="payuForm"] input[name="email"]').val(findGetParameter('email'));
    $('form[name="payuForm"] input[name="hash"]').val(findGetParameter('hash'));
    $('form[name="payuForm"] input[name="phone"]').val(findGetParameter('phone'));
    $('form[name="payuForm"] input[name="productinfo"]').val(findGetParameter('productinfo'));
    $('form[name="payuForm"] input[name="amount"]').val(findGetParameter('amount'));
    $('form[name="payuForm"] input[name="key"]').val(findGetParameter('key'));
    $('form[name="payuForm"] input[name="txnid"]').val(findGetParameter('txnid'));
    $('form[name="payuForm"] input[name="surl"]').val(findGetParameter('surl'));
    $('form[name="payuForm"] input[name="furl"]').val(findGetParameter('furl'));
    $('form[name="payuForm"] input[name="udf3"]').val(findGetParameter('udf3'));
    $('form[name="payuForm"] input[name="udf1"]').val(findGetParameter('udf1'));
    $('form[name="payuForm"] input[name="service_provider"]').val(findGetParameter('service_provider'));

    setTimeout(function () {
      document.payuForm.submit();
    }, 1000);
  }catch (e)
  {
    alert(e);
  }
</script>

`

答案 3 :(得分:0)

更新:2020 Payu发布了Cordova插件,用于集成到混合应用程序中 https://developer.payumoney.com/payumoney-cordova-plugin/

他们还提供了Wrapper JS文件来调用Native SDK插件