pub struct Carts { /* private fields */ }Expand description
Cart and Checkout operations
Implementations§
Source§impl Carts
impl Carts
Sourcepub fn create(&self, input: CreateCart) -> Result<Cart>
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()
})?;Sourcepub fn get_by_number(&self, cart_number: &str) -> Result<Option<Cart>>
pub fn get_by_number(&self, cart_number: &str) -> Result<Option<Cart>>
Get a cart by cart number (e.g., “CART-1234567890-0001”)
Sourcepub fn for_customer(&self, customer_id: CustomerId) -> Result<Vec<Cart>>
pub fn for_customer(&self, customer_id: CustomerId) -> Result<Vec<Cart>>
Get all carts for a customer
Sourcepub fn add_item(&self, cart_id: CartId, item: AddCartItem) -> Result<CartItem>
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()
})?;Sourcepub fn update_item(
&self,
item_id: Uuid,
input: UpdateCartItem,
) -> Result<CartItem>
pub fn update_item( &self, item_id: Uuid, input: UpdateCartItem, ) -> Result<CartItem>
Update a cart item (quantity, etc.)
Sourcepub fn remove_item(&self, item_id: Uuid) -> Result<()>
pub fn remove_item(&self, item_id: Uuid) -> Result<()>
Remove an item from the cart
Sourcepub fn clear_items(&self, cart_id: CartId) -> Result<()>
pub fn clear_items(&self, cart_id: CartId) -> Result<()>
Clear all items from the cart
Sourcepub fn set_shipping_address(
&self,
id: CartId,
address: CartAddress,
) -> Result<Cart>
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()),
})?;Sourcepub fn set_billing_address(
&self,
id: CartId,
address: CartAddress,
) -> Result<Cart>
pub fn set_billing_address( &self, id: CartId, address: CartAddress, ) -> Result<Cart>
Set the billing address
Sourcepub fn set_shipping(
&self,
id: CartId,
shipping: SetCartShipping,
) -> Result<Cart>
pub fn set_shipping( &self, id: CartId, shipping: SetCartShipping, ) -> Result<Cart>
Set shipping method and address
Sourcepub fn get_shipping_rates(&self, id: CartId) -> Result<Vec<ShippingRate>>
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.
Sourcepub fn set_payment(&self, id: CartId, payment: SetCartPayment) -> Result<Cart>
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()
})?;Sourcepub fn apply_discount(&self, id: CartId, coupon_code: &str) -> Result<Cart>
pub fn apply_discount(&self, id: CartId, coupon_code: &str) -> Result<Cart>
Apply a coupon/discount code to the cart
Sourcepub fn remove_discount(&self, id: CartId) -> Result<Cart>
pub fn remove_discount(&self, id: CartId) -> Result<Cart>
Remove the discount from the cart
Sourcepub fn mark_ready_for_payment(&self, id: CartId) -> Result<Cart>
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.)
Sourcepub fn begin_checkout(&self, id: CartId) -> Result<Cart>
pub fn begin_checkout(&self, id: CartId) -> Result<Cart>
Begin the checkout process (payment pending)
Sourcepub fn complete(&self, id: CartId) -> Result<CheckoutResult>
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);Sourcepub fn complete_settled_externally(&self, id: CartId) -> Result<CheckoutResult>
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.
Sourcepub fn reserve_inventory(&self, id: CartId) -> Result<Cart>
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.
Sourcepub fn release_inventory(&self, id: CartId) -> Result<Cart>
pub fn release_inventory(&self, id: CartId) -> Result<Cart>
Release inventory reservations for the cart
Sourcepub fn recalculate(&self, id: CartId) -> Result<Cart>
pub fn recalculate(&self, id: CartId) -> Result<Cart>
Recalculate cart totals
Sourcepub fn set_tax(&self, id: CartId, tax_amount: Decimal) -> Result<Cart>
pub fn set_tax(&self, id: CartId, tax_amount: Decimal) -> Result<Cart>
Set the tax amount for the cart
Sourcepub fn get_abandoned(&self) -> Result<Vec<Cart>>
pub fn get_abandoned(&self) -> Result<Vec<Cart>>
Get abandoned carts (for recovery campaigns)
Sourcepub fn get_expired(&self) -> Result<Vec<Cart>>
pub fn get_expired(&self) -> Result<Vec<Cart>>
Get expired carts
Sourcepub fn count(&self, filter: CartFilter) -> Result<u64>
pub fn count(&self, filter: CartFilter) -> Result<u64>
Count carts matching a filter