1.0.1 • Published 11 months ago

stripe-middleware v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

1.0.1

11 months ago

1.0.0

11 months ago