【发布时间】:2019-08-06 01:05:57
【问题描述】:
我正在将 PayPal 结帐与电子商务解决方案集成,在 PayPal 成功创建 PayPal 订单/付款后,我执行一些服务器端处理,最终返回 RedirectResult(相应的付款失败或成功的 URL ) 从我的控制器返回到客户端/前端。
我在下面有以下代码,并希望它自动重定向,但不会发生重定向。
paypal.Buttons({
createOrder: function (data, actions) {
return actions.order.create({
intent: "CAPTURE",
purchase_units: [{
amount: {
value: '5.20',
}
}]
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
return fetch('/umbraco/surface/PayPalPayment/process', {
method: 'post',
redirect: 'follow',
body: JSON.stringify({
OrderID: data.orderID,
PayerID: data.payerID,
}),
headers: {
'content-type': 'application/json'
}
});
}).catch(error=>console.log("Error capturing order!", error));
}
}).render('#paypal-button-container');
如果我使用下面的代码显式重定向,则执行该操作。
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
return fetch('/umbraco/surface/PayPalPayment/process', {
method: 'post',
redirect: 'follow',
body: JSON.stringify({
OrderID: data.orderID,
PayerID: data.payerID,
}),
headers: {
'content-type': 'application/json'
}
}).then(function () { window.location.replace('https://www.google.co.uk') });
}).catch(function (error) {
console.log("Error capturing order!", error);
window.location.replace('https://www.bbc.co.uk');
});
}
基本上,我想知道为什么 fetch 重定向不遵循从我的控制器返回的重定向。控制器重定向以获得完整的完整性:
return new RedirectResult("/checkout/thank-you") ;
【问题讨论】:
-
Basically, I'm wondering why fetch redirect does not follow the Redirect that is returned form my controller- 你能进一步解释一下吗?
标签: asp.net-mvc paypal paypal-sandbox fetch-api