Documentation
¶
Index ¶
- Constants
- func BurnCredits(db *datastore.Datastore, userId string, amount int64, meterId string) (int64, error)
- func CreateCreditGrant(c *gin.Context)
- func CreateMeter(c *gin.Context)
- func CreatePricingRule(c *gin.Context)
- func DeletePricingRule(c *gin.Context)
- func Deposit(c *gin.Context)
- func GetBalance(c *gin.Context)
- func GetBalanceAll(c *gin.Context)
- func GetCreditBalance(c *gin.Context)
- func GetMeter(c *gin.Context)
- func GetMeterEventsSummary(c *gin.Context)
- func GetUsage(c *gin.Context)
- func GrantStarterCredit(c *gin.Context)
- func InvoicePreview(c *gin.Context)
- func ListCreditGrants(c *gin.Context)
- func ListMeters(c *gin.Context)
- func ListPricingRules(c *gin.Context)
- func RecordMeterEvents(c *gin.Context)
- func RecordUsage(c *gin.Context)
- func Refund(c *gin.Context)
- func Route(r router.Router, args ...gin.HandlerFunc)
- func VoidCreditGrant(c *gin.Context)
- func ZapDispatch(c *gin.Context)
Constants ¶
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 ¶
CreateCreditGrant creates a new credit grant for a user.
POST /api/v1/billing/credit-grants
func CreatePricingRule ¶
CreatePricingRule creates a new pricing rule for a meter.
POST /api/v1/billing/pricing-rules
func DeletePricingRule ¶
DeletePricingRule removes a pricing rule by ID.
DELETE /api/v1/billing/pricing-rules/:id
func Deposit ¶
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 ¶
GetBalance returns the current balance for an IAM user.
GET /api/v1/billing/balance?user=hanzo/alice¤cy=usd
All amounts in cents. available = balance - holds.
func GetBalanceAll ¶
GetBalanceAll returns balances across all currencies for an IAM user.
GET /api/v1/billing/balance/all?user=hanzo/alice
func GetCreditBalance ¶
GetCreditBalance returns the total available credit balance for a user.
GET /api/v1/billing/credit-balance?userId=...
func GetMeterEventsSummary ¶
GetMeterEventsSummary returns aggregated usage for a meter+user+period.
GET /api/v1/billing/meter-events/summary?meterId=...&userId=...&periodStart=...&periodEnd=...
func GetUsage ¶
GetUsage returns usage transactions for an IAM user, filtered by tag "api-usage".
GET /api/v1/billing/usage?user=hanzo/alice¤cy=usd
func GrantStarterCredit ¶
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 ¶
InvoicePreview calculates an invoice preview: usage x pricing - credits.
POST /api/v1/billing/invoice-preview
func ListCreditGrants ¶
ListCreditGrants lists credit grants for a user.
GET /api/v1/billing/credit-grants?userId=...
func ListPricingRules ¶
ListPricingRules lists pricing rules, optionally filtered by meter or plan.
GET /api/v1/billing/pricing-rules?meterId=...&planId=...
func RecordMeterEvents ¶
RecordMeterEvents records one or more meter events (batch up to 100).
POST /api/v1/billing/meter-events
func RecordUsage ¶
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 ¶
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 ¶
VoidCreditGrant voids a specific credit grant, making it unusable.
POST /api/v1/billing/credit-grants/:id/void
func ZapDispatch ¶
ZapDispatch is the single ZAP-over-HTTP endpoint for billing.
Types ¶
This section is empty.