Paypal Express PHP - 在 onAuthorize 方法中发布 JS 变量
Paypal Express PHP - Posting JS variables in onAuthorize Method
我正在 PHP 中进行 Paypal Express Checkout,一旦执行 onAuthorize 方法,我会尝试 post 重定向 URL 上的其他变量。
一旦 onAuthorize 方法被调用,我已经尝试 运行 一个 Ajax 函数,但到目前为止没有成功。我的变量无法到达 redirect_urls 中设置的 URLs。
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";}?>'
}
我很想 post 值而不必创建外部 ajax 函数(postAjax() 在这种情况下)但我可以' 似乎找出如何。有人可以给我一些指示吗?非常感谢!
对于您的情况,我强烈建议您使用 Paypal PHP SDK,因为快速结账,是的,这很简单,但我有过这样的经历,即用户在支付完成后关闭浏览器paypal 选项卡,所以我在 onAuthorize()
的 then()
回调中执行付款时启动的 ajax 有时没有完成执行,相反,当 运行 服务器-端结帐,paypal window 将在您的代码完整执行后关闭。
因此,在您的情况下,一旦付款执行,就没有其他方法可以向服务器 post 发送内容,ajax 是您唯一的选择。如果您决定使用 PHP SDK 实现支付,您可以这样做:
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
});
}
我正在 PHP 中进行 Paypal Express Checkout,一旦执行 onAuthorize 方法,我会尝试 post 重定向 URL 上的其他变量。
一旦 onAuthorize 方法被调用,我已经尝试 运行 一个 Ajax 函数,但到目前为止没有成功。我的变量无法到达 redirect_urls 中设置的 URLs。
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";}?>'
}
我很想 post 值而不必创建外部 ajax 函数(postAjax() 在这种情况下)但我可以' 似乎找出如何。有人可以给我一些指示吗?非常感谢!
对于您的情况,我强烈建议您使用 Paypal PHP SDK,因为快速结账,是的,这很简单,但我有过这样的经历,即用户在支付完成后关闭浏览器paypal 选项卡,所以我在 onAuthorize()
的 then()
回调中执行付款时启动的 ajax 有时没有完成执行,相反,当 运行 服务器-端结帐,paypal window 将在您的代码完整执行后关闭。
因此,在您的情况下,一旦付款执行,就没有其他方法可以向服务器 post 发送内容,ajax 是您唯一的选择。如果您决定使用 PHP SDK 实现支付,您可以这样做:
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
});
}