我一直在寻找相同的东西,但没有运气。所以最终做了很多变通方法让它与我的 IONIC 1 应用程序一起工作。
我的方法可能并不完美,但我能够为我的 ionic 应用程序获得工作报酬。
首先,我想与你们分享我的应用程序,但我打包的凭据很少,所以在这里分享它是不安全的。是的,我的应用程序已在 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();
}`
其余代码是不言自明的。
希望这会有所帮助。
这是我的支付宝模板`
<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>
`