Documentation
¶
Index ¶
- type AuthService
- type BillingCalculationResult
- type BillingService
- type CustomerService
- type EntitlementService
- type EnvironmentService
- type EventService
- type FeatureService
- type InvoiceService
- type MeterService
- type PaymentProcessorService
- type PaymentService
- type PlanService
- type PriceService
- type SecretService
- type ServiceParams
- type SubscriptionService
- type TaskService
- type TenantService
- type UserService
- type WalletService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthService ¶
type AuthService interface {
SignUp(ctx context.Context, req *dto.SignUpRequest) (*dto.AuthResponse, error)
Login(ctx context.Context, req *dto.LoginRequest) (*dto.AuthResponse, error)
OnboardNewUserWithTenant(ctx context.Context, userID, email, tenantName, tenantID string) error
}
func NewAuthService ¶
func NewAuthService( cfg *config.Configuration, userRepo user.Repository, authRepo auth.Repository, tenantRepo tenant.Repository, environmentRepo environment.Repository, logger *logger.Logger, db postgres.IClient, ) AuthService
type BillingCalculationResult ¶
type BillingCalculationResult struct {
FixedCharges []dto.CreateInvoiceLineItemRequest
UsageCharges []dto.CreateInvoiceLineItemRequest
TotalAmount decimal.Decimal
Currency string
}
BillingCalculationResult holds all calculated charges for a billing period
type BillingService ¶
type BillingService interface {
// CalculateFixedCharges calculates all fixed charges for a subscription
CalculateFixedCharges(ctx context.Context, sub *subscription.Subscription, periodStart, periodEnd time.Time) ([]dto.CreateInvoiceLineItemRequest, decimal.Decimal, error)
// CalculateUsageCharges calculates all usage-based charges
CalculateUsageCharges(ctx context.Context, sub *subscription.Subscription, usage *dto.GetUsageBySubscriptionResponse, periodStart, periodEnd time.Time) ([]dto.CreateInvoiceLineItemRequest, decimal.Decimal, error)
// CalculateAllCharges calculates both fixed and usage charges
CalculateAllCharges(ctx context.Context, sub *subscription.Subscription, usage *dto.GetUsageBySubscriptionResponse, periodStart, periodEnd time.Time) (*BillingCalculationResult, error)
// PrepareSubscriptionInvoiceRequest prepares a complete invoice request for a subscription period
PrepareSubscriptionInvoiceRequest(ctx context.Context, sub *subscription.Subscription, periodStart, periodEnd time.Time, isPreview bool) (*dto.CreateInvoiceRequest, error)
}
BillingService handles all billing calculations
func NewBillingService ¶
func NewBillingService(params ServiceParams) BillingService
type CustomerService ¶
type CustomerService interface {
CreateCustomer(ctx context.Context, req dto.CreateCustomerRequest) (*dto.CustomerResponse, error)
GetCustomer(ctx context.Context, id string) (*dto.CustomerResponse, error)
GetCustomers(ctx context.Context, filter *types.CustomerFilter) (*dto.ListCustomersResponse, error)
UpdateCustomer(ctx context.Context, id string, req dto.UpdateCustomerRequest) (*dto.CustomerResponse, error)
DeleteCustomer(ctx context.Context, id string) error
GetCustomerByLookupKey(ctx context.Context, lookupKey string) (*dto.CustomerResponse, error)
}
func NewCustomerService ¶
func NewCustomerService(repo customer.Repository) CustomerService
type EntitlementService ¶
type EntitlementService interface {
CreateEntitlement(ctx context.Context, req dto.CreateEntitlementRequest) (*dto.EntitlementResponse, error)
GetEntitlement(ctx context.Context, id string) (*dto.EntitlementResponse, error)
ListEntitlements(ctx context.Context, filter *types.EntitlementFilter) (*dto.ListEntitlementsResponse, error)
UpdateEntitlement(ctx context.Context, id string, req dto.UpdateEntitlementRequest) (*dto.EntitlementResponse, error)
DeleteEntitlement(ctx context.Context, id string) error
GetPlanEntitlements(ctx context.Context, planID string) (*dto.ListEntitlementsResponse, error)
GetPlanFeatureEntitlements(ctx context.Context, planID, featureID string) (*dto.ListEntitlementsResponse, error)
}
EntitlementService defines the interface for entitlement operations
func NewEntitlementService ¶
func NewEntitlementService( repo entitlement.Repository, planRepo plan.Repository, featureRepo feature.Repository, meterRepo meter.Repository, log *logger.Logger, ) EntitlementService
type EnvironmentService ¶
type EnvironmentService interface {
CreateEnvironment(ctx context.Context, req dto.CreateEnvironmentRequest) (*dto.EnvironmentResponse, error)
GetEnvironment(ctx context.Context, id string) (*dto.EnvironmentResponse, error)
GetEnvironments(ctx context.Context, filter types.Filter) (*dto.ListEnvironmentsResponse, error)
UpdateEnvironment(ctx context.Context, id string, req dto.UpdateEnvironmentRequest) (*dto.EnvironmentResponse, error)
}
func NewEnvironmentService ¶
func NewEnvironmentService(repo environment.Repository) EnvironmentService
type EventService ¶
type EventService interface {
CreateEvent(ctx context.Context, createEventRequest *dto.IngestEventRequest) error
GetUsage(ctx context.Context, getUsageRequest *dto.GetUsageRequest) (*events.AggregationResult, error)
GetUsageByMeter(ctx context.Context, getUsageByMeterRequest *dto.GetUsageByMeterRequest) (*events.AggregationResult, error)
GetUsageByMeterWithFilters(ctx context.Context, req *dto.GetUsageByMeterRequest, filterGroups map[string]map[string][]string) ([]*events.AggregationResult, error)
GetEvents(ctx context.Context, req *dto.GetEventsRequest) (*dto.GetEventsResponse, error)
}
func NewEventService ¶
func NewEventService( eventRepo events.Repository, meterRepo meter.Repository, publisher publisher.EventPublisher, logger *logger.Logger, ) EventService
type FeatureService ¶
type FeatureService interface {
CreateFeature(ctx context.Context, req dto.CreateFeatureRequest) (*dto.FeatureResponse, error)
GetFeature(ctx context.Context, id string) (*dto.FeatureResponse, error)
GetFeatures(ctx context.Context, filter *types.FeatureFilter) (*dto.ListFeaturesResponse, error)
UpdateFeature(ctx context.Context, id string, req dto.UpdateFeatureRequest) (*dto.FeatureResponse, error)
DeleteFeature(ctx context.Context, id string) error
}
func NewFeatureService ¶
func NewFeatureService(repo feature.Repository, meterRepo meter.Repository, logger *logger.Logger) FeatureService
type InvoiceService ¶
type InvoiceService interface {
CreateInvoice(ctx context.Context, req dto.CreateInvoiceRequest) (*dto.InvoiceResponse, error)
GetInvoice(ctx context.Context, id string) (*dto.InvoiceResponse, error)
ListInvoices(ctx context.Context, filter *types.InvoiceFilter) (*dto.ListInvoicesResponse, error)
FinalizeInvoice(ctx context.Context, id string) error
VoidInvoice(ctx context.Context, id string) error
UpdatePaymentStatus(ctx context.Context, id string, status types.PaymentStatus, amount *decimal.Decimal) error
CreateSubscriptionInvoice(ctx context.Context, req *dto.CreateSubscriptionInvoiceRequest) (*dto.InvoiceResponse, error)
GetPreviewInvoice(ctx context.Context, req dto.GetPreviewInvoiceRequest) (*dto.InvoiceResponse, error)
GetCustomerInvoiceSummary(ctx context.Context, customerID string, currency string) (*dto.CustomerInvoiceSummary, error)
GetCustomerMultiCurrencyInvoiceSummary(ctx context.Context, customerID string) (*dto.CustomerMultiCurrencyInvoiceSummary, error)
}
func NewInvoiceService ¶
func NewInvoiceService(params ServiceParams) InvoiceService
type MeterService ¶
type MeterService interface {
CreateMeter(ctx context.Context, req *dto.CreateMeterRequest) (*meter.Meter, error)
GetMeter(ctx context.Context, id string) (*meter.Meter, error)
GetMeters(ctx context.Context, filter *types.MeterFilter) (*dto.ListMetersResponse, error)
GetAllMeters(ctx context.Context) (*dto.ListMetersResponse, error)
DisableMeter(ctx context.Context, id string) error
UpdateMeter(ctx context.Context, id string, filters []meter.Filter) (*meter.Meter, error)
}
func NewMeterService ¶
func NewMeterService(meterRepo meter.Repository) MeterService
type PaymentProcessorService ¶
type PaymentProcessorService interface {
ProcessPayment(ctx context.Context, id string) (*payment.Payment, error)
}
func NewPaymentProcessorService ¶
func NewPaymentProcessorService(params ServiceParams) PaymentProcessorService
type PaymentService ¶
type PaymentService interface {
// Core payment operations
CreatePayment(ctx context.Context, req dto.CreatePaymentRequest) (*dto.PaymentResponse, error)
GetPayment(ctx context.Context, id string) (*dto.PaymentResponse, error)
UpdatePayment(ctx context.Context, id string, req dto.UpdatePaymentRequest) (*dto.PaymentResponse, error)
ListPayments(ctx context.Context, filter *types.PaymentFilter) (*dto.ListPaymentsResponse, error)
DeletePayment(ctx context.Context, id string) error
}
PaymentService defines the interface for payment operations
func NewPaymentService ¶
func NewPaymentService(params ServiceParams) PaymentService
NewPaymentService creates a new payment service
type PlanService ¶
type PlanService interface {
CreatePlan(ctx context.Context, req dto.CreatePlanRequest) (*dto.CreatePlanResponse, error)
GetPlan(ctx context.Context, id string) (*dto.PlanResponse, error)
GetPlans(ctx context.Context, filter *types.PlanFilter) (*dto.ListPlansResponse, error)
UpdatePlan(ctx context.Context, id string, req dto.UpdatePlanRequest) (*dto.PlanResponse, error)
DeletePlan(ctx context.Context, id string) error
}
func NewPlanService ¶
func NewPlanService( client postgres.IClient, planRepo plan.Repository, priceRepo price.Repository, meterRepo meter.Repository, entitlementRepo entitlement.Repository, featureRepo feature.Repository, logger *logger.Logger, ) PlanService
type PriceService ¶
type PriceService interface {
CreatePrice(ctx context.Context, req dto.CreatePriceRequest) (*dto.PriceResponse, error)
GetPrice(ctx context.Context, id string) (*dto.PriceResponse, error)
GetPricesByPlanID(ctx context.Context, planID string) (*dto.ListPricesResponse, error)
GetPrices(ctx context.Context, filter *types.PriceFilter) (*dto.ListPricesResponse, error)
UpdatePrice(ctx context.Context, id string, req dto.UpdatePriceRequest) (*dto.PriceResponse, error)
DeletePrice(ctx context.Context, id string) error
CalculateCost(ctx context.Context, price *price.Price, quantity decimal.Decimal) decimal.Decimal
}
func NewPriceService ¶
func NewPriceService(repo price.Repository, meterRepo meter.Repository, logger *logger.Logger) PriceService
type SecretService ¶
type SecretService interface {
// API Key operations
CreateAPIKey(ctx context.Context, req *dto.CreateAPIKeyRequest) (*secret.Secret, string, error)
ListAPIKeys(ctx context.Context, filter *types.SecretFilter) (*dto.ListSecretsResponse, error)
Delete(ctx context.Context, id string) error
// Integration operations
CreateIntegration(ctx context.Context, req *dto.CreateIntegrationRequest) (*secret.Secret, error)
ListIntegrations(ctx context.Context, filter *types.SecretFilter) (*dto.ListSecretsResponse, error)
// Verification operations
VerifyAPIKey(ctx context.Context, apiKey string) (*secret.Secret, error)
ListLinkedIntegrations(ctx context.Context) ([]string, error)
// contains filtered or unexported methods
}
SecretService defines the interface for secret business logic
func NewSecretService ¶
func NewSecretService( repo secret.Repository, config *config.Configuration, logger *logger.Logger, ) SecretService
NewSecretService creates a new secret service
type ServiceParams ¶
type ServiceParams struct {
Logger *logger.Logger
Config *config.Configuration
DB postgres.IClient
// Repositories
AuthRepo auth.Repository
UserRepo user.Repository
EventRepo events.Repository
MeterRepo meter.Repository
PriceRepo price.Repository
CustomerRepo customer.Repository
PlanRepo plan.Repository
SubRepo subscription.Repository
WalletRepo wallet.Repository
TenantRepo tenant.Repository
InvoiceRepo invoice.Repository
FeatureRepo feature.Repository
EntitlementRepo entitlement.Repository
PaymentRepo payment.Repository
SecretRepo secret.Repository
// Publishers
EventPublisher publisher.EventPublisher
WebhookPublisher webhookPublisher.WebhookPublisher
}
ServiceParams holds common dependencies for services TODO: start using this for all services init
func NewServiceParams ¶
func NewServiceParams( logger *logger.Logger, config *config.Configuration, db postgres.IClient, authRepo auth.Repository, userRepo user.Repository, eventRepo events.Repository, meterRepo meter.Repository, priceRepo price.Repository, customerRepo customer.Repository, planRepo plan.Repository, subRepo subscription.Repository, walletRepo wallet.Repository, tenantRepo tenant.Repository, invoiceRepo invoice.Repository, featureRepo feature.Repository, entitlementRepo entitlement.Repository, paymentRepo payment.Repository, secretRepo secret.Repository, eventPublisher publisher.EventPublisher, webhookPublisher webhookPublisher.WebhookPublisher, ) ServiceParams
Common service params
type SubscriptionService ¶
type SubscriptionService interface {
CreateSubscription(ctx context.Context, req dto.CreateSubscriptionRequest) (*dto.SubscriptionResponse, error)
GetSubscription(ctx context.Context, id string) (*dto.SubscriptionResponse, error)
CancelSubscription(ctx context.Context, id string, cancelAtPeriodEnd bool) error
ListSubscriptions(ctx context.Context, filter *types.SubscriptionFilter) (*dto.ListSubscriptionsResponse, error)
GetUsageBySubscription(ctx context.Context, req *dto.GetUsageBySubscriptionRequest) (*dto.GetUsageBySubscriptionResponse, error)
UpdateBillingPeriods(ctx context.Context) (*dto.SubscriptionUpdatePeriodResponse, error)
// Pause-related methods
PauseSubscription(ctx context.Context, subscriptionID string, req *dto.PauseSubscriptionRequest) (*dto.PauseSubscriptionResponse, error)
ResumeSubscription(ctx context.Context, subscriptionID string, req *dto.ResumeSubscriptionRequest) (*dto.ResumeSubscriptionResponse, error)
GetPause(ctx context.Context, pauseID string) (*subscription.SubscriptionPause, error)
ListPauses(ctx context.Context, subscriptionID string) (*dto.ListSubscriptionPausesResponse, error)
CalculatePauseImpact(ctx context.Context, subscriptionID string, req *dto.PauseSubscriptionRequest) (*types.BillingImpactDetails, error)
CalculateResumeImpact(ctx context.Context, subscriptionID string, req *dto.ResumeSubscriptionRequest) (*types.BillingImpactDetails, error)
}
func NewSubscriptionService ¶
func NewSubscriptionService(params ServiceParams) SubscriptionService
type TaskService ¶
type TaskService interface {
CreateTask(ctx context.Context, req dto.CreateTaskRequest) (*dto.TaskResponse, error)
GetTask(ctx context.Context, id string) (*dto.TaskResponse, error)
ListTasks(ctx context.Context, filter *types.TaskFilter) (*dto.ListTasksResponse, error)
UpdateTaskStatus(ctx context.Context, id string, status types.TaskStatus) error
ProcessTask(ctx context.Context, id string) error
}
func NewTaskService ¶
func NewTaskService( taskRepo task.Repository, eventRepo events.Repository, meterRepo meter.Repository, customerRepo customer.Repository, publisher publisher.EventPublisher, db postgres.IClient, logger *logger.Logger, client httpclient.Client, ) TaskService
type TenantService ¶
type TenantService interface {
CreateTenant(ctx context.Context, req dto.CreateTenantRequest) (*dto.TenantResponse, error)
GetTenantByID(ctx context.Context, id string) (*dto.TenantResponse, error)
AssignTenantToUser(ctx context.Context, req dto.AssignTenantRequest) error
GetAllTenants(ctx context.Context) ([]*dto.TenantResponse, error)
}
func NewTenantService ¶
func NewTenantService(repo tenant.Repository, cfg *config.Configuration) TenantService
type UserService ¶
type UserService interface {
GetUserInfo(ctx context.Context) (*dto.UserResponse, error)
}
func NewUserService ¶
func NewUserService(userRepo user.Repository, tenantRepo tenant.Repository) UserService
type WalletService ¶
type WalletService interface {
// CreateWallet creates a new wallet for a customer
CreateWallet(ctx context.Context, req *dto.CreateWalletRequest) (*dto.WalletResponse, error)
// GetWalletsByCustomerID retrieves all wallets for a customer
GetWalletsByCustomerID(ctx context.Context, customerID string) ([]*dto.WalletResponse, error)
// GetWalletByID retrieves a wallet by its ID and calculates real-time balance
GetWalletByID(ctx context.Context, id string) (*dto.WalletResponse, error)
// GetWalletTransactions retrieves transactions for a wallet with pagination
GetWalletTransactions(ctx context.Context, walletID string, filter *types.WalletTransactionFilter) (*dto.ListWalletTransactionsResponse, error)
// TopUpWallet adds credits to a wallet
TopUpWallet(ctx context.Context, walletID string, req *dto.TopUpWalletRequest) (*dto.WalletResponse, error)
// GetWalletBalance retrieves the real-time balance of a wallet
GetWalletBalance(ctx context.Context, walletID string) (*dto.WalletBalanceResponse, error)
// TerminateWallet terminates a wallet by closing it and debiting remaining balance
TerminateWallet(ctx context.Context, walletID string) error
// UpdateWallet updates a wallet
UpdateWallet(ctx context.Context, id string, req *dto.UpdateWalletRequest) (*wallet.Wallet, error)
// DebitWallet processes a debit operation on a wallet
DebitWallet(ctx context.Context, req *wallet.WalletOperation) error
// CreditWallet processes a credit operation on a wallet
CreditWallet(ctx context.Context, req *wallet.WalletOperation) error
// ExpireCredits expires credits for a given transaction
ExpireCredits(ctx context.Context, transactionID string) error
}
WalletService defines the interface for wallet operations
func NewWalletService ¶
func NewWalletService(params ServiceParams) WalletService
NewWalletService creates a new instance of WalletService