const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); /* * Next available dates loaded from some database */ const calendar = require('./data/calendar.json'); exports.handler = async (event) => { const nextDates = getNextDates(calendar) const { startDate, endDate } = nextDates; const session = await stripe.checkout.sessions.create({ mode: 'payment', /* * This env var is set by Netlify and inserts the live site URL. If you want * to use a different URL, you can hard-code it here or check out the * other environment variables Netlify exposes: * https://docs.netlify.com/configure-builds/environment-variables/ */ success_url: `${process.env.URL}/success.html`, cancel_url: process.env.URL, line_items: [ { price_data: { currency: 'cad', unit_amount: 100000, // in cents product_data: { name: 'Product Coaching', description: dateDescription(nextDates), }, }, quantity: 1, }, ], // We are using the metadata to track which items were purchased. // We can access this meatadata in our webhook handler to then handle // the fulfillment process. // In a real application you would track this in an order object in your database. metadata: { start_date: startDate, end_date: endDate }, }); }