stripe's notebooks

  • Create {Payment|Setup}Intents Endpoint - /stripe/create-intents
    Last edited 5 years ago
    const stripe = require("stripe")(process.env.STRIPE_SECRET_TEST_KEY); const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use("/", function(req, res, next) { // Allow requests from localhost. const allowedOrigins = ['http://localhost:8080']; const origin = req.headers.origin; if (allowedOrigins.indexOf(origin) > -1) { res.setHeader("Access-Control-Allow-Headers", "*"); res.setHeader('Access-Control-Allow-Origin', origin); } next(); }); app.post("/payment_intents", async (req, res) => { const { options } = req.body; const paymentIntent = await stripe.paymentIntents.create(options); res.json(paymentIntent); }); app.post("/setup_intents", async (req, res) => { const { options } = req.body; const setupIntent = await stripe.setupIntents.create(options); res.json(setupIntent); });