Documentation
¶
Index ¶
- type Repo
- func (r *Repo) CancelOrder(ctx context.Context, id string, from domain.OrderStatus, canceledBy string, ...) error
- func (r *Repo) ChangeWorkspacePlan(ctx context.Context, workspaceID, toPlan, actor, reason string, now time.Time, ...) error
- func (r *Repo) ClearWorkspaceCancelRequested(ctx context.Context, workspaceID string) error
- func (r *Repo) CreateOrder(ctx context.Context, o domain.Order) (domain.Order, error)
- func (r *Repo) ExpireDueWorkspaces(ctx context.Context, now time.Time, limit int) ([]app.ExpiredWorkspace, error)
- func (r *Repo) ExpireStaleOrders(ctx context.Context, now time.Time, limit int) ([]app.ExpiredOrder, error)
- func (r *Repo) FailOrder(ctx context.Context, o domain.Order, e domain.PaymentEvent, ...) error
- func (r *Repo) FindOrderByChannelRef(ctx context.Context, channel, channelRef string) (domain.Order, bool, error)
- func (r *Repo) FindOrderByPaymentIntent(ctx context.Context, paymentIntentRef string) (domain.Order, bool, error)
- func (r *Repo) FindWorkspaceBySubscription(ctx context.Context, subscriptionRef string) (string, string, bool, error)
- func (r *Repo) GetChannelProduct(ctx context.Context, channel, planCode string, interval domain.BillingInterval) (domain.ChannelProduct, bool, error)
- func (r *Repo) GetMeter(ctx context.Context, slug string) (app.Meter, bool, error)
- func (r *Repo) GetOrder(ctx context.Context, id string) (domain.Order, bool, error)
- func (r *Repo) GetPlan(ctx context.Context, code string) (domain.Plan, bool, error)
- func (r *Repo) GetWorkspaceCancelRequested(ctx context.Context, workspaceID string) (time.Time, bool, error)
- func (r *Repo) GetWorkspacePlan(ctx context.Context, workspaceID string) (string, error)
- func (r *Repo) GetWorkspacePlanExpiry(ctx context.Context, workspaceID string) (time.Time, bool, error)
- func (r *Repo) GetWorkspaceSubscription(ctx context.Context, workspaceID string) (string, bool, error)
- func (r *Repo) InsertOverageOrder(ctx context.Context, o domain.Order) (domain.Order, bool, error)
- func (r *Repo) InsertPaymentEvent(ctx context.Context, e domain.PaymentEvent) (bool, error)
- func (r *Repo) LatestPaidOrderInterval(ctx context.Context, workspaceID string) (string, bool, error)
- func (r *Repo) ListAllOrders(ctx context.Context, f app.AdminOrderFilter, limit, offset int) ([]app.AdminOrderView, int, error)
- func (r *Repo) ListCancelRequestedWorkspaces(ctx context.Context, limit int) ([]app.CancelRequestView, error)
- func (r *Repo) ListChannelProducts(ctx context.Context) ([]domain.ChannelProduct, error)
- func (r *Repo) ListMeteredWorkspaces(ctx context.Context, limit int) ([]app.MeteredWorkspace, error)
- func (r *Repo) ListMeters(ctx context.Context) ([]app.Meter, error)
- func (r *Repo) ListOrdersByWorkspace(ctx context.Context, workspaceID string, limit int) ([]domain.Order, error)
- func (r *Repo) ListPaymentEvents(ctx context.Context, f app.PaymentEventFilter, limit, offset int) ([]app.PaymentEventView, int, error)
- func (r *Repo) ListPlanCodes(ctx context.Context) ([]string, error)
- func (r *Repo) ListPlans(ctx context.Context) ([]domain.Plan, error)
- func (r *Repo) MarkEventError(ctx context.Context, channel, channelEventID, processErr string) error
- func (r *Repo) MarkEventProcessed(ctx context.Context, channel, channelEventID string) error
- func (r *Repo) PayOrder(ctx context.Context, id string, emit func(pgx.Tx) error, now time.Time) error
- func (r *Repo) RegisterChannelProductAtomic(ctx context.Context, channel, planCode string, interval domain.BillingInterval, ...) (string, bool, error)
- func (r *Repo) RegisterMeter(ctx context.Context, m app.Meter) error
- func (r *Repo) ReviveOrderAfterExpiry(ctx context.Context, id string, now time.Time) (bool, error)
- func (r *Repo) SetOrderChannelRefAndExpiry(ctx context.Context, id, channelRef string, expiresAt time.Time) error
- func (r *Repo) SetOrderPaymentIntentRef(ctx context.Context, orderID, paymentIntentRef string) error
- func (r *Repo) SetWorkspaceCancelRequested(ctx context.Context, workspaceID string, now time.Time) error
- func (r *Repo) SetWorkspaceSubscription(ctx context.Context, workspaceID, subscriptionRef string, ...) error
- func (r *Repo) UpdateOrderStatus(ctx context.Context, id string, from, to domain.OrderStatus, now time.Time) error
- func (r *Repo) UpdatePlan(ctx context.Context, code, name, limitsJSON string, sortNo int, ...) (found bool, err error)
- func (r *Repo) UpsertChannelProduct(ctx context.Context, p domain.ChannelProduct) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) CancelOrder ¶ added in v0.13.0
func (r *Repo) CancelOrder(ctx context.Context, id string, from domain.OrderStatus, canceledBy string, now time.Time) error
CancelOrder is the cancel-flavored UpdateOrderStatus that also stamps canceled_by (migration 051): 'user' / 'admin' for the human cancel paths, 'expiry' for the abandoned-checkout sweep. canceled_by drives the revival rule — only 'expiry' rows may be revived by a late paid event (ReviveOrderAfterExpiry); NULL (pre-051 rows), 'user' and 'admin' are terminal. ErrStatusConflict when the from-status does not match.
func (*Repo) ChangeWorkspacePlan ¶
func (*Repo) ClearWorkspaceCancelRequested ¶ added in v0.17.0
func (*Repo) CreateOrder ¶
func (*Repo) ExpireDueWorkspaces ¶
func (*Repo) ExpireStaleOrders ¶ added in v0.13.0
func (r *Repo) ExpireStaleOrders(ctx context.Context, now time.Time, limit int) ([]app.ExpiredOrder, error)
ExpireStaleOrders flips pending orders whose checkout session expired to canceled (F15 abandoned-checkout sweep), stamping canceled_by = 'expiry' so a late paid event can revive them (migration 051). The status literals 'pending'/'canceled' are same-source with domain.OrderPending / domain.OrderCanceled (an OrderStatus value cannot be interpolated into a SET clause without losing the natural-expression scan style used below). Single UPDATE with a locking subquery — atomic without an explicit tx; SKIP LOCKED keeps concurrent sweepers from fighting over rows. The caller chooses the cutoff (repo semantics stay `expires_at <= $1`); the worker passes now-orderSweepGrace so in-flight webhook retries get a grace window.
func (*Repo) FindOrderByChannelRef ¶
func (*Repo) FindOrderByPaymentIntent ¶
func (*Repo) FindWorkspaceBySubscription ¶
func (*Repo) GetChannelProduct ¶ added in v0.13.0
func (r *Repo) GetChannelProduct(ctx context.Context, channel, planCode string, interval domain.BillingInterval) (domain.ChannelProduct, bool, error)
func (*Repo) GetWorkspaceCancelRequested ¶ added in v0.17.0
func (*Repo) GetWorkspacePlan ¶
func (*Repo) GetWorkspacePlanExpiry ¶ added in v0.17.0
func (r *Repo) GetWorkspacePlanExpiry(ctx context.Context, workspaceID string) (time.Time, bool, error)
GetWorkspacePlanExpiry reads workspace.plan_expires_at (R5): the end of the currently paid period — the renews_at field of the subscription view. NULL (perpetual/manual plan) answers ok=false.
func (*Repo) GetWorkspaceSubscription ¶
func (*Repo) InsertOverageOrder ¶
func (*Repo) InsertPaymentEvent ¶
func (*Repo) LatestPaidOrderInterval ¶
func (*Repo) ListAllOrders ¶
func (r *Repo) ListAllOrders(ctx context.Context, f app.AdminOrderFilter, limit, offset int) ([]app.AdminOrderView, int, error)
func (*Repo) ListCancelRequestedWorkspaces ¶ added in v0.17.0
func (*Repo) ListChannelProducts ¶ added in v0.13.0
func (*Repo) ListMeteredWorkspaces ¶
func (*Repo) ListOrdersByWorkspace ¶
func (*Repo) ListPaymentEvents ¶
func (r *Repo) ListPaymentEvents(ctx context.Context, f app.PaymentEventFilter, limit, offset int) ([]app.PaymentEventView, int, error)
func (*Repo) MarkEventError ¶
func (*Repo) MarkEventProcessed ¶
func (*Repo) RegisterChannelProductAtomic ¶ added in v0.13.0
func (r *Repo) RegisterChannelProductAtomic(ctx context.Context, channel, planCode string, interval domain.BillingInterval, register func(ctx context.Context) (string, error), syncedPriceCents int, syncedAt time.Time) (string, bool, error)
RegisterChannelProductAtomic closes the register double-click race (billing fix #12, 2026-10-24): check-then-create over the channel REST is not a DB-only sequence, so the mapping check and upsert are wrapped in one transaction holding pg_advisory_xact_lock keyed on (channel, plan, interval). The channel REST itself cannot join the transaction — the chosen trade-off is to run the register callback INSIDE the lock: concurrent double-clicks serialize (second caller blocks until the first commits, then sees the mapping and returns existed=true instead of creating a duplicate channel product). Residual risk, accepted and documented: the lock is held for the duration of one channel REST call, so a hung channel endpoint stalls other registrations of the SAME mapping only (different mappings hash to different lock keys and proceed in parallel).
func (*Repo) ReviveOrderAfterExpiry ¶ added in v0.13.0
ReviveOrderAfterExpiry performs the single sanctioned exit from canceled: canceled → paid, and only when canceled_by = 'expiry' (the abandoned-checkout sweep). A payment that actually arrived must beat the sweeper's guess — the money is real even if the webhook was late. canceled_by in ('user','admin') or NULL (pre-051 rows: provenance unknown) leaves the row untouched; the caller then keeps the "ignore paid event on canceled order" behavior. Returns false when no row was revived.
func (*Repo) SetOrderChannelRefAndExpiry ¶ added in v0.13.0
func (*Repo) SetOrderPaymentIntentRef ¶
func (*Repo) SetWorkspaceCancelRequested ¶ added in v0.17.0
func (*Repo) SetWorkspaceSubscription ¶
func (*Repo) UpdateOrderStatus ¶
func (*Repo) UpdatePlan ¶ added in v0.8.0
func (r *Repo) UpdatePlan(ctx context.Context, code, name, limitsJSON string, sortNo int, currency string) (found bool, err error)
UpdatePlan full-replaces the editable columns of a plan (the code in the WHERE clause is the immutable identity). found reports whether a row matched; false means the caller turns it into a not-found error.