Skip to main content

BillingApi

Struct BillingApi 

Source
pub struct BillingApi { /* private fields */ }
Expand description

Usage tracking, quota management, and Stripe webhooks

Implementations§

Source§

impl BillingApi

Source

pub async fn check_quota(&self) -> Result<Value>

Check tenant quota status

GET /api/v1/usage/quota

Required scopes: billing:read.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_usage(&self, params: &GetUsageParams) -> Result<UsageSummary>

Get current tenant usage

GET /api/v1/usage

Required scopes: billing:read.

Source

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.

Source

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

Source

pub async fn list_billing_plans(&self) -> Result<ListBillingPlansResponse>

List available billing plans

GET /api/v1/billing/plans

Required scopes: billing:read.

Source

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 returnedcheckout_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

Source§

fn clone(&self) -> BillingApi

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BillingApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more