billing

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StarterCreditCents = 500 // $5.00 USD
	StarterCreditDays  = 30  // expires in 30 days
	StarterCreditTag   = "starter-credit"
)

Starter credit constants.

Variables

This section is empty.

Functions

func BurnCredits

func BurnCredits(db *datastore.Datastore, userId string, amount int64, meterId string) (int64, error)

BurnCredits applies the credit burn-down algorithm: deducts amount from active grants in priority order. Returns the remaining amount (overage) and the grants that were modified.

func CreateCreditGrant

func CreateCreditGrant(c *gin.Context)

CreateCreditGrant creates a new credit grant for a user.

POST /api/v1/billing/credit-grants

func CreateMeter

func CreateMeter(c *gin.Context)

CreateMeter creates a new usage meter definition.

POST /api/v1/billing/meters

func CreatePricingRule

func CreatePricingRule(c *gin.Context)

CreatePricingRule creates a new pricing rule for a meter.

POST /api/v1/billing/pricing-rules

func DeletePricingRule

func DeletePricingRule(c *gin.Context)

DeletePricingRule removes a pricing rule by ID.

DELETE /api/v1/billing/pricing-rules/:id

func Deposit

func Deposit(c *gin.Context)

Deposit creates a deposit (credit) transaction for an IAM user.

POST /api/v1/billing/deposit

Used by internal services to add funds to a user's account (payment processor settlement, manual credit, promotional grants, etc.).

func GetBalance

func GetBalance(c *gin.Context)

GetBalance returns the current balance for an IAM user.

GET /api/v1/billing/balance?user=hanzo/alice&currency=usd

All amounts in cents. available = balance - holds.

func GetBalanceAll

func GetBalanceAll(c *gin.Context)

GetBalanceAll returns balances across all currencies for an IAM user.

GET /api/v1/billing/balance/all?user=hanzo/alice

func GetCreditBalance

func GetCreditBalance(c *gin.Context)

GetCreditBalance returns the total available credit balance for a user.

GET /api/v1/billing/credit-balance?userId=...

func GetMeter

func GetMeter(c *gin.Context)

GetMeter returns a single meter by ID.

GET /api/v1/billing/meters/:id

func GetMeterEventsSummary

func GetMeterEventsSummary(c *gin.Context)

GetMeterEventsSummary returns aggregated usage for a meter+user+period.

GET /api/v1/billing/meter-events/summary?meterId=...&userId=...&periodStart=...&periodEnd=...

func GetUsage

func GetUsage(c *gin.Context)

GetUsage returns usage transactions for an IAM user, filtered by tag "api-usage".

GET /api/v1/billing/usage?user=hanzo/alice&currency=usd

func GrantStarterCredit

func GrantStarterCredit(c *gin.Context)

GrantStarterCredit creates a $5 USD starter credit for a new user. The credit expires after 30 days if unused. Tagged "starter-credit" so it can be identified in transaction history.

POST /api/v1/billing/credit

func InvoicePreview

func InvoicePreview(c *gin.Context)

InvoicePreview calculates an invoice preview: usage x pricing - credits.

POST /api/v1/billing/invoice-preview

func ListCreditGrants

func ListCreditGrants(c *gin.Context)

ListCreditGrants lists credit grants for a user.

GET /api/v1/billing/credit-grants?userId=...

func ListMeters

func ListMeters(c *gin.Context)

ListMeters returns all meters for the organization.

GET /api/v1/billing/meters

func ListPricingRules

func ListPricingRules(c *gin.Context)

ListPricingRules lists pricing rules, optionally filtered by meter or plan.

GET /api/v1/billing/pricing-rules?meterId=...&planId=...

func RecordMeterEvents

func RecordMeterEvents(c *gin.Context)

RecordMeterEvents records one or more meter events (batch up to 100).

POST /api/v1/billing/meter-events

func RecordUsage

func RecordUsage(c *gin.Context)

RecordUsage records an API usage event as a Withdraw transaction.

POST /api/v1/billing/usage

Creates a withdraw transaction deducting the cost from the user's balance.

func Refund

func Refund(c *gin.Context)

Refund creates a deposit tagged "refund" to correct an overcharge. The metadata links back to the original transaction for auditability.

POST /api/v1/billing/refund

func Route

func Route(r router.Router, args ...gin.HandlerFunc)

Route registers billing endpoints for service-to-service calls. These are internal endpoints used by Cloud-API; require admin token.

func VoidCreditGrant

func VoidCreditGrant(c *gin.Context)

VoidCreditGrant voids a specific credit grant, making it unusable.

POST /api/v1/billing/credit-grants/:id/void

func ZapDispatch

func ZapDispatch(c *gin.Context)

ZapDispatch is the single ZAP-over-HTTP endpoint for billing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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