stripe-middleware

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i stripe-middleware

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

5.66 kB

Total Files

6

Last publish

Collaborators

  • archerhume