payment

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAmount          = errors.New("amount must be positive")
	ErrInvalidCurrency        = errors.New("invalid currency code")
	ErrQuoteExpired           = errors.New("fx quote has expired")
	ErrInvalidStateTransition = errors.New("invalid state transition")
	ErrSameCurrencyTransfer   = errors.New("source and target currency cannot be the same for international transfer")
)

Common domain errors

Functions

This section is empty.

Types

type Currency

type Currency string

Currency represents a 3-letter ISO 4217 currency code.

type FXRate

type FXRate struct {
	BaseCurrency   Currency  `json:"base_currency"`
	TargetCurrency Currency  `json:"target_currency"`
	Rate           float64   `json:"rate"` // Multiplier: Target = Base * Rate
	ExpiresAt      time.Time `json:"expires_at"`
	QuoteID        string    `json:"quote_id"`
}

FXRate represents an exchange rate between two currencies.

func (FXRate) Convert

func (r FXRate) Convert(source Money) (Money, error)

Convert calculates the target amount based on the source amount and rate. It returns the converted Money object.

func (FXRate) IsExpired

func (r FXRate) IsExpired() bool

IsExpired checks if the FX rate is no longer valid.

type Money

type Money struct {
	Amount   int64    `json:"amount"`   // Amount in minor units
	Currency Currency `json:"currency"` // ISO 4217 code
}

Money represents a monetary value in minor units (e.g., cents) to avoid floating-point errors.

func NewMoney

func NewMoney(amount int64, currency string) (Money, error)

NewMoney creates a new Money value object.

type Transfer

type Transfer struct {
	ID            string            `json:"id"`
	CustomerID    string            `json:"customer_id"`
	BeneficiaryID string            `json:"beneficiary_id"`
	SourceAmount  Money             `json:"source_amount"`
	TargetAmount  Money             `json:"target_amount"`
	Rate          FXRate            `json:"applied_rate"`
	Status        TransferStatus    `json:"status"`
	Reference     string            `json:"reference"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	FailureReason string            `json:"failure_reason,omitempty"`
	CreatedAt     time.Time         `json:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at"`
	CompletedAt   *time.Time        `json:"completed_at,omitempty"`
}

Transfer represents the aggregate root for an international payment.

func NewTransfer

func NewTransfer(id, customerID, beneficiaryID string, source Money, targetCurrency string) (*Transfer, error)

NewTransfer initializes a new transfer in Draft state.

func (*Transfer) ApplyQuote

func (t *Transfer) ApplyQuote(rate FXRate) error

ApplyQuote applies an FX rate to the transfer and transitions it to Quoted status.

func (*Transfer) Cancel

func (t *Transfer) Cancel(reason string) error

Cancel allows the user to cancel the transfer if it hasn't been processed yet.

func (*Transfer) Complete

func (t *Transfer) Complete() error

Complete finalizes the transfer.

func (*Transfer) Confirm

func (t *Transfer) Confirm() error

Confirm locks the transfer and moves it to Pending Funds.

func (*Transfer) Fail

func (t *Transfer) Fail(reason string) error

Fail marks the transfer as failed with a reason.

func (*Transfer) IsTerminal

func (t *Transfer) IsTerminal() bool

IsTerminal checks if the transfer is in a final state.

func (*Transfer) MarkProcessing

func (t *Transfer) MarkProcessing() error

MarkProcessing moves the transfer to Processing state (funds received).

type TransferStatus

type TransferStatus string

TransferStatus represents the lifecycle state of a payment.

const (
	TransferStatusDraft        TransferStatus = "DRAFT"
	TransferStatusQuoted       TransferStatus = "QUOTED"
	TransferStatusPendingFunds TransferStatus = "PENDING_FUNDS"
	TransferStatusProcessing   TransferStatus = "PROCESSING"
	TransferStatusCompleted    TransferStatus = "COMPLETED"
	TransferStatusFailed       TransferStatus = "FAILED"
	TransferStatusCancelled    TransferStatus = "CANCELLED"
)

Jump to

Keyboard shortcuts

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