Created
November 8, 2017 12:04
-
-
Save skomarfaruque/343fea2608bb21565383976d0163fd5d to your computer and use it in GitHub Desktop.
stripetoken backend nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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