Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // Add packages we need
  2. const express = require('express')
  3. const bodyParser = require('body-parser')
  4. var stripe = require('stripe')('YOUR SECRET KEY FROM STRIPE')
  5.  
  6. // Create an express app
  7. const app = express()
  8.  
  9. // Use body parser so we can parse the body of requests
  10. app.use(bodyParser.json())
  11.  
  12. // Just a sanity check endpoint we can hit in the browser
  13. app.get('/', function (req, res) {
  14. res.send('Hello World!')
  15. })
  16.  
  17. app.post('/pay', function (req, res) {
  18. console.log('Pay request')
  19.  
  20. var token = req.body.stripeToken
  21. var amount = req.body.amount
  22. var description = req.body.description
  23.  
  24. stripe.charges.create({
  25. amount: amount,
  26. currency: "cad",
  27. description: description,
  28. source: token,
  29. }, function(err, charge) {
  30. if (err !== null) {
  31. console.log('error capturing')
  32. console.log(err)
  33. res.status(400).send('error')
  34. } else {
  35. console.log('success')
  36. res.status(200).send('success')
  37. }
  38. });
  39. })
  40.  
  41. app.listen(3000, () => {
  42. console.log('apple-pay-backend app listening on port 3000')
  43. })
Add Comment
Please, Sign In to add comment