corporate

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: 13 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 (
	ErrInvalidScreeningRequest = errors.New("invalid screening request: missing required fields")
	ErrSanctionCheckFailed     = errors.New("failed to perform sanction screening")
	ErrAuditLogFailed          = errors.New("failed to record audit log")
)

Common errors for the compliance service.

View Source
var (
	ErrInvalidAccountID = errors.New("invalid account ID provided")
	ErrInvalidTimeRange = errors.New("invalid time range for forecasting")
	ErrDataSourceFailed = errors.New("failed to retrieve data from underlying source")
)

Common errors for the Treasury Service.

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent struct {
	ID        string                 `json:"id"`
	Timestamp time.Time              `json:"timestamp"`
	ActorID   string                 `json:"actor_id"`
	Action    string                 `json:"action"`
	Resource  string                 `json:"resource"`
	Payload   map[string]interface{} `json:"payload"`
	Hash      string                 `json:"hash"` // HMAC signature for integrity
}

AuditEvent represents an immutable record of a compliance action.

type AuditRepository

type AuditRepository interface {
	SaveEvent(ctx context.Context, event AuditEvent) error
	GetEventsByResource(ctx context.Context, resourceID string) ([]AuditEvent, error)
}

AuditRepository defines the storage for compliance audit logs.

type Card

type Card struct {
	ID             string       `json:"id"`
	AccountID      string       `json:"account_id"`
	HolderName     string       `json:"holder_name"`
	Last4          string       `json:"last_4"`
	ExpiryMonth    int          `json:"expiry_month"`
	ExpiryYear     int          `json:"expiry_year"`
	CVV            string       `json:"cvv,omitempty"` // Usually not stored, but returned on creation
	PAN            string       `json:"pan,omitempty"` // Primary Account Number (sensitive)
	Type           CardType     `json:"type"`
	Status         CardStatus   `json:"status"`
	Currency       Currency     `json:"currency"`
	Controls       CardControls `json:"controls"`
	ExternalCardID string       `json:"external_card_id"` // ID from the issuer (e.g., Stripe/Marqeta)
	CreatedAt      time.Time    `json:"created_at"`
	UpdatedAt      time.Time    `json:"updated_at"`
}

Card represents a corporate credit/debit card.

type CardControls

type CardControls struct {
	DailyLimit    int64    `json:"daily_limit"`     // In smallest currency unit (e.g., cents)
	MonthlyLimit  int64    `json:"monthly_limit"`   // In smallest currency unit
	AllowedMCCs   []string `json:"allowed_mccs"`    // Merchant Category Codes
	BlockedMCCs   []string `json:"blocked_mccs"`    // Merchant Category Codes
	AllowForeign  bool     `json:"allow_foreign"`   // Allow non-domestic transactions
	SingleTxLimit int64    `json:"single_tx_limit"` // Max amount per transaction
}

CardControls defines spending limits and restrictions.

type CardIssuerProvider

type CardIssuerProvider interface {
	IssueCard(ctx context.Context, req IssueCardRequest) (*IssuedCardDetails, error)
	FreezeCard(ctx context.Context, externalID string) error
	UnfreezeCard(ctx context.Context, externalID string) error
	CancelCard(ctx context.Context, externalID string) error
	UpdateControls(ctx context.Context, externalID string, controls CardControls) error
}

CardIssuerProvider defines the interface for the external card issuing platform.

type CardRepository

type CardRepository interface {
	Create(ctx context.Context, card *Card) error
	GetByID(ctx context.Context, id string) (*Card, error)
	ListByAccount(ctx context.Context, accountID string) ([]*Card, error)
	UpdateStatus(ctx context.Context, id string, status CardStatus) error
	UpdateControls(ctx context.Context, id string, controls CardControls) error
}

CardRepository defines the persistence layer requirements for cards.

type CardService

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

CardService handles business logic for corporate cards.

func NewCardService

func NewCardService(repo CardRepository, provider CardIssuerProvider, logger *slog.Logger) *CardService

NewCardService creates a new instance of CardService.

func (*CardService) CancelCard

func (s *CardService) CancelCard(ctx context.Context, cardID string) error

CancelCard permanently terminates a card.

func (*CardService) FreezeCard

func (s *CardService) FreezeCard(ctx context.Context, cardID string) error

FreezeCard temporarily disables a card.

func (*CardService) GetCard

