Skip to content

ArcherHume/stripe-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stripe-middleware

Stripe Logo

ExpressJS middleware for validating and handling Stripe webhooks.

Installation

Install the package via npm (never yarn):

npm install --save stripe-middleware

Usage

In your Express application, you can use the stripe-middleware to handle incoming Stripe webhook events and validate them using the Stripe Webhook Signing Secret.

Here's an example server setup:

const express = require("express");
const StripeMiddleware = require("stripe-middleware")("YOUR_WEBHOOK_SIGNING_SECRET");

const app = express();

app.use(
  express.json({
    verify: (req, res, buffer) => (req["rawBody"] = buffer),
  })
);

app.post(
  "/stripe-webhook",
  StripeMiddleware,
  (req, res) => {
    console.log(req.stripe);
    res.send("Hello World!");
  }
);

app.listen(3000, () => {
  console.log("Example app listening on port 3000!");
});

Replace "YOUR_WEBHOOK_SIGNING_SECRET" with your Stripe Webhook Signing Secret, which you can find in your Stripe Dashboard under the webhook endpoint details.

When using the middleware, the Express route handler will have access to the validated and constructed Stripe event object through req.stripe.

License

MIT

Author

Archer Hume

About

💳 ExpressJS middleware for validating and handling Stripe webhooks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published