Go · 8921 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4
5 package billingdb
6
7 import (
8 "context"
9
10 "github.com/jackc/pgx/v5/pgtype"
11 )
12
13 type Querier interface {
14 ApplySubscriptionSnapshot(ctx context.Context, db DBTX, arg ApplySubscriptionSnapshotParams) (ApplySubscriptionSnapshotRow, error)
15 // Mirrors ApplySubscriptionSnapshot for orgs minus the seat columns
16 // and with `user_plan` as the plan enum. The same CTE pattern keeps
17 // users.plan and user_billing_states.plan atomic.
18 ApplyUserSubscriptionSnapshot(ctx context.Context, db DBTX, arg ApplyUserSubscriptionSnapshotParams) (ApplyUserSubscriptionSnapshotRow, error)
19 ClearBillingLock(ctx context.Context, db DBTX, orgID int64) (ClearBillingLockRow, error)
20 ClearUserBillingLock(ctx context.Context, db DBTX, userID int64) (ClearUserBillingLockRow, error)
21 CountBillableOrgMembers(ctx context.Context, db DBTX, orgID int64) (int32, error)
22 CountPendingOrgInvitations(ctx context.Context, db DBTX, orgID int64) (int32, error)
23 // ─── billing_seat_snapshots ────────────────────────────────────────
24 CreateSeatSnapshot(ctx context.Context, db DBTX, arg CreateSeatSnapshotParams) (CreateSeatSnapshotRow, error)
25 // ─── billing_webhook_events ────────────────────────────────────────
26 CreateWebhookEventReceipt(ctx context.Context, db DBTX, arg CreateWebhookEventReceiptParams) (BillingWebhookEvent, error)
27 // SPDX-License-Identifier: AGPL-3.0-or-later
28 // ─── org_billing_states ────────────────────────────────────────────
29 GetOrgBillingState(ctx context.Context, db DBTX, orgID int64) (OrgBillingState, error)
30 GetOrgBillingStateByStripeCustomer(ctx context.Context, db DBTX, stripeCustomerID pgtype.Text) (OrgBillingState, error)
31 GetOrgBillingStateByStripeSubscription(ctx context.Context, db DBTX, stripeSubscriptionID pgtype.Text) (OrgBillingState, error)
32 // ─── user_billing_states (PRO03) ──────────────────────────────────
33 GetUserBillingState(ctx context.Context, db DBTX, userID int64) (UserBillingState, error)
34 GetUserBillingStateByStripeCustomer(ctx context.Context, db DBTX, stripeCustomerID pgtype.Text) (UserBillingState, error)
35 GetUserBillingStateByStripeSubscription(ctx context.Context, db DBTX, stripeSubscriptionID pgtype.Text) (UserBillingState, error)
36 GetWebhookEventReceipt(ctx context.Context, db DBTX, providerEventID string) (BillingWebhookEvent, error)
37 // PRO08 D4: returns true when an incoming Stripe event's timestamp
38 // is older than the last event we've already applied for this org.
39 // Stripe doesn't guarantee delivery order across retries; without
40 // this guard a stale `subscription.updated[active]` could re-activate
41 // a canceled subscription. Returns false when no prior event has
42 // been recorded (last_event_at IS NULL) — the first event is never
43 // stale.
44 IsOrgBillingEventStale(ctx context.Context, db DBTX, arg IsOrgBillingEventStaleParams) (bool, error)
45 IsUserBillingEventStale(ctx context.Context, db DBTX, arg IsUserBillingEventStaleParams) (bool, error)
46 // Operator query for "events we received but failed to process."
47 // A row is "failed" when it has a non-empty process_error OR when
48 // it has never been processed (processed_at NULL) and has at least
49 // one processing attempt. Rows that are merely new and untouched
50 // (attempts=0, processed_at NULL, no error) are excluded.
51 ListFailedWebhookEvents(ctx context.Context, db DBTX, limit int32) ([]ListFailedWebhookEventsRow, error)
52 // PRO03: filters on the polymorphic subject columns so the index
53 // billing_invoices_subject_created_idx services this query. The
54 // legacy `org_id` column is kept populated by UpsertInvoice for the
55 // transitional window; this query no longer reads it.
56 ListInvoicesForOrg(ctx context.Context, db DBTX, arg ListInvoicesForOrgParams) ([]BillingInvoice, error)
57 // Polymorphic invoice listing for PRO04+ callers. The org-flavored
58 // ListInvoicesForOrg above is the same query with subject_kind
59 // hard-coded; this surface lets a user-side caller pass kind='user'
60 // without forking the helper.
61 ListInvoicesForSubject(ctx context.Context, db DBTX, arg ListInvoicesForSubjectParams) ([]BillingInvoice, error)
62 ListSeatSnapshotsForOrg(ctx context.Context, db DBTX, arg ListSeatSnapshotsForOrgParams) ([]BillingSeatSnapshot, error)
63 MarkCanceled(ctx context.Context, db DBTX, arg MarkCanceledParams) (MarkCanceledRow, error)
64 // PRO08 D2: surface a Stripe-side refund in shithub. Stripe leaves
65 // the invoice.status='paid' after a refund and fires a charge.refunded
66 // event; this helper flips the shithub-side row to 'refunded' so the
67 // billing settings UI shows the refunded state.
68 //
69 // A NULL refunded_at means "no refund seen"; the value is set on the
70 // first call and preserved on subsequent calls (refund partial → full
71 // doesn't move the wall-clock timestamp).
72 MarkInvoiceRefunded(ctx context.Context, db DBTX, stripeInvoiceID string) (BillingInvoice, error)
73 MarkPastDue(ctx context.Context, db DBTX, arg MarkPastDueParams) (OrgBillingState, error)
74 MarkPaymentSucceeded(ctx context.Context, db DBTX, arg MarkPaymentSucceededParams) (MarkPaymentSucceededRow, error)
75 MarkUserCanceled(ctx context.Context, db DBTX, arg MarkUserCanceledParams) (MarkUserCanceledRow, error)
76 MarkUserPastDue(ctx context.Context, db DBTX, arg MarkUserPastDueParams) (UserBillingState, error)
77 MarkUserPaymentSucceeded(ctx context.Context, db DBTX, arg MarkUserPaymentSucceededParams) (MarkUserPaymentSucceededRow, error)
78 MarkWebhookEventFailed(ctx context.Context, db DBTX, arg MarkWebhookEventFailedParams) (BillingWebhookEvent, error)
79 MarkWebhookEventProcessed(ctx context.Context, db DBTX, providerEventID string) (BillingWebhookEvent, error)
80 SetStripeCustomer(ctx context.Context, db DBTX, arg SetStripeCustomerParams) (OrgBillingState, error)
81 SetUserStripeCustomer(ctx context.Context, db DBTX, arg SetUserStripeCustomerParams) (UserBillingState, error)
82 // Records the resolved subject on the receipt row after a successful
83 // subject-resolution step. Called from the apply path before guard +
84 // state mutation so the receipt carries the audit trail even if the
85 // subsequent apply fails. Migration 0075's CHECK constraint enforces
86 // both-or-neither; callers must pass a non-zero subject.
87 SetWebhookEventSubject(ctx context.Context, db DBTX, arg SetWebhookEventSubjectParams) error
88 // PRO08 D4: bump last_event_at on successful apply. Conditional so
89 // a fresh apply driven by an out-of-order-but-recent retry doesn't
90 // regress the timestamp (GREATEST). NULL last_event_at acquires the
91 // incoming value.
92 TouchOrgBillingLastEventAt(ctx context.Context, db DBTX, arg TouchOrgBillingLastEventAtParams) error
93 TouchUserBillingLastEventAt(ctx context.Context, db DBTX, arg TouchUserBillingLastEventAtParams) error
94 // PRO08 A3: transaction-scoped advisory lock keyed on the hash of
95 // the provider_event_id. Two concurrent webhook deliveries for the
96 // same event_id race past CreateWebhookEventReceipt before either has
97 // marked it processed; without serialization, both proceed to apply
98 // and double-mutate state. This lock makes the apply path mutually
99 // exclusive per event. Returns true when acquired; false means
100 // another worker holds it — caller should let Stripe retry.
101 //
102 // pg_try_advisory_xact_lock takes a bigint; hashtext returns int4
103 // which sign-extends safely. The lock auto-releases at txn end.
104 TryAcquireWebhookEventLock(ctx context.Context, db DBTX, hashtext string) (bool, error)
105 // ─── billing_invoices ──────────────────────────────────────────────
106 // PRO03: writes both legacy `org_id` and polymorphic
107 // `(subject_kind, subject_id)`. Callers continue to bind org_id only;
108 // the subject columns are derived. After PRO04 migrates all callers
109 // to the polymorphic shape, a follow-up migration drops `org_id` and
110 // this query loses the legacy column from its INSERT list.
111 UpsertInvoice(ctx context.Context, db DBTX, arg UpsertInvoiceParams) (BillingInvoice, error)
112 // PRO04 polymorphic invoice upsert. Writes (subject_kind,
113 // subject_id) directly; org_id stays NULL for user-kind rows (per
114 // the 0074 migration's nullable change). The existing
115 // UpsertInvoice query stays as the org-kind path during the
116 // transitional deploy — both can coexist because the UNIQUE
117 // (provider, stripe_invoice_id) prevents duplicate rows.
118 UpsertInvoiceForSubject(ctx context.Context, db DBTX, arg UpsertInvoiceForSubjectParams) (BillingInvoice, error)
119 }
120
121 var _ Querier = (*Queries)(nil)
122