transaction

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("transaction amount must be positive")
	ErrInvalidCurrency    = errors.New("invalid currency code")
	ErrMissingAccount     = errors.New("account identifier is required")
	ErrInvalidInterval    = errors.New("invalid recurring interval")
	ErrDisputeReasonEmpty = errors.New("dispute reason cannot be empty")
)

Common errors for transaction domain validation.

Functions

This section is empty.

Types

type Dispute

type Dispute struct {
	ID            string        `json:"id"`
	TransactionID string        `json:"transaction_id"`
	UserID        string        `json:"user_id"`
	Reason        string        `json:"reason"`
	Description   string        `json:"description,omitempty"`
	Status        DisputeStatus `json:"status"`
	Amount        int64         `json:"amount"` // Amount being disputed
	Evidence      []string      `json:"evidence,omitempty"`
	CreatedAt     time.Time     `json:"created_at"`
	UpdatedAt     time.Time     `json:"updated_at"`
	ResolvedAt    *time.Time    `json:"resolved_at,omitempty"`
	Resolution    string        `json:"resolution,omitempty"`
}

Dispute represents a customer challenge to a specific transaction.

func NewDispute

func NewDispute(id, txnID, userID, reason string, amount int64) (*Dispute, error)

NewDispute creates a new dispute for a transaction.

func (*Dispute) Resolve

func (d *Dispute) Resolve(won bool, resolutionNote string)

Resolve finalizes the dispute.

type DisputeStatus

type DisputeStatus string

DisputeStatus represents the lifecycle of a dispute.

const (
	DisputeOpen     DisputeStatus = "OPEN"
	DisputeReview   DisputeStatus = "UNDER_REVIEW"
	DisputeWon      DisputeStatus = "WON"
	DisputeLost     DisputeStatus = "LOST"
	DisputeCanceled DisputeStatus = "CANCELED"
)

type Interval

type Interval string

Interval defines the frequency of recurring transactions.

const (
	IntervalDaily   Interval = "DAILY"
	IntervalWeekly  Interval = "WEEKLY"
	IntervalMonthly Interval = "MONTHLY"
	IntervalYearly  Interval = "YEARLY"
)

type RecurringStatus

type RecurringStatus string

RecurringStatus represents the state of a recurring schedule.

const (
	RecurringActive    RecurringStatus = "ACTIVE"
	RecurringPaused    RecurringStatus = "PAUSED"
	RecurringCancelled RecurringStatus = "CANCELLED"
	RecurringFinished  RecurringStatus = "FINISHED"
)

type RecurringTransaction

type RecurringTransaction struct {
	ID              string          `json:"id"`
	UserID          string          `json:"user_id"`
	SourceAccountID string          `json:"source_account_id"`
	TargetAccountID string          `json:"target_account_id"`
	Amount          int64           `json:"amount"`
	Currency        string          `json:"currency"`
	Interval        Interval        `json:"interval"`
	Status          RecurringStatus `json:"status"`
	NextRunAt       time.Time       `json:"next_run_at"`
	LastRunAt       *time.Time      `json:"last_run_at,omitempty"`
	TotalRuns       int             `json:"total_runs"`
	MaxRuns         *int            `json:"max_runs,omitempty"` // nil means infinite
	CreatedAt       time.Time       `json:"created_at"`
	UpdatedAt       time.Time       `json:"updated_at"`
}

RecurringTransaction defines a schedule for automated transaction creation.

func (*RecurringTransaction) CalculateNextRun

func (rt *RecurringTransaction) CalculateNextRun(from time.Time) time.Time

CalculateNextRun computes the next execution time based on the interval.

func (*RecurringTransaction) ShouldRun

func (rt *RecurringTransaction) ShouldRun() bool

ShouldRun checks if the recurring transaction is due for execution.

type Status

type Status string

Status represents the lifecycle state of a transaction.

const (
	StatusPending    Status = "PENDING"
	StatusProcessing Status = "PROCESSING"
	StatusCompleted  Status = "COMPLETED"
	StatusFailed     Status = "FAILED"
	StatusCancelled  Status = "CANCELLED"
	StatusRefunded   Status = "REFUNDED"
)

type Transaction

type Transaction struct {
	ID              string            `json:"id"`
	UserID          string            `json:"user_id"`
	SourceAccountID string            `json:"source_account_id"`
	TargetAccountID string            `json:"target_account_id,omitempty"`
	Amount          int64             `json:"amount"` // Amount in minor units
	Currency        string            `json:"currency"`
	Type            Type              `json:"type"`
	Status          Status            `json:"status"`
	Reference       string            `json:"reference,omitempty"`
	Description     string            `json:"description,omitempty"`
	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"`
}

Transaction represents a core financial event within the system. It uses int64 for Amount to represent minor units (e.g., cents) to ensure precision.

func NewTransaction

func NewTransaction(id, userID, sourceID string, amount int64, currency string, txnType Type) (*Transaction, error)

NewTransaction creates a new transaction in the Pending state.

func (*Transaction) Complete

func (t *Transaction) Complete()

Complete marks the transaction as successful.

func (*Transaction) Fail

func (t *Transaction) Fail(reason string)

Fail marks the transaction as failed with a reason.

type Type

type Type string

Type defines the nature of the financial movement.

const (
	TypeDeposit    Type = "DEPOSIT"
	TypeWithdrawal Type = "WITHDRAWAL"
	TypeTransfer   Type = "TRANSFER"
	TypePayment    Type = "PAYMENT"
	TypeFee        Type = "FEE"
	TypeRefund     Type = "REFUND"
)

Jump to

Keyboard shortcuts

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