stripe-middleware
v1.0.1
Published
ExpressJS middleware for validating and handling Stripe webhooks.
Downloads
5
Maintainers
Readme
stripe-middleware
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