charges

package
v1.0.0-beta.231 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ErrCodeChargeInvalid models.ErrorCode = "charge_invalid"
View Source
const ErrCodeChargeNamespaceEmpty models.ErrorCode = "charge_namespace_empty"
View Source
const ErrCodeChargeNotFound models.ErrorCode = "charge_not_found"
View Source
const ErrCodeCreditRealizationsAlreadyAllocated models.ErrorCode = "credit_realizations_already_allocated"
View Source
const (
	EventSubsystem metadata.EventSubsystem = "billing"
)

Variables

View Source
var CreditNotesSupportedByLineUpdater = false

CreditNotesSupportedByLineUpdater controls whether charge-backed immutable invoice-line proration can materialize replacement gathering lines. The default behavior is false until the invoice line updater supports credit notes for correcting immutable invoice history.

Functions

func NewChargeNotFoundError

func NewChargeNotFoundError(namespace, id string) error

func NewLockKeyForCharge

func NewLockKeyForCharge(chargeID meta.ChargeID) (lockr.Key, error)

Types

type Adapter

type Adapter interface {
	ChargesSearchAdapter

	entutils.TxCreator
}

type AdvanceChargesEvent

type AdvanceChargesEvent struct {
	Namespace  string `json:"namespace"`
	CustomerID string `json:"customer_id"`
}

func (AdvanceChargesEvent) EventMetadata

func (e AdvanceChargesEvent) EventMetadata() metadata.EventMetadata

func (AdvanceChargesEvent) EventName

func (e AdvanceChargesEvent) EventName() string

func (AdvanceChargesEvent) Validate

func (e AdvanceChargesEvent) Validate() error

type AdvanceChargesInput

type AdvanceChargesInput struct {
	Customer customer.CustomerID
}

func (AdvanceChargesInput) Validate

func (i AdvanceChargesInput) Validate() error

type ApplyPatchesInput

type ApplyPatchesInput struct {
	CustomerID customer.CustomerID
	Creates    ChargeIntents

	// PatchesByChargeID is a map of charge ID to the patches to apply to the charge. This format is used to make sure
	// there's only a single patch affecting a single charge.
	PatchesByChargeID map[string]Patch
}

func ConcatenateApplyPatchesInputs

func ConcatenateApplyPatchesInputs(inputs ...ApplyPatchesInput) (ApplyPatchesInput, error)

ConcatenateApplyPatchesInputs concatenates the given inputs into a single input, while enforcing uniqueness constraints.

func (ApplyPatchesInput) IsEmpty

func (i ApplyPatchesInput) IsEmpty() bool

func (ApplyPatchesInput) Validate

func (i ApplyPatchesInput) Validate() error

type Charge

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

func (Charge) AsCreditPurchaseCharge

func (c Charge) AsCreditPurchaseCharge() (creditpurchase.Charge, error)

func (Charge) AsFlatFeeCharge

func (c Charge) AsFlatFeeCharge() (flatfee.Charge, error)

func (Charge) AsUsageBasedCharge

func (c Charge) AsUsageBasedCharge() (usagebased.Charge, error)

func (Charge) GetChargeID

func (c Charge) GetChargeID() (meta.ChargeID, error)

func (Charge) GetCurrency

func (c Charge) GetCurrency() (currencyx.Code, error)

func (Charge) GetCustomerID

func (c Charge) GetCustomerID() (customer.CustomerID, error)

func (Charge) GetID

func (c Charge) GetID() string

func (Charge) GetNamespace

func (c Charge) GetNamespace() string

func (Charge) GetUniqueReferenceID

func (c Charge) GetUniqueReferenceID() (*string, error)

func (Charge) SettlementMode

func (c Charge) SettlementMode() (productcatalog.SettlementMode, error)

func (Charge) Type

func (c Charge) Type() meta.ChargeType

func (Charge) Validate

func (c Charge) Validate() error

type ChargeIntent

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

func (ChargeIntent) AsCreditPurchaseIntent

func (i ChargeIntent) AsCreditPurchaseIntent() (creditpurchase.Intent, error)

func (ChargeIntent) AsFlatFeeIntent

func (i ChargeIntent) AsFlatFeeIntent() (flatfee.Intent, error)

func (ChargeIntent) AsUsageBasedIntent

func (i ChargeIntent) AsUsageBasedIntent() (usagebased.Intent, error)

func (ChargeIntent) GetUniqueReferenceID

func (c ChargeIntent) GetUniqueReferenceID() (*string, error)

func (ChargeIntent) TaxCodeID

func (i ChargeIntent) TaxCodeID() (string, error)

TaxCodeID returns the intent's configured tax code ID. It is empty when no tax code is set.

func (ChargeIntent) Type

func (i ChargeIntent) Type() meta.ChargeType

func (ChargeIntent) Validate

func (i ChargeIntent) Validate() error

func (ChargeIntent) WithTaxCodeID

func (i ChargeIntent) WithTaxCodeID(id string) (ChargeIntent, error)

WithTaxCodeID returns a copy of the intent with TaxCodeID set to id. Existing tax behavior and other intent fields are preserved.

type ChargeIntents

type ChargeIntents []ChargeIntent

func (ChargeIntents) ByType

func (i ChargeIntents) ByType() (ChargeIntentsByType, error)

func (ChargeIntents) CollectFeatureKeys

func (i ChargeIntents) CollectFeatureKeys() ([]string, error)

func (ChargeIntents) Validate

func (i ChargeIntents) Validate() error

type ChargeIntentsByType

