tenseleyflow/shithub / a72be94

Browse files

billing: export UserPlan/UserState types + GetUserBillingState helper

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
a72be9452857dc8313d196f77169b2e6d3a0d7d5
Parents
54c4e32
Tree
0b5063e

1 changed file

StatusFile+-
M internal/billing/billing.go 19 0
internal/billing/billing.gomodified
@@ -26,9 +26,11 @@ type Deps struct {
2626
 
2727
 type (
2828
 	Plan               = billingdb.OrgPlan
29
+	UserPlan           = billingdb.UserPlan
2930
 	SubscriptionStatus = billingdb.BillingSubscriptionStatus
3031
 	InvoiceStatus      = billingdb.BillingInvoiceStatus
3132
 	State              = billingdb.OrgBillingState
33
+	UserState          = billingdb.UserBillingState
3234
 )
3335
 
3436
 const (
@@ -36,6 +38,9 @@ const (
3638
 	PlanTeam       = billingdb.OrgPlanTeam
3739
 	PlanEnterprise = billingdb.OrgPlanEnterprise
3840
 
41
+	UserPlanFree = billingdb.UserPlanFree
42
+	UserPlanPro  = billingdb.UserPlanPro
43
+
3944
 	SubscriptionStatusNone       = billingdb.BillingSubscriptionStatusNone
4045
 	SubscriptionStatusIncomplete = billingdb.BillingSubscriptionStatusIncomplete
4146
 	SubscriptionStatusTrialing   = billingdb.BillingSubscriptionStatusTrialing
@@ -128,6 +133,20 @@ func GetOrgBillingState(ctx context.Context, deps Deps, orgID int64) (State, err
128133
 	return billingdb.New().GetOrgBillingState(ctx, deps.Pool, orgID)
129134
 }
130135
 
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
+
131150
 func GetOrgBillingStateByStripeCustomer(ctx context.Context, deps Deps, customerID string) (State, error) {
132151
 	if err := validateDeps(deps); err != nil {
133152
 		return State{}, err