fastify-xstripe
Stripe webhook plugin with simplified, testable handlers for subscription events.
fastify-xstripe
Stripe integration with webhook signature verification and simplified subscription event handlers.
Installation
npm install @xenterprises/fastify-xstripe
Quick Start
await fastify.register(xStripe, {
secretKey: process.env.STRIPE_SECRET_KEY,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
webhookPath: '/webhooks/stripe',
handlers: {
'customer.subscription.created': async (event) => {
const subscription = event.data.object
await db.users.update({
where: { stripeCustomerId: subscription.customer },
data: { plan: subscription.items.data[0].price.id }
})
},
'customer.subscription.deleted': async (event) => {
// handle cancellation
},
},
})
Direct Stripe Access
// Access Stripe SDK directly
const customer = await fastify.xstripe.client.customers.create({
email: user.email,
metadata: { userId: user.id },
})
AI Context
package: "@xenterprises/fastify-xstripe"
type: fastify-plugin
decorates: fastify.xstripe
routes: POST /webhooks/stripe (configurable)
use-when: Stripe subscriptions, one-time payments, webhook handling
webhook-verification: automatic signature verification using STRIPE_WEBHOOK_SECRET
common-events: [customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.payment_failed, checkout.session.completed]
env-required: [STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET]
