Skip to content

domain ​

go
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 ​

go
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 ​

go
func CheckCapacity(s *p.Subscription, members, doctors int) error

CheckCapacity rejects effective limits below the supplied active relationship counts.

func Current ​

go
func Current(s *p.Subscription) bool

Current identifies stored states that reserve the current agreement slot.

func Effective ​

go
func Effective(s *p.Subscription) p.Features

Effective merges snapshot features with the complete override map.

func EffectiveSubscription ​

go
func EffectiveSubscription(s *p.Subscription, now time.Time) *p.Subscription

EffectiveSubscription projects time expiry without mutating stored lifecycle state.

func Elapsed ​

go
func Elapsed(s *p.Subscription, now time.Time) bool

Elapsed evaluates the exclusive access and trial expiry boundaries.

func Eligible ​

go
func Eligible(s *p.Subscription, now time.Time) bool

Eligible evaluates the date and lifecycle portion of subscription eligibility.

func Invalid ​

go
func Invalid(message string) error

Invalid wraps invalid billing data with its stable input error.

func Limit ​

go
func Limit(v any) (int64, bool)

Limit decodes a nonnegative integer without losing numeric precision.

func Text ​

go
func Text(v string, maximumLength int, required bool) bool

Text validates bounded UTF-8 text without embedded NUL characters.

func ValidateFeatures ​

go
func ValidateFeatures(f map[string]any, required bool) error

ValidateFeatures checks feature types and required member/doctor capacities.

func ValidateInvoice ​

go
func ValidateInvoice(i *p.Invoice) error

ValidateInvoice checks a manual charge and its covered/invoice date pairs.

func ValidatePlan ​

go
func ValidatePlan(pn *p.Plan) error

ValidatePlan checks shared-offering pricing, interval, and complete features.

func ValidateSubscription ​

go
func ValidateSubscription(s *p.Subscription) error

ValidateSubscription checks agreed pricing, feature maps, and lifecycle dates.

type BillingInterval ​

BillingInterval represents how often a subscription is billed.

go
type BillingInterval string

go
const (
    // IntervalMonthly selects monthly billing.
    IntervalMonthly BillingInterval = "monthly"
    // IntervalYearly selects yearly billing.
    IntervalYearly BillingInterval = "yearly"
)

type Plan ​

Plan represents a subscription plan template.

go
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.

go
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.

go
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.

go
type SubscriptionStatus string

go
const (
    // 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

Documentation follows the source. Planned contracts are marked explicitly.