Skip to main content

Carts

Struct Carts 

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

Cart and Checkout operations

Implementations§

Source§

impl Carts

Source

pub fn create(&self, input: CreateCart) -> Result<Cart>

Create a new cart/checkout session

§Example
use stateset_embedded::{Commerce, CreateCart, AddCartItem, CurrencyCode};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

// Guest checkout
let cart = commerce.carts().create(CreateCart {
    customer_email: Some("guest@example.com".into()),
    items: Some(vec![AddCartItem {
        sku: "SKU-001".into(),
        name: "Widget".into(),
        quantity: 1,
        unit_price: dec!(19.99),
        ..Default::default()
    }]),
    ..Default::default()
})?;

// Authenticated customer checkout
let cart = commerce.carts().create(CreateCart {
    customer_id: Some(Uuid::new_v4().into()),
    currency: Some(CurrencyCode::USD),
    expires_in_minutes: Some(60),
    ..Default::default()
})?;
Source

pub fn get(&self, id: CartId) -> Result<Option<Cart>>

Get a cart by ID

Source

pub fn get_by_number(&self, cart_number: &str) -> Result<Option<Cart>>

Get a cart by cart number (e.g., “CART-1234567890-0001”)

Source

pub fn update(&self, id: CartId, input: UpdateCart) -> Result<Cart>

Update a cart

Source

pub fn list(&self, filter: CartFilter) -> Result<Vec<Cart>>

List carts with optional filtering

Source

pub fn for_customer(&self, customer_id: CustomerId) -> Result<Vec<Cart>>

Get all carts for a customer

Source

pub fn delete(&self, id: CartId) -> Result<()>

Delete a cart

Source

pub fn add_item(&self, cart_id: CartId, item: AddCartItem) -> Result<CartItem>

Add an item to the cart

§Example
use stateset_embedded::{Commerce, AddCartItem, ProductId};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

commerce.carts().add_item(Uuid::new_v4().into(), AddCartItem {
    product_id: Some(ProductId::new()),
    sku: "SKU-001".into(),
    name: "Premium Widget".into(),
    description: Some("A high-quality widget".into()),
    image_url: Some("https://example.com/widget.jpg".into()),
    quantity: 2,
    unit_price: dec!(49.99),
    original_price: Some(dec!(59.99)),
    ..Default::default()
})?;
Source

pub fn update_item( &self, item_id: Uuid, input: UpdateCartItem, ) -> Result<CartItem>

Update a cart item (quantity, etc.)

Source

pub fn remove_item(&self, item_id: Uuid) -> Result<()>

Remove an item from the cart

Source

pub fn get_items(&self, cart_id: CartId) -> Result<Vec<CartItem>>

Get all items in the cart

Source

pub fn clear_items(&self, cart_id: CartId) -> Result<()>

Clear all items from the cart

Source

pub fn set_shipping_address( &self, id: CartId, address: CartAddress, ) -> Result<Cart>

Set the shipping address

§Example
use stateset_embedded::{Commerce, CartAddress};
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

let cart = commerce.carts().set_shipping_address(Uuid::new_v4().into(), CartAddress {
    first_name: "Alice".into(),
    last_name: "Smith".into(),
    company: Some("Acme Corp".into()),
    line1: "123 Main St".into(),
    line2: Some("Suite 100".into()),
    city: "Anytown".into(),
    state: Some("CA".into()),
    postal_code: "12345".into(),
    country: "US".into(),
    phone: Some("555-1234".into()),
    email: Some("alice@example.com".into()),
})?;
Source

pub fn set_billing_address( &self, id: CartId, address: CartAddress, ) -> Result<Cart>

Set the billing address

Source

pub fn set_shipping( &self, id: CartId, shipping: SetCartShipping, ) -> Result<Cart>

Set shipping method and address

Source

pub fn get_shipping_rates(&self, id: CartId) -> Result<Vec<ShippingRate>>

Get available shipping rates for the cart

Returns available shipping options based on cart contents and shipping address.

Source

pub fn set_payment(&self, id: CartId, payment: SetCartPayment) -> Result<Cart>

Set payment method and token

§Example
use stateset_embedded::{Commerce, SetCartPayment};
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

let cart = commerce.carts().set_payment(Uuid::new_v4().into(), SetCartPayment {
    payment_method: "credit_card".into(),
    payment_token: Some("tok_visa".into()),
    ..Default::default()
})?;
Source

pub fn apply_discount(&self, id: CartId, coupon_code: &str) -> Result<Cart>

Apply a coupon/discount code to the cart

Source

pub fn remove_discount(&self, id: CartId) -> Result<Cart>

Remove the discount from the cart

Source

pub fn mark_ready_for_payment(&self, id: CartId) -> Result<Cart>

Mark the cart as ready for payment

This validates that all required information is present (shipping address, etc.)

Source

pub fn begin_checkout(&self, id: CartId) -> Result<Cart>

Begin the checkout process (payment pending)

Source

pub fn complete(&self, id: CartId) -> Result<CheckoutResult>

Complete the checkout and create an order.

The minted order is Confirmed with payment left Pending — record the payment through Payments, or use complete_settled_externally when settlement genuinely happened outside the engine.

§Example
use stateset_embedded::Commerce;
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

let result = commerce.carts().complete(Uuid::new_v4().into())?;
println!("Order ID: {}", result.order_id);
println!("Order Number: {}", result.order_number);
println!("Total Charged: {} {}", result.total_charged, result.currency);
Source

pub fn complete_settled_externally(&self, id: CartId) -> Result<CheckoutResult>

Complete the checkout for a cart settled outside the engine (ACP, external PSP): the minted order is Confirmed + Paid with no engine-side payment record. This is an explicit opt-in — prefer complete plus a payment record when the engine processes the payment.

Source

pub fn cancel(&self, id: CartId) -> Result<Cart>

Cancel the cart

Source

pub fn abandon(&self, id: CartId) -> Result<Cart>

Mark the cart as abandoned

Source

pub fn expire(&self, id: CartId) -> Result<Cart>

Expire the cart

Source

pub fn reserve_inventory(&self, id: CartId) -> Result<Cart>

Reserve inventory for cart items

Creates inventory reservations for all items in the cart. Reservations typically expire after 15 minutes.

Source

pub fn release_inventory(&self, id: CartId) -> Result<Cart>

Release inventory reservations for the cart

Source

pub fn recalculate(&self, id: CartId) -> Result<Cart>

Recalculate cart totals

Source

pub fn set_tax(&self, id: CartId, tax_amount: Decimal) -> Result<Cart>

Set the tax amount for the cart

Source

pub fn get_abandoned(&self) -> Result<Vec<Cart>>

Get abandoned carts (for recovery campaigns)

Source

pub fn get_expired(&self) -> Result<Vec<Cart>>

Get expired carts

Source

pub fn count(&self, filter: CartFilter) -> Result<u64>

Count carts matching a filter

Trait Implementations§

Source§

impl Debug for Carts

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Carts

§

impl !UnwindSafe for Carts

§

impl Freeze for Carts

§

impl Send for Carts

§

impl Sync for Carts

§

impl Unpin for Carts

§

impl UnsafeUnpin for Carts

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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