【发布时间】: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