Skip to main content

Overview

The Checkout API handles the final steps of the purchase process including payment collection, payment processing, and order completion. Base Path: /store/carts Source: packages/medusa/src/api/store/carts/[id]/complete/route.ts

Checkout Flow

The typical checkout flow consists of:
  1. Create or retrieve a cart
  2. Add shipping and billing addresses
  3. Select shipping method
  4. Apply promotion codes (optional)
  5. Initialize payment collection
  6. Process payment
  7. Complete the cart to create an order

Complete Cart

Complete the checkout process and create an order from the cart.

Path Parameters

string
required
The cart’s ID.

Request

Success Response

When the order is successfully created:
string
Response type: "order" on success or "cart" if action required.
object
The created order object.

Error Response

When additional action is required (e.g., payment authorization failed):
string
Returns "cart" when the cart cannot be completed.
object
The cart object with current state.
object
Error details explaining why completion failed.
Source: packages/medusa/src/api/store/carts/[id]/complete/route.ts:13
The complete endpoint uses the workflow engine and may return the cart with errors if the workflow cannot finish (see line 25-30). Common errors include payment failures and inventory issues.

Payment Collection

Initialize Payment Collection

Create a payment collection for the cart.

Request Body

string
required
The cart ID to create payment collection for.

Request

Response

Source: packages/medusa/src/api/store/payment-collections/route.ts

Payment Processing

Create Payment Session

Initialize a payment session with a payment provider.

Path Parameters

string
required
The payment collection ID.

Request Body

string
required
Payment provider ID (e.g., “pp_stripe”, “pp_paypal”).
object
Provider-specific data required to initialize payment.
object
Additional context for the payment session.

Request

Response

object
Provider-specific data needed by the client (e.g., Stripe client secret for card processing).

Authorize Payment Session

Authorize a payment session after customer completes payment on the client.

Path Parameters

string
required
The payment collection ID.
string
required
The payment session ID.

Request Body

object
Additional authorization context required by the payment provider.

Request

Response

Payment Providers

List Payment Providers

Retrieve available payment providers for a region.

Query Parameters

string
Filter by region to get region-specific providers.
boolean
Filter by enabled status.

Request

Response

Source: packages/medusa/src/api/store/payment-providers/route.ts

Checkout Validation

Before completing checkout, ensure:
  1. Cart has items
  2. Shipping address is set
  3. Billing address is set
  4. Shipping method is selected
  5. Payment is authorized
  6. Email is provided

Error Handling

Common Checkout Errors

Resolution: Customer needs to retry payment with valid payment method.
Resolution: Customer needs to complete 3D Secure or similar authentication.
Resolution: Remove or reduce quantity of out-of-stock items.
Resolution: Provide missing cart information before completing.
Source: Error handling logic at packages/medusa/src/api/store/carts/[id]/complete/route.ts:39-73

Complete Checkout Example

Here’s a complete checkout flow:

Next Steps

Order Module

Learn about order management

Customers

Manage customer account