Skip to content

Instantly share code, notes, and snippets.

@bennetthardwick
Created December 18, 2017 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennetthardwick/9a9b49e78503364a5898d7b9a5b02175 to your computer and use it in GitHub Desktop.
Save bennetthardwick/9a9b49e78503364a5898d7b9a5b02175 to your computer and use it in GitHub Desktop.
Charge someone $9.99 with stripe in only 34 lines!
var stripe = require('stripe')('sk_test...');
var app = require('express')();
var bodyParser = require('body-parser');
var magic_seven_lines = '<form action="/charge" method="POST">\
<script\
src="https://checkout.stripe.com/checkout.js" class="stripe-button"\
data-key="pk_test..."\
data-amount="999"\
data-name="Test!"\
data-description="Widget"\
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"\
data-locale="auto"\
data-zip-code="false">\
</script>\
</form>';
app.use(bodyParser.urlencoded());
app.get('/checkout', (req, res) => {
res.send(magic_seven_lines);
})
app.post('/charge', (req, res) => {
stripe.charge.create({
amount: 999,
currency: 'usd',
description: 'Some money for my worries.',
source: req.body.stripeToken,
}).then(charge => res.send('Success!'))
.catch(err => res.send('Failed!'));
});
app.listen('3000', () => console.log('listening on 3000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment