Created
December 18, 2017 05:34
-
-
Save bennetthardwick/9a9b49e78503364a5898d7b9a5b02175 to your computer and use it in GitHub Desktop.
Charge someone $9.99 with stripe in only 34 lines!
This file contains 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
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