node.js - How to correctly create 'charge' in Stripe nodejs library? -


client

i'm using stripe checkout custom integration - https://stripe.com/docs/checkout#integration-custom - in following way:

  var handler = stripecheckout.configure({     key: 'your_key_here',     image: 'images/logo-48px.png',     token: function(token, args) {         $.post("http://localhost:3000/charge", {token: token}, function(res) {             console.log("response charge: " + res);         })     }   }) 

using custom contrary simple - how can modify stripe checkout instead send ajax request? - because simple not allow me make ajax call.

server

https://stripe.com/docs/tutorials/charges

you've got token user's credit card details, what? charge them money.

app.post('/charge', function(req, res) {     console.log(json.stringify(req.body, null, 2));     var stripetoken = req.body.token;      var charge = stripe.charges.create({         amount: 0005, // amount in cents, again         currency: "usd",         card: stripetoken,         description: "payinguser@example.com"     }, function(err, charge) {         if (err && err.type === 'stripecarderror') {             console.log(json.stringify(err, null, 2));         }         res.send("completed payment!")     }); }); 

here error:

enter image description here

is seems me have last4, exp_month, exp_year reason don't have number. suggestions / hints / ideas?

googling "the card object must have value 'number'" - 12 results, not help.

the "token" have give card argument should token id (e.g.: "tok_425dva2ezvkylo2clck8dnwq"), not full object. using checkout app never sees card number.

you therefeore need change:

var stripetoken = req.body.token; 

to:

var stripetoken = req.body.token.id; 

the documentation isn't clear card option, stripe api reference has example.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -