我正在用PHP编写Paypal签出,并且在执行onAuthorize方法后,我尝试在重定向urls上发布其他变量。
一旦调用了onAuthorize方法,我就尝试运行Ajax函数,但到目前为止还没有成功。我的变量无法到达redirect_urls中设置的URL。
onAuthorize方法:
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
postAjax();
actions.redirect();
});
}Ajax函数名为postAjax
function postAjax() {
jQuery.ajax({
type: "POST",
ataType: 'text',
url: "<?php if ($langue == $fr) {echo "http://localhost/index.php/fr/confirmation";} else {echo "http://localhost/index.php/en/confirmation";}?>",
data: {idFif : "testValue123"},
success: function(){
alert(data);
}
});
}URL重定向
redirect_urls: {
return_url: '
<?php if ($langue == $fr) {
echo "http://localhost/index.php/fr/confirmation"; }
else {echo "http://localhost/index.php/en/confirmation";}?>'
}我很想在不需要创建外部ajax函数的情况下发布这些值(在这种情况下是postAjax()),但我似乎无法找到方法。有人能给我指点吗?非常感谢!
发布于 2019-01-07 18:32:48
对于您的情况,我强烈建议您使用paypal,因为快速结帐很容易,但我有经验表明,用户在完成paypal选项卡付款时关闭浏览器,所以在onAuthorize()的then()回调中执行付款时启动的ajax有时没有完成执行,而是在运行服务器端签出时,贝宝窗口在代码完整执行后关闭。
因此,在您的例子中,没有其他方法可以在付款执行后向服务器发布一些东西,ajax是您唯一的选择。如果您决定使用PHP实现支付,您可以这样做:
onAuthorize: function(data, actions) {
// Make a request to your server
return actions.request.post('urlServerPost', {
paymentID: data.paymentID,
payerID: data.payerID,
variable1: 'something',
variable2: 'something2'
})
.then(function(res) {
//Your payment has already been approved and the process on the server has been finished also
});
}https://stackoverflow.com/questions/54079437
复制相似问题