Versions in this module Expand all Collapse all v0 v0.1.1 Oct 25, 2026 v0.1.0 Oct 12, 2026 Changes in this version + const KindAdjustment + const KindChargeback + const KindExpiry + const KindForfeit + const KindRefund + const KindTopUp + const KindUsage + const MaxChargeCents + const MaxHistoryPage + var ErrAmount = errors.New("credits: the purchase amount is outside the allowed range") + var ErrConflict = errors.New("credits: the reference was already used differently") + var ErrInsufficient = errors.New("credits: insufficient credit") + var ErrInvalid = errors.New("credits: invalid amount, reference or description") + var ErrNotFound = errors.New("credits: account not found") + var ErrPurchasesOff = errors.New("credits: buying credit is not available") + var Migrations = app.Migrations + func FormatEuros(cents int64) string + func Label(e Entry) string + func ParseEuros(s string) (int64, bool) + type Config struct + Holds func(ctx context.Context, tx *sql.Tx, accountID string) (int64, error) + Payments payments.Provider + Policy Policy + type Credits struct + func New(a *app.App, accts *accounts.Accounts, cfg Config) (*Credits, error) + func (cr *Credits) Adjust(ctx context.Context, accountID string, cents int64, ...) error + func (cr *Credits) Debit(ctx context.Context, accountID string, cents int64, ...) error + func (cr *Credits) History(ctx context.Context, accountID string, page, perPage int) ([]Entry, bool, error) + func (cr *Credits) Mount(r gin.IRouter, layout ui.Layout) + func (cr *Credits) PaymentStatus(ctx context.Context, accountID, intentID string) (string, error) + func (cr *Credits) Purchase(ctx context.Context, account accounts.Account, creditCents int64, ...) (Purchase, error) + func (cr *Credits) Purchasing() bool + func (cr *Credits) Quote(creditCents int64) (Quote, error) + func (cr *Credits) Summary(ctx context.Context, accountID string) (Summary, error) + func (cr *Credits) Webhook(c *gin.Context) + func (cr *Credits) WithAccount(ctx context.Context, accountID string, fn func(tx *Tx) error) error + type Entry struct + AmountCents int64 + CreatedAt time.Time + Description string + ID string + Kind string + Reference string + type Policy struct + FeeBasisPoints int64 + FeeFixedCents int64 + MaxPurchaseCents int64 + MinPurchaseCents int64 + func (p Policy) Fee(creditCents int64) int64 + type Purchase struct + CheckoutURL string + IntentID string + type Quote struct + ChargeCents int64 + CreditCents int64 + FeeCents int64 + type Summary struct + AvailableCents int64 + BalanceCents int64 + HeldCents int64 + type Tx struct + func (t *Tx) Available() (int64, error) + func (t *Tx) Balance() (int64, error) + func (t *Tx) Capture(cents int64, reference, description string) error + func (t *Tx) Debit(cents int64, reference, description string) error + func (t *Tx) Expire(cents int64) error + func (t *Tx) SQL() *sql.Tx