Overview
ThecompleteActiveCart mutation converts a cart into an order after payment is captured. This is the final step in the checkout flow and creates an immutable order record.
GraphQL Mutation
Parameters
The ID of the cart to complete
The ID of the payment session to capture. Required for paid orders. Optional for account-based orders (B2B).If omitted, the order is added to the authenticated user’s business account balance instead of processing payment.
Response
Unique identifier for the created order
Human-readable order number (timestamp-based)
Order status. Initially set to
pendingSecret key for guest order tracking (only present for non-authenticated orders)
Formatted order total including tax and shipping
Formatted subtotal (sum of line items before tax, shipping, and discounts)
Formatted tax amount based on region tax rate
Formatted shipping cost
Formatted total discount amount (if applicable)
Delivery address snapshot
Snapshot of order line items
Example Request
Complete with Payment (Storefront)
Complete without Payment (B2B Account)
Payment Flow
Storefront Orders (with paymentSessionId)
WhenpaymentSessionId is provided:
-
Payment Capture - The system captures payment based on the provider:
- Stripe: Retrieves and captures the payment intent
- PayPal: Verifies the PayPal order is approved/completed
- Cash on Delivery: Marks payment as
manual_pending
-
Order Creation - Creates order with:
- Line items snapshot (prices frozen at time of purchase)
- Address snapshots
- Total calculations
- Order event log
- Payment Record - Creates payment record linked to order
- Cart Completion - Marks cart as completed (links to order)
B2B Account Orders (without paymentSessionId)
WhenpaymentSessionId is omitted:
- Credit Check - Validates user has sufficient credit limit
- Order Creation - Creates order without payment processing
- Account Update - Adds order to business account balance
- Account Line Item - Creates account line item for tracking
Prerequisites
Before completing a cart, ensure:Cart has line items - At least one product variant added
Addresses set - Both shipping and billing addresses configured
Shipping method - Shipping method selected
Payment ready - Payment session created and authorized (for paid orders)
Credit available - Sufficient credit limit (for account orders)
Order Creation Process
The completion process:1. Validation
- Verifies cart exists and has required data
- Validates payment session (if provided)
- Checks credit limit (if account order)
2. Payment Processing
- Captures payment with provider
- Verifies payment success
- Handles payment failures gracefully
3. Order Snapshot
- Creates immutable OrderLineItems with frozen prices
- Creates OrderMoneyAmounts for price history
- Snapshots product and variant data
- Copies addresses, shipping, and discounts
4. Payment Record
- Links payment to order
- Records payment provider data
- Sets captured timestamp
5. Order Events
- Creates
ORDER_PLACEDevent - Tracks guest vs authenticated orders
- Initializes order audit trail
Error Handling
Guest vs Authenticated Orders
Guest Orders
- Generate a
secretKeyfor order tracking - Create guest user account automatically
- Require secretKey in confirmation URL
- Limited order history access
Authenticated Orders
- No secretKey generated
- Full order history in account
- Saved addresses for future orders
- Email notifications
Next Steps
After completing a cart:- Clear cart cookie on client
- Redirect to order confirmation page
- Send order confirmation email
- Begin fulfillment process
- Update inventory
Complete Checkout Flow
Here’s the full cart-to-order flow:Related
- Create Cart - Initialize a new cart
- Add to Cart - Add product variants
- Create Payment Sessions - Set up payment methods
- Set Shipping Method - Select delivery option