billingservice

package
v1.0.0-beta.231 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteTriggerWithAllowInStates

func ExecuteTriggerWithAllowInStates(states ...billing.StandardInvoiceStatus) executeTriggerApplyOptionFunc

func ExecuteTriggerWithArgs

func ExecuteTriggerWithArgs(args ...any) executeTriggerApplyOptionFunc

func ExecuteTriggerWithEditCallback

func ExecuteTriggerWithEditCallback(cb editCallbackFunc) executeTriggerApplyOptionFunc

func ExecuteTriggerWithIncludeDeletedLines

func ExecuteTriggerWithIncludeDeletedLines(includeDeletedLines bool) executeTriggerApplyOptionFunc

func ExecuteTriggerWithPreTriggerCallback

func ExecuteTriggerWithPreTriggerCallback(cb preTriggerCallbackFunc) executeTriggerApplyOptionFunc

Types

type Config

type Config struct {
	Adapter                      billing.Adapter
	SequenceService              sequence.Service
	CustomerService              customer.Service
	AppService                   app.Service
	TaxCodeService               taxcode.Service
	RatingService                rating.Service
	Logger                       *slog.Logger
	FeatureService               feature.FeatureConnector
	MeterService                 meter.Service
	StreamingConnector           streaming.Connector
	Publisher                    eventbus.Publisher
	AdvancementStrategy          billing.AdvancementStrategy
	FSNamespaceLockdown          []string
	MaxParallelQuantitySnapshots int
}

func (Config) Validate

func (c Config) Validate() error

type GatheringLinesWithEngine

type GatheringLinesWithEngine struct {
	Engine billing.LineEngine
	Lines  billing.GatheringLines
}

type InvoiceStateMachine

type InvoiceStateMachine struct {
	Invoice             billing.StandardInvoice
	NeedsDBSave         bool
	Calculator          invoicecalc.Calculator
	StateMachine        *stateless.StateMachine
	Logger              *slog.Logger
	Publisher           eventbus.Publisher
	Service             *Service
	FSNamespaceLockdown []string
}

func (*InvoiceStateMachine) AdvanceUntilStateStable

func (m *InvoiceStateMachine) AdvanceUntilStateStable(ctx context.Context) error

func (*InvoiceStateMachine) CanFire

func (m *InvoiceStateMachine) CanFire(ctx context.Context, trigger billing.InvoiceTrigger, args ...any) (bool, error)

func (*InvoiceStateMachine) FireAndActivate

func (m *InvoiceStateMachine) FireAndActivate(ctx context.Context, trigger billing.InvoiceTrigger, args ...any) error

FireAndActivate fires the trigger and activates the new state, if activation fails it automatically transitions to the failed state and activates that. In addition to the activation a calculation is always performed to ensure that the invoice is up to date.

func (*InvoiceStateMachine) HandleInvoiceTrigger

func (m *InvoiceStateMachine) HandleInvoiceTrigger(ctx context.Context, trigger billing.InvoiceTriggerInput) error

func (*InvoiceStateMachine) StatusDetails

func (*InvoiceStateMachine) TriggerFailed

func (m *InvoiceStateMachine) TriggerFailed(ctx context.Context) error

type InvoiceStateMachineCallback

type InvoiceStateMachineCallback func(context.Context, *InvoiceStateMachine) error

type Service

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

func New

func New(config Config) (*Service, error)

func (*Service) AdvanceInvoice

func (*Service) ApproveInvoice

func (*Service) CreatePendingInvoiceLines

TODO[later]: Move this to gatheringinvoice.go

func (*Service) CreateProfile

func (s *Service) CreateProfile(ctx context.Context, input billing.CreateProfileInput) (*billing.Profile, error)

func (*Service) CreateStandardInvoiceFromGatheringLines

func (s *Service) CreateStandardInvoiceFromGatheringLines(ctx context.Context, in billing.CreateStandardInvoiceFromGatheringLinesInput) (*billing.StandardInvoice, error)

createStandardInvoiceFromGatheringLines creates a standard invoice from the gathering invoice lines. Invariant: - the standard invoice is in draft.created state, and is calculated and persisted to the database - the gathering invoice's lines are deleted, and persisted to the database

