Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renenielsendk/nextjs-stripe-webhook
A plug-and-play Next.js application designed for seamless handling of Stripe webhooks. Start accepting events from Stripe in under 10 minutes.
https://github.com/renenielsendk/nextjs-stripe-webhook
nextjs nextjs14 stripe webhook
Last synced: about 1 month ago
JSON representation
A plug-and-play Next.js application designed for seamless handling of Stripe webhooks. Start accepting events from Stripe in under 10 minutes.
- Host: GitHub
- URL: https://github.com/renenielsendk/nextjs-stripe-webhook
- Owner: renenielsendk
- License: mit
- Created: 2024-08-18T09:50:52.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-29T21:59:29.000Z (4 months ago)
- Last Synced: 2024-08-29T23:54:30.954Z (4 months ago)
- Topics: nextjs, nextjs14, stripe, webhook
- Language: TypeScript
- Homepage: https://github.com/renenielsendk/nextjs-stripe-webhook/blob/main/README.md
- Size: 2.88 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NextJS Stripe Webhook
The NextJS Stripe Webhook project sets up the core structure for handling Stripe webhook events in a Next.js app. It handles all the boilerplate around processing webhooks, letting you focus on implementing your custom logic.
You get a clean, ready-to-use setupβjust drop in your business logic and start managing Stripe events effortlessly.
- [Introduction](#introduction)
- [Built with](#built-with)
- [Features](#features)
- [Streamlined Logging](#streamlined-logging)
- [Uniform Error Handling](#uniform-error-handling)
- [Code Prettier](#code-prettier)
- [Code Validation](#code-validation)
- [Example Implementations](#example-implementations)
- [Getting Started](#getting-started)
- [Local Development](#step-1-local-development)
- [Deploy Your Application](#step-2-deploy-your-application)
- [Configure Stripe Webhook](#step-3-configure-stripe-webhook)
- [License](#license)
- [Links](#links)## Built with
- [Next.js](https://nextjs.org/)
- [Stripe](https://stripe.com/)
- [TypeScript](https://www.typescriptlang.org/)
- [Node.js](https://nodejs.org/)## Features
### Streamlined Logging
This project utilizes [Pino logger](https://github.com/pinojs/pino) for streamlined logging, enabling you to easily trace logs throughout the application.
![Logging](./docs/logging.png)
### Uniform Error Handling
You can throw errors anywhere in your implementation using the [APIError](https://github.com/renenielsendk/nextjs-stripe-webhook/blob/3f5c97cee5b270d28445dc06940be0744957ee6f/src/_shared/types/api.ts#L6).
These errors are consistently caught and returned as HTTP responses.
Example:
```
const user = await db.user.find({ id: '1' });if (!user) {
throw new ApiError({
type: 'NotFoundError',
message: 'User not found', // optional
});
}
```The above example will return Http Status `404` with body `{ message: 'User not found'}`.
![Postman error](./docs/postman-error.png)
### Code Prettier
Running `yarn prettier` will format your code to a consistent style, ensuring a uniform codebase.
### Code Validation
Running `yarn validate` will validate the entire codebase, helping to maintain code quality and consistency.
![Validation](./docs/validating.png)
## Example Implementations
This project includes example implementations for handling specific Stripe webhook events. These examples show how to manage the following events within your application:
### API Route
- **Method**: POST
- **Path**: `/api/webhook`
- **Description**: Handles incoming Stripe webhook events.### Supported Webhook Events
- **`payment_intent.succeeded`**: Handles successful payment intents.
- **`account.updated`**: Handles updates to Stripe accounts.These events are implemented with example handlers, demonstrating how to process them effectively in your application.
## Getting Started
### Step 1: Local Development
To start working with this project locally, follow these steps:
1. **Fork this repository**: Create your own fork of this repository on GitHub.
2. **Clone the repository**: Clone your forked repository to your local machine.
3. **Navigate to the project directory**: Move into the directory where the project was cloned.
4. **Install dependencies**: Run `yarn install` to install all required dependencies.
5. **Set up environment variables**: Copy `.env.example` to `.env.local` and update the environment variables with your Stripe secret keys and other necessary configurations.
6. **Start the development server**: Run `yarn dev` to start the development server.### Step 2: Deploy Your Application
Once your business logic is implemented and tested locally, deploy your application using your preferred hosting service (e.g., Vercel, Netlify, Heroku).
### Step 3: Configure Stripe Webhook
After deploying your application, configure the Stripe webhook to point to your deployed endpoint. Follow [this guide](./docs/stripe-dashboard-add-webhook/README.md) to set up the webhook in your Stripe dashboard.
### Step 4: Celebrate
![Success](./docs/success-1.png)
πππ
![Success 2](./docs/success-2.png)
πππ
![Great success](./docs/success-3.gif)
## License
Licensed under [MIT](./LICENSE.md).
## Links
Looking for more exciting projects and insights?
ππ
Connect with me on [π @renenielsendk](https://x.com/renenielsendk) for updates, tips, and more awesome content!
#nextjs, #stripe, #stripe-checkout, #subscription, #api, #template, #webhook