finance

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdempotencyKey

type IdempotencyKey struct {
	ID        string `gorm:"primaryKey"`
	Scope     string `gorm:"index:idx_scope_key,unique"`
	Key       string `gorm:"index:idx_scope_key,unique"`
	CreatedAt time.Time
}

IdempotencyKey prevents duplicate processing of the same operation.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements the mdk.Module interface for Finance.

func NewModule

func NewModule() *Module

func (*Module) CompensatePayment

func (m *Module) CompensatePayment(ctx context.Context, input any) (any, error)

CompensatePayment handles refunding a payment if a subsequent step fails.

func (*Module) CompensatePaymentStep

func (m *Module) CompensatePaymentStep(sCtx mdk.StepContext) mdk.StepResult

CompensatePaymentStep wraps CompensatePayment to mdk.StepHandler.

func (*Module) FieldResolvers

func (m *Module) FieldResolvers() map[string]any

func (*Module) GetPayment

func (m *Module) GetPayment(ctx context.Context, id string) (*Payment, error)

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

func (*Module) ListOrderPayments

func (m *Module) ListOrderPayments(ctx context.Context, orderID string) ([]*Payment, error)

func (*Module) Models

func (m *Module) Models() []any

func (*Module) Mutations

func (m *Module) Mutations() map[string]any

func (*Module) ProcessPayment

func (m *Module) ProcessPayment(ctx context.Context, input any) (any, error)

ProcessPayment processes the payment for an order and creates a Payment record.

func (*Module) ProcessPaymentStep

func (m *Module) ProcessPaymentStep(sCtx mdk.StepContext) mdk.StepResult

ProcessPaymentStep wraps ProcessPayment to mdk.StepHandler.

func (*Module) Queries

func (m *Module) Queries() map[string]any

func (*Module) Repo

func (m *Module) Repo() *Repository

func (*Module) Routes

func (m *Module) Routes() []mdk.Route

func (*Module) Shutdown

func (m *Module) Shutdown(ctx context.Context) error

type Payment

type Payment struct {
	ID        string         `gorm:"primaryKey" json:"id"`
	OrderID   string         `gorm:"index" json:"order_id"`
	Amount    float64        `json:"amount"`
	Status    PaymentStatus  `gorm:"not null" json:"status"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

Payment represents a financial transaction.

type PaymentStatus

type PaymentStatus string
const (
	PaymentPending  PaymentStatus = "PENDING"
	PaymentSuccess  PaymentStatus = "SUCCESS"
	PaymentFailed   PaymentStatus = "FAILED"
	PaymentRefunded PaymentStatus = "REFUNDED"
)

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository handles data access for finance models.

func NewRepository

func NewRepository(database *gorm.DB) *Repository

NewRepository creates a new Repository.

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, id string) (*Payment, error)

GetByID retrieves a payment by its ID.

func (*Repository) ListByOrderID

func (r *Repository) ListByOrderID(ctx context.Context, orderID string) ([]*Payment, error)

ListByOrderID retrieves all payments for an order.

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, p *Payment) error

Save persists a payment to the database.

Jump to

Keyboard shortcuts

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