service

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package service provides business logic services for the subscription plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOnService

type AddOnService struct {
	// contains filtered or unexported fields
}

AddOnService handles add-on business logic

func NewAddOnService

NewAddOnService creates a new add-on service

func (*AddOnService) Create

func (s *AddOnService) Create(ctx context.Context, appID xid.ID, req *core.CreateAddOnRequest) (*core.AddOn, error)

Create creates a new add-on

func (*AddOnService) Delete

func (s *AddOnService) Delete(ctx context.Context, id xid.ID) error

Delete deletes an add-on

func (*AddOnService) GetAvailableForPlan

func (s *AddOnService) GetAvailableForPlan(ctx context.Context, planID xid.ID) ([]*core.AddOn, error)

GetAvailableForPlan retrieves add-ons available for a specific plan

func (*AddOnService) GetByID

func (s *AddOnService) GetByID(ctx context.Context, id xid.ID) (*core.AddOn, error)

GetByID retrieves an add-on by ID

func (*AddOnService) GetBySlug

func (s *AddOnService) GetBySlug(ctx context.Context, appID xid.ID, slug string) (*core.AddOn, error)

GetBySlug retrieves an add-on by slug

func (*AddOnService) List

func (s *AddOnService) List(ctx context.Context, appID xid.ID, activeOnly, publicOnly bool, page, pageSize int) ([]*core.AddOn, int, error)

List retrieves add-ons with filtering

func (*AddOnService) Update

func (s *AddOnService) Update(ctx context.Context, id xid.ID, req *core.UpdateAddOnRequest) (*core.AddOn, error)

Update updates an existing add-on

type AddOnServiceInterface

type AddOnServiceInterface interface {
	Create(ctx context.Context, appID xid.ID, req *core.CreateAddOnRequest) (*core.AddOn, error)
	Update(ctx context.Context, id xid.ID, req *core.UpdateAddOnRequest) (*core.AddOn, error)
	Delete(ctx context.Context, id xid.ID) error
	GetByID(ctx context.Context, id xid.ID) (*core.AddOn, error)
	GetBySlug(ctx context.Context, appID xid.ID, slug string) (*core.AddOn, error)
	List(ctx context.Context, appID xid.ID, activeOnly, publicOnly bool, page, pageSize int) ([]*core.AddOn, int, error)
	GetAvailableForPlan(ctx context.Context, planID xid.ID) ([]*core.AddOn, error)
}

AddOnServiceInterface defines the add-on service interface

type AlertService

type AlertService struct {
	// contains filtered or unexported fields
}

AlertService handles usage alerts and notifications

func NewAlertService

NewAlertService creates a new alert service

func (*AlertService) AcknowledgeAlert

func (s *AlertService) AcknowledgeAlert(ctx context.Context, req *core.AcknowledgeAlertRequest) error

AcknowledgeAlert marks an alert as acknowledged

func (*AlertService) CheckTrialEndings

func (s *AlertService) CheckTrialEndings(ctx context.Context, appID xid.ID) error

CheckTrialEndings checks for subscriptions with trials ending soon This would typically be called by a scheduled job

func (*AlertService) CheckUsageThresholds

func (s *AlertService) CheckUsageThresholds(ctx context.Context, appID xid.ID) error

CheckUsageThresholds checks all organizations for usage threshold alerts This would typically be called by a scheduled job

func (*AlertService) CreateAlert

func (s *AlertService) CreateAlert(ctx context.Context, alert *core.Alert) error

CreateAlert creates a new alert

func (*AlertService) CreateAlertConfig

func (s *AlertService) CreateAlertConfig(ctx context.Context, appID xid.ID, req *core.CreateAlertConfigRequest) (*core.AlertConfig, error)

CreateAlertConfig creates a new alert configuration

func (*AlertService) DeleteAlertConfig

func (s *AlertService) DeleteAlertConfig(ctx context.Context, id xid.ID) error

DeleteAlertConfig deletes an alert config

func (*AlertService) GetAlert

func (s *AlertService) GetAlert(ctx context.Context, id xid.ID) (*core.Alert, error)

GetAlert returns an alert by ID

func (*AlertService) GetAlertConfig

func (s *AlertService) GetAlertConfig(ctx context.Context, id xid.ID) (*core.AlertConfig, error)

GetAlertConfig returns an alert config by ID

func (*AlertService) GetAlertSummary

func (s *AlertService) GetAlertSummary(ctx context.Context, orgID xid.ID) (*core.AlertSummary, error)

GetAlertSummary returns an alert summary for an organization

func (*AlertService) ListAlertConfigs

func (s *AlertService) ListAlertConfigs(ctx context.Context, orgID xid.ID) ([]*core.AlertConfig, error)

ListAlertConfigs returns all alert configs for an organization

func (*AlertService) ListAlerts

func (s *AlertService) ListAlerts(ctx context.Context, orgID xid.ID, status *core.AlertStatus, page, pageSize int) ([]*core.Alert, int, error)

ListAlerts returns alerts for an organization

func (*AlertService) ProcessPendingAlerts

func (s *AlertService) ProcessPendingAlerts(ctx context.Context) error

ProcessPendingAlerts processes and sends pending alerts This would typically be called by a scheduled job

func (*AlertService) ResolveAlert

func (s *AlertService) ResolveAlert(ctx context.Context, req *core.ResolveAlertRequest) error

ResolveAlert marks an alert as resolved

func (*AlertService) SetupDefaultAlerts

func (s *AlertService) SetupDefaultAlerts(ctx context.Context, appID, orgID xid.ID) error

SetupDefaultAlerts creates default alert configs for a new organization

func (*AlertService) SnoozeAlertConfig

func (s *AlertService) SnoozeAlertConfig(ctx context.Context, id xid.ID, until time.Time) error

SnoozeAlertConfig snoozes alerts for a config

func (*AlertService) TriggerAlert

func (s *AlertService) TriggerAlert(ctx context.Context, appID xid.ID, req *core.TriggerAlertRequest) (*core.Alert, error)

