1/**
2 * Stripe webhook event classes. Each class is both the subscribe key
3 * (`events: [CustomerCreated]`) and the value the handler receives.
4 */
5import type {
6 Account,
7 CheckoutSession,
8 Customer,
9 Invoice,
10 PaymentIntent,
11 Subscription,
12} from "@distilled.cloud/stripe/stripe";
13
14export interface StripeEventClass<
15 Type extends string = string,
16 Object = unknown,
17> {
18 readonly type: Type;
19 new (object: any): StripeEventInstance<Type, Object>;
20}
21
22export interface StripeEventInstance<
23 Type extends string = string,
24 Object = unknown,
25> {
26 readonly type: Type;
27 readonly object: Object;
28}
29
30export class CustomerCreated {
31 static readonly type = "customer.created" as const;
32 readonly type = "customer.created" as const;
33 constructor(readonly object: Customer) {}
34}
35export class CustomerUpdated {
36 static readonly type = "customer.updated" as const;
37 readonly type = "customer.updated" as const;
38 constructor(readonly object: Customer) {}
39}
40export class CustomerDeleted {
41 static readonly type = "customer.deleted" as const;
42 readonly type = "customer.deleted" as const;
43 constructor(readonly object: Customer) {}
44}
45export class InvoicePaid {
46 static readonly type = "invoice.paid" as const;
47 readonly type = "invoice.paid" as const;
48 constructor(readonly object: Invoice) {}
49}
50export class InvoicePaymentFailed {
51 static readonly type = "invoice.payment_failed" as const;
52 readonly type = "invoice.payment_failed" as const;
53 constructor(readonly object: Invoice) {}
54}
55export class CheckoutSessionCompleted {
56 static readonly type = "checkout.session.completed" as const;
57 readonly type = "checkout.session.completed" as const;
58 constructor(readonly object: CheckoutSession) {}
59}
60export class PaymentIntentSucceeded {
61 static readonly type = "payment_intent.succeeded" as const;
62 readonly type = "payment_intent.succeeded" as const;
63 constructor(readonly object: PaymentIntent) {}
64}
65export class PaymentIntentFailed {
66 static readonly type = "payment_intent.payment_failed" as const;
67 readonly type = "payment_intent.payment_failed" as const;
68 constructor(readonly object: PaymentIntent) {}
69}
70export class CustomerSubscriptionCreated {
71 static readonly type = "customer.subscription.created" as const;
72 readonly type = "customer.subscription.created" as const;
73 constructor(readonly object: Subscription) {}
74}
75export class CustomerSubscriptionUpdated {
76 static readonly type = "customer.subscription.updated" as const;
77 readonly type = "customer.subscription.updated" as const;
78 constructor(readonly object: Subscription) {}
79}
80export class CustomerSubscriptionDeleted {
81 static readonly type = "customer.subscription.deleted" as const;
82 readonly type = "customer.subscription.deleted" as const;
83 constructor(readonly object: Subscription) {}
84}
85/**
86 * Fires whenever a Connect account changes — most usefully when a merchant
87 * finishes hosted onboarding and `charges_enabled` / `payouts_enabled`
88 * flip to `true`.
89 */
90export class AccountUpdated {
91 static readonly type = "account.updated" as const;
92 readonly type = "account.updated" as const;
93 constructor(readonly object: Account) {}
94}