Skip to content

Latest commit

 

History

History

ugliest-todo-stripe-netlify

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Ugliest Todo using Netlify Functions & Stripe

Overview

This sample project uses Stripe's client-only Checkout to charge for a one-time product or a recurring subscription and uses Netlify Functions to handle the payment succeeded webhook to the update our Userbase user status to paid.

Setup

Runing locally

  1. Create your .env file and add your secrets:
cp .env.example .env
  1. Add your client-side identifiers to the public/client_config.js file.

Note: make sure not to mix up the public identifiers in the client_confi.js with the secret keys in the .env file. The content of the .env file needs to be kept secret and never commited to git. That's why we have .env in our .gitignore file.

  1. Install the Stripe CLI & login with your Stripe account.

  2. Start the webhook event forwarding:

stripe listen --forward-to http://localhost:34567/checkout

Note: The Stripe CLI will return your webhook signing secret: whsec_1234. Copy the secret and paste it into your .env file.

  1. In a separate terminal window, install the Netlify cli

  2. Install the dependencies for the function:

npm install
  1. Run the Netlify dev server
netlify dev

🎉 Watch your terminal windows for webhook events and error logs.

Deploy to Netlify

Your Netlify Function will have the following URL shape (https://your-project-name.netlify.com/.netlify/functions/checkout). Use this to create a live webhook endpoint in your Stripe dashboard.

Your live webhook will have a different signing secret, which you can retrieve from the webhook details page. Use this secret in your Netlify deploy settings.

The Netlify deploy command will not set up the variables from your .env file. You will need to set up your secrets manually in the Netlify build settings.

Now run:

netlify deploy --prod --functions=functions