TriggerAlert manually triggers an alert

func (*AlertService) UpdateAlertConfig

func (s *AlertService) UpdateAlertConfig(ctx context.Context, id xid.ID, req *core.UpdateAlertConfigRequest) (*core.AlertConfig, error)

UpdateAlertConfig updates an alert config

type AnalyticsService

type AnalyticsService struct {
	// contains filtered or unexported fields
}

AnalyticsService handles analytics and metrics calculations

func NewAnalyticsService

func NewAnalyticsService(
	analyticsRepo repository.AnalyticsRepository,
	subRepo repository.SubscriptionRepository,
	planRepo repository.PlanRepository,
) *AnalyticsService

NewAnalyticsService creates a new analytics service

func (*AnalyticsService) GetChurnRate added in v0.0.5

func (s *AnalyticsService) GetChurnRate(ctx context.Context, appID xid.ID, startDate, endDate time.Time) (float64, error)

GetChurnRate calculates churn rate for the period

func (*AnalyticsService) GetDashboardMetrics

func (s *AnalyticsService) GetDashboardMetrics(ctx context.Context, appID xid.ID, startDate, endDate time.Time, currency string) (*core.DashboardMetrics, error)

GetDashboardMetrics calculates comprehensive dashboard metrics

func (*AnalyticsService) GetMRRHistory added in v0.0.5

func (s *AnalyticsService) GetMRRHistory(ctx context.Context, appID xid.ID, startDate, endDate time.Time, currency string) ([]*core.MRRBreakdown, error)

GetMRRHistory returns MRR breakdown over time

func (*AnalyticsService) GetRevenueByOrg added in v0.0.5

func (s *AnalyticsService) GetRevenueByOrg(ctx context.Context, appID xid.ID, startDate, endDate time.Time) ([]*core.OrgRevenue, error)

GetRevenueByOrg returns revenue breakdown by organization

func (*AnalyticsService) GetSubscriptionGrowth added in v0.0.5

func (s *AnalyticsService) GetSubscriptionGrowth(ctx context.Context, appID xid.ID, startDate, endDate time.Time) ([]*core.GrowthPoint, error)

GetSubscriptionGrowth returns subscription growth data points

type CouponService

type CouponService struct {
	// contains filtered or unexported fields
}

CouponService handles coupon and discount operations

func NewCouponService

NewCouponService creates a new coupon service

func (*CouponService) ArchiveCoupon

func (s *CouponService) ArchiveCoupon(ctx context.Context, id xid.ID) error

ArchiveCoupon archives a coupon

func (*CouponService) CreateCoupon

func (s *CouponService) CreateCoupon(ctx context.Context, appID xid.ID, req *core.CreateCouponRequest) (*core.Coupon, error)

CreateCoupon creates a new coupon

func (*CouponService) CreatePromotionCode

func (s *CouponService) CreatePromotionCode(ctx context.Context, appID xid.ID, req *core.CreatePromotionCodeRequest) (*core.PromotionCode, error)

CreatePromotionCode creates a promotion code for a coupon

func (*CouponService) GetCoupon

func (s *CouponService) GetCoupon(ctx context.Context, id xid.ID) (*core.Coupon, error)

GetCoupon returns a coupon by ID

func (*CouponService) GetCouponByCode

func (s *CouponService) GetCouponByCode(ctx context.Context, appID xid.ID, code string) (*core.Coupon, error)

GetCouponByCode returns a coupon by code

func (*CouponService) ListCoupons

func (s *CouponService) ListCoupons(ctx context.Context, appID xid.ID, status *core.CouponStatus, page, pageSize int) ([]*core.Coupon, int, error)

ListCoupons returns all coupons for an app

func (*CouponService) ListOrgRedemptions

func (s *CouponService) ListOrgRedemptions(ctx context.Context, orgID xid.ID) ([]*core.CouponRedemption, error)

ListOrgRedemptions lists all redemptions for an organization

func (*CouponService) ListPromotionCodes

func (s *CouponService) ListPromotionCodes(ctx context.Context, couponID xid.ID, page, pageSize int) ([]*core.PromotionCode, int, error)

ListPromotionCodes lists promotion codes for a coupon

func (*CouponService) ListRedemptions

func (s *CouponService) ListRedemptions(ctx context.Context, couponID xid.ID, page, pageSize int) ([]*core.CouponRedemption, int, error)

ListRedemptions lists redemptions for a coupon

func (*CouponService) RedeemCoupon

func (s *CouponService) RedeemCoupon(ctx context.Context, appID xid.ID, req *core.RedeemCouponRequest) (*core.CouponRedemption, error)

RedeemCoupon redeems a coupon for a subscription

func (*CouponService) UpdateCoupon

func (s *CouponService) UpdateCoupon(ctx context.Context, id xid.ID, req *core.UpdateCouponRequest) (*core.Coupon, error)

UpdateCoupon updates a coupon

func (*CouponService) ValidateCoupon

ValidateCoupon validates a coupon code

type CurrencyService

type CurrencyService struct {
	// contains filtered or unexported fields
}

CurrencyService handles currency and exchange rate operations

func NewCurrencyService

func NewCurrencyService(repo repository.CurrencyRepository) *CurrencyService

NewCurrencyService creates a new currency service

func (*CurrencyService) Convert

Convert converts an amount from one currency to another

func (*CurrencyService) CreateCurrency

func (s *CurrencyService) CreateCurrency(ctx context.Context, currency *core.SupportedCurrency) error

CreateCurrency creates a new supported currency

func (*CurrencyService) CreateExchangeRate

func (s *CurrencyService) CreateExchangeRate(ctx context.Context, req *core.CreateExchangeRateRequest, appID xid.ID) (*core.ExchangeRate, error)

CreateExchangeRate creates a new exchange rate

func (*CurrencyService) FormatAmount

func (s *CurrencyService) FormatAmount(amount int64, currency string) string

FormatAmount formats an amount for display

func (*CurrencyService) GetCurrency

func (s *CurrencyService) GetCurrency(ctx context.Context, code string) (*core.SupportedCurrency, error)

