Documentation
¶
Index ¶
- func ExecuteTriggerWithAllowInStates(states ...billing.StandardInvoiceStatus) executeTriggerApplyOptionFunc
- func ExecuteTriggerWithArgs(args ...any) executeTriggerApplyOptionFunc
- func ExecuteTriggerWithEditCallback(cb editCallbackFunc) executeTriggerApplyOptionFunc
- func ExecuteTriggerWithIncludeDeletedLines(includeDeletedLines bool) executeTriggerApplyOptionFunc
- func ExecuteTriggerWithPreTriggerCallback(cb preTriggerCallbackFunc) executeTriggerApplyOptionFunc
- type Config
- type GatheringLinesWithEngine
- type InvoiceStateMachine
- func (m *InvoiceStateMachine) AdvanceUntilStateStable(ctx context.Context) error
- func (m *InvoiceStateMachine) CanFire(ctx context.Context, trigger billing.InvoiceTrigger, args ...any) (bool, error)
- func (m *InvoiceStateMachine) FireAndActivate(ctx context.Context, trigger billing.InvoiceTrigger, args ...any) error
- func (m *InvoiceStateMachine) HandleInvoiceTrigger(ctx context.Context, trigger billing.InvoiceTriggerInput) error
- func (m *InvoiceStateMachine) StatusDetails(ctx context.Context) (billing.StandardInvoiceStatusDetails, error)
- func (m *InvoiceStateMachine) TriggerFailed(ctx context.Context) error
- type InvoiceStateMachineCallback
- type Service
- func (s *Service) AdvanceInvoice(ctx context.Context, input billing.AdvanceInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) ApproveInvoice(ctx context.Context, input billing.ApproveInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) CreatePendingInvoiceLines(ctx context.Context, input billing.CreatePendingInvoiceLinesInput) (*billing.CreatePendingInvoiceLinesResult, error)
- func (s *Service) CreateProfile(ctx context.Context, input billing.CreateProfileInput) (*billing.Profile, error)
- func (s *Service) CreateStandardInvoiceFromGatheringLines(ctx context.Context, in billing.CreateStandardInvoiceFromGatheringLinesInput) (*billing.StandardInvoice, error)
- func (s *Service) DeleteCustomerOverride(ctx context.Context, input billing.DeleteCustomerOverrideInput) error
- func (s *Service) DeleteGatheringInvoice(ctx context.Context, input billing.DeleteInvoiceInput) (billing.GatheringInvoice, error)
- func (s *Service) DeleteInvoice(ctx context.Context, input billing.DeleteInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) DeleteProfile(ctx context.Context, input billing.DeleteProfileInput) error
- func (s *Service) DeleteSplitLineGroup(ctx context.Context, input billing.DeleteSplitLineGroupInput) error
- func (s *Service) DeregisterLineEngine(engineType billing.LineEngineType) error
- func (s *Service) ForceCollectInvoice(ctx context.Context, input billing.ForceCollectInvoiceInput) (billing.StandardInvoice, error)
- func (s Service) GetAdvancementStrategy() billing.AdvancementStrategy
- func (s *Service) GetCustomerApp(ctx context.Context, input billing.GetCustomerAppInput) (app.App, error)
- func (s *Service) GetCustomerOverride(ctx context.Context, input billing.GetCustomerOverrideInput) (billing.CustomerOverrideWithDetails, error)
- func (s *Service) GetDefaultProfile(ctx context.Context, input billing.GetDefaultProfileInput) (*billing.Profile, error)
- func (s *Service) GetGatheringInvoiceById(ctx context.Context, input billing.GetGatheringInvoiceByIdInput) (billing.GatheringInvoice, error)
- func (s *Service) GetInvoiceById(ctx context.Context, input billing.GetInvoiceByIdInput) (billing.Invoice, error)
- func (s *Service) GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error)
- func (s *Service) GetProfile(ctx context.Context, input billing.GetProfileInput) (*billing.Profile, error)
- func (s *Service) GetRegisteredLineEngines() []billing.LineEngineType
- func (s *Service) GetSplitLineGroup(ctx context.Context, input billing.GetSplitLineGroupInput) (billing.SplitLineHierarchy, error)
- func (s *Service) GetStandardInvoiceById(ctx context.Context, input billing.GetStandardInvoiceByIdInput) (billing.StandardInvoice, error)
- func (s Service) InvoiceCalculator() invoicecalc.Calculator
- func (s *Service) InvoicePendingLines(ctx context.Context, input billing.InvoicePendingLinesInput, ...) ([]billing.StandardInvoice, error)
- func (s *Service) IsAppUsed(ctx context.Context, appID app.AppID) error
- func (s *Service) ListCustomerOverrides(ctx context.Context, input billing.ListCustomerOverridesInput) (billing.ListCustomerOverridesResult, error)
- func (s *Service) ListGatheringInvoices(ctx context.Context, input billing.ListGatheringInvoicesInput) (pagination.Result[billing.GatheringInvoice], error)
- func (s *Service) ListInvoices(ctx context.Context, input billing.ListInvoicesInput) (billing.ListInvoicesResponse, error)
- func (s *Service) ListProfiles(ctx context.Context, input billing.ListProfilesInput) (billing.ListProfilesResult, error)
- func (s *Service) ListStandardInvoices(ctx context.Context, input billing.ListStandardInvoicesInput) (billing.ListStandardInvoicesResponse, error)
- func (s *Service) OnUnsupportedCreditNote(ctx context.Context, input billing.OnUnsupportedCreditNoteInput) error
- func (s *Service) PaymentAuthorized(ctx context.Context, input billing.PaymentAuthorizedInput) (billing.StandardInvoice, error)
- func (s *Service) ProvisionDefaultBillingProfile(ctx context.Context, namespace string) error
- func (s *Service) RecalculateGatheringInvoices(ctx context.Context, input billing.RecalculateGatheringInvoicesInput) error
- func (s *Service) RegisterCreateLineRouter(router billing.CreateLineRouter) error
- func (s *Service) RegisterLineEngine(eng billing.LineEngine) error
- func (s *Service) RegisterStandardInvoiceHooks(hooks ...billing.StandardInvoiceHook)
- func (s *Service) ResolveStripeAppIDFromBillingProfile(ctx context.Context, namespace string, customerId *customer.CustomerID) (app.AppID, error)
- func (s *Service) RetryInvoice(ctx context.Context, input billing.RetryInvoiceInput) (billing.StandardInvoice, error)
- func (s Service) SimulateInvoice(ctx context.Context, input billing.SimulateInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) SnapshotLineQuantities(ctx context.Context, invoice billing.StandardInvoice, ...) error
- func (s *Service) SnapshotLineQuantity(ctx context.Context, input billing.SnapshotLineQuantityInput) (*billing.StandardLine, error)
- func (s *Service) SyncDraftInvoice(ctx context.Context, input billing.SyncDraftStandardInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) SyncIssuingInvoice(ctx context.Context, input billing.SyncIssuingStandardInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) TriggerInvoice(ctx context.Context, input billing.InvoiceTriggerServiceInput) error
- func (s *Service) UpdateGatheringInvoice(ctx context.Context, input billing.UpdateGatheringInvoiceInput) (billing.GatheringInvoice, error)
- func (s *Service) UpdateInvoiceFields(ctx context.Context, input billing.UpdateInvoiceFieldsInput) error
- func (s *Service) UpdateProfile(ctx context.Context, input billing.UpdateProfileInput) (*billing.Profile, error)
- func (s *Service) UpdateSplitLineGroup(ctx context.Context, input billing.UpdateSplitLineGroupInput) (billing.SplitLineGroup, error)
- func (s *Service) UpdateStandardInvoice(ctx context.Context, input billing.UpdateStandardInvoiceInput) (billing.StandardInvoice, error)
- func (s *Service) UpsertCustomerOverride(ctx context.Context, input billing.UpsertCustomerOverrideInput) (billing.CustomerOverrideWithDetails, error)
- func (s *Service) UpsertValidationIssues(ctx context.Context, input billing.UpsertValidationIssuesInput) error
- func (s Service) WithAdvancementStrategy(strategy billing.AdvancementStrategy) billing.Service
- func (s Service) WithInvoiceCalculator(calc invoicecalc.Calculator) *Service
- func (s *Service) WithInvoiceStateMachine(ctx context.Context, invoice billing.StandardInvoice, ...) (billing.StandardInvoice, error)
- func (s *Service) WithLock(ctx context.Context, customerID customer.CustomerID, ...) error
- func (s *Service) WithLockedNamespaces(namespaces []string) billing.Service
- type StandardLinesWithEngine
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
}
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 (m *InvoiceStateMachine) StatusDetails(ctx context.Context) (billing.StandardInvoiceStatusDetails, error)
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 (*Service) AdvanceInvoice ¶
func (s *Service) AdvanceInvoice(ctx context.Context, input billing.AdvanceInvoiceInput) (billing.StandardInvoice, error)
func (*Service) ApproveInvoice ¶
func (s *Service) ApproveInvoice(ctx context.Context, input billing.ApproveInvoiceInput) (billing.StandardInvoice, error)
func (*Service) CreatePendingInvoiceLines ¶
func (s *Service) CreatePendingInvoiceLines(ctx context.Context, input billing.CreatePendingInvoiceLinesInput) (*billing.CreatePendingInvoiceLinesResult, error)
TODO[later]: Move this to gatheringinvoice.go
func (*Service) CreateProfile ¶
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 (*Service) DeleteGatheringInvoice ¶
func (s *Service) DeleteGatheringInvoice(ctx context.Context, input billing.DeleteInvoiceInput) (billing.GatheringInvoice, error)
func (*Service) DeleteInvoice ¶
func (s *Service) DeleteInvoice(ctx context.Context, input billing.DeleteInvoiceInput) (billing.StandardInvoice, error)
func (*Service) DeleteProfile ¶
func (*Service) DeleteSplitLineGroup ¶
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) GetCustomerOverride ¶
func (s *Service) GetCustomerOverride(ctx context.Context, input billing.GetCustomerOverrideInput) (billing.CustomerOverrideWithDetails, error)
func (*Service) GetDefaultProfile ¶
func (*Service) GetGatheringInvoiceById ¶
func (s *Service) GetGatheringInvoiceById(ctx context.Context, input billing.GetGatheringInvoiceByIdInput) (billing.GatheringInvoice, error)
func (*Service) GetInvoiceById ¶
func (*Service) GetLinesForSubscription ¶
func (s *Service) GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error)
func (*Service) GetProfile ¶
func (*Service) GetRegisteredLineEngines ¶
func (s *Service) GetRegisteredLineEngines() []billing.LineEngineType
func (*Service) GetSplitLineGroup ¶
func (s *Service) GetSplitLineGroup(ctx context.Context, input billing.GetSplitLineGroupInput) (billing.SplitLineHierarchy, error)
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 ¶
func (s *Service) InvoicePendingLines(ctx context.Context, input billing.InvoicePendingLinesInput, opts ...billing.InvoicePendingLinesOption) ([]billing.StandardInvoice, error)
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) ListCustomerOverrides ¶
func (s *Service) ListCustomerOverrides(ctx context.Context, input billing.ListCustomerOverridesInput) (billing.ListCustomerOverridesResult, error)
func (*Service) ListGatheringInvoices ¶
func (s *Service) ListGatheringInvoices(ctx context.Context, input billing.ListGatheringInvoicesInput) (pagination.Result[billing.GatheringInvoice], error)
func (*Service) ListInvoices ¶
func (s *Service) ListInvoices(ctx context.Context, input billing.ListInvoicesInput) (billing.ListInvoicesResponse, error)
func (*Service) ListProfiles ¶
func (s *Service) ListProfiles(ctx context.Context, input billing.ListProfilesInput) (billing.ListProfilesResult, error)
func (*Service) ListStandardInvoices ¶
func (s *Service) ListStandardInvoices(ctx context.Context, input billing.ListStandardInvoicesInput) (billing.ListStandardInvoicesResponse, error)
func (*Service) OnUnsupportedCreditNote ¶
func (*Service) PaymentAuthorized ¶
func (s *Service) PaymentAuthorized(ctx context.Context, input billing.PaymentAuthorizedInput) (billing.StandardInvoice, error)
func (*Service) ProvisionDefaultBillingProfile ¶
func (*Service) RecalculateGatheringInvoices ¶
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 (*Service) RetryInvoice ¶
func (s *Service) RetryInvoice(ctx context.Context, input billing.RetryInvoiceInput) (billing.StandardInvoice, error)
func (Service) SimulateInvoice ¶
func (s Service) SimulateInvoice(ctx context.Context, input billing.SimulateInvoiceInput) (billing.StandardInvoice, error)
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 (s *Service) SyncDraftInvoice(ctx context.Context, input billing.SyncDraftStandardInvoiceInput) (billing.StandardInvoice, error)
func (*Service) SyncIssuingInvoice ¶
func (s *Service) SyncIssuingInvoice(ctx context.Context, input billing.SyncIssuingStandardInvoiceInput) (billing.StandardInvoice, error)
func (*Service) TriggerInvoice ¶
func (*Service) UpdateGatheringInvoice ¶
func (s *Service) UpdateGatheringInvoice(ctx context.Context, input billing.UpdateGatheringInvoiceInput) (billing.GatheringInvoice, error)
func (*Service) UpdateInvoiceFields ¶
func (*Service) UpdateProfile ¶
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) UpsertCustomerOverride ¶
func (s *Service) UpsertCustomerOverride(ctx context.Context, input billing.UpsertCustomerOverrideInput) (billing.CustomerOverrideWithDetails, error)
func (*Service) UpsertValidationIssues ¶
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)
type StandardLinesWithEngine ¶
type StandardLinesWithEngine struct {
Engine billing.LineEngine
Lines billing.StandardLines
}