billingservice

package
v1.0.0-beta.211 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteTriggerWithAllowInStates

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

func ExecuteTriggerWithEditCallback

func ExecuteTriggerWithEditCallback(cb editCallbackFunc) executeTriggerApplyOptionFunc

func ExecuteTriggerWithIncludeDeletedLines

func ExecuteTriggerWithIncludeDeletedLines(includeDeletedLines bool) executeTriggerApplyOptionFunc

func GetEarliestValidInvoiceAt

func GetEarliestValidInvoiceAt(lines billing.LineChildren) time.Time

func GetInvoiceWithEarliestCollectionAt

func GetInvoiceWithEarliestCollectionAt(invoices []billing.Invoice) billing.Invoice

func GetLatestValidInvoiceAtAsOf

func GetLatestValidInvoiceAtAsOf(lines billing.LineChildren, asOf time.Time) time.Time

func TranscationForGatheringInvoiceManipulation

func TranscationForGatheringInvoiceManipulation[T any](ctx context.Context, svc *Service, customerID customer.CustomerID, fn func(ctx context.Context) (T, error)) (T, error)

TranscationForGatheringInvoiceManipulation is a helper function that wraps the given function in a transaction and ensures that an update lock is held on the customer record. This is useful when you need to manipulate the gathering invoices, as we cannot lock an invoice, that doesn't exist yet.

func UpdateInvoiceCollectionAt

func UpdateInvoiceCollectionAt(invoice *billing.Invoice, collection billing.CollectionConfig) bool

UpdateInvoiceCollectionAt updates the collectionAt attribute of the invoice with gathering type using the customers collection configuration. It returns true if the attribute has been updated. The collectionAt is calculated by adding the collection interval (from CollectionConfig) to the earliest invoicedAt timestamp of the invoice lines on the gathering invoice.

Types

type Config

type Config struct {
	Adapter             billing.Adapter
	CustomerService     customer.Service
	AppService          app.Service
	Logger              *slog.Logger
	FeatureService      feature.FeatureConnector
	MeterService        meter.Service
	StreamingConnector  streaming.Connector
	Publisher           eventbus.Publisher
	AdvancementStrategy billing.AdvancementStrategy
}

func (Config) Validate

func (c Config) Validate() error

type InvoiceStateMachine

type InvoiceStateMachine struct {
	Invoice      billing.Invoice
	Calculator   invoicecalc.Calculator
	StateMachine *stateless.StateMachine
}

func (*InvoiceStateMachine) AdvanceUntilStateStable

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

func (*InvoiceStateMachine) CanFire

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

func (*InvoiceStateMachine) FireAndActivate

func (m *InvoiceStateMachine) FireAndActivate(ctx context.Context, trigger billing.InvoiceTrigger) 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 (s *Service) AdvanceInvoice(ctx context.Context, input billing.AdvanceInvoiceInput) (billing.Invoice, error)

func (*Service) ApproveInvoice

func (s *Service) ApproveInvoice(ctx context.Context, input billing.ApproveInvoiceInput) (billing.Invoice, error)

func (*Service) CreatePendingInvoiceLines

func (s *Service) CreatePendingInvoiceLines(ctx context.Context, input billing.CreateInvoiceLinesInput) ([]*billing.Line, error)

func (*Service) CreateProfile

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

func (*Service) DeleteCustomerOverride

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

func (*Service) DeleteInvoice

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

func (*Service) DeleteProfile

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

func (*Service) GenerateInvoiceSequenceNumber

func (s *Service) GenerateInvoiceSequenceNumber(ctx context.Context, in billing.SequenceGenerationInput, def billing.SequenceDefinition) (string, error)

func (Service) GetAdvancementStrategy

func (s Service) GetAdvancementStrategy() billing.AdvancementStrategy

func (*Service) GetDefaultProfile

func (s *Service) GetDefaultProfile(ctx context.Context, input billing.GetDefaultProfileInput) (*billing.Profile, 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.Line, error)

func (*Service) GetProfile

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

func (Service) InvoiceCalculator

func (s Service) InvoiceCalculator() invoicecalc.Calculator

func (*Service) InvoicePendingLines

func (s *Service) InvoicePendingLines(ctx context.Context, input billing.InvoicePendingLinesInput) ([]billing.Invoice, error)

func (*Service) IsAppUsed

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

func (*Service) ListInvoices

func (*Service) ListProfiles

func (*Service) ProvisionDefaultBillingProfile

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

func (*Service) RetryInvoice

func (s *Service) RetryInvoice(ctx context.Context, input billing.RetryInvoiceInput) (billing.Invoice, error)

func (Service) SimulateInvoice

func (s Service) SimulateInvoice(ctx context.Context, input billing.SimulateInvoiceInput) (billing.Invoice, error)

func (*Service) SnapshotLineQuantity

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

func (*Service) TriggerInvoice

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

func (*Service) UpdateInvoice

func (s *Service) UpdateInvoice(ctx context.Context, input billing.UpdateInvoiceInput) (billing.Invoice, 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) UpsertValidationIssues

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

func (Service) WithInvoiceCalculator

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

func (*Service) WithInvoiceStateMachine

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

Directories

Path Synopsis
lineservice package contains the implementation of the LineAdapter interface which acts as a adapter between the specific line types and the billing service.
lineservice package contains the implementation of the LineAdapter interface which acts as a adapter between the specific line types and the billing service.

Jump to

Keyboard shortcuts

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