GetCurrency returns a currency by code

func (*CurrencyService) GetExchangeRate

func (s *CurrencyService) GetExchangeRate(ctx context.Context, fromCurrency, toCurrency string) (*core.ExchangeRate, error)

GetExchangeRate returns the current exchange rate between two currencies

func (*CurrencyService) ListCurrencies

func (s *CurrencyService) ListCurrencies(ctx context.Context) ([]*core.SupportedCurrency, error)

ListCurrencies returns all supported currencies

func (*CurrencyService) ListExchangeRates

func (s *CurrencyService) ListExchangeRates(ctx context.Context, appID xid.ID) ([]*core.ExchangeRate, error)

ListExchangeRates returns all exchange rates for an app

func (*CurrencyService) SetDefaultCurrency

func (s *CurrencyService) SetDefaultCurrency(ctx context.Context, code string) error

SetDefaultCurrency sets a currency as the default

type CustomerService

type CustomerService struct {
	// contains filtered or unexported fields
}

CustomerService handles billing customer management

func NewCustomerService

func NewCustomerService(
	repo repository.CustomerRepository,
	provider providers.PaymentProvider,
	eventRepo repository.EventRepository,
) *CustomerService

NewCustomerService creates a new customer service

func (*CustomerService) Create

Create creates a new billing customer

func (*CustomerService) GetByOrganizationID

func (s *CustomerService) GetByOrganizationID(ctx context.Context, orgID xid.ID) (*core.Customer, error)

GetByOrganizationID retrieves a customer by organization ID

func (*CustomerService) GetOrCreate

func (s *CustomerService) GetOrCreate(ctx context.Context, orgID xid.ID, email, name string) (*core.Customer, error)

GetOrCreate gets an existing customer or creates a new one

func (*CustomerService) SyncToProvider

func (s *CustomerService) SyncToProvider(ctx context.Context, id xid.ID) error

SyncToProvider syncs customer data to the provider

func (*CustomerService) Update

Update updates a customer

type CustomerServiceInterface

type CustomerServiceInterface interface {
	Create(ctx context.Context, req *core.CreateCustomerRequest) (*core.Customer, error)
	Update(ctx context.Context, id xid.ID, req *core.UpdateCustomerRequest) (*core.Customer, error)
	GetByOrganizationID(ctx context.Context, orgID xid.ID) (*core.Customer, error)
	GetOrCreate(ctx context.Context, orgID xid.ID, email, name string) (*core.Customer, error)
	SyncToProvider(ctx context.Context, id xid.ID) error
}

CustomerServiceInterface defines the customer service interface

type EnforcementService

type EnforcementService struct {
	// contains filtered or unexported fields
}

EnforcementService handles subscription limit enforcement

func NewEnforcementService

func NewEnforcementService(
	subRepo repository.SubscriptionRepository,
	planRepo repository.PlanRepository,
	usageRepo repository.UsageRepository,
	orgService *organization.Service,
	config core.Config,
) *EnforcementService

NewEnforcementService creates a new enforcement service

func (*EnforcementService) CheckFeatureAccess

func (s *EnforcementService) CheckFeatureAccess(ctx context.Context, orgID xid.ID, feature string) (bool, error)

CheckFeatureAccess checks if an organization has access to a feature

func (*EnforcementService) CheckFeatureAccessEnhanced

func (s *EnforcementService) CheckFeatureAccessEnhanced(ctx context.Context, orgID xid.ID, featureKey string) (*core.FeatureAccess, error)

CheckFeatureAccessEnhanced checks feature access using the new feature system Falls back to legacy system if new system is not configured

func (*EnforcementService) EnforceSeatLimit

func (s *EnforcementService) EnforceSeatLimit(ctx context.Context, orgIDStr string, userID xid.ID) error

EnforceSeatLimit is a hook to enforce seat limits when adding members

func (*EnforcementService) EnforceSubscriptionRequired

func (s *EnforcementService) EnforceSubscriptionRequired(ctx context.Context, req interface{}) error

EnforceSubscriptionRequired is a hook to enforce subscription requirement

func (*EnforcementService) EnforceTeamLimit

func (s *EnforcementService) EnforceTeamLimit(ctx context.Context, orgID xid.ID) error

EnforceTeamLimit enforces team creation limits

func (*EnforcementService) GetAllLimits

func (s *EnforcementService) GetAllLimits(ctx context.Context, orgID xid.ID) (map[string]*core.UsageLimit, error)

GetAllLimits returns all limits and current usage for an organization

func (*EnforcementService) GetEffectiveLimitEnhanced

func (s *EnforcementService) GetEffectiveLimitEnhanced(ctx context.Context, orgID xid.ID, featureKey string) (int64, error)

GetEffectiveLimitEnhanced returns the effective limit for a feature including grants

func (*EnforcementService) GetFeatureLimit

func (s *EnforcementService) GetFeatureLimit(ctx context.Context, orgID xid.ID, feature string) (int64, error)

GetFeatureLimit returns the limit for a feature

func (*EnforcementService) GetRemainingSeats

func (s *EnforcementService) GetRemainingSeats(ctx context.Context, orgID xid.ID) (int, error)

GetRemainingSeats returns the number of available seats

func (*EnforcementService) SetFeatureRepositories

func (s *EnforcementService) SetFeatureRepositories(featureRepo repository.FeatureRepository, featureUsageRepo repository.FeatureUsageRepository)

SetFeatureRepositories sets the feature repositories for enhanced feature checking

type EnforcementServiceInterface

type EnforcementServiceInterface interface {
	CheckFeatureAccess(ctx context.Context, orgID xid.ID, feature string) (bool, error)
	GetRemainingSeats(ctx context.Context, orgID xid.ID) (int, error)
	GetFeatureLimit(ctx context.Context, orgID xid.ID, feature string) (int64, error)
	GetAllLimits(ctx context.Context, orgID xid.ID) (map[string]*core.UsageLimit, error)
	EnforceSubscriptionRequired(ctx context.Context, req interface{}) error
	EnforceSeatLimit(ctx context.Context, orgID string, userID xid.ID) error
}

