Skip to main content
Aarunya AppsAarunya Apps

Stripe Webhook TypeScript Types

Auto-generated TypeScript interfaces for the Stripe checkout.session.completed webhook event. Copy the types directly into your project.

Stripe Webhook — Sample JSON

{
  "id": "evt_1OsZQH2eZvKYlo2C8BXF3tDj",
  "object": "event",
  "api_version": "2023-10-16",
  "created": 1711928400,
  "data": {
    "object": {
      "id": "cs_test_a1b2c3d4e5f6g7h8",
      "object": "checkout.session",
      "amount_total": 4999,
      "currency": "usd",
      "customer": "cus_Px1234567890ab",
      "customer_email": "user@example.com",
      "mode": "payment",
      "payment_intent": "pi_3OzXXXX2eZvKYlo2C",
      "payment_status": "paid",
      "status": "complete",
      "success_url": "https://example.com/success"
    }
  },
  "livemode": false,
  "pending_webhooks": 1,
  "type": "checkout.session.completed"
}

Generated TypeScript

export interface Object {
  id: string;
  object: string;
  amount_total: number;
  currency: string;
  customer: string;
  customer_email: string;
  mode: string;
  payment_intent: string;
  payment_status: string;
  status: string;
  success_url: string;
}

export interface Data {
  object: Object;
}

export interface StripeCheckoutEvent {
  id: string;
  object: string;
  api_version: string;
  created: number;
  data: Data;
  livemode: boolean;
  pending_webhooks: number;
  type: string;
}

How to use

Copy the TypeScript above into a types.ts file in your project. Import the root interface and use it to type your API responses: const data: StripeCheckoutEvent = await res.json()

Working with a different JSON payload? Paste any JSON and generate TypeScript interfaces instantly.

Convert your own JSON →

FAQ

How do I use these TypeScript types in my Stripe webhook handler?

Copy the generated interfaces into a types file (e.g. stripe.types.ts), then import and use them to type your webhook handler: async function handleWebhook(event: StripeCheckoutEvent) { ... }. This gives you autocomplete on event.data.object.amount_total, event.type, etc.

Do I need @types/stripe if I use these generated types?

Not necessarily. The Stripe npm SDK ships its own TypeScript types which are more complete (handling all event types). These generated types are useful for quick prototyping, Cloudflare Workers, or environments where you don't want to install the full Stripe SDK.

Why does the generated TypeScript use 'unknown' for some fields?

The generator infers types from the sample JSON. Fields that are null in the sample (like logprobs, stageVariables) are typed as unknown because there's no value to infer from. You can manually refine these to the correct type after generating.

Powered by Aarunya Apps