domain
import "github.com/prescriptoo/prescriptoo-api/services/subscription/internal/domain"Package domain contains core business entities for the subscription service. Legacy prototype definitions in this file are unmounted; production uses the billing implementation.
Index
- Variables
- func CheckCapacity(s *p.Subscription, members, doctors int) error
- func Current(s *p.Subscription) bool
- func Effective(s *p.Subscription) p.Features
- func EffectiveSubscription(s *p.Subscription, now time.Time) *p.Subscription
- func Elapsed(s *p.Subscription, now time.Time) bool
- func Eligible(s *p.Subscription, now time.Time) bool
- func Invalid(message string) error
- func Limit(v any) (int64, bool)
- func Text(v string, maximumLength int, required bool) bool
- func ValidateFeatures(f map[string]any, required bool) error
- func ValidateInvoice(i *p.Invoice) error
- func ValidatePlan(pn *p.Plan) error
- func ValidateSubscription(s *p.Subscription) error
- type BillingInterval
- type Plan
- type PlanOverride
- type Subscription
- type SubscriptionStatus
Variables
var (
// ErrPlanNotFound indicates that a subscription plan does not exist.
ErrPlanNotFound = errors.New("plan not found")
// ErrPlanAlreadyExists indicates that a plan slug is already in use.
ErrPlanAlreadyExists = errors.New("plan with this slug already exists")
// ErrSubscriptionNotFound indicates that a subscription does not exist.
ErrSubscriptionNotFound = errors.New("subscription not found")
// ErrInvalidSubscription indicates that a subscription status is invalid.
ErrInvalidSubscription = errors.New("invalid subscription status")
)func CheckCapacity
func CheckCapacity(s *p.Subscription, members, doctors int) errorCheckCapacity rejects effective limits below the supplied active relationship counts.
func Current
func Current(s *p.Subscription) boolCurrent identifies stored states that reserve the current agreement slot.
func Effective
func Effective(s *p.Subscription) p.FeaturesEffective merges snapshot features with the complete override map.
func EffectiveSubscription
func EffectiveSubscription(s *p.Subscription, now time.Time) *p.SubscriptionEffectiveSubscription projects time expiry without mutating stored lifecycle state.
func Elapsed
func Elapsed(s *p.Subscription, now time.Time) boolElapsed evaluates the exclusive access and trial expiry boundaries.
func Eligible
func Eligible(s *p.Subscription, now time.Time) boolEligible evaluates the date and lifecycle portion of subscription eligibility.
func Invalid
func Invalid(message string) errorInvalid wraps invalid billing data with its stable input error.
func Limit
func Limit(v any) (int64, bool)Limit decodes a nonnegative integer without losing numeric precision.
func Text
func Text(v string, maximumLength int, required bool) boolText validates bounded UTF-8 text without embedded NUL characters.
func ValidateFeatures
func ValidateFeatures(f map[string]any, required bool) errorValidateFeatures checks feature types and required member/doctor capacities.
func ValidateInvoice
func ValidateInvoice(i *p.Invoice) errorValidateInvoice checks a manual charge and its covered/invoice date pairs.
func ValidatePlan
func ValidatePlan(pn *p.Plan) errorValidatePlan checks shared-offering pricing, interval, and complete features.
func ValidateSubscription
func ValidateSubscription(s *p.Subscription) errorValidateSubscription checks agreed pricing, feature maps, and lifecycle dates.
type BillingInterval
BillingInterval represents how often a subscription is billed.
type BillingInterval stringconst (
// IntervalMonthly selects monthly billing.
IntervalMonthly BillingInterval = "monthly"
// IntervalYearly selects yearly billing.
IntervalYearly BillingInterval = "yearly"
)type Plan
Plan represents a subscription plan template.
type Plan struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
PriceCents int64 `json:"price_cents"`
Interval BillingInterval `json:"interval"`
// Features is a JSON object containing feature flags and limits.
// Example: { "max_doctors": 10, "max_prescriptions": 1000, "custom_branding": true }
Features map[string]any `json:"features"`
IsPublic bool `json:"is_public"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type PlanOverride
PlanOverride represents a per-organization customization to a plan.
type PlanOverride struct {
ID string `json:"id"`
SubscriptionID string `json:"subscription_id"`
FeatureKey string `json:"feature_key"`
CustomValue any `json:"custom_value"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type Subscription
Subscription represents an organization's subscription to a plan.
type Subscription struct {
ID string `json:"id"`
OrganizationID string `json:"organization_id"`
PlanID string `json:"plan_id"`
Status SubscriptionStatus `json:"status"`
CurrentPeriodStart time.Time `json:"current_period_start"`
CurrentPeriodEnd time.Time `json:"current_period_end"`
PriceCents int64 `json:"price_cents"`
TrialEndsAt *time.Time `json:"trial_ends_at,omitempty"`
CanceledAt *time.Time `json:"canceled_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type SubscriptionStatus
SubscriptionStatus represents the current state of a subscription.
type SubscriptionStatus stringconst (
// SubscriptionTrialing marks a subscription in its trial period.
SubscriptionTrialing SubscriptionStatus = "trialing"
// SubscriptionActive marks an active subscription.
SubscriptionActive SubscriptionStatus = "active"
// SubscriptionPastDue marks a subscription with an overdue payment.
SubscriptionPastDue SubscriptionStatus = "past_due"
// SubscriptionCanceled marks a canceled subscription.
SubscriptionCanceled SubscriptionStatus = "canceled"
// SubscriptionExpired marks an expired subscription.
SubscriptionExpired SubscriptionStatus = "expired"
)Generated by gomarkdoc