Skip to main content

Overview

The Carts API allows you to create and manage shopping carts for point-of-sale transactions. Carts track items being purchased, calculate totals, apply discounts, and record payment information. Each cart can be associated with a user (client) or remain anonymous for walk-in customers.

Cart Lifecycle

Carts progress through the following statuses:
  • pending - Cart is active and items can be added/modified
  • completed - Transaction has been finalized and payment received
  • cancelled - Cart was abandoned or transaction cancelled

Endpoints

List Carts

Retrieve all carts with optional filtering by status.
GET /api/sales/carts

Query Parameters

status
string
Filter carts by status: pending, completed, or cancelled

Response

Returns an array of cart objects ordered by creation date (newest first).
cart_id
string
required
Unique identifier for the cart (UUID)
user_id
string
ID of the associated user/client. Null for anonymous carts
user
object
User information if cart is associated with a client
status
string
required
Current cart status: pending, completed, or cancelled
subtotal
number
required
Sum of all item prices before discounts
discount
number
required
Total discount amount applied to the cart
total
number
required
Final amount after discounts (subtotal - discount)
payment_method
string
Payment method used: cash, card, transfer, or mixed
notes
string
Additional notes or comments about the transaction
applied_coupon
string
Coupon code applied during checkout
applied_giftcard
string
Gift card code used for payment
items
array
required
Array of cart items (see CartItem schema)
debts
array
Associated debt records if payment is incomplete
created_at
string
required
ISO 8601 timestamp when cart was created
updated_at
string
required
ISO 8601 timestamp when cart was last updated

Example Request

curl -X GET 'https://api.beils.com/api/sales/carts?status=pending' \
  -H 'Authorization: Bearer YOUR_TOKEN'

Example Response

[
  {
    "cart_id": "550e8400-e29b-41d4-a716-446655440000",
    "user_id": "123e4567-e89b-12d3-a456-426614174000",
    "user": {
      "name": "Maria",
      "surname": "Garcia",
      "email": "[email protected]"
    },
    "status": "pending",
    "subtotal": 150.00,
    "discount": 15.00,
    "total": 135.00,
    "payment_method": "card",
    "notes": null,
    "applied_coupon": "SUMMER10",
    "applied_giftcard": null,
    "items": [
      {
        "cart_item_id": "660e8400-e29b-41d4-a716-446655440001",
        "item_type": "service",
        "item_id": "770e8400-e29b-41d4-a716-446655440002",
        "name": "Facial Treatment",
        "quantity": 1,
        "unit_price": 80.00,
        "tax_rate": 21.0,
        "subtotal": 80.00,
        "total": 80.00
      },
      {
        "cart_item_id": "660e8400-e29b-41d4-a716-446655440003",
        "item_type": "product",
        "item_id": "770e8400-e29b-41d4-a716-446655440004",
        "name": "Moisturizing Cream",
        "quantity": 1,
        "unit_price": 70.00,
        "tax_rate": 21.0,
        "subtotal": 70.00,
        "total": 70.00
      }
    ],
    "debts": [],
    "created_at": "2026-03-05T10:30:00Z",
    "updated_at": "2026-03-05T10:30:00Z"
  }
]

Create Cart

Create a new shopping cart with items.
POST /api/sales/carts

Request Body

user_id
string
ID of the client. Omit for anonymous walk-in customers
status
string
default:"pending"
Initial cart status: pending, completed, or cancelled
payment_method
string
default:"cash"
Payment method: cash, card, transfer, or mixed
discount
number
default:"0"
Manual discount amount to apply
notes
string
Additional notes about the transaction
applied_coupon
string
Coupon code to apply (stores code for history)
applied_giftcard
string
Gift card code used (stores code for history)
items
array
required
Array of items to add to the cart
Transaction Safety: Cart creation uses database transactions to ensure data consistency. The subtotal and total are automatically calculated from items to prevent client-side tampering.

Example Request

curl -X POST 'https://api.beils.com/api/sales/carts' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "user_id": "123e4567-e89b-12d3-a456-426614174000",
    "status": "pending",
    "payment_method": "card",
    "discount": 10.00,
    "applied_coupon": "WELCOME10",
    "items": [
      {
        "item_type": "service",
        "item_id": "770e8400-e29b-41d4-a716-446655440002",
        "name": "Manicure",
        "quantity": 1,
        "unit_price": 35.00,
        "tax_rate": 21.0
      },
      {
        "item_type": "product",
        "item_id": "770e8400-e29b-41d4-a716-446655440005",
        "name": "Nail Polish",
        "quantity": 2,
        "unit_price": 12.00,
        "tax_rate": 21.0
      }
    ]
  }'

Example Response

{
  "cart_id": "550e8400-e29b-41d4-a716-446655440000",
  "user_id": "123e4567-e89b-12d3-a456-426614174000",
  "status": "pending",
  "subtotal": 59.00,
  "discount": 10.00,
  "total": 49.00,
  "payment_method": "card",
  "notes": null,
  "applied_coupon": "WELCOME10",
  "applied_giftcard": null,
  "items": [
    {
      "cart_item_id": "660e8400-e29b-41d4-a716-446655440001",
      "cart_id": "550e8400-e29b-41d4-a716-446655440000",
      "item_type": "service",
      "item_id": "770e8400-e29b-41d4-a716-446655440002",
      "name": "Manicure",
      "quantity": 1,
      "unit_price": 35.00,
      "tax_rate": 21.0,
      "subtotal": 35.00,
      "total": 35.00,
      "created_at": "2026-03-05T11:00:00Z",
      "updated_at": "2026-03-05T11:00:00Z"
    },
    {
      "cart_item_id": "660e8400-e29b-41d4-a716-446655440003",
      "cart_id": "550e8400-e29b-41d4-a716-446655440000",
      "item_type": "product",
      "item_id": "770e8400-e29b-41d4-a716-446655440005",
      "name": "Nail Polish",
      "quantity": 2,
      "unit_price": 12.00,
      "tax_rate": 21.0,
      "subtotal": 24.00,
      "total": 24.00,
      "created_at": "2026-03-05T11:00:00Z",
      "updated_at": "2026-03-05T11:00:00Z"
    }
  ],
  "user": {
    "name": "Maria",
    "surname": "Garcia"
  },
  "created_at": "2026-03-05T11:00:00Z",
  "updated_at": "2026-03-05T11:00:00Z"
}

