https://github.com/thorwebdev/checkout-netlify-serverless
https://github.com/thorwebdev/checkout-netlify-serverless
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thorwebdev/checkout-netlify-serverless
- Owner: thorwebdev
- License: mit
- Created: 2020-04-14T01:13:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T01:14:13.000Z (about 6 years ago)
- Last Synced: 2025-03-26T02:52:00.375Z (about 1 year ago)
- Language: HTML
- Size: 750 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless Stripe Checkout with Netlify Functions
Use Stripe Checkout with Netlify Functions to sell your products online.
## Demo
- https://checkout-netlify-serverless.netlify.com
- [Written tutorial](https://www.netlify.com/blog/2020/04/13/learn-how-to-accept-money-on-jamstack-sites-in-38-minutes/)
- [Video lessons on egghead](https://jason.af/egghead/stripe-products)
- Live coding session on [learnwithjason.dev](https://www.learnwithjason.dev/sell-products-on-the-jamstack)

## Features:
- Load products from a JSON product catalogue
- Create Checkout Sessions with Netlify Functions
- Process Stripe webhook events with Netlify Functions to handle fulfillment
## How to run locally
### Prerequisites
- [Node](https://nodejs.org/en/) >= 10
- [Netlify CLI](https://docs.netlify.com/cli/get-started/#installation)
- [Stripe CLI](https://stripe.com/docs/stripe-cli)
Follow the steps below to run locally.
**1. Clone and configure the sample**
The Stripe CLI is the fastest way to clone and configure a sample to run locally.
**Using the Stripe CLI**
If you haven't already installed the CLI, follow the [installation steps](https://github.com/stripe/stripe-cli#installation) in the project README. The CLI is useful for cloning samples and locally testing webhooks and Stripe integrations.
In your terminal shell, run the Stripe CLI command to clone the sample:
```
stripe samples create checkout-netlify-serverless
```
The CLI will walk you through picking your integration type, server and client languages, and configuring your .env config file with your Stripe API keys.
**Installing and cloning manually**
If you do not want to use the Stripe CLI, you can manually clone and configure the sample yourself:
```
git clone https://github.com/stripe-samples/checkout-netlify-serverless
```
Copy the .env.example file into a file named .env in the functions folder. For example:
```
cp functions/.env.example functions/.env
```
You will need a Stripe account in order to run the demo. Once you set up your account, go to the Stripe [developer dashboard](https://stripe.com/docs/development#api-keys) to find your API keys.
```
STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET_KEY=
```
**2. Run Netlify Functions locally:**
You can run the Netlify Functions locally with Netlify Dev:
```
npm run functions
netlify dev
```
**3. [Optional] Run a webhook locally:**
If you want to test the `using-webhooks` integration with a local webhook on your machine, you can use the Stripe CLI to easily spin one up.
Make sure to [install the CLI](https://stripe.com/docs/stripe-cli) and [link your Stripe account](https://stripe.com/docs/stripe-cli#link-account).
In a separate tab run
```
stripe listen --forward-to localhost:8888/.netlify/functions/handle-purchase
```
Or use the shorthand `npm run webhook`
The CLI will print a webhook secret key to the console. Set `STRIPE_WEBHOOK_SECRET` to this value in your .env file.
You should see events logged in the console where the CLI is running.
When you are ready to create a live webhook endpoint, follow our guide in the docs on [configuring a webhook endpoint in the dashboard](https://stripe.com/docs/webhooks/setup#configure-webhook-settings).
### 💫 Deploy with Netlify
[](https://app.netlify.com/start/deploy?repository=https://github.com/stripe-samples/checkout-netlify-serverless)
## Authors
- [jlengstorf](https://twitter.com/jlengstorf)
- [thorsten-stripe](https://twitter.com/thorwebdev)