Skip to content

Instantly share code, notes, and snippets.

@ademcan
Created March 24, 2020 16: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 ademcan/9f389aa3ccfe0a110d0c881b757edb47 to your computer and use it in GitHub Desktop.
Save ademcan/9f389aa3ccfe0a110d0c881b757edb47 to your computer and use it in GitHub Desktop.
// import all the required packages
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const logger = require("morgan");
// define port number
const port = process.env.PORT || 3001;
// instantiate express with the correct parameters
app.use(logger('dev'));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// create a Router
const router = express.Router();
// example of a GET method that returns a simple "Hello World"
router.get('/', (req, res) => {
res.send( "Hello World!" );
});
var stripe_sk = 'sk_test_XXXXXXXXXX';
router.post('/createStripePaymentIntent', function (req, res) {
var stripe = require("stripe")(stripe_sk);
stripe.paymentIntents.create({
amount: 1099,
currency: 'usd'
}, function (err, paymentIntent) {
res.json({
setupIntentId: paymentIntent.client_secret
})
});
})
// define the router to use
app.use('/', router);
// start express
app.listen(port, function() {
console.log("Runnning on " + port);
});
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment