Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 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.
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.
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 ¶
ApplyQuote applies an FX rate to the transfer and transitions it to Quoted status.
func (*Transfer) Cancel ¶
Cancel allows the user to cancel the transfer if it hasn't been processed yet.
func (*Transfer) IsTerminal ¶
IsTerminal checks if the transfer is in a final state.
func (*Transfer) MarkProcessing ¶
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" )