因此,当前我正在尝试创建一个门户,人们可以在其中选择旅行,输入付款,旅行并将付款提交到数据库,如果成功发生,那么我将重定向到一个订单完成/收据页面,该页面将显示他们他们的订单详细信息
当我使用location.href重定向时,我已经完成了条带化付款,创建费用并提交到数据库,它将推送到该页面,但是,一旦我尝试获取:order_number该页面出现GET错误
这是提交订单功能
$scope.submitOrder = function() {
$http.post('/submit-order', {person: ui.person, cc: ui.cc, trip: ui.trip})
.then(function(response) {
if(!response.data.error) {
console.log(response.data, 'submit order complete');
location.href = "/order-complete";
} else {
alert(response.data.error);
}
})
}
这是api函数,其中条纹api称为
app.post('/submit-order', async function (req, res) {
console.log(req.body, 'submitting order');
stripe.tokens.create({
card: {
number: req.body.cc.number,
exp_month: req.body.cc.exp_month,
exp_year: req.body.cc.exp_year,
cvc: req.body.cc.cvc
}
}, function(err, token) {
if(err) console.error(err.message);
if(!err) {
console.log(token.id, 'token generating');
stripe.charges.create({
amount: 2000,
currency: "usd",
source: token.id, // obtained with Stripe.js
description: `Charge for ${req.body.person.email}`
}, async function(err, charge) {
if(err) console.error(err.message);
if(!err){
console.log(charge.id, 'charge successful');
var parameters = {
order_number: moment().unix(),
created: moment().unix(),
name: req.body.person.name,
email: req.body.person.email,
phone: req.body.person.phone,
charge_id: charge.id,
trip_start: moment(req.body.trip.startDate).unix(),
trip_end: moment(req.body.trip.endDate).unix()
}
await db.query(db.insertData('orders', parameters));
res.json({order_number: parameters.order_number});
} else {
res.json(err.message);
}
});
} else {
res.json({error: err.message});
}
});
});
这是我的路线(这是我认为要出错的地方)
app.get('/order-complete/:order_number', async function (req, res) {
var order = await db.query(`SELECT * FROM orders WHERE order_number='${req.params.order_number}'`);
order = order.rows[0];
res.render('orderComplete', order);
});
我在哪里指定刚刚发生的特定订单号?还是angularjs已经做到了?
我得到的错误是:
无法获取/订单完成
我希望显示订单号,然后可以显示订单中的一些详细信息,如下所示:
include header
.container
p Your Trip
p Start Date: {{ui.trip_start}}
p End Date: {{ui.trip_end}}
include footer