payments

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const EvidenceTimestampTolerance = 2 * time.Second

Variables

This section is empty.

Functions

func CreateResponse

func CreateResponse(payment *domain.Payment, cfg config.Config) map[string]any

func FromRecord

func FromRecord(record *core.Record) *domain.Payment

func PublicPayment

func PublicPayment(payment *domain.Payment) map[string]any

Types

type CapacityPool

type CapacityPool struct {
	RequestedAmountPaise int64   `json:"requestedAmountPaise"`
	RequestedAmount      string  `json:"requestedAmount"`
	Pending              int64   `json:"pending"`
	Quarantined          int64   `json:"quarantined"`
	Blocked              int64   `json:"blocked"`
	Available            int64   `json:"available"`
	UtilizationPercent   float64 `json:"utilizationPercent"`
	Level                string  `json:"level"`
}

type CapacitySnapshot

type CapacitySnapshot struct {
	Pools         []CapacityPool `json:"pools"`
	WarningPools  int            `json:"warningPools"`
	CriticalPools int            `json:"criticalPools"`
}

type CreateInput

type CreateInput struct {
	AmountRupees   int64
	ExternalID     string
	Metadata       any
	IdempotencyKey string
}

type MatchResult

type MatchResult struct {
	Payment *domain.Payment
	Action  string
}

type Service

type Service struct {
	App      core.App
	Config   config.Config
	Webhooks WebhookScheduler
	Now      func() time.Time

	// SuffixStart is injectable for deterministic tests. Production uses crypto/rand.
	SuffixStart func() (int64, error)
}

func NewService

func NewService(app core.App, cfg config.Config, webhooks WebhookScheduler) *Service

func (*Service) Cancel

func (s *Service) Cancel(id string) (*domain.Payment, error)

func (*Service) Capacity

func (s *Service) Capacity() (CapacitySnapshot, error)

func (*Service) Create

func (s *Service) Create(input CreateInput) (*domain.Payment, bool, error)

func (*Service) ExpireDue

func (s *Service) ExpireDue() (int, error)

func (*Service) ExpireDueInApp

func (s *Service) ExpireDueInApp(tx core.App, now time.Time) (int, error)

ExpireDueInApp changes only currently pending records whose persisted expiry timestamp is due. Existing reuse_after is retained because it was fixed at creation as expires_at + quarantine.

func (*Service) Get

func (s *Service) Get(id string) (*domain.Payment, error)

func (*Service) ManualMatchInApp

func (s *Service) ManualMatchInApp(tx core.App, paymentID string, parsed domain.ParsedSMS, now time.Time) (*core.Record, string, bool, error)

ManualMatchInApp explicitly links reviewed bank evidence to one payment. It still enforces exact amount equality and global RRN uniqueness; the operator chooses the payment, but cannot override those monetary invariants.

func (*Service) Match

func (s *Service) Match(parsed domain.ParsedSMS) (*MatchResult, error)

func (*Service) MatchInApp

func (s *Service) MatchInApp(tx core.App, parsed domain.ParsedSMS, now time.Time) (*core.Record, string, bool, error)

MatchInApp applies exact-amount matching inside the caller's transaction. It returns whether outgoing webhook work was queued so the caller can wake the delivery loop only after the transaction commits.

func (*Service) Stats

func (s *Service) Stats() (map[string]int64, error)

func (*Service) WakeWebhooks

func (s *Service) WakeWebhooks()

type WebhookScheduler

type WebhookScheduler interface {
	Schedule(app core.App, event string, payment *core.Record, at time.Time) error
	Wake()
}

Jump to

Keyboard shortcuts

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