Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository interface {
// Wallet operations
CreateWallet(ctx context.Context, w *Wallet) error
GetWalletByID(ctx context.Context, id string) (*Wallet, error)
GetWalletsByCustomerID(ctx context.Context, customerID string) ([]*Wallet, error)
GetWalletsByFilter(ctx context.Context, filter *types.WalletFilter) ([]*Wallet, error)
UpdateWalletStatus(ctx context.Context, id string, status types.WalletStatus) error
UpdateWallet(ctx context.Context, id string, wallet *Wallet) error
// Transaction operations
GetTransactionByID(ctx context.Context, id string) (*Transaction, error)
ListWalletTransactions(ctx context.Context, f *types.WalletTransactionFilter) ([]*Transaction, error)
ListAllWalletTransactions(ctx context.Context, f *types.WalletTransactionFilter) ([]*Transaction, error)
CountWalletTransactions(ctx context.Context, f *types.WalletTransactionFilter) (int, error)
UpdateTransactionStatus(ctx context.Context, id string, status types.TransactionStatus) error
// Credit/Debit specific operations
FindEligibleCredits(ctx context.Context, walletID string, requiredAmount decimal.Decimal, pageSize int) ([]*Transaction, error)
ConsumeCredits(ctx context.Context, credits []*Transaction, amount decimal.Decimal) error
CreateTransaction(ctx context.Context, tx *Transaction) error
UpdateWalletBalance(ctx context.Context, walletID string, finalBalance, newCreditBalance decimal.Decimal) error
}
Repository defines the interface for wallet persistence operations
type Transaction ¶
type Transaction struct {
ID string `db:"id" json:"id"`
WalletID string `db:"wallet_id" json:"wallet_id"`
Type types.TransactionType `db:"type" json:"type"`
Amount decimal.Decimal `db:"amount" json:"amount"`
CreditAmount decimal.Decimal `db:"credit_amount" json:"credit_amount"`
CreditBalanceBefore decimal.Decimal `db:"credit_balance_before" json:"credit_balance_before"`
CreditBalanceAfter decimal.Decimal `db:"credit_balance_after" json:"credit_balance_after"`
TxStatus types.TransactionStatus `db:"transaction_status" json:"transaction_status"`
ReferenceType types.WalletTxReferenceType `db:"reference_type" json:"reference_type"`
ReferenceID string `db:"reference_id" json:"reference_id"`
Description string `db:"description" json:"description"`
Metadata types.Metadata `db:"metadata" json:"metadata"`
ExpiryDate *time.Time `db:"expiry_date" json:"expiry_date"`
CreditsAvailable decimal.Decimal `db:"credits_available" json:"credits_available"`
TransactionReason types.TransactionReason `db:"transaction_reason" json:"transaction_reason"`
Priority *int `db:"priority" json:"priority"`
IdempotencyKey string `db:"idempotency_key" json:"idempotency_key"`
EnvironmentID string `db:"environment_id" json:"environment_id"`
types.BaseModel
}
Transaction represents a wallet transaction
func TransactionFromEnt ¶
func TransactionFromEnt(e *ent.WalletTransaction) *Transaction
FromEnt converts an ent transaction to a domain transaction
func TransactionListFromEnt ¶
func TransactionListFromEnt(dataList []*ent.WalletTransaction) []*Transaction
TransactionListFromEnt converts a slice of ent.WalletTransaction pointers to domain transactions
func (Transaction) ApplyConversionRate ¶
func (t Transaction) ApplyConversionRate(rate decimal.Decimal) Transaction
ApplyConversionRate applies the conversion rate to the transaction so for conversion rate of 2 means 1 credit = 2 dollars (assuming USD) and similarly for conversion rate of 0.5 means 1 dollar = 0.5 credits
func (*Transaction) TableName ¶
func (t *Transaction) TableName() string
func (*Transaction) ToEnt ¶
func (t *Transaction) ToEnt() *ent.WalletTransaction
ToEnt converts a domain transaction to an ent transaction
func (*Transaction) Validate ¶
func (t *Transaction) Validate() error
type Wallet ¶
type Wallet struct {
ID string `db:"id" json:"id"`
CustomerID string `db:"customer_id" json:"customer_id"`
Currency string `db:"currency" json:"currency"`
Balance decimal.Decimal `db:"balance" json:"balance"`
CreditBalance decimal.Decimal `db:"credit_balance" json:"credit_balance"`
WalletStatus types.WalletStatus `db:"wallet_status" json:"wallet_status"`
Name string `db:"name" json:"name,omitempty"`
Description string `db:"description" json:"description"`
Metadata types.Metadata `db:"metadata" json:"metadata"`
AutoTopupTrigger types.AutoTopupTrigger `db:"auto_topup_trigger" json:"auto_topup_trigger"`
AutoTopupMinBalance decimal.Decimal `db:"auto_topup_min_balance" json:"auto_topup_min_balance"`
AutoTopupAmount decimal.Decimal `db:"auto_topup_amount" json:"auto_topup_amount"`
WalletType types.WalletType `db:"wallet_type" json:"wallet_type"`
Config types.WalletConfig `db:"config" json:"config"`
ConversionRate decimal.Decimal `db:"conversion_rate" json:"conversion_rate"`
EnvironmentID string `db:"environment_id" json:"environment_id"`
AlertEnabled bool `db:"alert_enabled" json:"alert_enabled"`
AlertConfig *types.AlertConfig `db:"alert_config" json:"alert_config,omitempty"`
AlertState string `db:"alert_state" json:"alert_state"`
types.BaseModel
}
Wallet represents a credit wallet for a customer
func FromEntList ¶
FromEntList converts a list of ent wallets to domain wallets
func (*Wallet) ApplyConversionRate ¶
ApplyConversionRate applies the conversion rate to the wallet so for conversion rate of 2 means 1 credit = 2 dollars (assuming USD) and similarly for conversion rate of 0.5 means 1 dollar = 0.5 credits
type WalletOperation ¶
type WalletOperation struct {
WalletID string `json:"wallet_id"`
Type types.TransactionType `json:"type"`
// Amount is the amount of the transaction in the wallet's currency
Amount decimal.Decimal `json:"amount"`
// CreditAmount is the amount of the transaction in the wallet's credit currency
// If both are provided, Amount is used
CreditAmount decimal.Decimal `json:"credit_amount"`
ReferenceType types.WalletTxReferenceType `json:"reference_type,omitempty"`
ReferenceID string `json:"reference_id,omitempty"`
Description string `json:"description,omitempty"`
Metadata types.Metadata `json:"metadata,omitempty"`
IdempotencyKey string `json:"idempotency_key,omitempty"`
ExpiryDate *int `json:"expiry_date,omitempty"` // YYYYMMDD format
Priority *int `json:"priority,omitempty"` // lower number means higher priority
TransactionReason types.TransactionReason `json:"transaction_reason,omitempty"`
}
WalletOperation represents the request to credit or debit a wallet
func (*WalletOperation) Validate ¶
func (w *WalletOperation) Validate() error