func (*Service) DeleteCustomerOverride

func (s *Service) DeleteCustomerOverride(ctx context.Context, input billing.DeleteCustomerOverrideInput) error

func (*Service) DeleteGatheringInvoice

func (s *Service) DeleteGatheringInvoice(ctx context.Context, input billing.DeleteInvoiceInput) (billing.GatheringInvoice, error)

func (*Service) DeleteInvoice

func (*Service) DeleteProfile

func (s *Service) DeleteProfile(ctx context.Context, input billing.DeleteProfileInput) error

func (*Service) DeleteSplitLineGroup

func (s *Service) DeleteSplitLineGroup(ctx context.Context, input billing.DeleteSplitLineGroupInput) error

func (*Service) DeregisterLineEngine

func (s *Service) DeregisterLineEngine(engineType billing.LineEngineType) error

func (*Service) ForceCollectInvoice

func (s *Service) ForceCollectInvoice(ctx context.Context, input billing.ForceCollectInvoiceInput) (billing.StandardInvoice, error)

ForceCollectInvoice bypasses the invoice collection period and moves the invoice into collection immediately.

func (Service) GetAdvancementStrategy

func (s Service) GetAdvancementStrategy() billing.AdvancementStrategy

func (*Service) GetCustomerApp

func (s *Service) GetCustomerApp(ctx context.Context, input billing.GetCustomerAppInput) (app.App, error)

TODO: remove this once legacy API is removed GetCustomerApp returns the app for a customer, it will return the first app found for the app type

func (*Service) GetDefaultProfile

func (s *Service) GetDefaultProfile(ctx context.Context, input billing.GetDefaultProfileInput) (*billing.Profile, error)

func (*Service) GetGatheringInvoiceById

func (s *Service) GetGatheringInvoiceById(ctx context.Context, input billing.GetGatheringInvoiceByIdInput) (billing.GatheringInvoice, error)

func (*Service) GetInvoiceById

func (s *Service) GetInvoiceById(ctx context.Context, input billing.GetInvoiceByIdInput) (billing.Invoice, error)

func (*Service) GetLinesForSubscription

func (s *Service) GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error)

func (*Service) GetProfile

func (s *Service) GetProfile(ctx context.Context, input billing.GetProfileInput) (*billing.Profile, error)

func (*Service) GetRegisteredLineEngines

func (s *Service) GetRegisteredLineEngines() []billing.LineEngineType

func (*Service) GetSplitLineGroup

func (*Service) GetStandardInvoiceById

func (s *Service) GetStandardInvoiceById(ctx context.Context, input billing.GetStandardInvoiceByIdInput) (billing.StandardInvoice, error)

func (Service) InvoiceCalculator

func (s Service) InvoiceCalculator() invoicecalc.Calculator

func (*Service) InvoicePendingLines

InvoicePendingLines invoices the pending lines for the customer. Flow (overview):

1) We fetch the gathering invoices of the customer and collect the lines that can be invoiced asOf input.AsOf.

A line is considered billable if it's invoice_at <= input.AsOf OR if progressive billing is enabled and as per the line service the line can be invoiced in multiple parts.

2) We prepare the lines to be billed on the gathering invoice and update it in the database. (prepareLinesToBill)

If a line needs to be split the splitGatheringInvoiceLine method is used, what it does:

  • It creates a new split line group if it doesn't exist (it groups together the lines on multiple invoices when a single gathering line is billed on multiple invoices)
  • It creates a new line for the period up to the split at time, decreases the existing line's period end to the split at time.
  • Note: ChildUniqueReferenceID is set to nil to avoid conflicts on the gathering invoice, the SplitLineGroup owns this unique reference.

3) We create a new standard invoice from the gathering invoice and associate the lines to it. (createStandardInvoiceFromGatheringLines)

  • The in-scope lines are moved from the gathering invoice to the new standard invoice (moveLinesToInvoice)

4) We update the gathering invoice to remove the lines that have been associated to the new invoice. (updateGatheringInvoice)

5) We publish the invoice created event.

6) We return the created invoices.

func (*Service) IsAppUsed

