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
| Field | Type | Required | Description |
|---|---|---|---|
| address | Integer | Yes | Customer address ID for shipping/billing |
| payment_method | Integer | Yes | Active payment method ID |
| shipping_method | Integer | Yes | Active shipping method ID |
| notes | String | No | Order notes (max 500 chars) |
Example Requests
- 🐍 Python
- 🌐 Curl
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}1# Checkout cart
2curl -X POST "http://www.example.com/api/shop/checkout/cart" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
3 "address": 123,
4 "payment_method": 1,
5 "shipping_method": 2,
6 "notes": "Please deliver after 5 PM"
7}'Status Codes
| Code | Description |
|---|---|
| 200 | Checkout successful |
| 400 | Bad request — validation errors |
| 401 | Unauthorized — authentication required |
| 503 | Service unavailable — payment service error |
| 500 | Internal server error |
Response Fields
Success Response (Direct Payment):
| Field | Type | Description |
|---|---|---|
| order_key | String | Order tracking key for the new order |
Success Response (Redirect Payment):
| Field | Type | Description |
|---|---|---|
| next_step | String | URL to redirect user for payment |
Error Response:
| Field | Type | Description |
|---|---|---|
| error | String | Error 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
- Order Creation: Creates order from cart items with billing information
- Status Update: Order status set to "HOLD" during payment processing
- Payment Initiation:
- For redirect payments: Returns
next_stepURL for external gateway (For examplePayPal,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 examplepay on delivery)
- For redirect payments: Returns
- Cart Cleanup: Cart is deleted after successful payment
- Order Completion: Order status updated to "PROCESSING" after payment verification