Documentation
¶
Overview ¶
Package payment provides services related to payment processing, including foreign exchange, transaction handling, and account management.
Index ¶
- Constants
- Variables
- type ComplianceProvider
- type FXProvider
- type FXService
- type InternationalService
- func (s *InternationalService) BatchProcess(ctx context.Context, requests []InternationalTransferRequest) ([]*TransferResult, []error)
- func (s *InternationalService) GetQuote(ctx context.Context, sourceCurrency, targetCurrency string, amount float64) (*TransferQuote, error)
- func (s *InternationalService) InitiateTransfer(ctx context.Context, req InternationalTransferRequest) (*TransferResult, error)
- func (s *InternationalService) TrackTransfer(ctx context.Context, transactionID string) (TransactionStatus, error)
- type InternationalTransferRequest
- type Logger
- type PaymentGateway
- type Repository
- type TransactionStatus
- type TransferQuote
- type TransferResult
Constants ¶
const ( // DefaultBaseCurrency is the currency used for triangulation if a direct rate is not found. // Using a major currency like USD is a common practice. DefaultBaseCurrency = payment.USD )
Variables ¶
var ( ErrInvalidAmount = errors.New("amount must be greater than zero") ErrUnsupportedCurrency = errors.New("unsupported currency pair") ErrInsufficientFunds = errors.New("insufficient funds in source account") ErrComplianceCheckFailed = errors.New("transaction blocked by compliance checks") ErrInvalidIBAN = errors.New("invalid IBAN format") ErrInvalidSWIFT = errors.New("invalid SWIFT/BIC code format") ErrGatewayFailure = errors.New("payment gateway failed to process transaction") )
Common errors for the international payment service.
Functions ¶
This section is empty.
Types ¶
type ComplianceProvider ¶
type ComplianceProvider interface {
ScreenTransaction(ctx context.Context, senderID, recipientName string, amount float64, currency string) (bool, string, error)
}
ComplianceProvider defines the interface for AML/KYC checks.
type FXProvider ¶
type FXProvider interface {
GetExchangeRate(ctx context.Context, source, target string) (float64, error)
}
FXProvider defines the interface for foreign exchange rates.
type FXService ¶
type FXService interface {
// GetRate retrieves the exchange rate between two currencies.
GetRate(ctx context.Context, from, to payment.Currency) (*payment.FXRate, error)
// Convert transforms a monetary amount from one currency to another.
Convert(ctx context.Context, amount payment.Money, toCurrency payment.Currency) (*payment.Money, error)
}
FXService defines the interface for foreign exchange operations. It abstracts the complexities of rate retrieval, including caching, triangulation, and fetching from external providers.
func NewFXService ¶
func NewFXService(fxRepo repository.FXRateRepository, logger log.Logger) FXService
NewFXService creates a new instance of the FX service. It requires a repository for data access and a logger for observability.
type InternationalService ¶
type InternationalService struct {
// contains filtered or unexported fields
}
InternationalService handles the business logic for cross-border payments.
func NewInternationalService ¶
func NewInternationalService( repo Repository, fx FXProvider, compliance ComplianceProvider, gateway PaymentGateway, logger Logger, ) *InternationalService
NewInternationalService creates a new instance of the InternationalService.
func (*InternationalService) BatchProcess ¶
func (s *InternationalService) BatchProcess(ctx context.Context, requests []InternationalTransferRequest) ([]*TransferResult, []error)
BatchProcess allows processing multiple transfers concurrently (e.g., for corporate payroll).
func (*InternationalService) GetQuote ¶
func (s *InternationalService) GetQuote(ctx context.Context, sourceCurrency, targetCurrency string, amount float64) (*TransferQuote, error)
GetQuote calculates the exchange rate and fees for a potential transfer.
func (*InternationalService) InitiateTransfer ¶
func (s *InternationalService) InitiateTransfer(ctx context.Context, req InternationalTransferRequest) (*TransferResult, error)
InitiateTransfer orchestrates the international payment process.
func (*InternationalService) TrackTransfer ¶
func (s *InternationalService) TrackTransfer(ctx context.Context, transactionID string) (TransactionStatus, error)
TrackTransfer retrieves the current status of a transfer. This might aggregate data from the local DB and the external gateway.
type InternationalTransferRequest ¶
type InternationalTransferRequest struct {
SenderID string
RecipientID string
RecipientName string
SourceCurrency string
TargetCurrency string
Amount float64 // Represented as major units (e.g., 100.50 USD). In real systems, use big.Int or decimal.
IBAN string
SWIFTCode string
Reference string
IdempotencyKey string
}
InternationalTransferRequest represents the payload for initiating a cross-border payment.
type Logger ¶
type Logger interface {
Info(msg string, keysAndValues ...interface{})
Error(msg string, keysAndValues ...interface{})
Debug(msg string, keysAndValues ...interface{})
With(keysAndValues ...interface{}) Logger
}
Logger defines a structured logging interface.
type PaymentGateway ¶
type PaymentGateway interface {
ExecuteTransfer(ctx context.Context, txID string, req InternationalTransferRequest) (string, error)
}
PaymentGateway defines the interface for the external banking rail (e.g., SWIFT).
type Repository ¶
type Repository interface {
CreateTransaction(ctx context.Context, req InternationalTransferRequest, quote TransferQuote, status TransactionStatus) (string, error)
UpdateStatus(ctx context.Context, transactionID string, status TransactionStatus, gatewayRef string) error
GetBalance(ctx context.Context, userID string, currency string) (float64, error)
HoldFunds(ctx context.Context, userID string, currency string, amount float64) error
ReleaseFunds(ctx context.Context, userID string, currency string, amount float64) error
CommitFunds(ctx context.Context, userID string, currency string, amount float64) error
}
Repository defines data access for payments.
type TransactionStatus ¶
type TransactionStatus string
TransactionStatus defines the state of a transfer.
const ( StatusPending TransactionStatus = "PENDING" StatusProcessing TransactionStatus = "PROCESSING" StatusCompleted TransactionStatus = "COMPLETED" StatusFailed TransactionStatus = "FAILED" StatusCancelled TransactionStatus = "CANCELLED" )
type TransferQuote ¶
type TransferQuote struct {
QuoteID string
SourceCurrency string
TargetCurrency string
SourceAmount float64
TargetAmount float64
ExchangeRate float64
Fee float64
ExpiresAt time.Time
}
TransferQuote represents a pre-transaction quote including FX rates and fees.
type TransferResult ¶
type TransferResult struct {
TransactionID string
Status TransactionStatus
CreatedAt time.Time
EstimatedArrival time.Time
Quote TransferQuote
}
TransferResult contains the details of a submitted transfer.