Skip to content

Instantly share code, notes, and snippets.

@skomarfaruque
Created November 8, 2017 12:04
Show Gist options
  • Save skomarfaruque/343fea2608bb21565383976d0163fd5d to your computer and use it in GitHub Desktop.
Save skomarfaruque/343fea2608bb21565383976d0163fd5d to your computer and use it in GitHub Desktop.
stripetoken backend nodejs
await stripe.tokens.create({
card: {
"number": '4242424242424242',
"exp_month": 12,
"exp_year": 2018,
"cvc": '123'
}
}, function(err, token) {
stripe.customers.create({
email: '[email protected]'
}).then(function(customer){
return stripe.customers.createSource(customer.id, {
source: token.id
});
}).then(function(source) {
return stripe.charges.create({
amount: amount,
currency: 'usd',
customer: source.customer,
metadata: {'order_id': '6735'}
});
}).then(function(charge) {
data = charge
console.log(charge)
// New charge created on a new customer
}).catch(function(err) {
console.log(err)
// Deal with an error
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment