lending

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 indicates the monetary amount is invalid (e.g., negative or zero).
	ErrInvalidAmount = errors.New("amount must be greater than zero")
	// ErrInvalidDuration indicates the loan duration is invalid.
	ErrInvalidDuration = errors.New("duration must be between 1 and 120 months")
	// ErrApplicationNotPending indicates an operation was attempted on a non-pending application.
	ErrApplicationNotPending = errors.New("loan application is not in a pending state")
	// ErrOfferExpired indicates an attempt to accept an expired offer.
	ErrOfferExpired = errors.New("loan offer has expired")
	// ErrOfferNotAvailable indicates the offer is no longer available for acceptance.
	ErrOfferNotAvailable = errors.New("loan offer is not in a generated state")
)

Functions

This section is empty.

Types

type ApplicationStatus

type ApplicationStatus string

ApplicationStatus represents the lifecycle state of a LoanApplication.

const (
	ApplicationStatusPending     ApplicationStatus = "PENDING"
	ApplicationStatusUnderReview ApplicationStatus = "UNDER_REVIEW"
	ApplicationStatusApproved    ApplicationStatus = "APPROVED"
	ApplicationStatusRejected    ApplicationStatus = "REJECTED"
	ApplicationStatusCancelled   ApplicationStatus = "CANCELLED"
)

type LoanApplication

type LoanApplication struct {
	ID              uuid.UUID         `json:"id"`
	BorrowerID      uuid.UUID         `json:"borrower_id"`
	RequestedAmount Money             `json:"requested_amount"`
	DurationMonths  int               `json:"duration_months"`
	Purpose         string            `json:"purpose"`
	Status          ApplicationStatus `json:"status"`
	Metadata        map[string]string `json:"metadata,omitempty"`
	CreatedAt       time.Time         `json:"created_at"`
	UpdatedAt       time.Time         `json:"updated_at"`
}

LoanApplication is the aggregate root representing a user's request for a loan.

func NewLoanApplication

func NewLoanApplication(borrowerID uuid.UUID, amount int64, currency string, durationMonths int, purpose string) (*LoanApplication, error)

NewLoanApplication creates a new LoanApplication with initial validation.

func (*LoanApplication) Approve

func (la *LoanApplication) Approve()

Approve marks the application as approved.

func (*LoanApplication) Reject

func (la *LoanApplication) Reject()

Reject marks the application as rejected.

func (*LoanApplication) Review

func (la *LoanApplication) Review() error

Review transitions the application to the UnderReview state.

type LoanOffer

type LoanOffer struct {
	ID              uuid.UUID   `json:"id"`
	ApplicationID   uuid.UUID   `json:"application_id"`
	Principal       Money       `json:"principal"`
	InterestRateBps int64       `json:"interest_rate_bps"` // Basis Points (e.g., 500 = 5.00%)
	TermMonths      int         `json:"term_months"`
	MonthlyPayment  Money       `json:"monthly_payment"`
	TotalRepayment  Money       `json:"total_repayment"`
	Status          OfferStatus `json:"status"`
	ExpiresAt       time.Time   `json:"expires_at"`
	CreatedAt       time.Time   `json:"created_at"`
	UpdatedAt       time.Time   `json:"updated_at"`
}

LoanOffer represents a formal offer extended to the borrower based on an application.

func NewLoanOffer

func NewLoanOffer(appID uuid.UUID, principal Money, rateBps int64, term int, monthlyPayment Money, totalRepayment Money, validityDuration time.Duration) *LoanOffer

NewLoanOffer creates a new offer for a specific application.

func (*LoanOffer) Accept

func (lo *LoanOffer) Accept() error

Accept marks the offer as accepted by the borrower.

func (*LoanOffer) Expire

func (lo *LoanOffer) Expire()

Expire forces the offer status to expired.

func (*LoanOffer) IsExpired

func (lo *LoanOffer) IsExpired() bool

IsExpired checks if the offer is past its expiration time.

func (*LoanOffer) Reject

func (lo *LoanOffer) Reject() error

Reject marks the offer as rejected by the borrower.

type Money

type Money struct {
	Amount   int64  `json:"amount"`   // Amount in minor units (e.g., cents)
	Currency string `json:"currency"` // ISO 4217 Currency Code (e.g., "USD")
}

Money represents a monetary value safely using integer math for minor units.

type OfferStatus

type OfferStatus string

OfferStatus represents the lifecycle state of a LoanOffer.

const (
	OfferStatusGenerated OfferStatus = "GENERATED"
	OfferStatusAccepted  OfferStatus = "ACCEPTED"
	OfferStatusRejected  OfferStatus = "REJECTED"
	OfferStatusExpired   OfferStatus = "EXPIRED"
)

Jump to

Keyboard shortcuts

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