EnforcementServiceInterface defines the enforcement service interface

type ExportData added in v0.0.4

type ExportData struct {
	Version    string          `json:"version"`
	ExportedAt time.Time       `json:"exportedAt"`
	AppID      string          `json:"appId"`
	Features   []ExportFeature `json:"features"`
	Plans      []ExportPlan    `json:"plans"`
}

ExportData represents the exported data structure

type ExportFeature added in v0.0.4

type ExportFeature struct {
	Key          string                 `json:"key"`
	Name         string                 `json:"name"`
	Description  string                 `json:"description"`
	Type         string                 `json:"type"`
	Unit         string                 `json:"unit"`
	ResetPeriod  string                 `json:"resetPeriod"`
	IsPublic     bool                   `json:"isPublic"`
	DisplayOrder int                    `json:"displayOrder"`
	Icon         string                 `json:"icon,omitempty"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	Tiers        []ExportFeatureTier    `json:"tiers,omitempty"`
}

ExportFeature represents a feature in export format

type ExportFeatureTier added in v0.0.4

type ExportFeatureTier struct {
	UpTo  int64  `json:"upTo"`
	Value string `json:"value"`
	Label string `json:"label"`
}

ExportFeatureTier represents a feature tier in export format

type ExportImportService added in v0.0.4

type ExportImportService struct {
	// contains filtered or unexported fields
}

ExportImportService handles export/import of features and plans

func NewExportImportService added in v0.0.4

func NewExportImportService(
	featureRepo repository.FeatureRepository,
	planRepo repository.PlanRepository,
	eventRepo repository.EventRepository,
) *ExportImportService

NewExportImportService creates a new export/import service

func (*ExportImportService) ExportFeaturesAndPlans added in v0.0.4

func (s *ExportImportService) ExportFeaturesAndPlans(ctx context.Context, appID xid.ID) (*ExportData, error)

ExportFeaturesAndPlans exports all features and plans for an app

func (*ExportImportService) ImportFeaturesAndPlans added in v0.0.4

func (s *ExportImportService) ImportFeaturesAndPlans(ctx context.Context, appID xid.ID, data *ExportData, overwriteExisting bool) (*ImportResult, error)

ImportFeaturesAndPlans imports features and plans from export data

type ExportPlan added in v0.0.4

type ExportPlan struct {
	Name            string                 `json:"name"`
	Slug            string                 `json:"slug"`
	Description     string                 `json:"description"`
	BillingPattern  string                 `json:"billingPattern"`
	BillingInterval string                 `json:"billingInterval"`
	BasePrice       int64                  `json:"basePrice"`
	Currency        string                 `json:"currency"`
	TrialDays       int                    `json:"trialDays"`
	TierMode        string                 `json:"tierMode"`
	IsActive        bool                   `json:"isActive"`
	IsPublic        bool                   `json:"isPublic"`
	DisplayOrder    int                    `json:"displayOrder"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
	Features        []ExportPlanFeature    `json:"features,omitempty"`
	PriceTiers      []ExportPriceTier      `json:"priceTiers,omitempty"`
}

ExportPlan represents a plan in export format

type ExportPlanFeature added in v0.0.4

type ExportPlanFeature struct {
	FeatureKey    string      `json:"featureKey"`
	Value         interface{} `json:"value"`
	IsHighlighted bool        `json:"isHighlighted,omitempty"`
	IsBlocked     bool        `json:"isBlocked,omitempty"`
}

ExportPlanFeature represents a plan feature link in export format

type ExportPriceTier added in v0.0.4

type ExportPriceTier struct {
	UpTo       int64 `json:"upTo"`
	UnitAmount int64 `json:"unitAmount"`
	FlatAmount int64 `json:"flatAmount"`
}

ExportPriceTier represents a price tier in export format

type FeatureService

type FeatureService struct {
	// contains filtered or unexported fields
}

FeatureService handles feature business logic

func NewFeatureService

func NewFeatureService(
	featureRepo repository.FeatureRepository,
	planRepo repository.PlanRepository,
	eventRepo repository.EventRepository,
	provider types.PaymentProvider,
) *FeatureService

NewFeatureService creates a new feature service

func (*FeatureService) Create

func (s *FeatureService) Create(ctx context.Context, appID xid.ID, req *core.CreateFeatureRequest) (*core.Feature, error)

Create creates a new feature

func (*FeatureService) Delete

