【发布时间】:2017-07-01 18:01:18
【问题描述】:
我正在尝试在我的应用中实现支付系统,方法是运行一个单独的服务器来处理 Braintree 的支付。我不知道如何向我的客户发送错误(当付款出错时)以处理结果客户端。如何根据 result.success 强制我的客户进入而不是然后?或者我如何在我的 .then 中获得 result.success ?实际上我的结果对象没有包含我的 result.success 的属性 (result.success 是一个布尔值)
服务器:
router.post("/checkout", function (req, res) {
var nonceFromTheClient = req.body.payment_method_nonce;
var amount = req.body.amount;
gateway.transaction.sale({
amount: amount,
paymentMethodNonce: nonceFromTheClient,
}, function (err, result) {
res.send(result.success);
console.log("purchase result: " + result.success);
});
});
客户:
fetch('https://test.herokuapp.com/checkout', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ payment_method_nonce: nonce, amount: this.props.amount })
}).then((result) => {
console.log(result);
}).catch(() => {
alert("error");
});
}
【问题讨论】:
标签: javascript node.js paypal httprequest braintree