Documentation
¶
Index ¶
- func ValidateExpiredRouteFilter(route ledger.RouteFilter) error
- type Adapter
- type BreakageImpact
- type Config
- type CreateRecordsInput
- type ListExpiredBreakageImpactsInput
- type ListExpiredBreakageImpactsResult
- type ListExpiredRecordsInput
- type ListPlansInput
- type ListReleasesInput
- type NoopService
- func (NoopService) ListExpiredBreakageImpacts(context.Context, ListExpiredBreakageImpactsInput) (ListExpiredBreakageImpactsResult, error)
- func (NoopService) ListExpiredRecords(context.Context, ListExpiredRecordsInput) ([]Record, error)
- func (NoopService) ListPlans(context.Context, ListPlansInput) ([]Plan, error)
- func (NoopService) ListReleases(context.Context, ListReleasesInput) ([]Release, error)
- func (NoopService) PersistCommittedRecords(context.Context, []PendingRecord, ledger.TransactionGroup) error
- func (NoopService) PlanIssuance(context.Context, PlanIssuanceInput) ([]ledger.TransactionInput, []PendingRecord, error)
- func (NoopService) ReleasePlan(context.Context, ReleasePlanInput) (ledger.TransactionInput, PendingRecord, error)
- func (NoopService) ReopenRelease(context.Context, ReopenReleaseInput) (ledger.TransactionInput, PendingRecord, error)
- type PendingRecord
- type Plan
- type PlanIssuanceImmediateRelease
- type PlanIssuanceInput
- type Record
- type Release
- type ReleasePlanInput
- type ReopenReleaseInput
- type Service
- type SourceKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateExpiredRouteFilter ¶
func ValidateExpiredRouteFilter(route ledger.RouteFilter) error
Types ¶
type Adapter ¶
type Adapter interface {
// CreateRecords persists planned/released/reopened breakage rows.
CreateRecords(ctx context.Context, input CreateRecordsInput) error
// ListCandidateRecords returns plan and adjustment rows needed to compute
// open plans. Implementations should lock returned rows when the caller is in
// a transaction so concurrent collectors cannot release the same open amount.
ListCandidateRecords(ctx context.Context, input ListPlansInput) ([]Record, error)
// ListReleaseRecords returns release and reopen rows for the given source
// entries. Implementations should lock returned rows when the caller is in a
// transaction so concurrent corrections cannot reopen the same release amount.
ListReleaseRecords(ctx context.Context, input ListReleasesInput) ([]Record, error)
// ListExpiredRecords returns breakage rows whose expiry is visible as of the
// query time. The caller owns netting plan/release/reopen rows into a
// customer-facing expired transaction.
ListExpiredRecords(ctx context.Context, input ListExpiredRecordsInput) ([]Record, error)
}
type BreakageImpact ¶
type BreakageImpact struct {
ID models.NamespacedID
CreatedAt time.Time
BookedAt time.Time
CustomerID customer.CustomerID
Currency currencyx.Code
Amount alpacadecimal.Decimal
SourceKind SourceKind
Annotations models.Annotations
}
BreakageImpact is the customer-facing effect of breakage that has reached its expiration timestamp. Amount is negative because expiry reduces FBO balance.
func (BreakageImpact) Cursor ¶
func (i BreakageImpact) Cursor() ledger.TransactionCursor
type Config ¶
type Config struct {
// Adapter stores durable record rows. The ledger entries themselves are
// still committed through the caller's ledger transaction group.
Adapter Adapter
Dependencies transactions.ResolverDependencies
}
type CreateRecordsInput ¶
type CreateRecordsInput struct {
Records []Record
}
CreateRecordsInput persists record rows for already committed breakage ledger transactions.
func (CreateRecordsInput) Validate ¶
func (i CreateRecordsInput) Validate() error
type ListExpiredBreakageImpactsInput ¶
type ListExpiredBreakageImpactsInput struct {
CustomerID customer.CustomerID
Currency *currencyx.Code
AsOf time.Time
After *ledger.TransactionCursor
Before *ledger.TransactionCursor
Limit int
Route ledger.RouteFilter
}
ListExpiredBreakageImpactsInput selects customer-visible breakage impact rows. Impacts are derived by netting expired plan/release/reopen records by expiry.
func (ListExpiredBreakageImpactsInput) Validate ¶
func (i ListExpiredBreakageImpactsInput) Validate() error
type ListExpiredBreakageImpactsResult ¶
type ListExpiredBreakageImpactsResult struct {
Items []BreakageImpact
HasMore bool
}
ListExpiredBreakageImpactsResult contains breakage impacts ordered by ledger cursor descending, matching customer transaction listing semantics.
type ListExpiredRecordsInput ¶
type ListExpiredRecordsInput struct {
CustomerID customer.CustomerID
Currency *currencyx.Code
AsOf time.Time
Route ledger.RouteFilter
}
ListExpiredRecordsInput selects breakage rows that have reached their expiration timestamp and can be presented as customer-visible expired credit.
type ListPlansInput ¶
type ListPlansInput struct {
CustomerID customer.CustomerID
Currency currencyx.Code
AsOf time.Time
}
ListPlansInput selects expiring credit that can still produce breakage as of the collector's AsOf time. Plans expiring at or before AsOf are not candidates because those credits are already expired from the collector's perspective.
type ListReleasesInput ¶
type ListReleasesInput struct {
CustomerID customer.CustomerID
SourceEntryID []string
SourceTransactionGroupID []string
ReleaseSourceKind []SourceKind
}
ListReleasesInput selects usage release rows that may need to be reopened by a correction of the original FBO collection source entries or by unwinding an advance backfill.
type NoopService ¶
type NoopService struct{}
NoopService disables breakage while keeping constructors explicit. It is useful for legacy tests and deployments that wire credit purchases without expiration support.
func (NoopService) ListExpiredBreakageImpacts ¶
func (NoopService) ListExpiredBreakageImpacts(context.Context, ListExpiredBreakageImpactsInput) (ListExpiredBreakageImpactsResult, error)
func (NoopService) ListExpiredRecords ¶
func (NoopService) ListExpiredRecords(context.Context, ListExpiredRecordsInput) ([]Record, error)
func (NoopService) ListPlans ¶
func (NoopService) ListPlans(context.Context, ListPlansInput) ([]Plan, error)
func (NoopService) ListReleases ¶
func (NoopService) ListReleases(context.Context, ListReleasesInput) ([]Release, error)
func (NoopService) PersistCommittedRecords ¶
func (NoopService) PersistCommittedRecords(context.Context, []PendingRecord, ledger.TransactionGroup) error
func (NoopService) PlanIssuance ¶
func (NoopService) PlanIssuance(context.Context, PlanIssuanceInput) ([]ledger.TransactionInput, []PendingRecord, error)
func (NoopService) ReleasePlan ¶
func (NoopService) ReleasePlan(context.Context, ReleasePlanInput) (ledger.TransactionInput, PendingRecord, error)
func (NoopService) ReopenRelease ¶
func (NoopService) ReopenRelease(context.Context, ReopenReleaseInput) (ledger.TransactionInput, PendingRecord, error)
type PendingRecord ¶
PendingRecord is a record row that has been planned before the ledger commit. PersistCommittedRecords fills in committed ledger ids after CommitGroup succeeds. SourceEntryIdentityKey is transient; it lets usage releases attach to the committed FBO source entry without knowing the entry id before commit.
type Plan ¶
type Plan struct {
Record
OpenAmount alpacadecimal.Decimal
FBOAddress ledger.PostingAddress
BreakageAddress ledger.PostingAddress
}
Plan is a planned breakage row with its current unreleased amount and the posting addresses needed to book a release. It is calculated from plan rows minus releases plus reopens.
type PlanIssuanceImmediateRelease ¶
type PlanIssuanceImmediateRelease struct {
Amount alpacadecimal.Decimal
SpendChargeID *string
}
type PlanIssuanceInput ¶
type PlanIssuanceInput struct {
CustomerID customer.CustomerID
Amount alpacadecimal.Decimal
ImmediateReleases []PlanIssuanceImmediateRelease
Currency currencyx.Code
TaxCode *string
TaxBehavior *ledger.TaxBehavior
CostBasis *alpacadecimal.Decimal
CreditPriority *int
Features []string
ExpiresAt time.Time
SourceChargeID *string
}
PlanIssuanceInput describes newly issued expiring credit and, optionally, the slice that immediately covers already-consumed advance.
func (PlanIssuanceInput) Validate ¶
func (i PlanIssuanceInput) Validate() error
type Record ¶
type Record struct {
ID models.NamespacedID
Kind ledger.BreakageKind
Amount alpacadecimal.Decimal
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
CustomerID customer.CustomerID
Currency currencyx.Code
CreditPriority int
ExpiresAt time.Time
SourceKind SourceKind
SourceChargeID *string
SourceTransactionGroupID *string
SourceTransactionID *string
SourceEntryID *string
BreakageTransactionGroupID string
BreakageTransactionID string
FBOSubAccountID string
BreakageSubAccountID string
PlanID *string
ReleaseID *string
Annotations models.Annotations
}
Record is the durable bookkeeping row for one breakage ledger transaction.
It intentionally repeats the fields the allocator needs to find and lock open plans without joining back through ledger transactions or parsing annotations. The ledger entry remains the accounting source of truth; the record is the allocation/index layer that ties plan, release, and reopen transactions together.
func (Record) ValidateForReference ¶
type Release ¶
type Release struct {
Record
OpenAmount alpacadecimal.Decimal
FBOAddress ledger.PostingAddress
BreakageAddress ledger.PostingAddress
}
Release is a breakage release row with the amount that can still be reopened by corrections.
type ReleasePlanInput ¶
type ReleasePlanInput struct {
Plan Plan
Amount alpacadecimal.Decimal
SourceKind SourceKind
SourceEntryIdentityKey string
SourceChargeID *string
SpendChargeID *string
}
ReleasePlanInput describes how much of one open plan should be released and which business flow caused the release.
func (ReleasePlanInput) Validate ¶
func (i ReleasePlanInput) Validate() error
type ReopenReleaseInput ¶
type ReopenReleaseInput struct {
Release Release
Amount alpacadecimal.Decimal
SourceKind SourceKind
SourceChargeID *string
SpendChargeID *string
}
ReopenReleaseInput describes how much of one released plan should be reopened and which correction flow caused it.
func (ReopenReleaseInput) Validate ¶
func (i ReopenReleaseInput) Validate() error
type Service ¶
type Service interface {
// PlanIssuance creates the future expiration entries for newly issued
// expiring credit. ImmediateReleases handles credit that covers already
// consumed advance: the issued credit has an expiry, but the covered slice is
// already used, so its planned breakage is released in the same ledger group.
PlanIssuance(ctx context.Context, input PlanIssuanceInput) ([]ledger.TransactionInput, []PendingRecord, error)
// ReleasePlan creates a future-dated inverse entry that reduces a planned
// breakage amount because the underlying expiring credit has been consumed or
// otherwise removed before expiry.
ReleasePlan(ctx context.Context, input ReleasePlanInput) (ledger.TransactionInput, PendingRecord, error)
// ReopenRelease creates a future-dated entry that increases breakage again
// because a correction made previously consumed expiring credit unused.
ReopenRelease(ctx context.Context, input ReopenReleaseInput) (ledger.TransactionInput, PendingRecord, error)
// ListPlans returns unreleased planned breakage in the same order the FBO
// collector must consume expiring credit.
ListPlans(ctx context.Context, input ListPlansInput) ([]Plan, error)
// ListReleases returns usage releases keyed by the original FBO source entry
// ids, with already-reopened amounts removed.
ListReleases(ctx context.Context, input ListReleasesInput) ([]Release, error)
// ListExpiredRecords returns raw breakage rows that have reached expiry.
// Consumers must net plan/release/reopen rows before showing customer-facing
// expired credit transactions.
ListExpiredRecords(ctx context.Context, input ListExpiredRecordsInput) ([]Record, error)
// ListExpiredBreakageImpacts returns customer-visible breakage impacts by
// netting raw breakage rows that have reached expiry.
ListExpiredBreakageImpacts(ctx context.Context, input ListExpiredBreakageImpactsInput) (ListExpiredBreakageImpactsResult, error)
// PersistCommittedRecords turns pending record metadata into durable
// rows after the corresponding breakage ledger transactions have committed.
PersistCommittedRecords(ctx context.Context, pending []PendingRecord, group ledger.TransactionGroup) error
}
func NewNoopService ¶
func NewNoopService() Service
NewNoopService returns a breakage service that never plans or releases breakage.
func NewService ¶
type SourceKind ¶
type SourceKind = ledger.BreakageSourceKind
const ( SourceKindCreditPurchase SourceKind = ledger.BreakageSourceKindCreditPurchase SourceKindUsage SourceKind = ledger.BreakageSourceKindUsage SourceKindUsageCorrection SourceKind = ledger.BreakageSourceKindUsageCorrection // SourceKindCreditPurchaseCorrection is reserved for a future credit-purchase // correction flow. The breakage primitive is clear, but the charge domain does // not yet define correction/delete semantics, source-specific removable amount // checks, or policy for already-consumed purchased credit. SourceKindCreditPurchaseCorrection SourceKind = ledger.BreakageSourceKindCreditPurchaseCorrection SourceKindAdvanceBackfill SourceKind = ledger.BreakageSourceKindAdvanceBackfill )