Skip to main content

Overview

The checkout validation endpoint ensures that the cart is ready for order processing. It performs comprehensive validation checks before allowing the user to proceed to payment.

Validate Checkout

Validate the current cart and ensure all requirements are met for checkout.
POST /api/v2/checkout/validate
This endpoint requires user authentication via the @auth_required decorator.

Authentication

The request must include a valid authentication token in the Authorization header:
Authorization: Bearer <jwt_token>

Request

No request body is required. The endpoint validates the authenticated user’s current cart.
curl -X POST https://api.example.com/api/v2/checkout/validate \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json"

Validation Checks

The endpoint performs the following validations:

1. Stock Availability

Ensures all selected products are in stock (except JIT products or external API orders).
stock
integer
Available stock must be greater than or equal to requested quantity

2. Quantity Limits

Validates that each product quantity does not exceed the maximum allowed.
quantity
integer
Maximum 10 units per product

3. Mystery Product Limits

For mystery products, ensures only one unit per parent product.
Mystery products cannot have more than 1 unit per parent product across the entire cart.

4. Membership Requirements

Products in membership-only categories require an active membership or membership product in cart.
categories
array
Products with membership categories require:
  • User has is_exclusive = true, OR
  • Cart contains an exclusive membership product

5. Minimum Order Amount

Validates that the order meets the minimum required amount.
MIN_ORDER_AMOUNT
float
Minimum order value (excluding certain exempted products)
Exemptions:
  • Exclusive upgrade products
  • Products in EXCLUDE_MIN_ORDER_AMOUNT list
  • Users in MIN_ORDER_EXEMPT_USER_IDS list
Calculation:
order_value = main_sub_total - used_tss_points + gift_wrap_amount + shipping_charges

6. Product Selection

Only validates products marked as selected in the cart.
Products with select: false are skipped during validation.

Response

Success Response

true
response
boolean
Returns true if all validations pass

Error Responses

If validation fails, the endpoint returns a 400 Bad Request with a descriptive error message.

Stock Validation Error

{
  "title": "Bad Request",
  "description": "One or more products has gone out of stock. Kindly remove them to proceed further."
}

Quantity Limit Error

{
  "title": "Bad Request",
  "description": "Per product quantity should be less than or equal to 10."
}

Membership Required Error

{
  "title": "Bad Request",
  "description": "This product requires an active membership. Please add membership to continue."
}
The exact error message for membership products is configured via CART_VALIDATION_MEMBERSHIP_PRODUCT_ERROR_MSG.

Mystery Product Error

{
  "title": "Bad Request",
  "description": "Can not add more than one mystery products"
}

Minimum Order Error

{
  "title": "Bad Request",
  "description": "Minimum order amount should be 499."
}

Validation Flow

Example Scenarios

Scenario 1: Valid Cart

Cart Contents:
  • Product A: qty 2, stock 10, price 500
  • Product B: qty 1, stock 5, price 300
  • Total: 1300 (above minimum)
Result: ✅ Validation passes

Scenario 2: Out of Stock

Cart Contents:
  • Product A: qty 5, stock 3
Result: ❌ Error: “One or more products has gone out of stock”

Scenario 3: Quantity Exceeded

Cart Contents:
  • Product A: qty 15
Result: ❌ Error: “Per product quantity should be less than or equal to 10”

Scenario 4: Below Minimum

Cart Contents:
  • Product A: qty 1, price 200
  • Total: 200 (below 499 minimum)
Result: ❌ Error: “Minimum order amount should be 499”

Scenario 5: Membership Required

Cart Contents:
  • Member-only Product: qty 1
  • User: not exclusive member
  • No membership in cart
Result: ❌ Error: Membership required message

Scenario 6: Mystery Product Limit

Cart Contents:
  • Mystery Product A (parent: 1000): qty 1
  • Mystery Product B (parent: 1000): qty 1
  • Total mystery for parent 1000: 2
Result: ❌ Error: “Can not add more than one mystery products”

Integration Notes

Before Checkout

  1. User adds products to cart via Cart API
  2. User navigates to checkout page
  3. Call validate endpoint
  4. If validation passes, show payment options
  5. If validation fails, show error and redirect to cart

After Validation

Once validation passes, proceed with:
  1. Address selection/entry
  2. Shipping method selection
  3. Payment method selection
  4. Order placement

Error Handling

try {
  const response = await fetch('/api/v2/checkout/validate', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    }
  });
  
  if (response.ok) {
    // Validation passed - proceed to payment
    showPaymentOptions();
  } else {
    const error = await response.json();
    // Show error and redirect to cart
    showError(error.description);
    redirectToCart();
  }
} catch (error) {
  // Handle network errors
  showError('Unable to validate checkout. Please try again.');
}

Configuration Variables

The following settings control validation behavior:
MIN_ORDER_AMOUNT
float
Minimum order value required (e.g., 499.0)
EXCLUSIVE_UPGRADE_PRODUCT
dict
Product IDs that exempt the minimum order requirement
EXCLUDE_MIN_ORDER_AMOUNT
list
Product IDs exempt from minimum order validation
PRODUCT_WITH_MEMBERSHIP_CATEGORY
list
Category IDs that require membership
CART_VALIDATION_MEMBERSHIP_PRODUCT_ERROR_MSG
string
Custom error message for membership requirement
MIN_ORDER_EXEMPT_USER_IDS
list
User IDs exempt from minimum order validation

Best Practices

Always validate before payment - Call this endpoint before showing payment options
Handle errors gracefully - Show clear error messages and guide users to fix issues
Real-time cart updates - Revalidate if cart is modified during checkout
Stock checking - This validation includes real-time stock checks
Do not cache validation results. Always perform fresh validation before order placement.

Cart Operations

Manage cart contents before checkout

Cart Overview

Understand cart structure and data

Build docs developers (and LLMs) love