Skip to content

Cart API - Direct Product Purchase

This API allows users to directly purchase a product with a variant (if applicable) by specifying the product, variant, and quantity.


Endpoints Overview

Method Endpoint Description
POST /api/v1/cart/direct-product-purchase/ Directly purchase a product with the specified variant and quantity.

Cart API - Direct Product Purchase

1. Handle Direct Product Purchase (Buy Now)

Endpoint

  • URL: /api/v1/cart/direct-product-purchase/
  • Method: POST
  • Permission Required: IsAuthenticated

Description

Allows users to directly purchase a product, including selecting a variant (if available), specifying the quantity, and checking stock availability. If all conditions are met, a cart item is created, and the purchase process is initiated.

Request Body

  • product_id (Required): ID of the product being purchased.
  • variant_id (Optional): ID of the product variant (if applicable).
  • quantity (Optional, default 1): Number of items to purchase.

Example Request

This is the endpoint

POST /api/v1/cart/direct-product-purchase/


Request Body

This is the request body

{
  "product_id": 1,
  "variant_id": 2,
  "quantity": 2
}


Success

{
  "order_id": "12345",
  "product": "Sample Product",
  "quantity": 2,
  "total_purchased": 100.0,
  "discount": 10.0,
  "net_amount": 90.0
}
Error
{
  "error": "No available variants with stock for this product."
}