@@ -26,9 +26,11 @@ type Deps struct { |
| 26 | 26 | |
| 27 | 27 | type ( |
| 28 | 28 | Plan = billingdb.OrgPlan |
| 29 | + UserPlan = billingdb.UserPlan |
| 29 | 30 | SubscriptionStatus = billingdb.BillingSubscriptionStatus |
| 30 | 31 | InvoiceStatus = billingdb.BillingInvoiceStatus |
| 31 | 32 | State = billingdb.OrgBillingState |
| 33 | + UserState = billingdb.UserBillingState |
| 32 | 34 | ) |
| 33 | 35 | |
| 34 | 36 | const ( |
@@ -36,6 +38,9 @@ const ( |
| 36 | 38 | PlanTeam = billingdb.OrgPlanTeam |
| 37 | 39 | PlanEnterprise = billingdb.OrgPlanEnterprise |
| 38 | 40 | |
| 41 | + UserPlanFree = billingdb.UserPlanFree |
| 42 | + UserPlanPro = billingdb.UserPlanPro |
| 43 | + |
| 39 | 44 | SubscriptionStatusNone = billingdb.BillingSubscriptionStatusNone |
| 40 | 45 | SubscriptionStatusIncomplete = billingdb.BillingSubscriptionStatusIncomplete |
| 41 | 46 | SubscriptionStatusTrialing = billingdb.BillingSubscriptionStatusTrialing |
@@ -128,6 +133,20 @@ func GetOrgBillingState(ctx context.Context, deps Deps, orgID int64) (State, err |
| 128 | 133 | return billingdb.New().GetOrgBillingState(ctx, deps.Pool, orgID) |
| 129 | 134 | } |
| 130 | 135 | |
| 136 | +// GetUserBillingState is the user-side counterpart to |
| 137 | +// GetOrgBillingState. Returns pgx.ErrNoRows if the user has no |
| 138 | +// seeded billing state (shouldn't happen post-PRO03 backfill but |
| 139 | +// callers handle defensively). |
| 140 | +func GetUserBillingState(ctx context.Context, deps Deps, userID int64) (UserState, error) { |
| 141 | + if err := validateDeps(deps); err != nil { |
| 142 | + return UserState{}, err |
| 143 | + } |
| 144 | + if userID == 0 { |
| 145 | + return UserState{}, ErrOrgIDRequired // reuse: "subject id required" |
| 146 | + } |
| 147 | + return billingdb.New().GetUserBillingState(ctx, deps.Pool, userID) |
| 148 | +} |
| 149 | + |
| 131 | 150 | func GetOrgBillingStateByStripeCustomer(ctx context.Context, deps Deps, customerID string) (State, error) { |
| 132 | 151 | if err := validateDeps(deps); err != nil { |
| 133 | 152 | return State{}, err |