func (s *FeatureService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a feature

func (*FeatureService) GetByID

func (s *FeatureService) GetByID(ctx context.Context, id xid.ID) (*core.Feature, error)

GetByID retrieves a feature by ID

func (*FeatureService) GetByKey

func (s *FeatureService) GetByKey(ctx context.Context, appID xid.ID, key string) (*core.Feature, error)

GetByKey retrieves a feature by key

func (*FeatureService) GetPlanFeatures

func (s *FeatureService) GetPlanFeatures(ctx context.Context, planID xid.ID) ([]*core.PlanFeatureLink, error)

GetPlanFeatures retrieves all features linked to a plan

func (*FeatureService) GetPublicFeatures

func (s *FeatureService) GetPublicFeatures(ctx context.Context, appID xid.ID) ([]*core.PublicFeature, error)

GetPublicFeatures retrieves public features for pricing pages

func (*FeatureService) GetPublicPlanFeatures

func (s *FeatureService) GetPublicPlanFeatures(ctx context.Context, planID xid.ID) ([]*core.PublicPlanFeature, error)

GetPublicPlanFeatures retrieves features for a plan formatted for public API

func (*FeatureService) LinkToPlan

func (s *FeatureService) LinkToPlan(ctx context.Context, planID xid.ID, req *core.LinkFeatureRequest) (*core.PlanFeatureLink, error)

LinkToPlan links a feature to a plan

func (*FeatureService) List

func (s *FeatureService) List(ctx context.Context, appID xid.ID, featureType string, publicOnly bool, page, pageSize int) ([]*core.Feature, int, error)

List retrieves features with filtering

func (*FeatureService) SyncAllFromProvider added in v0.0.5

func (s *FeatureService) SyncAllFromProvider(ctx context.Context, productID string) ([]*core.Feature, error)

SyncAllFromProvider syncs all features from the provider for a product

func (*FeatureService) SyncFromProvider added in v0.0.5

func (s *FeatureService) SyncFromProvider(ctx context.Context, providerFeatureID string) (*core.Feature, error)

SyncFromProvider syncs a feature from the payment provider

func (*FeatureService) SyncToProvider added in v0.0.5

func (s *FeatureService) SyncToProvider(ctx context.Context, id xid.ID) error

SyncToProvider manually syncs a feature to the payment provider

func (*FeatureService) UnlinkFromPlan

func (s *FeatureService) UnlinkFromPlan(ctx context.Context, planID, featureID xid.ID) error

UnlinkFromPlan removes a feature from a plan

func (*FeatureService) Update

Update updates an existing feature

func (s *FeatureService) UpdatePlanLink(ctx context.Context, planID, featureID xid.ID, req *core.UpdateLinkRequest) (*core.PlanFeatureLink, error)

UpdatePlanLink updates a feature-plan link

type FeatureServiceInterface added in v0.0.5

type FeatureServiceInterface interface {
	Create(ctx context.Context, appID xid.ID, req *core.CreateFeatureRequest) (*core.Feature, error)
	Update(ctx context.Context, id xid.ID, req *core.UpdateFeatureRequest) (*core.Feature, error)
	Delete(ctx context.Context, id xid.ID) error
	GetByID(ctx context.Context, id xid.ID) (*core.Feature, error)
	GetByKey(ctx context.Context, appID xid.ID, key string) (*core.Feature, error)
	List(ctx context.Context, appID xid.ID, featureType string, publicOnly bool, page, pageSize int) ([]*core.Feature, int, error)
	LinkToPlan(ctx context.Context, planID xid.ID, req *core.LinkFeatureRequest) (*core.PlanFeatureLink, error)
	UpdatePlanLink(ctx context.Context, planID, featureID xid.ID, req *core.UpdateLinkRequest) (*core.PlanFeatureLink, error)
	UnlinkFromPlan(ctx context.Context, planID, featureID xid.ID) error
	GetPlanFeatures(ctx context.Context, planID xid.ID) ([]*core.PlanFeatureLink, error)
	GetPublicFeatures(ctx context.Context, appID xid.ID) ([]*core.PublicFeature, error)
	GetPublicPlanFeatures(ctx context.Context, planID xid.ID) ([]*core.PublicPlanFeature, error)
	SyncToProvider(ctx context.Context, id xid.ID) error
	SyncFromProvider(ctx context.Context, providerFeatureID string) (*core.Feature, error)
	SyncAllFromProvider(ctx context.Context, productID string) ([]*core.Feature, error)
}

FeatureServiceInterface defines the feature service interface

type FeatureUsageService

type FeatureUsageService struct {
	// contains filtered or unexported fields
}

FeatureUsageService handles feature usage tracking and enforcement

func NewFeatureUsageService

NewFeatureUsageService creates a new feature usage service

func (*FeatureUsageService) CheckAccess

func (s *FeatureUsageService) CheckAccess(ctx context.Context, orgID xid.ID, featureKey string) (*core.FeatureAccess, error)

CheckAccess checks if an organization has access to a feature

func (*FeatureUsageService) ConsumeFeature

ConsumeFeature consumes feature quota for an organization

func (*FeatureUsageService) GetAllUsage

func (s *FeatureUsageService) GetAllUsage(ctx context.Context, orgID xid.ID) ([]*core.FeatureUsageResponse, error)

GetAllUsage retrieves all feature usage for an organization

func (*FeatureUsageService) GetEffectiveLimit

func (s *FeatureUsageService) GetEffectiveLimit(ctx context.Context, orgID xid.ID, featureKey string) (int64, error)

GetEffectiveLimit returns the total limit for a feature (plan limit + grants)

func (*FeatureUsageService) GetUsage

func (s *FeatureUsageService) GetUsage(ctx context.Context, orgID xid.ID, featureKey string) (*core.FeatureUsageResponse, error)

GetUsage retrieves current usage for a feature

func (*FeatureUsageService) GrantFeature

GrantFeature grants additional feature quota to an organization

func (*FeatureUsageService) ListGrants

func (s *FeatureUsageService) ListGrants(ctx context.Context, orgID xid.ID) ([]*core.FeatureGrant, error)

ListGrants lists all active grants for an organization

func (*FeatureUsageService) ProcessResets

func (s *FeatureUsageService) ProcessResets(ctx context.Context) error

ProcessResets processes usage resets for features that need it

func (*FeatureUsageService) ResetUsage

func (s *FeatureUsageService) ResetUsage(ctx context.Context, orgID xid.ID, featureKey string, actorID *xid.ID, reason string) error

ResetUsage resets usage for a feature

func (*FeatureUsageService) RevokeGrant

func (s *FeatureUsageService) RevokeGrant(ctx context.Context, grantID xid.ID) error

RevokeGrant revokes a feature grant

type ImportResult added in v0.0.4

type ImportResult struct {
	FeaturesCreated int      `json:"featuresCreated"`
	FeaturesSkipped int      `json:"featuresSkipped"`
	PlansCreated    int      `json:"plansCreated"`
	PlansSkipped    int      `json:"plansSkipped"`
	Errors          []string `json:"errors,omitempty"`
}

ImportResult contains the results of an import operation

type InvoiceService

type InvoiceService struct {
	// contains filtered or unexported fields
}

InvoiceService handles invoice business logic

func NewInvoiceService

NewInvoiceService creates a new invoice service

func (*InvoiceService) AddItem

func (s *InvoiceService) AddItem(ctx context.Context, invoiceID xid.ID, description string, quantity, unitAmount int64) error

AddItem adds a line item to an invoice

func (*InvoiceService) Create

func (s *InvoiceService) Create(ctx context.Context, subID, orgID xid.ID, periodStart, periodEnd time.Time) (*core.Invoice, error)

Create creates a new invoice

func (*InvoiceService) Finalize

func (s *InvoiceService) Finalize(ctx context.Context, id xid.ID) error

Finalize finalizes an invoice

func (*InvoiceService) GetByID

func (s *InvoiceService) GetByID(ctx context.Context, id xid.ID) (*core.Invoice, error)

GetByID retrieves an invoice by ID

func (*InvoiceService) GetByNumber

func (s *InvoiceService) GetByNumber(ctx context.Context, number string) (*core.Invoice, error)

GetByNumber retrieves an invoice by number

func (*InvoiceService) GetPDFURL

func (s *InvoiceService) GetPDFURL(ctx context.Context, id xid.ID) (string, error)

GetPDFURL returns the PDF URL for an invoice

func (*InvoiceService) List

func (s *InvoiceService) List(ctx context.Context, orgID, subID *xid.ID, status string, page, pageSize int) ([]*core.Invoice, int, error)

List retrieves invoices with filtering

func (*InvoiceService) MarkPaid

func (s *InvoiceService) MarkPaid(ctx context.Context, id xid.ID) error

MarkPaid marks an invoice as paid

func (*InvoiceService) SyncFromProvider

func (s *InvoiceService) SyncFromProvider(ctx context.Context, providerInvoiceID string) (*core.Invoice, error)

SyncFromProvider syncs an invoice from the provider

func (*InvoiceService) Void

func (s *InvoiceService) Void(ctx context.Context, id xid.ID) error

Void voids an invoice

type InvoiceServiceInterface

type InvoiceServiceInterface interface {
	GetByID(ctx context.Context, id xid.ID) (*core.Invoice, error)
	GetByNumber(ctx context.Context, number string) (*core.Invoice, error)
	List(ctx context.Context, orgID, subID *xid.ID, status string, page, pageSize int) ([]*core.Invoice, int, error)
	GetPDFURL(ctx context.Context, id xid.ID) (string, error)
	Void(ctx context.Context, id xid.ID) error
	SyncFromProvider(ctx context.Context, providerInvoiceID string) (*core.Invoice, error)
}

InvoiceServiceInterface defines the invoice service interface

type PaymentService

type PaymentService struct {
	// contains filtered or unexported fields
}

PaymentService handles payment method management

func NewPaymentService

NewPaymentService creates a new payment service

func (*PaymentService) AddPaymentMethod

func (s *PaymentService) AddPaymentMethod(ctx context.Context, orgID xid.ID, providerMethodID string, setDefault bool) (*core.PaymentMethod, error)

AddPaymentMethod adds a payment method from provider

func (*PaymentService) CreateSetupIntent

func (s *PaymentService) CreateSetupIntent(ctx context.Context, orgID xid.ID) (*core.SetupIntentResult, error)

CreateSetupIntent creates a setup intent for adding a payment method

func (*PaymentService) GetDefaultPaymentMethod

func (s *PaymentService) GetDefaultPaymentMethod(ctx context.Context, orgID xid.ID) (*core.PaymentMethod, error)

GetDefaultPaymentMethod gets the default payment method

func (*PaymentService) ListPaymentMethods

func (s *PaymentService) ListPaymentMethods(ctx context.Context, orgID xid.ID) ([]*core.PaymentMethod, error)

ListPaymentMethods lists all payment methods for an organization

func (*PaymentService) RemovePaymentMethod

func (s *PaymentService) RemovePaymentMethod(ctx context.Context, id xid.ID) error

RemovePaymentMethod removes a payment method

func (*PaymentService) SetDefaultPaymentMethod

func (s *PaymentService) SetDefaultPaymentMethod(ctx context.Context, orgID, paymentMethodID xid.ID) error

SetDefaultPaymentMethod sets a payment method as default

type PaymentServiceInterface

type PaymentServiceInterface interface {
	CreateSetupIntent(ctx context.Context, orgID xid.ID) (*core.SetupIntentResult, error)
	AddPaymentMethod(ctx context.Context, req *core.AddPaymentMethodRequest) (*core.PaymentMethod, error)
	RemovePaymentMethod(ctx context.Context, id xid.ID) error
	SetDefaultPaymentMethod(ctx context.Context, orgID, paymentMethodID xid.ID) error
	ListPaymentMethods(ctx context.Context, orgID xid.ID) ([]*core.PaymentMethod, error)
	GetDefaultPaymentMethod(ctx context.Context, orgID xid.ID) (*core.PaymentMethod, error)
}

PaymentServiceInterface defines the payment service interface

type PlanService

type PlanService struct {
	// contains filtered or unexported fields
}

PlanService handles plan business logic

func NewPlanService

func NewPlanService(
	repo repository.PlanRepository,
	provider providers.PaymentProvider,
	eventRepo repository.EventRepository,
) *PlanService

NewPlanService creates a new plan service

func (*PlanService) Create

func (s *PlanService) Create(ctx context.Context, appID xid.ID, req *core.CreatePlanRequest) (*core.Plan, error)

Create creates a new plan

func (*PlanService) Delete

func (s *PlanService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a plan

func (*PlanService) GetByID

func (s *PlanService) GetByID(ctx context.Context, id xid.ID) (*core.Plan, error)

GetByID retrieves a plan by ID

func (*PlanService) GetBySlug

func (s *PlanService) GetBySlug(ctx context.Context, appID xid.ID, slug string) (*core.Plan, error)

GetBySlug retrieves a plan by slug

func (*PlanService) List

func (s *PlanService) List(ctx context.Context, appID xid.ID, activeOnly, publicOnly bool, page, pageSize int) ([]*core.Plan, int, error)

List retrieves plans with filtering

func (*PlanService) SetActive

func (s *PlanService) SetActive(ctx context.Context, id xid.ID, active bool) error

SetActive sets the active status of a plan

func (*PlanService) SetAutoSyncPlans

func (s *PlanService) SetAutoSyncPlans(enabled bool)

SetAutoSyncPlans enables or disables automatic plan sync to provider

func (*PlanService) SetPublic

func (s *PlanService) SetPublic(ctx context.Context, id xid.ID, public bool) error

SetPublic sets the public visibility of a plan

func (*PlanService) SyncAllFromProvider

func (s *PlanService) SyncAllFromProvider(ctx context.Context, appID xid.ID) ([]*core.Plan, error)

SyncAllFromProvider syncs all plans from the payment provider for a given app. It fetches all products from the provider that have AuthSome metadata, creates new local records for products that don't exist locally, and updates existing local records with data from the provider.

func (*PlanService) SyncFromProvider

func (s *PlanService) SyncFromProvider(ctx context.Context, providerPlanID string) (*core.Plan, error)

SyncFromProvider syncs a single plan from the payment provider using the provider plan ID. If the plan exists locally, it updates the local record with data from the provider. If the plan doesn't exist locally but has AuthSome metadata, it creates a new local record.

func (*PlanService) SyncToProvider

func (s *PlanService) SyncToProvider(ctx context.Context, id xid.ID) error

SyncToProvider syncs the plan to the payment provider

func (*PlanService) Update

func (s *PlanService) Update(ctx context.Context, id xid.ID, req *core.UpdatePlanRequest) (*core.Plan, error)

Update updates an existing plan

type PlanServiceInterface

type PlanServiceInterface interface {
	Create(ctx context.Context, appID xid.ID, req *core.CreatePlanRequest) (*core.Plan, error)
	Update(ctx context.Context, id xid.ID, req *core.UpdatePlanRequest) (*core.Plan, error)
	Delete(ctx context.Context, id xid.ID) error
	GetByID(ctx context.Context, id xid.ID) (*core.Plan, error)
	GetBySlug(ctx context.Context, appID xid.ID, slug string) (*core.Plan, error)
	List(ctx context.Context, appID xid.ID, activeOnly, publicOnly bool, page, pageSize int) ([]*core.Plan, int, error)
	SetActive(ctx context.Context, id xid.ID, active bool) error
	SetPublic(ctx context.Context, id xid.ID, public bool) error
	SyncToProvider(ctx context.Context, id xid.ID) error
	SyncFromProvider(ctx context.Context, providerPlanID string) (*core.Plan, error)
	SyncAllFromProvider(ctx context.Context, appID xid.ID) ([]*core.Plan, error)
}

PlanServiceInterface defines the plan service interface

type SubscriptionService

type SubscriptionService struct {
	// contains filtered or unexported fields
}

SubscriptionService handles subscription business logic

func NewSubscriptionService

NewSubscriptionService creates a new subscription service

func (*SubscriptionService) AttachAddOn

func (s *SubscriptionService) AttachAddOn(ctx context.Context, subID, addOnID xid.ID, quantity int) error

AttachAddOn attaches an add-on to a subscription

func (*SubscriptionService) Cancel

Cancel cancels a subscription

func (*SubscriptionService) ChangePlan

func (s *SubscriptionService) ChangePlan(ctx context.Context, id, newPlanID xid.ID) (*core.Subscription, error)

ChangePlan changes the subscription plan

func (*SubscriptionService) Create

Create creates a new subscription

func (*SubscriptionService) DetachAddOn

func (s *SubscriptionService) DetachAddOn(ctx context.Context, subID, addOnID xid.ID) error

DetachAddOn detaches an add-on from a subscription

func (*SubscriptionService) GetByID

func (s *SubscriptionService) GetByID(ctx context.Context, id xid.ID) (*core.Subscription, error)

GetByID retrieves a subscription by ID

func (*SubscriptionService) GetByOrganizationID

func (s *SubscriptionService) GetByOrganizationID(ctx context.Context, orgID xid.ID) (*core.Subscription, error)

GetByOrganizationID retrieves the active subscription for an organization

func (*SubscriptionService) List

func (s *SubscriptionService) List(ctx context.Context, appID, orgID, planID *xid.ID, status string, page, pageSize int) ([]*core.Subscription, int, error)

List retrieves subscriptions with filtering

func (*SubscriptionService) Pause

Pause pauses a subscription

func (*SubscriptionService) Resume

func (s *SubscriptionService) Resume(ctx context.Context, id xid.ID) error

Resume resumes a paused subscription

func (*SubscriptionService) SyncFromProvider

func (s *SubscriptionService) SyncFromProvider(ctx context.Context, providerSubID string) (*core.Subscription, error)

SyncFromProvider syncs subscription data from the provider

func (*SubscriptionService) SyncFromProviderByID added in v0.0.5

func (s *SubscriptionService) SyncFromProviderByID(ctx context.Context, id xid.ID) (*core.Subscription, error)

SyncFromProviderByID syncs subscription data from provider using local subscription ID

func (*SubscriptionService) SyncToProvider added in v0.0.5

func (s *SubscriptionService) SyncToProvider(ctx context.Context, id xid.ID) error

SyncToProvider syncs a subscription to the payment provider

func (*SubscriptionService) Update

Update updates a subscription

func (*SubscriptionService) UpdateQuantity

func (s *SubscriptionService) UpdateQuantity(ctx context.Context, id xid.ID, quantity int) (*core.Subscription, error)

UpdateQuantity updates the subscription quantity

type SubscriptionServiceInterface

type SubscriptionServiceInterface interface {
	Create(ctx context.Context, req *core.CreateSubscriptionRequest) (*core.Subscription, error)
	Update(ctx context.Context, id xid.ID, req *core.UpdateSubscriptionRequest) (*core.Subscription, error)
	Cancel(ctx context.Context, id xid.ID, req *core.CancelSubscriptionRequest) error
	Pause(ctx context.Context, id xid.ID, req *core.PauseSubscriptionRequest) error
	Resume(ctx context.Context, id xid.ID) error
	GetByID(ctx context.Context, id xid.ID) (*core.Subscription, error)
	GetByOrganizationID(ctx context.Context, orgID xid.ID) (*core.Subscription, error)
	List(ctx context.Context, appID, orgID, planID *xid.ID, status string, page, pageSize int) ([]*core.Subscription, int, error)
	ChangePlan(ctx context.Context, id, newPlanID xid.ID) (*core.Subscription, error)
	UpdateQuantity(ctx context.Context, id xid.ID, quantity int) (*core.Subscription, error)
	AttachAddOn(ctx context.Context, subID, addOnID xid.ID, quantity int) error
	DetachAddOn(ctx context.Context, subID, addOnID xid.ID) error
	SyncFromProvider(ctx context.Context, providerSubID string) (*core.Subscription, error)
	SyncFromProviderByID(ctx context.Context, id xid.ID) (*core.Subscription, error)
	SyncToProvider(ctx context.Context, id xid.ID) error
}

SubscriptionServiceInterface defines the subscription service interface

type TaxService

type TaxService struct {
	// contains filtered or unexported fields
}

TaxService handles tax rate and calculation operations

func NewTaxService

func NewTaxService(repo repository.TaxRepository) *TaxService

NewTaxService creates a new tax service

func (*TaxService) CalculateTax

func (s *TaxService) CalculateTax(ctx context.Context, appID xid.ID, req *core.CalculateTaxRequest) (*core.TaxCalculation, error)

CalculateTax calculates tax for an amount

func (*TaxService) CreateCustomerTaxID

func (s *TaxService) CreateCustomerTaxID(ctx context.Context, appID xid.ID, req *core.CreateTaxIDRequest) (*core.CustomerTaxID, error)

CreateCustomerTaxID creates a tax ID for an organization

func (*TaxService) CreateTaxExemption

func (s *TaxService) CreateTaxExemption(ctx context.Context, appID xid.ID, req *core.CreateTaxExemptionRequest) (*core.TaxExemption, error)

CreateTaxExemption creates a tax exemption for an organization

func (*TaxService) CreateTaxRate

func (s *TaxService) CreateTaxRate(ctx context.Context, appID xid.ID, req *core.CreateTaxRateRequest) (*core.TaxRate, error)

CreateTaxRate creates a new tax rate

func (*TaxService) DeleteTaxRate

func (s *TaxService) DeleteTaxRate(ctx context.Context, id xid.ID) error

DeleteTaxRate deletes a tax rate

func (*TaxService) GetTaxRate

func (s *TaxService) GetTaxRate(ctx context.Context, id xid.ID) (*core.TaxRate, error)

GetTaxRate returns a tax rate by ID

func (*TaxService) GetTaxRateForLocation

func (s *TaxService) GetTaxRateForLocation(ctx context.Context, appID xid.ID, country, state string) (*core.TaxRate, error)

GetTaxRateForLocation returns the applicable tax rate for a location

func (*TaxService) ListCustomerTaxIDs

func (s *TaxService) ListCustomerTaxIDs(ctx context.Context, orgID xid.ID) ([]*core.CustomerTaxID, error)

ListCustomerTaxIDs lists tax IDs for an organization

func (*TaxService) ListTaxExemptions

func (s *TaxService) ListTaxExemptions(ctx context.Context, orgID xid.ID) ([]*core.TaxExemption, error)

ListTaxExemptions lists tax exemptions for an organization

func (*TaxService) ListTaxRates

func (s *TaxService) ListTaxRates(ctx context.Context, appID xid.ID, activeOnly bool) ([]*core.TaxRate, error)

ListTaxRates returns all tax rates for an app

func (*TaxService) UpdateTaxRate

func (s *TaxService) UpdateTaxRate(ctx context.Context, id xid.ID, req *core.UpdateTaxRateRequest) (*core.TaxRate, error)

UpdateTaxRate updates a tax rate

func (*TaxService) ValidateVAT

func (s *TaxService) ValidateVAT(ctx context.Context, countryCode, vatNumber string) (*core.VATValidationResult, error)

ValidateVAT validates a VAT number (stub - would call VIES or similar)

func (*TaxService) VerifyTaxExemption

func (s *TaxService) VerifyTaxExemption(ctx context.Context, id xid.ID) error

VerifyTaxExemption marks an exemption as verified

type UsageService

type UsageService struct {
	// contains filtered or unexported fields
}

UsageService handles usage tracking and metering

func NewUsageService

NewUsageService creates a new usage service

func (*UsageService) GetCurrentPeriodUsage

func (s *UsageService) GetCurrentPeriodUsage(ctx context.Context, subID xid.ID) (map[string]int64, error)

GetCurrentPeriodUsage gets all usage for the current billing period

func (*UsageService) GetSummary

GetSummary retrieves usage summary for a subscription and metric

func (*UsageService) GetUsageLimit

func (s *UsageService) GetUsageLimit(ctx context.Context, orgID xid.ID, metricKey string) (*core.UsageLimit, error)

GetUsageLimit retrieves current usage against limit for a metric

func (*UsageService) List

func (s *UsageService) List(ctx context.Context, subID, orgID *xid.ID, metricKey string, reported *bool, page, pageSize int) ([]*core.UsageRecord, int, error)

List retrieves usage records with filtering

func (*UsageService) RecordUsage

func (s *UsageService) RecordUsage(ctx context.Context, req *core.RecordUsageRequest) (*core.UsageRecord, error)

RecordUsage records a usage event

func (*UsageService) ReportToProvider

func (s *UsageService) ReportToProvider(ctx context.Context, batchSize int) error

ReportToProvider reports unreported usage to the payment provider

type UsageServiceInterface

type UsageServiceInterface interface {
	RecordUsage(ctx context.Context, req *core.RecordUsageRequest) (*core.UsageRecord, error)
	GetSummary(ctx context.Context, req *core.GetUsageSummaryRequest) (*core.UsageSummary, error)
	GetUsageLimit(ctx context.Context, orgID xid.ID, metricKey string) (*core.UsageLimit, error)
	ReportToProvider(ctx context.Context, batchSize int) error
}

UsageServiceInterface defines the usage service interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL