billingworkersubscription

package
v1.0.0-beta.217 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SubscriptionSyncComponentName billing.ComponentName = "subscription-sync"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BillingService      billing.Service
	SubscriptionService subscription.Service
	TxCreator           transaction.Creator
	FeatureFlags        FeatureFlags
	Logger              *slog.Logger
	Tracer              trace.Tracer
}

func (Config) Validate

func (c Config) Validate() error

type FeatureFlags

type FeatureFlags struct {
	EnableFlatFeeInAdvanceProrating bool
	EnableFlatFeeInArrearsProrating bool
	UseUsageBasedFlatFeeLines       bool
}

type Handler

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

func New

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

func (*Handler) HandleCancelledEvent

func (h *Handler) HandleCancelledEvent(ctx context.Context, event *subscription.CancelledEvent) error

HandleCancelledEvent is a handler for the subscription cancel event, it will make sure that we synchronize the

func (*Handler) HandleInvoiceCreation

func (h *Handler) HandleInvoiceCreation(ctx context.Context, event billing.EventInvoice) error

HandleInvoiceCreation is a handler for the invoice creation event, it will make sure that we are backfilling the items consumed by invoice creation into the gathering invoice.

func (*Handler) SyncronizeSubscription

func (h *Handler) SyncronizeSubscription(ctx context.Context, subs subscription.SubscriptionView, asOf time.Time) error

func (*Handler) SyncronizeSubscriptionAndInvoiceCustomer

func (h *Handler) SyncronizeSubscriptionAndInvoiceCustomer(ctx context.Context, subs subscription.SubscriptionView, asOf time.Time) error

type InvoiceByID

type InvoiceByID map[string]billing.Invoice

func (InvoiceByID) IsGatheringInvoice

func (i InvoiceByID) IsGatheringInvoice(invoiceID string) bool

type InvoiceUpdater

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

func NewInvoiceUpdater

func NewInvoiceUpdater(billingService billing.Service) *InvoiceUpdater

func (*InvoiceUpdater) ApplyPatches

func (u *InvoiceUpdater) ApplyPatches(ctx context.Context, customerID customer.CustomerID, patches []linePatch) error

type PhaseIterator

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

func NewPhaseIterator

func NewPhaseIterator(logger *slog.Logger, tracer trace.Tracer, subs subscription.SubscriptionView, phaseKey string) (*PhaseIterator, error)

func (*PhaseIterator) Generate

func (it *PhaseIterator) Generate(ctx context.Context, iterationEnd time.Time) ([]subscriptionItemWithPeriods, error)

Generate generates the lines for the phase so that all active subscription item's are generated up to the point where either the item gets deactivated or the last item's invoice_at >= iterationEnd and it's period's end is equal to or after iterationEnd.

This ensures that we always have the upcoming lines stored on the gathering invoice.

func (*PhaseIterator) GetMinimumBillableTime

func (it *PhaseIterator) GetMinimumBillableTime() time.Time

GetMinimumBillableTime returns the minimum time that we can bill for the phase (e.g. the first time we would be yielding a line item)

func (*PhaseIterator) HasInvoicableItems

func (it *PhaseIterator) HasInvoicableItems() bool

func (*PhaseIterator) PhaseEnd

func (it *PhaseIterator) PhaseEnd() *time.Time

func (*PhaseIterator) PhaseStart

func (it *PhaseIterator) PhaseStart() time.Time

type Reconciler

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

Reconciler is a component that periodically reconciles the subscription state with the billing state this is essential, as the invoice creation is purley event driven. In case a processing error happens, we might fail to create an invoice, and stop processing the subscription.

func NewReconciler

func NewReconciler(config ReconcilerConfig) (*Reconciler, error)

func (*Reconciler) All

func (*Reconciler) ListSubscriptions

func (*Reconciler) ReconcileSubscription

func (r *Reconciler) ReconcileSubscription(ctx context.Context, subsID models.NamespacedID) error

type ReconcilerAllInput

type ReconcilerAllInput = ReconcilerListSubscriptionsInput

type ReconcilerConfig

type ReconcilerConfig struct {
	SubscriptionSync    *Handler
	SubscriptionService subscription.Service
	CustomerService     customer.Service
	Logger              *slog.Logger
}

func (ReconcilerConfig) Validate

func (c ReconcilerConfig) Validate() error

type ReconcilerListSubscriptionsInput

type ReconcilerListSubscriptionsInput struct {
	Namespaces []string
	Customers  []string
	Lookback   time.Duration
}

func (ReconcilerListSubscriptionsInput) Validate

Jump to

Keyboard shortcuts

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