pub struct BillingApi { /* private fields */ }Expand description
Usage tracking, quota management, and Stripe webhooks
Implementations§
Source§impl BillingApi
impl BillingApi
Sourcepub async fn check_quota(&self) -> Result<Value>
pub async fn check_quota(&self) -> Result<Value>
Check tenant quota status
GET /api/v1/usage/quota
Required scopes: billing:read.
Sourcepub async fn create_billing_portal_session(
&self,
body: &CreateBillingPortalSessionRequest,
) -> Result<CreateBillingPortalSessionResponse>
pub async fn create_billing_portal_session( &self, body: &CreateBillingPortalSessionRequest, ) -> Result<CreateBillingPortalSessionResponse>
Create a Stripe Customer Portal session URL
Returns a Stripe-hosted URL where the customer can manage subscriptions and payment methods.
return_url must be same-origin as the request; defaults to \<origin\>/admin/billing.
POST /api/v1/billing/portal-session
Required scopes: billing:write.
Sourcepub async fn create_checkout_session(
&self,
body: &CreateCheckoutSessionRequest,
) -> Result<CreateCheckoutSessionResponse>
pub async fn create_checkout_session( &self, body: &CreateCheckoutSessionRequest, ) -> Result<CreateCheckoutSessionResponse>
Create Stripe checkout session
POST /api/v1/billing/checkout-session
Required scopes: billing:read.
Sourcepub async fn create_spec_package_checkout_session(
&self,
package_id: &str,
body: &CreateSpecPackageCheckoutSessionRequest,
) -> Result<CreateSpecPackageCheckoutSessionResponse>
pub async fn create_spec_package_checkout_session( &self, package_id: &str, body: &CreateSpecPackageCheckoutSessionRequest, ) -> Result<CreateSpecPackageCheckoutSessionResponse>
Start Stripe checkout for a SPEC package
Answers a Stripe-hosted URL to redirect to.
success_url and cancel_url must be SAME-ORIGIN with the request; anything else is
refused. Both default to the billing settings page, so a caller that has no opinion should
omit them rather than construct one.
Three refusals worth telling apart. 501 — billing is not configured on this deployment. Not 502, deliberately: no upstream was contacted, and a 502 sends an operator hunting an outage when the fix is one admin setting. 400 — the package exists but has no Stripe price wired, and the message names the admin screen that creates one. 404 — no such package, or it is archived.
POST /api/v1/billing/spec-packages/{packageId}/checkout-session
Required scopes: billing:read.
Sourcepub async fn get_billing_trial(&self) -> Result<GetBillingTrialResponse>
pub async fn get_billing_trial(&self) -> Result<GetBillingTrialResponse>
Trial window and a live usage-based plan recommendation
GET /api/v1/billing/trial
Required scopes: billing:read.
Sourcepub async fn get_media_usage(&self) -> Result<GetMediaUsageResponse>
pub async fn get_media_usage(&self) -> Result<GetMediaUsageResponse>
Image and video generation usage against plan quotas
GET /api/v1/usage/media
Required scopes: billing:read.
Sourcepub async fn get_usage(&self, params: &GetUsageParams) -> Result<UsageSummary>
pub async fn get_usage(&self, params: &GetUsageParams) -> Result<UsageSummary>
Get current tenant usage
GET /api/v1/usage
Required scopes: billing:read.
Sourcepub async fn get_usage_timeseries(
&self,
params: &GetUsageTimeseriesParams,
) -> Result<GetUsageTimeseriesResponse>
pub async fn get_usage_timeseries( &self, params: &GetUsageTimeseriesParams, ) -> Result<GetUsageTimeseriesResponse>
Get usage analytics over time
GET /api/v1/usage/timeseries
Required scopes: billing:read.
Sourcepub async fn handle_stripe_webhook(
&self,
body: &HandleStripeWebhookRequest,
params: &HandleStripeWebhookParams,
) -> Result<HandleStripeWebhookResponse>
pub async fn handle_stripe_webhook( &self, body: &HandleStripeWebhookRequest, params: &HandleStripeWebhookParams, ) -> Result<HandleStripeWebhookResponse>
Handle Stripe webhook events
Processes incoming Stripe events (invoice.paid, invoice.payment_failed,
customer.subscription.deleted). Bypasses normal auth — Stripe-Signature header is
HMAC-verified against the webhook signing secret.
POST /api/v1/webhooks/stripe
Sourcepub async fn list_billing_plans(&self) -> Result<ListBillingPlansResponse>
pub async fn list_billing_plans(&self) -> Result<ListBillingPlansResponse>
List available billing plans
GET /api/v1/billing/plans
Required scopes: billing:read.
Sourcepub async fn list_billing_spec_packages(
&self,
) -> Result<ListBillingSpecPackagesResponse>
pub async fn list_billing_spec_packages( &self, ) -> Result<ListBillingSpecPackagesResponse>
SPEC packages this tenant can see, with entitlement
The tenant-facing view, and deliberately narrower than the admin one: archived packages are
omitted and the Stripe price id is never returned — checkout_available is the boolean
derived from whether one is wired.
entitlement is a three-way discriminator a client should branch on rather than infer:
plan_included (comes with the tenant’s plan tier), purchased (bought a la carte),
available (not entitled, and buyable). It carries the same values as
/api/v1/billing/packages so one card component serves both.
program is the nav entry and pages a package contributes, and is ABSENT for agent-only
packages with no UI — which is what lets a client build the entitlement-gated navigation
from this single call.
Sorted by display_order, then by name.
GET /api/v1/billing/spec-packages
Required scopes: billing:read.
Trait Implementations§
Source§impl Clone for BillingApi
impl Clone for BillingApi
Source§fn clone(&self) -> BillingApi
fn clone(&self) -> BillingApi
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more