pub struct CommerceClient { /* private fields */ }Expand description
The browser’s commerce client — one purchase in flight at a time (buying is a deliberate act, not a queue), plus an independent entitlements read.
Implementations§
Source§impl CommerceClient
impl CommerceClient
pub fn new(base: impl Into<String>) -> Self
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Read the base URL from INFINITE_COMMERCE_BASE (falls back to the public API).
Sourcepub fn with_token(self, token: Option<String>) -> Self
pub fn with_token(self, token: Option<String>) -> Self
Present a Passport on purchases (Authorization: Bearer <token>).
None/empty → anonymous: browsing works, buying doesn’t.
Sourcepub fn has_token(&self) -> bool
pub fn has_token(&self) -> bool
Whether a Passport is presented — the purchase UI gates its Buy on this.
Sourcepub fn buy(&mut self, offer: Offer) -> bool
pub fn buy(&mut self, offer: Offer) -> bool
Start a purchase on a background thread. Returns false (and does
nothing) without a Passport or while another purchase is settling.
Sourcepub fn poll(&mut self) -> Option<(Offer, Result<Receipt, String>)>
pub fn poll(&mut self) -> Option<(Offer, Result<Receipt, String>)>
Collect a settled purchase, if any. Call once per frame.
Sourcepub fn entitlements(&mut self, project_id: &str)
pub fn entitlements(&mut self, project_id: &str)
Fetch what the traveler holds against a project (background thread). No-op without a Passport or while a previous read is in flight.
Sourcepub fn poll_entitlements(&mut self) -> Option<Result<Entitlement, String>>
pub fn poll_entitlements(&mut self) -> Option<Result<Entitlement, String>>
Collect a finished entitlements read, if any. Call once per frame.