func (s *CardService) GetCard(ctx context.Context, cardID string) (*Card, error)

GetCard retrieves a card by its ID.

func (*CardService) IssueVirtualCard

func (s *CardService) IssueVirtualCard(ctx context.Context, req IssueCardRequest) (*Card, error)

IssueVirtualCard creates a new virtual card via the provider and stores it.

func (*CardService) ListCards

func (s *CardService) ListCards(ctx context.Context, accountID string) ([]*Card, error)

ListCards retrieves all cards for a specific corporate account.

func (*CardService) UnfreezeCard

func (s *CardService) UnfreezeCard(ctx context.Context, cardID string) error

UnfreezeCard reactivates a frozen card.

func (*CardService) UpdateCardControls

func (s *CardService) UpdateCardControls(ctx context.Context, cardID string, controls CardControls) error

UpdateCardControls modifies spending limits and restrictions.

type CardStatus

type CardStatus string

CardStatus represents the current state of a corporate card.

const (
	CardStatusActive   CardStatus = "ACTIVE"
	CardStatusFrozen   CardStatus = "FROZEN"
	CardStatusCanceled CardStatus = "CANCELED"
	CardStatusPending  CardStatus = "PENDING"
)

type CardType

type CardType string

CardType distinguishes between virtual and physical cards.

const (
	CardTypeVirtual  CardType = "VIRTUAL"
	CardTypePhysical CardType = "PHYSICAL"
)

type CashFlowForecastRequest

type CashFlowForecastRequest struct {
	AccountIDs []string  `json:"account_ids"`
	StartDate  time.Time `json:"start_date"`
	EndDate    time.Time `json:"end_date"`
	Interval   string    `json:"interval"` // e.g., "daily", "weekly", "monthly"
}

CashFlowForecastRequest defines parameters for generating a forecast.

type CashFlowForecastResponse

type CashFlowForecastResponse struct {
	GeneratedAt time.Time          `json:"generated_at"`
	Currency    Currency           `json:"currency"`
	Intervals   []ForecastInterval `json:"intervals"`
	TotalNet    Money              `json:"total_net"`
}

CashFlowForecastResponse contains the generated forecast data.

type ComplianceService

type ComplianceService interface {
	// ScreenEntity performs a full compliance check on an entity.
	ScreenEntity(ctx context.Context, req ScreeningRequest) (*ScreeningResult, error)
	// LogAction records a compliance-related action for audit purposes.
	LogAction(ctx context.Context, actorID, action, resource string, details map[string]interface{}) error
	// GetAuditTrail retrieves the history of actions for a specific resource.
	GetAuditTrail(ctx context.Context, resourceID string) ([]AuditEvent, error)
}

ComplianceService defines the business logic for compliance operations.

func NewComplianceService

func NewComplianceService(
	sr SanctionRepository,
	ar AuditRepository,
	logger *slog.Logger,
	secretKey string,
) ComplianceService

NewComplianceService creates a new instance of the compliance service.

type Currency

type Currency string

Currency represents a standard ISO 4217 currency code.

const (
	CurrencyUSD Currency = "USD"
	CurrencyEUR Currency = "EUR"
	CurrencyGBP Currency = "GBP"
)

type EntityType

type EntityType string

EntityType defines the type of entity being screened.

const (
	EntityTypeIndividual EntityType = "INDIVIDUAL"
	EntityTypeCompany    EntityType = "COMPANY"
)

type ForecastInterval

type ForecastInterval struct {
	PeriodStart    time.Time `json:"period_start"`
	PeriodEnd      time.Time `json:"period_end"`
	ProjectedIn    Money     `json:"projected_in"`
	ProjectedOut   Money     `json:"projected_out"`
	NetFlow        Money     `json:"net_flow"`
	ConfidenceRate float64   `json:"confidence_rate"` // 0.0 to 1.0
}

ForecastInterval represents a single time slice in the forecast.

type HistoricalFlow

type HistoricalFlow struct {
	Date      time.Time
	Amount    *big.Float
	Direction string
	Currency  Currency
}

HistoricalFlow represents past transaction data for trend analysis.

type IssueCardRequest

type IssueCardRequest struct {
	AccountID  string       `json:"account_id"`
	HolderName string       `json:"holder_name"`
	Type       CardType     `json:"type"`
	Currency   Currency     `json:"currency"`
	Controls   CardControls `json:"controls"`
}

