node.js - Angular 导航到 Paypal 网址响应

标签 node.js angular paypal

我正在尝试集成 Paypal API
我使用 AngularNode.jsMongoDB 堆栈。

我成功创建了付款

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/

相关文章:

javascript - Bookshelf.js 或 Knex.js 中 2 个表的外部连接

html - Nodejs如何从ejs文件生成pdf文件

node.js - 如何在 Graphql 中将字段包含在 api 服务器中并在将结果返回给客户端之前将其删除

angular - @NgModule 是新的吗?

javascript - 如何以 Angular 对html表的每一行进行组件化

javascript - NPM package.json 基/根属性?

javascript - 检测单词和句子的完成情况

php - Magento 中的 Paypal 状态

paypal - 在 UWP 应用中销售实物商品

paypal - 沙盒 Paypal 服务器有问题吗