Carts
Overview
The Cart object is the central entity in Violet's unified checkout API that represents a shopping cart containing products from one or more merchants. It serves as the primary container for managing multi-merchant checkout flows and automatically organizes items into "bags" based on the merchant they come from.
Key Concepts
Cart vs Order
Cart: Active shopping session that can be modified (add/remove items, apply discounts, set shipping)
Order: Immutable record created after cart submission to merchants' platforms
Multi-Merchant Architecture
A single cart can contain products from multiple merchants
Items are automatically organized into bags - one bag per merchant
Each bag mirrors the cart/order structure of the merchant's ecommerce platform
Core Properties
Identification
{
"id": 10000, // Unique cart ID in Violet
"token": "fz8x7gksdjsy2p9...", // Cart token for secure access
"app_order_id": "order_123", // Your system's order identifier
"external_id": "ref_456" // Optional reference ID
}Ownership & Context
Financial Summary
All monetary values are in cents in the base currency:
Bags Structure
Each cart contains an array of bags - one per merchant:
Bag Lifecycle States
IN_PROGRESS: Cart is being built, can be modifiedSUBMITTED: Cart has been sent to merchant platformACCEPTED: Merchant platform confirmed the orderCOMPLETED: All items fulfilled and shippedREFUNDED: All items returned and refunded
SKU (Product Items) Structure
Each bag contains SKUs representing individual products:
Customer Information
Payment Integration
Standard Payment Flow
Wallet-Based Checkout (Apple Pay, Google Pay)
Error Handling
Carts include comprehensive error tracking:
Important: Always check the errors array - the API returns 200 even with bag-level errors.
Special Features
Multi-Currency Support
Set currency at cart creation with
base_currencyparameterOnce a cart has been created in a currency, you cannot change it. You will need to create a new cart with the updated base_currency to achieve this.
Real-time exchange rates applied automatically or using presentment currencies
Discount Codes
Discount codes can be added during cart creation ([POST]/checkout/cart) or through an exclusive endpoint ([POST]/checkout/cart/:cart_id/discounts)
Validated against each merchant's platform
States:
PENDING,APPLIED,INVALID,EXPIRED,ERRORSee Discounts section for more info
Shipping Methods
Automatically retrieved from each merchant's platform
Applied per bag (per merchant)
Calculated based on shipping address and item weights
Key API Endpoints
Create cart
/checkout/cart
POST
Get cart
/checkout/cart/{id}
GET
Get by token
/checkout/cart/byToken/{token}
GET
Delete cart
/checkout/cart/{id}
DELETE
Add items
/checkout/cart/{id}/items
POST
Apply payment
/checkout/cart/{id}/payment
POST
Set shipping
/checkout/cart/{id}/shipping
POST
Add discounts
/checkout/cart/{id}/discounts
POST
Submit cart
/checkout/cart/{id}/submit
POST
Best Practices
Cart Management
Use app_order_id: While not enforced unique in Violet's system, it is strongly recommended that unique values are used for each cart to help correlate identifiers between Violet's system and yours.
Error Checking: Always examine the
errorsarray after any cart operationCurrency Immutability: Choose currency carefully at creation - it cannot be changed later
Bag Awareness: Remember that multi-merchant carts create multiple bags, each potentially with different shipping methods, discounts, and states
Performance Considerations
Carts persist indefinitely - implement cleanup for abandoned carts
Carts with wallet_based_checkout set to true cannot be completed without completing the front end client work listed below, specifically the Stripe Element integration and the client side Payment Confirmation. There is no API-only path complete such an order
Security
Use cart tokens for client-side access instead of cart IDs
Validate cart ownership before allowing modifications
Implement proper authentication for cart operations
Example: Basic Cart Creation
This cart object design enables Violet's core value proposition: unified multi-merchant checkout through a single API interface, while maintaining the flexibility and features of individual ecommerce platforms.
Last updated
Was this helpful?