type ChargeIntentsByType struct {
	FlatFee        []WithIndex[flatfee.Intent]
	CreditPurchase []WithIndex[creditpurchase.Intent]
	UsageBased     []WithIndex[usagebased.Intent]
}

type ChargeSearchItem

type ChargeSearchItem struct {
	ID         meta.ChargeID
	Type       meta.ChargeType
	CustomerID string
}

func (*ChargeSearchItem) Validate

func (c *ChargeSearchItem) Validate() error

type ChargeSearchItems

type ChargeSearchItems []ChargeSearchItem

func (ChargeSearchItems) Validate

func (c ChargeSearchItems) Validate() error

type ChargeService

type ChargeService interface {
	GetByID(ctx context.Context, input GetByIDInput) (Charge, error)
	GetByIDs(ctx context.Context, input GetByIDsInput) (Charges, error)
	Create(ctx context.Context, input CreateInput) (Charges, error)
	CreatePendingInvoiceLines(ctx context.Context, input CreatePendingInvoiceLinesInput) (*CreatePendingInvoiceLinesResult, error)
	UpdateSubscriptionItemID(ctx context.Context, charge Charge, newSubscriptionItemID string) (Charge, error)

	AdvanceCharges(ctx context.Context, input AdvanceChargesInput) (Charges, error)
	ListCustomersToAdvance(ctx context.Context, input ListCustomersToAdvanceInput) (pagination.Result[customer.CustomerID], error)
	// ApplyPatches currently returns no affected-charge payload. If exact post-apply
	// results are needed, shrink/extend must first be implemented properly instead of
	// going through the temporary delete+create remap.
	ApplyPatches(ctx context.Context, input ApplyPatchesInput) error
	ListCharges(ctx context.Context, input ListChargesInput) (pagination.Result[Charge], error)
}

type Charges

type Charges []Charge

func (Charges) Validate

func (c Charges) Validate() error

type ChargesSearchAdapter

type ChargesSearchAdapter interface {
	GetByIDs(ctx context.Context, input GetByIDsInput) (ChargeSearchItems, error)
	ListCharges(ctx context.Context, input ListChargesInput) (pagination.Result[ChargeSearchItem], error)
	ListCustomersToAdvance(ctx context.Context, input ListCustomersToAdvanceInput) (pagination.Result[customer.CustomerID], error)
}

type CreateInput

type CreateInput struct {
	Namespace string
	Intents   ChargeIntents
}

func (CreateInput) Validate

func (i CreateInput) Validate() error

type CreatePendingInvoiceLinesInput

type CreatePendingInvoiceLinesInput = billing.CreatePendingInvoiceLinesInput

type CreatePendingInvoiceLinesResult

type CreatePendingInvoiceLinesResult = billing.CreatePendingInvoiceLinesResult

type CreditPurchaseFacadeService

type CreditPurchaseFacadeService interface {
	HandleCreditPurchaseExternalPaymentStateTransition(ctx context.Context, input HandleCreditPurchaseExternalPaymentStateTransitionInput) (creditpurchase.Charge, error)
}

type GetByIDInput

type GetByIDInput struct {
	ChargeID meta.ChargeID
	Expands  meta.Expands
}

func (GetByIDInput) Validate

func (i GetByIDInput) Validate() error

type GetByIDsInput

type GetByIDsInput struct {
	Namespace string
	IDs       []string
	Expands   meta.Expands
}

func (GetByIDsInput) Validate

func (i GetByIDsInput) Validate() error

type HandleCreditPurchaseExternalPaymentStateTransitionInput

type HandleCreditPurchaseExternalPaymentStateTransitionInput struct {
	ChargeID meta.ChargeID

	TargetPaymentState payment.Status
}

func (HandleCreditPurchaseExternalPaymentStateTransitionInput) Validate

type ListChargesDeletedAtFilter

type ListChargesDeletedAtFilter string
const (
	ListChargesDeletedAtFilterEffective  ListChargesDeletedAtFilter = "effective"
	ListChargesDeletedAtFilterBaseIntent ListChargesDeletedAtFilter = "base_intent"
)

func (ListChargesDeletedAtFilter) Validate

func (f ListChargesDeletedAtFilter) Validate() error

type ListChargesInput

type ListChargesInput struct {
	pagination.Page

	Namespace       string
	CustomerIDs     []string
	SubscriptionIDs []string
	ChargeTypes     []meta.ChargeType
	StatusIn        []meta.ChargeStatus
	StatusNotIn     []meta.ChargeStatus
	IncludeDeleted  bool
	// DeletedAtFilter selects which deleted-at field is used when IncludeDeleted is false.
	// Empty defaults to effective charge deletion.
	DeletedAtFilter ListChargesDeletedAtFilter

	// OrderBy is the field to sort by. Supported values: id, created_at,
	// service_period.from, billing_period.from.
	// Defaults to created_at when empty.
	OrderBy string
	Order   sortx.Order

	Expands meta.Expands
}

func (ListChargesInput) Validate

func (i ListChargesInput) Validate() error

type ListCustomersToAdvanceInput

type ListCustomersToAdvanceInput struct {
	pagination.Page

	Namespaces      []string
	AdvanceAfterLTE time.Time
}

func (ListCustomersToAdvanceInput) Validate

func (i ListCustomersToAdvanceInput) Validate() error

type Patch

type Patch = meta.Patch

type Service

type Service interface {
	ChargeService

	// Facade interfaces provide convinience helpers for the API layer.
	CreditPurchaseFacadeService
}

type WithIndex

type WithIndex[T any] struct {
	Index int
	Value T
}

Jump to

Keyboard shortcuts

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