Get Cart

Retrieve a specific cart by ID with full details.
GET /api/sales/carts/{cart_id}

Path Parameters

cart_id
string
required
The unique identifier of the cart

Response

Returns a cart object with complete user and item information.

Example Request

curl -X GET 'https://api.beils.com/api/sales/carts/550e8400-e29b-41d4-a716-446655440000' \
  -H 'Authorization: Bearer YOUR_TOKEN'

Example Response

{
  "cart_id": "550e8400-e29b-41d4-a716-446655440000",
  "user_id": "123e4567-e89b-12d3-a456-426614174000",
  "user": {
    "name": "Maria",
    "surname": "Garcia",
    "email": "[email protected]",
    "phone": "+34612345678"
  },
  "status": "completed",
  "subtotal": 120.00,
  "discount": 12.00,
  "total": 108.00,
  "payment_method": "card",
  "notes": "Client requested receipt",
  "applied_coupon": "LOYAL10",
  "applied_giftcard": null,
  "items": [
    {
      "cart_item_id": "660e8400-e29b-41d4-a716-446655440001",
      "item_type": "service",
      "item_id": "770e8400-e29b-41d4-a716-446655440002",
      "name": "Hair Cut",
      "quantity": 1,
      "unit_price": 45.00,
      "tax_rate": 21.0,
      "subtotal": 45.00,
      "total": 45.00
    },
    {
      "cart_item_id": "660e8400-e29b-41d4-a716-446655440002",
      "item_type": "service",
      "item_id": "770e8400-e29b-41d4-a716-446655440003",
      "name": "Hair Coloring",
      "quantity": 1,
      "unit_price": 75.00,
      "tax_rate": 21.0,
      "subtotal": 75.00,
      "total": 75.00
    }
  ],
  "debts": [],
  "created_at": "2026-03-05T09:00:00Z",
  "updated_at": "2026-03-05T11:30:00Z"
}

Update Cart

Update cart status, payment method, or notes. The cart itself is immutable after creation, but these metadata fields can be updated.
PUT /api/sales/carts/{cart_id}

Path Parameters

cart_id
string
required
The unique identifier of the cart

Request Body

status
string
Update cart status: pending, completed, or cancelled
payment_method
string
Update payment method: cash, card, transfer, or mixed
notes
string
Update or add notes
Once a cart is created, items cannot be modified through this endpoint. To change items, create a new cart. This ensures transaction integrity.

Example Request

curl -X PUT 'https://api.beils.com/api/sales/carts/550e8400-e29b-41d4-a716-446655440000' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "status": "completed",
    "payment_method": "card",
    "notes": "Payment confirmed"
  }'

Example Response

{
  "cart_id": "550e8400-e29b-41d4-a716-446655440000",
  "user_id": "123e4567-e89b-12d3-a456-426614174000",
  "status": "completed",
  "subtotal": 120.00,
  "discount": 12.00,
  "total": 108.00,
  "payment_method": "card",
  "notes": "Payment confirmed",
  "applied_coupon": "LOYAL10",
  "applied_giftcard": null,
  "created_at": "2026-03-05T09:00:00Z",
  "updated_at": "2026-03-05T11:35:00Z"
}

Delete Cart

Delete a cart permanently. This will cascade delete all cart items.
DELETE /api/sales/carts/{cart_id}

Path Parameters

cart_id
string
required
The unique identifier of the cart
Deleting a cart removes all associated cart items due to cascade delete. Associated debts will have their cart reference set to null rather than being deleted.

Example Request

curl -X DELETE 'https://api.beils.com/api/sales/carts/550e8400-e29b-41d4-a716-446655440000' \
  -H 'Authorization: Bearer YOUR_TOKEN'

Example Response

{
  "success": true
}

Common Use Cases

Processing a Walk-in Sale

For customers without an account:
curl -X POST 'https://api.beils.com/api/sales/carts' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "status": "completed",
    "payment_method": "cash",
    "items": [
      {
        "item_type": "product",
        "item_id": "prod-123",
        "name": "Shampoo",
        "quantity": 1,
        "unit_price": 15.00,
        "tax_rate": 21.0
      }
    ]
  }'

Applying Multiple Discounts

Combine coupon codes and manual discounts:
curl -X POST 'https://api.beils.com/api/sales/carts' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "user_id": "user-123",
    "discount": 25.00,
    "applied_coupon": "VIP20",
    "applied_giftcard": "GIFT50",
    "payment_method": "mixed",
    "items": [...]
  }'

Tracking Daily Sales

Filter completed carts for reporting:
curl -X GET 'https://api.beils.com/api/sales/carts?status=completed' \
  -H 'Authorization: Bearer YOUR_TOKEN'

Error Responses

Cart Not Found

{
  "statusCode": 404,
  "statusMessage": "Cart not found"
}

Missing Cart ID

{
  "statusCode": 400,
  "statusMessage": "Cart ID is required"
}

Debts

Manage customer payment debts and installments

Coupons

Create and manage discount coupons

Gift Cards

Issue and redeem gift cards

Clients

Manage customer information

Build docs developers (and LLMs) love