func (s *Service) IsAppUsed(ctx context.Context, appID app.AppID) error

func (*Service) ListInvoices

func (*Service) ListProfiles

func (*Service) OnUnsupportedCreditNote

func (s *Service) OnUnsupportedCreditNote(ctx context.Context, input billing.OnUnsupportedCreditNoteInput) error

func (*Service) PaymentAuthorized

func (s *Service) PaymentAuthorized(ctx context.Context, input billing.PaymentAuthorizedInput) (billing.StandardInvoice, error)

func (*Service) ProvisionDefaultBillingProfile

func (s *Service) ProvisionDefaultBillingProfile(ctx context.Context, namespace string) error

func (*Service) RecalculateGatheringInvoices

func (s *Service) RecalculateGatheringInvoices(ctx context.Context, input billing.RecalculateGatheringInvoicesInput) error

func (*Service) RegisterCreateLineRouter

func (s *Service) RegisterCreateLineRouter(router billing.CreateLineRouter) error

func (*Service) RegisterLineEngine

func (s *Service) RegisterLineEngine(eng billing.LineEngine) error

func (*Service) RegisterStandardInvoiceHooks

func (s *Service) RegisterStandardInvoiceHooks(hooks ...billing.StandardInvoiceHook)

func (*Service) ResolveStripeAppIDFromBillingProfile

func (s *Service) ResolveStripeAppIDFromBillingProfile(ctx context.Context, namespace string, customerId *customer.CustomerID) (app.AppID, error)

func (*Service) RetryInvoice

func (Service) SimulateInvoice

func (*Service) SnapshotLineQuantities

func (s *Service) SnapshotLineQuantities(ctx context.Context, invoice billing.StandardInvoice, lines billing.StandardLines) error

func (*Service) SnapshotLineQuantity

func (s *Service) SnapshotLineQuantity(ctx context.Context, input billing.SnapshotLineQuantityInput) (*billing.StandardLine, error)

func (*Service) SyncDraftInvoice

func (*Service) SyncIssuingInvoice

func (*Service) TriggerInvoice

func (s *Service) TriggerInvoice(ctx context.Context, input billing.InvoiceTriggerServiceInput) error

func (*Service) UpdateGatheringInvoice

func (s *Service) UpdateGatheringInvoice(ctx context.Context, input billing.UpdateGatheringInvoiceInput) (billing.GatheringInvoice, error)

func (*Service) UpdateInvoiceFields

func (s *Service) UpdateInvoiceFields(ctx context.Context, input billing.UpdateInvoiceFieldsInput) error

func (*Service) UpdateProfile

func (s *Service) UpdateProfile(ctx context.Context, input billing.UpdateProfileInput) (*billing.Profile, error)

func (*Service) UpdateSplitLineGroup

func (s *Service) UpdateSplitLineGroup(ctx context.Context, input billing.UpdateSplitLineGroupInput) (billing.SplitLineGroup, error)

func (*Service) UpdateStandardInvoice

func (s *Service) UpdateStandardInvoice(ctx context.Context, input billing.UpdateStandardInvoiceInput) (billing.StandardInvoice, error)

func (*Service) UpsertValidationIssues

func (s *Service) UpsertValidationIssues(ctx context.Context, input billing.UpsertValidationIssuesInput) error

func (Service) WithAdvancementStrategy

func (s Service) WithAdvancementStrategy(strategy billing.AdvancementStrategy) billing.Service

func (Service) WithInvoiceCalculator

func (s Service) WithInvoiceCalculator(calc invoicecalc.Calculator) *Service

func (*Service) WithInvoiceStateMachine

func (s *Service) WithInvoiceStateMachine(ctx context.Context, invoice billing.StandardInvoice, cb InvoiceStateMachineCallback) (billing.StandardInvoice, error)

func (*Service) WithLock

func (s *Service) WithLock(ctx context.Context, customerID customer.CustomerID, fn func(ctx context.Context) error) error

func (*Service) WithLockedNamespaces

func (s *Service) WithLockedNamespaces(namespaces []string) billing.Service

type StandardLinesWithEngine

type StandardLinesWithEngine struct {
	Engine billing.LineEngine
	Lines  billing.StandardLines
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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