Documentation
¶
Index ¶
- Constants
- func AddInvoiceLineItem(c *gin.Context)
- func AdjustCustomerBalance(c *gin.Context)
- func ApplyInvoiceDiscount(c *gin.Context)
- func BurnCredits(db *datastore.Datastore, userId string, amount int64, meterId string) (int64, error)
- func BurnCreditsPreview(db *datastore.Datastore, userId string, amount int64) (int64, error)
- func CalculateInvoiceTax(c *gin.Context)
- func CancelBillingSubscription(c *gin.Context)
- func CancelPaymentIntent(c *gin.Context)
- func CancelPayout(c *gin.Context)
- func CancelSetupIntent(c *gin.Context)
- func CancelSubscriptionSchedule(c *gin.Context)
- func CapturePaymentIntent(c *gin.Context)
- func CloseDispute(c *gin.Context)
- func ConfirmPaymentIntent(c *gin.Context)
- func ConfirmSetupIntent(c *gin.Context)
- func CreateBankTransferInstruction(c *gin.Context)
- func CreateBillingSubscription(c *gin.Context)
- func CreateCreditGrant(c *gin.Context)
- func CreateCreditNote(c *gin.Context)
- func CreateInvoice(c *gin.Context)
- func CreateMeter(c *gin.Context)
- func CreatePaymentIntent(c *gin.Context)
- func CreatePaymentMethod(c *gin.Context)
- func CreatePayout(c *gin.Context)
- func CreatePricingRule(c *gin.Context)
- func CreateRefund(c *gin.Context)
- func CreateSetupIntent(c *gin.Context)
- func CreateSubscriptionItem(c *gin.Context)
- func CreateSubscriptionSchedule(c *gin.Context)
- func CreateWebhookEndpoint(c *gin.Context)
- func DeletePricingRule(c *gin.Context)
- func DeleteSubscriptionItem(c *gin.Context)
- func DeleteWebhookEndpoint(c *gin.Context)
- func Deposit(c *gin.Context)
- func DetachPaymentMethod(c *gin.Context)
- func FinalizeInvoice(c *gin.Context)
- func GetBalance(c *gin.Context)
- func GetBalanceAll(c *gin.Context)
- func GetBankTransferInstruction(c *gin.Context)
- func GetBillingEvent(c *gin.Context)
- func GetBillingSubscription(c *gin.Context)
- func GetCapabilities(c *gin.Context)
- func GetCreditBalance(c *gin.Context)
- func GetCreditNote(c *gin.Context)
- func GetCustomerBalance(c *gin.Context)
- func GetDispute(c *gin.Context)
- func GetInvoice(c *gin.Context)
- func GetMeter(c *gin.Context)
- func GetMeterEventsSummary(c *gin.Context)
- func GetPaymentIntent(c *gin.Context)
- func GetPaymentMethod(c *gin.Context)
- func GetPayout(c *gin.Context)
- func GetRefund(c *gin.Context)
- func GetSetupIntent(c *gin.Context)
- func GetSubscriptionItem(c *gin.Context)
- func GetSubscriptionSchedule(c *gin.Context)
- func GetUsage(c *gin.Context)
- func GetWebhookEndpoint(c *gin.Context)
- func GrantStarterCredit(c *gin.Context)
- func InvoicePreview(c *gin.Context)
- func ListBalanceTransactions(c *gin.Context)
- func ListBankTransferInstructions(c *gin.Context)
- func ListBillingEvents(c *gin.Context)
- func ListBillingSubscriptions(c *gin.Context)
- func ListCreditGrants(c *gin.Context)
- func ListCreditNotes(c *gin.Context)
- func ListDisputes(c *gin.Context)
- func ListInvoices(c *gin.Context)
- func ListMeters(c *gin.Context)
- func ListPaymentIntents(c *gin.Context)
- func ListPaymentMethods(c *gin.Context)
- func ListPayouts(c *gin.Context)
- func ListPricingRules(c *gin.Context)
- func ListRefunds(c *gin.Context)
- func ListSubscriptionItems(c *gin.Context)
- func ListSubscriptionSchedules(c *gin.Context)
- func ListWebhookEndpoints(c *gin.Context)
- func PayInvoice(c *gin.Context)
- func PortalInvoices(c *gin.Context)
- func PortalOverview(c *gin.Context)
- func PortalPaymentMethods(c *gin.Context)
- func PortalSubscriptions(c *gin.Context)
- func ReactivateBillingSubscription(c *gin.Context)
- func ReconcileInboundTransfer(c *gin.Context)
- func RecordMeterEvents(c *gin.Context)
- func RecordUsage(c *gin.Context)
- func Refund(c *gin.Context)
- func ReleaseSubscriptionSchedule(c *gin.Context)
- func RemoveInvoiceLineItem(c *gin.Context)
- func RenewBillingSubscription(c *gin.Context)
- func Route(r router.Router, args ...gin.HandlerFunc)
- func SetDefaultPaymentMethod(c *gin.Context)
- func SubmitDisputeEvidence(c *gin.Context)
- func UpcomingInvoice(c *gin.Context)
- func UpdateBillingSubscription(c *gin.Context)
- func UpdatePaymentMethod(c *gin.Context)
- func UpdateSubscriptionItem(c *gin.Context)
- func UpdateSubscriptionSchedule(c *gin.Context)
- func UpdateWebhookEndpoint(c *gin.Context)
- func VoidCreditGrant(c *gin.Context)
- func VoidCreditNote(c *gin.Context)
- func VoidInvoice(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 AddInvoiceLineItem ¶ added in v1.34.0
AddInvoiceLineItem appends a line item to a draft invoice and recalculates the subtotal.
POST /api/v1/billing/invoices/:id/line-items
func AdjustCustomerBalance ¶ added in v1.34.0
AdjustCustomerBalance manually adjusts a customer's balance.
POST /api/v1/billing/customer-balance/adjustments
func ApplyInvoiceDiscount ¶ added in v1.34.0
ApplyInvoiceDiscount applies a discount to a draft invoice and recalculates the amount due.
POST /api/v1/billing/invoices/:id/apply-discount
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 BurnCreditsPreview ¶ added in v1.34.0
BurnCreditsPreview calculates credit burn without actually deducting. Returns the remaining amount after credits would be applied.
func CalculateInvoiceTax ¶ added in v1.34.0
CalculateInvoiceTax computes tax for an invoice based on a customer address and updates the invoice with the resulting tax lines.
POST /api/v1/billing/invoices/:id/calculate-tax?country=...&state=...
func CancelBillingSubscription ¶ added in v1.34.0
CancelBillingSubscription cancels a subscription.
POST /api/v1/billing/subscriptions/:id/cancel
func CancelPaymentIntent ¶ added in v1.34.0
CancelPaymentIntent cancels a payment intent.
POST /api/v1/billing/payment-intents/:id/cancel
func CancelPayout ¶ added in v1.34.0
CancelPayout cancels a pending payout.
POST /api/v1/billing/payouts/:id/cancel
func CancelSetupIntent ¶ added in v1.34.0
CancelSetupIntent cancels a setup intent.
POST /api/v1/billing/setup-intents/:id/cancel
func CancelSubscriptionSchedule ¶ added in v1.34.0
CancelSubscriptionSchedule cancels a subscription schedule.
POST /api/v1/billing/subscription-schedules/:id/cancel
func CapturePaymentIntent ¶ added in v1.34.0
CapturePaymentIntent captures a previously authorized payment intent.
POST /api/v1/billing/payment-intents/:id/capture
func CloseDispute ¶ added in v1.34.0
CloseDispute closes a dispute.
POST /api/v1/billing/disputes/:id/close
func ConfirmPaymentIntent ¶ added in v1.34.0
ConfirmPaymentIntent confirms a payment intent.
POST /api/v1/billing/payment-intents/:id/confirm
func ConfirmSetupIntent ¶ added in v1.34.0
ConfirmSetupIntent confirms a setup intent, saving the payment method.
POST /api/v1/billing/setup-intents/:id/confirm
func CreateBankTransferInstruction ¶ added in v1.34.0
CreateBankTransferInstruction creates bank transfer details for a customer.
POST /api/v1/billing/bank-transfer-instructions
func CreateBillingSubscription ¶ added in v1.34.0
CreateBillingSubscription creates a new subscription and starts the billing lifecycle.
POST /api/v1/billing/subscriptions
func CreateCreditGrant ¶
CreateCreditGrant creates a new credit grant for a user.
POST /api/v1/billing/credit-grants
func CreateCreditNote ¶ added in v1.34.0
CreateCreditNote creates a credit note against an invoice.
POST /api/v1/billing/credit-notes
func CreateInvoice ¶ added in v1.34.0
CreateInvoice creates a new draft billing invoice.
POST /api/v1/billing/invoices
func CreatePaymentIntent ¶ added in v1.34.0
CreatePaymentIntent creates a new payment intent.
POST /api/v1/billing/payment-intents
func CreatePaymentMethod ¶ added in v1.34.0
CreatePaymentMethod creates and attaches a payment method to a customer.
POST /api/v1/billing/payment-methods
func CreatePayout ¶ added in v1.34.0
CreatePayout creates a new outbound payout.
POST /api/v1/billing/payouts
func CreatePricingRule ¶
CreatePricingRule creates a new pricing rule for a meter.
POST /api/v1/billing/pricing-rules
func CreateRefund ¶ added in v1.34.0
CreateRefund creates a full or partial refund.
POST /api/v1/billing/refunds
func CreateSetupIntent ¶ added in v1.34.0
CreateSetupIntent creates a new setup intent for saving a payment method.
POST /api/v1/billing/setup-intents
func CreateSubscriptionItem ¶ added in v1.34.0
CreateSubscriptionItem adds an item to a subscription.
POST /api/v1/billing/subscription-items
func CreateSubscriptionSchedule ¶ added in v1.34.0
CreateSubscriptionSchedule creates a new subscription schedule.
POST /api/v1/billing/subscription-schedules
func CreateWebhookEndpoint ¶ added in v1.34.0
CreateWebhookEndpoint registers a new webhook endpoint.
POST /api/v1/billing/webhook-endpoints
func DeletePricingRule ¶
DeletePricingRule removes a pricing rule by ID.
DELETE /api/v1/billing/pricing-rules/:id
func DeleteSubscriptionItem ¶ added in v1.34.0
DeleteSubscriptionItem removes an item from a subscription.
DELETE /api/v1/billing/subscription-items/:id
func DeleteWebhookEndpoint ¶ added in v1.34.0
DeleteWebhookEndpoint removes a webhook endpoint.
DELETE /api/v1/billing/webhook-endpoints/: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 DetachPaymentMethod ¶ added in v1.34.0
DetachPaymentMethod detaches (soft-deletes) a payment method.
DELETE /api/v1/billing/payment-methods/:id
func FinalizeInvoice ¶ added in v1.34.0
FinalizeInvoice transitions an invoice from draft to open.
POST /api/v1/billing/invoices/:id/finalize
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 GetBankTransferInstruction ¶ added in v1.34.0
GetBankTransferInstruction returns a single bank transfer instruction by ID.
GET /api/v1/billing/bank-transfer-instructions/:id
func GetBillingEvent ¶ added in v1.34.0
GetBillingEvent retrieves a single billing event.
GET /api/v1/billing/events/:id
func GetBillingSubscription ¶ added in v1.34.0
GetBillingSubscription returns a single subscription.
GET /api/v1/billing/subscriptions/:id
func GetCapabilities ¶ added in v1.34.0
GetCapabilities returns the billing platform's supported features, payment methods, and currencies.
GET /api/v1/billing/capabilities
func GetCreditBalance ¶
GetCreditBalance returns the total available credit balance for a user.
GET /api/v1/billing/credit-balance?userId=...
func GetCreditNote ¶ added in v1.34.0
GetCreditNote retrieves a credit note by ID.
GET /api/v1/billing/credit-notes/:id
func GetCustomerBalance ¶ added in v1.34.0
GetCustomerBalance retrieves the customer balance for a customer+currency.
GET /api/v1/billing/customer-balance?customerId=...¤cy=...
func GetDispute ¶ added in v1.34.0
GetDispute retrieves a dispute by ID.
GET /api/v1/billing/disputes/:id
func GetInvoice ¶ added in v1.34.0
GetInvoice returns a single billing invoice by ID.
GET /api/v1/billing/invoices/:id
func GetMeterEventsSummary ¶
GetMeterEventsSummary returns aggregated usage for a meter+user+period.
GET /api/v1/billing/meter-events/summary?meterId=...&userId=...&periodStart=...&periodEnd=...
func GetPaymentIntent ¶ added in v1.34.0
GetPaymentIntent retrieves a payment intent by ID.
GET /api/v1/billing/payment-intents/:id
func GetPaymentMethod ¶ added in v1.34.0
GetPaymentMethod retrieves a payment method by ID.
GET /api/v1/billing/payment-methods/:id
func GetPayout ¶ added in v1.34.0
GetPayout retrieves a payout by ID.
GET /api/v1/billing/payouts/:id
func GetRefund ¶ added in v1.34.0
GetRefund retrieves a refund by ID.
GET /api/v1/billing/refunds/:id
func GetSetupIntent ¶ added in v1.34.0
GetSetupIntent retrieves a setup intent by ID.
GET /api/v1/billing/setup-intents/:id
func GetSubscriptionItem ¶ added in v1.34.0
GetSubscriptionItem retrieves a subscription item by ID.
GET /api/v1/billing/subscription-items/:id
func GetSubscriptionSchedule ¶ added in v1.34.0
GetSubscriptionSchedule retrieves a subscription schedule by ID.
GET /api/v1/billing/subscription-schedules/:id
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 GetWebhookEndpoint ¶ added in v1.34.0
GetWebhookEndpoint retrieves a webhook endpoint.
GET /api/v1/billing/webhook-endpoints/:id
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 ListBalanceTransactions ¶ added in v1.34.0
ListBalanceTransactions lists balance transactions for a customer.
GET /api/v1/billing/balance-transactions?customerId=...
func ListBankTransferInstructions ¶ added in v1.34.0
ListBankTransferInstructions lists bank transfer instructions, optionally filtered by customerId.
GET /api/v1/billing/bank-transfer-instructions?customerId=...
func ListBillingEvents ¶ added in v1.34.0
ListBillingEvents lists billing events, optionally filtered by type or objectId.
GET /api/v1/billing/events?type=...&objectId=...
func ListBillingSubscriptions ¶ added in v1.34.0
ListBillingSubscriptions lists subscriptions for a user.
GET /api/v1/billing/subscriptions?userId=...
func ListCreditGrants ¶
ListCreditGrants lists credit grants for a user.
GET /api/v1/billing/credit-grants?userId=...
func ListCreditNotes ¶ added in v1.34.0
ListCreditNotes lists credit notes, optionally filtered by invoiceId or customerId.
GET /api/v1/billing/credit-notes?invoiceId=...&customerId=...
func ListDisputes ¶ added in v1.34.0
ListDisputes lists disputes.
GET /api/v1/billing/disputes?paymentIntentId=...
func ListInvoices ¶ added in v1.34.0
ListInvoices lists billing invoices, optionally filtered by userId and status.
GET /api/v1/billing/invoices?userId=...&status=...
func ListPaymentIntents ¶ added in v1.34.0
ListPaymentIntents lists payment intents, optionally filtered by customerId.
GET /api/v1/billing/payment-intents?customerId=...
func ListPaymentMethods ¶ added in v1.34.0
ListPaymentMethods lists payment methods for a customer.
GET /api/v1/billing/payment-methods?customerId=...&type=...
func ListPricingRules ¶
ListPricingRules lists pricing rules, optionally filtered by meter or plan.
GET /api/v1/billing/pricing-rules?meterId=...&planId=...
func ListRefunds ¶ added in v1.34.0
ListRefunds lists refunds, optionally filtered by paymentIntentId or invoiceId.
GET /api/v1/billing/refunds?paymentIntentId=...&invoiceId=...
func ListSubscriptionItems ¶ added in v1.34.0
ListSubscriptionItems lists items for a subscription.
GET /api/v1/billing/subscription-items?subscriptionId=...
func ListSubscriptionSchedules ¶ added in v1.34.0
ListSubscriptionSchedules lists subscription schedules.
GET /api/v1/billing/subscription-schedules?customerId=...&status=...
func ListWebhookEndpoints ¶ added in v1.34.0
ListWebhookEndpoints lists all webhook endpoints.
GET /api/v1/billing/webhook-endpoints
func PayInvoice ¶ added in v1.34.0
PayInvoice attempts to collect payment on an open invoice.
POST /api/v1/billing/invoices/:id/pay
func PortalInvoices ¶ added in v1.34.0
PortalInvoices returns the customer's invoice list.
GET /api/v1/billing/portal/invoices?customerId=...
func PortalOverview ¶ added in v1.34.0
PortalOverview returns a billing summary for the authenticated customer.
GET /api/v1/billing/portal/overview?customerId=...
func PortalPaymentMethods ¶ added in v1.34.0
PortalPaymentMethods returns the customer's payment methods.
GET /api/v1/billing/portal/payment-methods?customerId=...
func PortalSubscriptions ¶ added in v1.34.0
PortalSubscriptions returns the customer's subscriptions.
GET /api/v1/billing/portal/subscriptions?customerId=...
func ReactivateBillingSubscription ¶ added in v1.34.0
ReactivateBillingSubscription reactivates a canceled subscription.
POST /api/v1/billing/subscriptions/:id/reactivate
func ReconcileInboundTransfer ¶ added in v1.34.0
ReconcileInboundTransfer matches an incoming bank transfer by reference and creates a balance transaction for the customer.
POST /api/v1/billing/bank-transfer-instructions/reconciliation/match
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 ReleaseSubscriptionSchedule ¶ added in v1.34.0
ReleaseSubscriptionSchedule releases a subscription schedule.
POST /api/v1/billing/subscription-schedules/:id/release
func RemoveInvoiceLineItem ¶ added in v1.34.0
RemoveInvoiceLineItem removes a line item from a draft invoice by index or line item ID.
DELETE /api/v1/billing/invoices/:id/line-items/:itemId
func RenewBillingSubscription ¶ added in v1.34.0
RenewBillingSubscription manually triggers a billing cycle renewal. Normally this would be automated by Temporal, but this endpoint allows manual triggering for testing and for deployments without Temporal.
POST /api/v1/billing/subscriptions/:id/renew
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 SetDefaultPaymentMethod ¶ added in v1.34.0
SetDefaultPaymentMethod sets the default payment method for a customer.
POST /api/v1/billing/customers/:id/default-payment-method
func SubmitDisputeEvidence ¶ added in v1.34.0
SubmitDisputeEvidence submits evidence for a dispute.
PATCH /api/v1/billing/disputes/:id
func UpcomingInvoice ¶ added in v1.34.0
UpcomingInvoice generates a preview of the next invoice for a subscription.
GET /api/v1/billing/invoices/upcoming?userId=...&subscriptionId=...
func UpdateBillingSubscription ¶ added in v1.34.0
UpdateBillingSubscription updates a subscription (plan change, quantity).
PATCH /api/v1/billing/subscriptions/:id
func UpdatePaymentMethod ¶ added in v1.34.0
UpdatePaymentMethod updates a payment method.
PATCH /api/v1/billing/payment-methods/:id
func UpdateSubscriptionItem ¶ added in v1.34.0
UpdateSubscriptionItem updates a subscription item (e.g. seat count).
PATCH /api/v1/billing/subscription-items/:id
func UpdateSubscriptionSchedule ¶ added in v1.34.0
UpdateSubscriptionSchedule updates phases or end behavior.
PATCH /api/v1/billing/subscription-schedules/:id
func UpdateWebhookEndpoint ¶ added in v1.34.0
UpdateWebhookEndpoint updates a webhook endpoint configuration.
PATCH /api/v1/billing/webhook-endpoints/:id
func VoidCreditGrant ¶
VoidCreditGrant voids a specific credit grant, making it unusable.
POST /api/v1/billing/credit-grants/:id/void
func VoidCreditNote ¶ added in v1.34.0
VoidCreditNote voids a credit note.
POST /api/v1/billing/credit-notes/:id/void
func VoidInvoice ¶ added in v1.34.0
VoidInvoice voids a draft or open invoice.
POST /api/v1/billing/invoices/:id/void
func ZapDispatch ¶
ZapDispatch is the single ZAP-over-HTTP endpoint for billing.
Types ¶
This section is empty.
Source Files
¶
- balance.go
- bank_transfers.go
- capabilities.go
- credit_grants.go
- credit_notes.go
- customer_balance.go
- deposit.go
- disputes.go
- events.go
- handlers.go
- invoice_enhancements.go
- invoice_preview.go
- invoices.go
- meter_events.go
- meters.go
- payment_intents.go
- payment_methods.go
- payouts.go
- portal.go
- pricing_rules.go
- refund.go
- refunds.go
- setup_intents.go
- subscription_items.go
- subscription_schedules.go
- subscriptions.go
- usage.go
- zap.go