Created
March 10, 2022 14:11
-
-
Save guillaumeduhan/72b069939a8c01fb16eb05e862cf75b0 to your computer and use it in GitHub Desktop.
Stripe API create-payment-intent
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
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