X Framework
Adapters

Stripe Adapter

Add Stripe payments to your X Framework application

Stripe Adapter

The Stripe adapter provides a type-safe wrapper around your Stripe client and handles webhook verification.

Installation

pnpm add @xframework/stripe stripe

Usage

import Stripe from "stripe";
import { StripeAdapter } from "@xframework/stripe";
 
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
 
const x = createX()
  .syncAdapter(
    "stripe",
    () =>
      new StripeAdapter({
        client: stripe,
        webhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
      }),
  )
  .build();
 
// Access Stripe client
const customer = await x.stripe.client.customers.create({
  email: "[email protected]",
});

Webhook Handler

The adapter provides a handleWebhookRequest method that verifies the webhook signature:

x.hono.post("/webhook", async (c) => {
  const event = await x.stripe.handleWebhookRequest(c.req.raw);
  // event is a verified Stripe webhook event
  return c.text("ok");
});

For more details on using Stripe, see the Stripe documentation.

On this page