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.`})
    }
  })
})