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: 14 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

Overview

Package payment provides services related to payment processing, including foreign exchange, transaction handling, and account management.

Index

Constants

View Source
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

View Source
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

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.

Jump to

Keyboard shortcuts

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