IssueCardRequest contains data required to issue a new card.

type IssuedCardDetails

type IssuedCardDetails struct {
	ExternalID  string
	PAN         string
	CVV         string
	ExpiryMonth int
	ExpiryYear  int
	Last4       string
}

IssuedCardDetails contains sensitive data returned by the issuer.

type LiquidityPosition

type LiquidityPosition struct {
	AccountID   string    `json:"account_id"`
	EntityID    string    `json:"entity_id"`
	TotalAssets Money     `json:"total_assets"`
	Liabilities Money     `json:"liabilities"`
	NetPosition Money     `json:"net_position"`
	LastUpdated time.Time `json:"last_updated"`
}

LiquidityPosition represents the current cash position of an account or entity.

type Money

type Money struct {
	Amount   *big.Float
	Currency Currency
}

Money represents a monetary value with high precision.

type RiskLevel

type RiskLevel string

RiskLevel represents the calculated risk associated with an entity.

const (
	RiskLevelLow      RiskLevel = "LOW"
	RiskLevelMedium   RiskLevel = "MEDIUM"
	RiskLevelHigh     RiskLevel = "HIGH"
	RiskLevelCritical RiskLevel = "CRITICAL"
)

type SanctionMatch

type SanctionMatch struct {
	ListSource   string  `json:"list_source"`
	EntityName   string  `json:"entity_name"`
	MatchScore   float64 `json:"match_score"` // 0.0 to 1.0
	Reason       string  `json:"reason"`
	SanctionDate string  `json:"sanction_date"`
}

SanctionMatch represents a potential match found in a sanction list.

type SanctionRepository

type SanctionRepository interface {
	// SearchSanctionLists searches for entities matching the name and country.
	SearchSanctionLists(ctx context.Context, name string, countryCode string) ([]SanctionMatch, error)
	// IsHighRiskCountry checks if the country is on a watchlist (e.g., FATF).
	IsHighRiskCountry(ctx context.Context, countryCode string) (bool, error)
}

SanctionRepository defines the data access layer for sanction lists.

type ScheduledTransaction

type ScheduledTransaction struct {
	ID        string
	AccountID string
	Amount    *big.Float
	Direction string // "INFLOW" or "OUTFLOW"
	DueDate   time.Time
	Currency  Currency
}

ScheduledTransaction represents a known future transaction.

type ScreeningRequest

type ScreeningRequest struct {
	ReferenceID string            `json:"reference_id"`
	Name        string            `json:"name"`
	Type        EntityType        `json:"type"`
	CountryCode string            `json:"country_code"` // ISO 3166-1 alpha-2
	TaxID       string            `json:"tax_id,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

ScreeningRequest contains the data required to screen an entity.

type ScreeningResult

type ScreeningResult struct {
	ScreeningID  string          `json:"screening_id"`
	Timestamp    time.Time       `json:"timestamp"`
	RiskLevel    RiskLevel       `json:"risk_level"`
	IsSanctioned bool            `json:"is_sanctioned"`
	Matches      []SanctionMatch `json:"matches"`
	Flags        []string        `json:"flags"`
}

ScreeningResult is the outcome of a compliance check.

type TreasuryRepository

type TreasuryRepository interface {
	GetAccountBalance(ctx context.Context, accountID string) (Money, error)
	GetPendingLiabilities(ctx context.Context, accountID string) (Money, error)
	GetScheduledTransactions(ctx context.Context, accountIDs []string, start, end time.Time) ([]ScheduledTransaction, error)
	GetHistoricalFlows(ctx context.Context, accountIDs []string, start, end time.Time) ([]HistoricalFlow, error)
}

TreasuryRepository defines the data access layer requirements for treasury operations.

type TreasuryService

type TreasuryService interface {
	GetLiquidityPosition(ctx context.Context, accountID string) (*LiquidityPosition, error)
	GetConsolidatedLiquidity(ctx context.Context, entityID string, accountIDs []string) (*LiquidityPosition, error)
	GenerateCashFlowForecast(ctx context.Context, req CashFlowForecastRequest) (*CashFlowForecastResponse, error)
}

TreasuryService defines the interface for corporate treasury operations.

func NewTreasuryService

func NewTreasuryService(repo TreasuryRepository, logger *slog.Logger) TreasuryService

NewTreasuryService creates a new instance of the Treasury Service.

Jump to

Keyboard shortcuts

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