Skip to main content

Cart Checkout

Creates an order from the customer's shopping cart and initiates the payment process.

HTTP Request

POST/api/shop/checkout/cart

Authorization

Authorization

  • Required: Yes
  • Permission: Authenticated users
  • Authentication: Token-based authentication

Request Body

FieldTypeRequiredDescription
addressIntegerYesCustomer address ID for shipping/billing
payment_methodIntegerYesActive payment method ID
shipping_methodIntegerYesActive shipping method ID
notesStringNoOrder notes (max 500 chars)

Example Requests

1import requests
2
3# Checkout cart
4response = requests.post('http://www.example.com/api/shop/checkout/cart', 
5  json={
6      'address': 123,
7      'payment_method': 1,
8      'shipping_method': 2,
9      'notes': 'Please deliver after 5 PM'
10  },
11  headers={'Authorization': 'Token <your_api_key>'}
12)
13print(response.json())
14
15# Example responses:
16# For redirect-based payments (e.g., PayPal, Stripe):
17{
18  "next_step": "https://payment-gateway.com/pay?token=abc123"
19}
20
21# For direct payments or already processed:
22{
23  "order_key": "ORD-2024-001"
24}

Status Codes

CodeDescription
200Checkout successful
400Bad request — validation errors
401Unauthorized — authentication required
503Service unavailable — payment service error
500Internal server error

Response Fields

Success Response (Direct Payment):

FieldTypeDescription
order_keyStringOrder tracking key for the new order

Success Response (Redirect Payment):

FieldTypeDescription
next_stepStringURL to redirect user for payment

Error Response:

FieldTypeDescription
errorStringError message

Validation Rules

  • Cart Validation: Cart must not be empty
  • Stock Validation: All cart items must be in stock with sufficient quantity
  • Profile Validation: Customer profile must be completed
  • Address Validation: Address must belong to the authenticated customer
  • Payment Method: Must be active and support the cart content
  • Shipping Method: Must be active and support the cart content

Checkout Process Flow

  1. Order Creation: Creates order from cart items with billing information
  2. Status Update: Order status set to "HOLD" during payment processing
  3. Payment Initiation:
    • For redirect payments: Returns next_step URL for external gateway (For example PayPal, Stripe, Zarinpal, etc.)
      • User must complete payment on the gateway site
      • After payment, user is redirected back to the site with order key
    • For direct payments: Processes immediately and returns order_key (For example pay on delivery)
  4. Cart Cleanup: Cart is deleted after successful payment
  5. Order Completion: Order status updated to "PROCESSING" after payment verification