Documentation
¶
Index ¶
- Variables
- type BuildInput
- type Builder
- type PhaseIterator
- func (it *PhaseIterator) Generate(ctx context.Context, iterationEnd time.Time) ([]SubscriptionItemWithPeriods, error)
- func (it *PhaseIterator) GetMinimumBillableTime() time.Time
- func (it *PhaseIterator) HasInvoicableItems() bool
- func (it *PhaseIterator) PhaseEnd() *time.Time
- func (it *PhaseIterator) PhaseStart() time.Time
- type State
- type StateItem
- type SubscriptionItemWithPeriods
Constants ¶
This section is empty.
Variables ¶
var ErrExpectedLineIsEmpty = errors.New("expected line is empty")
var (
TimeInfinity = time.Date(9999, 12, 31, 23, 59, 59, 999999999, time.UTC)
)
TimeInfinity is a big enough time that we can use to represent infinity (biggest possible date for our system).
Functions ¶
This section is empty.
Types ¶
type BuildInput ¶
type BuildInput struct {
AsOf time.Time
CustomerDeletedAt *time.Time
SubscriptionEndProrationMode billing.SubscriptionEndProrationMode
SubscriptionView *subscription.SubscriptionView
Persisted persistedstate.State
}
func (BuildInput) Validate ¶
func (i BuildInput) Validate() 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)
The response always truncated to capture that billing has 1s resolution.
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 StateItem ¶
type StateItem struct {
SubscriptionItemWithPeriods
CurrencyCalculator currencyx.Calculator
Subscription subscription.Subscription
SubscriptionEndProrationMode billing.SubscriptionEndProrationMode
}
func (StateItem) GetExpectedLine ¶
func (r StateItem) GetExpectedLine() (*billing.GatheringLine, error)
func (StateItem) GetExpectedLineOrErr ¶
func (r StateItem) GetExpectedLineOrErr() (billing.GatheringLine, error)
func (StateItem) GetServicePeriod ¶
func (r StateItem) GetServicePeriod() timeutil.ClosedPeriod
func (StateItem) IsBillable ¶
IsBillable returns true if the item is billable (e.g. we can create a gathering line for it even if it's value is 0 or create a charge for it)
Note: GetExpectedLine might return nil in other cases, e.g. we don't want to create a flat fee line when pro-rating is in effect and the service period and the currency rounding results in a 0 amount.
type SubscriptionItemWithPeriods ¶
type SubscriptionItemWithPeriods struct {
subscription.SubscriptionItemView
// References
UniqueID string
PhaseID string
PhaseKey string
PeriodIndex int
ItemVersion int
// ServicePeriod is the de-facto service period that the item is billed for
ServicePeriod timeutil.ClosedPeriod
// FullServicePeriod is the full service period that the item is billed for (previously nonTruncatedPeriod)
FullServicePeriod timeutil.ClosedPeriod
// BillingPeriod as determined by alignment and service period
BillingPeriod timeutil.ClosedPeriod
}
func (SubscriptionItemWithPeriods) GetInvoiceAt ¶
func (r SubscriptionItemWithPeriods) GetInvoiceAt() time.Time
func (SubscriptionItemWithPeriods) PeriodPercentage ¶
func (r SubscriptionItemWithPeriods) PeriodPercentage() alpacadecimal.Decimal
PeriodPercentage returns the percentage of the period that is actually billed, compared to the non-truncated period can be used to calculate prorated prices