【问题标题】:Angular navigate to paypal url response角度导航到贝宝 url 响应
【发布时间】:2018-01-13 14:05:32
【问题描述】:

我正在尝试集成 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;

我在我的前端检索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]); 我了解错误消息"Error: Cannot match any routes."。我读到我可以使用window.location.href = '...'; 转到外部链接。但这会是最好的方法吗?我不知道。有什么建议吗?

如果我将链接复制到浏览器中,我将被重定向到贝宝进行付款。

redirectUrl:"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_e....."

谢谢

【问题讨论】:

    标签: node.js angular paypal


    【解决方案1】:

    this.router.navigate 是一种角度方法,用于在您的路由定义中查找匹配的路由。由于贝宝为您提供了一个外部链接,它与您的任何应用程序的路由都不匹配。这就是为什么您会看到错误“错误:无法匹配任何路由。”

    你是对的,当导航到应用程序外部的外部链接时,你应该使用

    window.location.href = this.paypalObject.redirectUrl;
    

    【讨论】:

      猜你喜欢
      • 2014-10-26
      • 2013-02-14
      • 2022-01-13
      • 2016-01-20
      • 2013-01-11
      • 1970-01-01
      • 2017-02-14
      • 2013-05-10
      • 1970-01-01
      相关资源
      最近更新 更多