Skip to content

Instantly share code, notes, and snippets.

@shiningabdul
Last active January 9, 2018 05:51
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 shiningabdul/3f2514f2f7c580ba98f46e5de3cf22ca to your computer and use it in GitHub Desktop.
Save shiningabdul/3f2514f2f7c580ba98f46e5de3cf22ca to your computer and use it in GitHub Desktop.
// 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