Skip to content

Instantly share code, notes, and snippets.

@guillaumeduhan
Created March 10, 2022 14:11
Show Gist options
  • Save guillaumeduhan/72b069939a8c01fb16eb05e862cf75b0 to your computer and use it in GitHub Desktop.
Save guillaumeduhan/72b069939a8c01fb16eb05e862cf75b0 to your computer and use it in GitHub Desktop.
Stripe API create-payment-intent
require("dotenv").config()
const express = require('express')
const app = express()
const cors = require('cors')
const bodyParser = require('body-parser')
const PORT = process.env.PORT || 4000
app.use(cors());
app.use(express.json());
app.use(bodyParser.json(), cors())
app.options('*', cors());
const Stripe = require('stripe');
app.get('/', (req, res) => {
res.send('🟢 Stripe working good bro.')
})
app.post('/create-payment-intent', async (req, res) => {
const { data, env } = req.body;
const finalEnv = process.env[env === 'development' ? 'STRIPE_TEST' : 'STRIPE_LIVE'];
const stripe = Stripe(finalEnv);
const paymentIntent = await stripe.paymentIntents.create(data);
res.send(paymentIntent)
})
app.listen(PORT, () => console.log('Launched on port ' + PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment