我正在尝试集成 Paypal API。
我使用 Angular
、Node.js
、MongoDB
堆栈。
我成功创建了付款
paypal_api.payment.create(create_payment_json, config_opts, function(err,res) {
var response = {};
if (err) {
throw err;
}
if (res) {
if (res.payer.payment_method === "paypal") {
console.log("Create Payment Response");
console.log(res);
response.payment = res;
response.paymentId = res.id;
for (var i = 0; i < res.links.length; i++) {
var link = res.links[i];
if (link.method === "REDIRECT") {
var redirectUrl = link.href;
}
}
response.redirectUrl = redirectUrl;
resultat.status(200).json({
message: "Success",
obj: response
});
}
}
});
module.exports = router;
我在我的 FrontEnd 中检索了 redirectUrl
,见下文
PayNow() {
this.contactClientService.PayNowPaypal().subscribe(
(paypalObject: Payment) => {
this.paypalObject = paypalObject;
console.log(this.paypalObject.redirectUrl);
this.router.navigate([this.paypalObject.redirectUrl]);
},
error => {
this.errorMessage = <any>error
});
}
关于this.router.navigate([this.paypalObject.redirectUrl]);
我理解错误消息 “错误:无法匹配任何路由。”
。我读到我可以使用 window.location.href = '...';
转到外部链接。但这是最好的方法吗?我不知道。有什么建议吗?
如果我将链接复制到我的浏览器中,我将被重定向到 paypal 以进行付款。
redirectUrl:"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_e....."
谢谢
最佳答案
this.router.navigate 是一种 Angular 方法,用于在您的路由定义中查找匹配的路由。由于 paypal 为您提供了一个外部链接,因此它与您的应用程序的任何路由都不匹配。这就是为什么您会看到错误“错误:无法匹配任何路由。”
你是对的,当导航到应用程序外部的外部链接时,你应该使用
window.location.href = this.paypalObject.redirectUrl;
关于node.js - Angular 导航到 Paypal 网址响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45527044/