Skip to content

Instantly share code, notes, and snippets.

@ColeTownsend
Created April 22, 2017 01:16
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 ColeTownsend/1c17cfe0f1101609bffaeb7027c121f7 to your computer and use it in GitHub Desktop.
Save ColeTownsend/1c17cfe0f1101609bffaeb7027c121f7 to your computer and use it in GitHub Desktop.
For Micro Stripe Demo
require('dotenv').config(); // we need our dotenv stuff
const {send, json} = require('micro');
const post = require('./post'); // we'll make this soon don't worry.
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); // this is our stripe key! use your testing key for now.
module.exports = post(async (req, res) => {
const data = await json(req);
stripe.charges.create(data, (err, resp) => {
if (err) {
send(res, 400, {error: `Charge could not be created.`})
}
else {
send(res, 200, {message: `Charge created.`})
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment