Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Stripe和NodeJS-传递要收费的金额_Javascript_Node.js_Stripe Payments - Fatal编程技术网

Javascript Stripe和NodeJS-传递要收费的金额

Javascript Stripe和NodeJS-传递要收费的金额,javascript,node.js,stripe-payments,Javascript,Node.js,Stripe Payments,编辑:为了澄清,费用确实在处理,我唯一不能做的就是动态设置费用金额 我工作了一整天,没有找到任何解决办法。这是我的server.js: app.post('/charge', function(req, res) { var stripeToken = req.body.stripeToken; var amount = 12000; console.log(req); stripe.charges.create({ card: stripeToken, currency: 'u

编辑:为了澄清,费用确实在处理,我唯一不能做的就是动态设置费用金额

我工作了一整天,没有找到任何解决办法。这是我的server.js:

app.post('/charge', function(req, res) {
var stripeToken = req.body.stripeToken;
var amount = 12000;
console.log(req);
stripe.charges.create({
    card: stripeToken,
    currency: 'usd',
    amount: amount
},
function(err, charge) {
    if (err) {
        res.send(500, err);
    } else {

        res.send(204);
    }
});
});
这是我的动态条纹按钮

$('#calcTransAmount').click(function(event) {
var amount = $('#transAmount').scope().totall;
//console.log(amount);
var holder = document.getElementById('hello');
var script = document.createElement('script');
script.src = 'https://checkout.stripe.com/checkout.js';
script.setAttribute('class', 'stripe-button');
script.setAttribute('data-amount', amount);
script.setAttribute('data-key',"KEY");
script.setAttribute('data-image', "IMG");
script.setAttribute('data-name', "NAME");
script.setAttribute('data-billing-address', "true");
script.setAttribute('data-description', "Purchase");
script.setAttribute('data-locale', "auto");
document.getElementById('btnCont').appendChild(script);
});
该按钮与动态金额和所有内容一起工作,现在我似乎无法理解post to
/charge
如何接收金额并将其设置为变量

这是我的
req
对象:

{ stripeToken: 'tok_19t9jcLhf04QCVXXXXXXXX',
 stripeTokenType: 'card',
 stripeEmail: 'me@gmail.com',
 stripeBillingName: 'Clark',
 stripeBillingAddressCountry: 'United States',
 stripeBillingAddressCountryCode: 'US',
 stripeBillingAddressZip: 'Zip',
 stripeBillingAddressLine1: 'My address',
 stripeBillingAddressCity: 'City',
 stripeBillingAddressState: 'State' }
而且我找不到一种方法来从按钮获取我的数据量属性到服务器以收取动态金额

特别感谢@koopajah为解决方案提供的灵感

在客户端的表单中,除了javascript按钮外,我还使用一个隐藏的输入框传递了一个键值,这将允许我的服务器端从数据库中获取购物车总数

<form action="/charge" method="POST"> 
    <input name="coKey" value ="{{currentUser.coKey}}">
</form>


然后在服务器端,我可以像这样拉取适当的键:
var coKey=req.body.coKey

这里的问题是,您确实不希望金额来自客户。任何人都可以更改金额,然后为订单支付1美元而不是99美元。由于安全原因,必须根据客户订购的内容在服务器端知道数量。这实际上是一个很好的观点!非常感谢。因此,我的后续问题是,是否有一种方法可以通过Stripe按钮将自定义变量传递到我的服务器端,从而允许服务器在数据库中查找购物车?