更改使用不同对象收取的金额以查找价格

时间:2017-01-31 00:11:00

标签: javascript mongodb stripe-payments

我正在尝试使用Stripe创建一种方式来接受我网站上的付款,但我想要根据我加载的目录中的wat对象来更改价格。我的显示页面从mongo中提取数据作为对象,所以在我的对象中我有不同的字段,在对象中我有我希望传递到我的strip.charges.create({})的字段;所以这是我的充电页面看起来我从条纹文档得到它:

app.post('/charge', function(req, res) {
    var stripeToken = req.body.stripeToken;

    //console.log("print the price "+req.data.price);
    console.log("print the price "+data.price2);
    console.log("print the price "+req.params.price);
    console.log("print the price "+req.params.amount);
    console.log("print the price "+req.body(JSON.stringify(data)));
    //console.log("print the price "+JSON.stringify(req.data.price));
    var amount = 1122;<= i want to make this change depending on wat item i load into the show page is there a function call like anything similiar to what i have tried above on my console.logs 

    stripe.charges.create({
        card: stripeToken,
        currency: 'usd',
        amount: amount
    },
    function(err, charge) {
        if (err) {
            res.send(500, err);
        } else {
            res.send(204);
        }
    });
});

现在我的金额是静态的,无论我在我的目录中点击什么项目,它总是收取11.22而不是需要收取的价格。有没有办法实现这个?

1 个答案:

答案 0 :(得分:0)

您需要将隐藏的<input>元素与表单一起发送,以指明他们购买的产品ID,然后您可以使用它来查询数据存储区中的价格。