【问题标题】:In-Context Checkout: No response handler found for post message response errorIn-Context Checkout:没有为发布消息响应错误找到响应处理程序
【发布时间】:2017-01-15 05:28:09
【问题描述】:

我使用Advanced In-Context Checkout integration

我使用 AJAX 并利用这些功能,正如他们的文档所解释的那样:

paypal.checkout.setup()
paypal.checkout.initXO()
paypal.checkout.startFlow()
paypal.checkout.closeFlow()

Execute the payment step 之后,我经常遇到这个烦人的错误。他们没有费心去解释他们的 API 文档。它只是丢失了。

new Error("No response handler found for post message response "+t.name+" in "+window.location.href);

错误是什么意思?需要什么样的用于发布消息响应的响应处理程序?如何提供?

我的客户端代码如下所示:

onCheckoutBtnClick(ev) {
    paypal.checkout.initXO();
    $.post('/checkout', {
        user: JSON.stringify(this.props.user),
        data: JSON.stringify(this.props.WCs),
    })
    .done(res => {
        paypal.checkout.startFlow(res.approval_url);
    })
    .fail(err => {
        paypal.checkout.closeFlow();
    });
},

服务器端如下:

router.post('/checkout', (req, res, next) => {
    var payment_json = {

        // huge config to create a payment
        // the pivotal value is "return_url"
        redirect_urls: {
            "return_url": "http://example.com:3000/complete_payment",
            "cancel_url": "http://example.com:3000/cancel_payment"
        },
    }
});

还有return_url代码

router.get('/complete_payment', (req, res, next) => {
    paypal.payment.execute(req.query.paymentId, execute_payment_json, function (err, payment) {

        // After this step the error in thrown on the client
        res.redirect('http://example.com:3000/show_complete_page_to_buyer');
    })
})

【问题讨论】:

    标签: paypal-sandbox paypal-rest-sdk paypal


    【解决方案1】:

    我解决了将按钮初始化函数包装在 $(window).load() 中的问题

    【讨论】:

    • 欢迎来到 Stack Overflow!不幸的是,这篇文章似乎没有为这个问题提供quality answer。请编辑您的答案,为其添加源代码,或将其作为问题下方的评论移动。谢谢!
    • 最好的答案,因为当我将代码放入 $(document).ready(function () {....}); 时,它立即解决了我的问题;
    【解决方案2】:

    沙盒对我来说也有问题,经常在刷新时自行纠正。使用 Chrome 开发人员工具 (Ctrl-Shift-I) 并查看控制台日志,我看到了以下堆栈跟踪:

    types.js:19 Uncaught Error: No handler found for post message ack for message: postrobot_method from http://localhost:50834 in https://www.sandbox.paypal.com/webapps/hermes/button
    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_ack] (https://www.paypalobjects.com/api/checkout.js:2514:33)
    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2465:77)
    at messageListener (https://www.paypalobjects.com/api/checkout.js:2486:13)
    

    我还观察到该错误可能由我的代码中其他地方未处理的 javascript 异常触发。

    【讨论】:

      【解决方案3】:

      这似乎只是一个沙盒问题。在 Sandbox 中一直看到这个错误,而在生产模式下也看到了这个错误。 我已经向 Paypal 开发人员发送了邮件,抱怨沙盒和生产之间的许多差异。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-10
        • 1970-01-01
        • 2013-06-16
        相关资源
        最近更新 更多