Last active
January 9, 2018 05:51
-
-
Save shiningabdul/3f2514f2f7c580ba98f46e5de3cf22ca to your computer and use it in GitHub Desktop.
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
// Add packages we need | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
var stripe = require('stripe')('YOUR SECRET KEY FROM STRIPE') | |
// Create an express app | |
const app = express() | |
// Use body parser so we can parse the body of requests | |
app.use(bodyParser.json()) | |
// Just a sanity check endpoint we can hit in the browser | |
app.get('/', function (req, res) { | |
res.send('Hello World!') | |
}) | |
app.post('/pay', function (req, res) { | |
console.log('Pay request') | |
var token = req.body.stripeToken | |
var amount = req.body.amount | |
var description = req.body.description | |
stripe.charges.create({ | |
amount: amount, | |
currency: "cad", | |
description: description, | |
source: token, | |
}, function(err, charge) { | |
if (err !== null) { | |
console.log('error capturing') | |
console.log(err) | |
res.status(400).send('error') | |
} else { | |
console.log('success') | |
res.status(200).send('success') | |
} | |
}); | |
}) | |
app.listen(3000, () => { | |
console.log('apple-pay-backend app listening on port 3000') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment