Documentation
¶
Overview ¶
Package credit provides reusable starter credit logic. Shared between api/billing handlers and middleware/iammiddleware.
Index ¶
Constants ¶
const ( StarterCreditCents = 10000 // $100.00 USD StarterCreditDays = 365 // expires in 365 days StarterCreditTag = "starter-credit" )
Starter credit constants.
Variables ¶
This section is empty.
Functions ¶
func GrantIfEligible ¶
GrantIfEligible checks if the user already has a starter credit and grants one if not. It is idempotent: duplicate calls for the same user are safe. The trigger parameter records what initiated the grant (e.g. "payment-method-added", "org-created").
This function is intended to be called from a goroutine; it only logs on failure and never panics. For the synchronous form that reports whether a grant was created, use GrantIfEligibleNow.
func GrantIfEligibleNow ¶ added in v1.42.38
GrantIfEligibleNow is the synchronous form of GrantIfEligible. It ensures the subject (userId — an IAM "owner/name" per-user key, or an org slug for pooled billing) has received exactly one starter-credit Deposit, and reports whether THIS call created it (false = one already existed).
Idempotent + race-safe: the check-and-create runs inside a datastore transaction so concurrent callers can never double-grant (no bleed). The dedupe key is (DestinationId=userId, Tags=StarterCreditTag).
The grant is a real Deposit transaction (tag "starter-credit", $5, 30-day expiry) — so it nets into GET /v1/billing/balance, which is the account the cloud gateway's balance gate reads and its usage debit withdraws from. (It is deliberately NOT a credit-grant record; those live in a separate ledger the balance endpoint does not read.)
Types ¶
This section is empty.