Documentation
¶
Index ¶
- func UsageBookedAt(paymentTerm productcatalog.PaymentTermType, ...) time.Time
- type Adapter
- type AdvanceChargeInput
- type Charge
- type ChargeAdapter
- type ChargeBase
- type ChargeCreditAllocationAdapter
- type ChargeDetailedLineAdapter
- type ChargeInvoicedUsageAdapter
- type ChargePaymentAdapter
- type ChargeRunAdapter
- type ChargeWithGatheringLine
- type CorrectCreditAllocationsInput
- type CreateChargesInput
- type CreateCurrentRunInput
- type CreateInput
- type CreateInvoicedUsageInput
- type DetailedLine
- type DetailedLines
- type FlatFeeService
- type GetByIDInput
- type GetByIDsInput
- type GetByMetasInput
- type Handler
- type Intent
- type IntentWithInitialStatus
- type OnAllocateCreditsInput
- type OnInvoiceUsageAccruedInput
- type OnPaymentAuthorizedInput
- type OnPaymentSettledInput
- type PaymentEventInput
- type ProRatingModeAdapterEnum
- type RealizationRun
- type RealizationRunBase
- type RealizationRunID
- type RealizationRunType
- type RealizationRuns
- type Realizations
- type Service
- type State
- type Status
- type UpdateRealizationRunInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UsageBookedAt ¶
func UsageBookedAt(paymentTerm productcatalog.PaymentTermType, servicePeriod timeutil.ClosedPeriod) time.Time
UsageBookedAt returns the ledger booking time for a flat-fee service period.
Types ¶
type AdvanceChargeInput ¶
func (AdvanceChargeInput) Validate ¶
func (i AdvanceChargeInput) Validate() error
type Charge ¶
type Charge struct {
ChargeBase
Realizations Realizations `json:"realizations"`
}
func (Charge) GetBase ¶
func (c Charge) GetBase() ChargeBase
func (Charge) WithBase ¶
func (c Charge) WithBase(base ChargeBase) Charge
func (Charge) WithStatus ¶
type ChargeAdapter ¶
type ChargeAdapter interface {
CreateCharges(ctx context.Context, charges CreateChargesInput) ([]Charge, error)
UpdateCharge(ctx context.Context, charge ChargeBase) (ChargeBase, error)
UpdateSubscriptionItemID(ctx context.Context, charge Charge, newSubscriptionItemID string) (Charge, error)
DeleteCharge(ctx context.Context, charge Charge) error
GetByIDs(ctx context.Context, ids GetByIDsInput) ([]Charge, error)
GetByID(ctx context.Context, id GetByIDInput) (Charge, error)
}
type ChargeBase ¶
type ChargeBase struct {
meta.ManagedResource
Intent Intent `json:"intent"`
Status Status `json:"status"`
State State `json:"state"`
}
func (ChargeBase) ErrorAttributes ¶
func (c ChargeBase) ErrorAttributes() models.Attributes
func (ChargeBase) GetChargeID ¶
func (c ChargeBase) GetChargeID() meta.ChargeID
func (ChargeBase) GetCurrency ¶
func (c ChargeBase) GetCurrency() currencyx.Code
func (ChargeBase) GetCustomerID ¶
func (c ChargeBase) GetCustomerID() customer.CustomerID
func (ChargeBase) Validate ¶
func (c ChargeBase) Validate() error
type ChargeCreditAllocationAdapter ¶
type ChargeCreditAllocationAdapter interface {
CreateCreditAllocations(ctx context.Context, runID RealizationRunID, creditAllocations creditrealization.CreateInputs) (creditrealization.Realizations, error)
}
type ChargeDetailedLineAdapter ¶
type ChargeDetailedLineAdapter interface {
UpsertDetailedLines(ctx context.Context, runID RealizationRunID, lines DetailedLines) error
FetchCurrentRunDetailedLines(ctx context.Context, charge Charge) (Charge, error)
}
type ChargeInvoicedUsageAdapter ¶
type ChargeInvoicedUsageAdapter interface {
CreateInvoicedUsage(ctx context.Context, input CreateInvoicedUsageInput) (invoicedusage.AccruedUsage, error)
}
type ChargePaymentAdapter ¶
type ChargeRunAdapter ¶
type ChargeRunAdapter interface {
CreateCurrentRun(ctx context.Context, input CreateCurrentRunInput) (RealizationRunBase, error)
UpdateRealizationRun(ctx context.Context, input UpdateRealizationRunInput) (RealizationRunBase, error)
DetachCurrentRun(ctx context.Context, chargeID meta.ChargeID) error
}
type ChargeWithGatheringLine ¶
type ChargeWithGatheringLine struct {
Charge Charge
GatheringLineToCreate *billing.GatheringLine
}
type CorrectCreditAllocationsInput ¶
type CorrectCreditAllocationsInput struct {
Charge Charge `json:"charge"`
BookedAt time.Time `json:"bookedAt"`
Corrections creditrealization.CorrectionRequest `json:"corrections"`
LineageSegmentsByRealization lineage.ActiveSegmentsByRealizationID `json:"-"`
}
func (CorrectCreditAllocationsInput) Validate ¶
func (i CorrectCreditAllocationsInput) Validate() error
func (CorrectCreditAllocationsInput) ValidateWith ¶
func (i CorrectCreditAllocationsInput) ValidateWith(currencyCalculator currencyx.Calculator) error
type CreateChargesInput ¶
type CreateChargesInput struct {
Namespace string
Intents []IntentWithInitialStatus
}
func (CreateChargesInput) Validate ¶
func (i CreateChargesInput) Validate() error
type CreateCurrentRunInput ¶
type CreateCurrentRunInput struct {
Charge ChargeBase
ServicePeriod timeutil.ClosedPeriod
AmountAfterProration alpacadecimal.Decimal
NoFiatTransactionRequired bool
Immutable bool
LineID *string
InvoiceID *string
}
func (CreateCurrentRunInput) Validate ¶
func (i CreateCurrentRunInput) Validate() error
type CreateInput ¶
type CreateInput struct {
Namespace string
Intents []Intent
FeatureMeters feature.FeatureMeters
}
func (CreateInput) Validate ¶
func (i CreateInput) Validate() error
type CreateInvoicedUsageInput ¶
type CreateInvoicedUsageInput struct {
RunID RealizationRunID
LineID string
InvoiceID string
InvoicedUsage invoicedusage.AccruedUsage
}
func (CreateInvoicedUsageInput) Validate ¶
func (i CreateInvoicedUsageInput) Validate() error
type DetailedLine ¶
type DetailedLine = stddetailedline.Base
type DetailedLines ¶
type DetailedLines []DetailedLine
func (DetailedLines) Clone ¶
func (l DetailedLines) Clone() DetailedLines
func (DetailedLines) Validate ¶
func (l DetailedLines) Validate() error
type FlatFeeService ¶
type FlatFeeService interface {
Create(ctx context.Context, input CreateInput) ([]ChargeWithGatheringLine, error)
GetByIDs(ctx context.Context, input GetByIDsInput) ([]Charge, error)
GetByID(ctx context.Context, input GetByIDInput) (Charge, error)
UpdateSubscriptionItemID(ctx context.Context, charge Charge, newSubscriptionItemID string) (Charge, error)
AdvanceCharge(ctx context.Context, input AdvanceChargeInput) (*Charge, error)
TriggerPatch(ctx context.Context, charge meta.ChargeID, patch meta.Patch) (meta.TriggerPatchResult[Charge], error)
}
type GetByIDInput ¶
func (GetByIDInput) Validate ¶
func (i GetByIDInput) Validate() error
type GetByIDsInput ¶
func (GetByIDsInput) Validate ¶
func (i GetByIDsInput) Validate() error
type GetByMetasInput ¶
func (GetByMetasInput) Validate ¶
func (i GetByMetasInput) Validate() error
type Handler ¶
type Handler interface {
// OnAllocateCredits is called when a flat fee allocates credits.
OnAllocateCredits(ctx context.Context, input OnAllocateCreditsInput) (creditrealization.CreateAllocationInputs, error)
// OnFlatFeeStandardInvoiceUsageAccrued is called when the remaining usage is sent to the customer on a standard invoice.
OnInvoiceUsageAccrued(ctx context.Context, input OnInvoiceUsageAccruedInput) (ledgertransaction.GroupReference, error)
// OnCorrectCreditAllocations is called when a credit allocation needs to be corrected.
OnCorrectCreditAllocations(ctx context.Context, input CorrectCreditAllocationsInput) (creditrealization.CreateCorrectionInputs, error)
// OnFlatFeePaymentAuthorized is called when a flat fee payment is authorized.
OnPaymentAuthorized(ctx context.Context, input OnPaymentAuthorizedInput) (ledgertransaction.GroupReference, error)
// OnFlatFeePaymentSettled is called when a flat fee payment is settled.
OnPaymentSettled(ctx context.Context, input OnPaymentSettledInput) (ledgertransaction.GroupReference, error)
// OnFlatFeePaymentUncollectible is called when a flat fee payment is uncollectible
OnPaymentUncollectible(ctx context.Context, charge Charge) (ledgertransaction.GroupReference, error)
}
type Intent ¶
type Intent struct {
meta.Intent
InvoiceAt time.Time `json:"invoiceAt"`
SettlementMode productcatalog.SettlementMode `json:"settlementMode"`
PaymentTerm productcatalog.PaymentTermType `json:"paymentTerm"`
FeatureKey string `json:"featureKey,omitempty"`
PercentageDiscounts *productcatalog.PercentageDiscount `json:"percentageDiscounts"`
ProRating productcatalog.ProRatingConfig `json:"proRating"`
AmountBeforeProration alpacadecimal.Decimal `json:"amountBeforeProration"`
}
func (Intent) CalculateAmountAfterProration ¶
func (i Intent) CalculateAmountAfterProration() (alpacadecimal.Decimal, error)
CalculateAmountAfterProration computes the prorated amount from AmountBeforeProration, ServicePeriod, and FullServicePeriod. Returns AmountBeforeProration when proration is not applicable (disabled, unsupported mode, or zero-length periods).
func (Intent) Normalized ¶
type IntentWithInitialStatus ¶
type IntentWithInitialStatus struct {
Intent
FeatureID *string
InitialStatus Status
InitialAdvanceAfter *time.Time
AmountAfterProration alpacadecimal.Decimal
NoFiatTransactionRequired bool
}
func (IntentWithInitialStatus) Validate ¶
func (i IntentWithInitialStatus) Validate() error
type OnAllocateCreditsInput ¶
type OnAllocateCreditsInput struct {
Charge Charge `json:"charge"`
ServicePeriod timeutil.ClosedPeriod `json:"servicePeriod"`
BookedAt time.Time `json:"bookedAt"`
// PreTaxAmountToAllocate is the pre-tax amount to allocate from credits.
// The input charge's settlement mode governs whether this may create a negative balance.
PreTaxAmountToAllocate alpacadecimal.Decimal `json:"preTaxAmountToAllocate"`
}
func (OnAllocateCreditsInput) Validate ¶
func (i OnAllocateCreditsInput) Validate() error
type OnInvoiceUsageAccruedInput ¶
type OnInvoiceUsageAccruedInput struct {
Charge Charge `json:"charge"`
ServicePeriod timeutil.ClosedPeriod `json:"servicePeriod"`
BookedAt time.Time `json:"bookedAt"`
Totals totals.Totals `json:"totals"`
}
func (OnInvoiceUsageAccruedInput) Validate ¶
func (i OnInvoiceUsageAccruedInput) Validate() error
type OnPaymentAuthorizedInput ¶
type OnPaymentAuthorizedInput = PaymentEventInput
type OnPaymentSettledInput ¶
type OnPaymentSettledInput = PaymentEventInput
type PaymentEventInput ¶
type PaymentEventInput struct {
Charge Charge `json:"charge"`
EventAt time.Time `json:"eventAt"`
Amount alpacadecimal.Decimal `json:"amount"`
}
func (PaymentEventInput) Validate ¶
func (i PaymentEventInput) Validate() error
type ProRatingModeAdapterEnum ¶
type ProRatingModeAdapterEnum string
const ( ProratePricesProratingAdapterMode ProRatingModeAdapterEnum = ProRatingModeAdapterEnum(productcatalog.ProRatingModeProratePrices) NoProratingAdapterMode ProRatingModeAdapterEnum = "no_prorate" )
func (ProRatingModeAdapterEnum) Values ¶
func (e ProRatingModeAdapterEnum) Values() []string
type RealizationRun ¶
type RealizationRun struct {
RealizationRunBase
CreditRealizations creditrealization.Realizations `json:"creditRealizations"`
AccruedUsage *invoicedusage.AccruedUsage `json:"accruedUsage"`
Payment *payment.Invoiced `json:"payment"`
DetailedLines mo.Option[DetailedLines] `json:"detailedLines,omitzero"`
}
func (RealizationRun) IsVoidedBillingHistory ¶
func (r RealizationRun) IsVoidedBillingHistory() bool
IsVoidedBillingHistory reports whether this run must be ignored as billing history. Deleted runs were already cleaned up through billing; unsupported credit-note runs are retained for audit even though the invoice line should have been removed once prorating/credit-note support exists.
func (RealizationRun) Validate ¶
func (r RealizationRun) Validate() error
type RealizationRunBase ¶
type RealizationRunBase struct {
ID RealizationRunID `json:"id"`
models.ManagedModel
LineID *string `json:"lineId,omitempty"`
InvoiceID *string `json:"invoiceId,omitempty"`
Type RealizationRunType `json:"type"`
InitialType RealizationRunType `json:"initialType"`
ServicePeriod timeutil.ClosedPeriod `json:"servicePeriod"`
AmountAfterProration alpacadecimal.Decimal `json:"amountAfterProration"`
Totals totals.Totals `json:"totals"`
NoFiatTransactionRequired bool `json:"noFiatTransactionRequired"`
// Immutable means the backing invoice line can no longer be updated in place.
// When true, deleting this run requires issuing a credit note instead of mutating the invoice line.
Immutable bool `json:"immutable"`
}
func (RealizationRunBase) Normalized ¶
func (r RealizationRunBase) Normalized() RealizationRunBase
func (RealizationRunBase) Validate ¶
func (r RealizationRunBase) Validate() error
type RealizationRunID ¶
type RealizationRunID models.NamespacedID
func (RealizationRunID) Validate ¶
func (i RealizationRunID) Validate() error
type RealizationRunType ¶
type RealizationRunType string
const ( RealizationRunTypeFinalRealization RealizationRunType = "final_realization" RealizationRunTypeInvalidDueToUnsupportedCreditNote RealizationRunType = "invalid_due_to_unsupported_credit_note" )
func (RealizationRunType) IsVoidedBillingHistory ¶
func (t RealizationRunType) IsVoidedBillingHistory() bool
func (RealizationRunType) Validate ¶
func (t RealizationRunType) Validate() error
func (RealizationRunType) Values ¶
func (t RealizationRunType) Values() []string
type RealizationRuns ¶
type RealizationRuns []RealizationRun
func (RealizationRuns) Validate ¶
func (r RealizationRuns) Validate() error
type Realizations ¶
type Realizations struct {
CurrentRun *RealizationRun `json:"currentRun,omitempty"`
PriorRuns RealizationRuns `json:"priorRuns,omitempty"`
}
func (Realizations) GetByLineID ¶
func (r Realizations) GetByLineID(lineID string) (RealizationRun, error)
func (Realizations) Validate ¶
func (r Realizations) Validate() error
type Service ¶
type Service interface {
FlatFeeService
GetLineEngine() billing.LineEngine
}
type State ¶
type State struct {
AdvanceAfter *time.Time `json:"advanceAfter,omitempty"`
FeatureID *string `json:"featureId,omitempty"`
AmountAfterProration alpacadecimal.Decimal `json:"amountAfterProration"`
}
func (State) Normalized ¶
type Status ¶
type Status string
const ( StatusCreated Status = Status(meta.ChargeStatusCreated) StatusActive Status = Status(meta.ChargeStatusActive) StatusActiveRealizationStarted Status = "active.realization.started" StatusActiveRealizationWaitingForCollection Status = "active.realization.waiting_for_collection" StatusActiveRealizationProcessing Status = "active.realization.processing" StatusActiveRealizationIssuing Status = "active.realization.issuing" StatusActiveRealizationCompleted Status = "active.realization.completed" StatusActiveAwaitingPaymentSettlement Status = "active.awaiting_payment_settlement" StatusFinal Status = Status(meta.ChargeStatusFinal) StatusDeleted Status = Status(meta.ChargeStatusDeleted) )
func (Status) ToMetaChargeStatus ¶
func (s Status) ToMetaChargeStatus() (meta.ChargeStatus, error)
type UpdateRealizationRunInput ¶
type UpdateRealizationRunInput struct {
ID RealizationRunID
Type mo.Option[RealizationRunType] `json:"type"`
DeletedAt mo.Option[*time.Time] `json:"deletedAt,omitempty"`
LineID mo.Option[*string] `json:"lineId,omitempty"`
InvoiceID mo.Option[*string] `json:"invoiceId,omitempty"`
ServicePeriod mo.Option[timeutil.ClosedPeriod] `json:"servicePeriod"`
AmountAfterProration mo.Option[alpacadecimal.Decimal] `json:"amountAfterProration"`
Totals mo.Option[totals.Totals] `json:"totals"`
NoFiatTransactionRequired mo.Option[bool] `json:"noFiatTransactionRequired"`
Immutable mo.Option[bool] `json:"immutable"`
}
func (UpdateRealizationRunInput) Normalized ¶
func (r UpdateRealizationRunInput) Normalized() UpdateRealizationRunInput
func (UpdateRealizationRunInput) Validate ¶
func (r UpdateRealizationRunInput) Validate() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.