Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/akibanks/tienda_musica_web/llms.txt

Use this file to discover all available pages before exploring further.

The /checkout endpoint is the final step in the VinylVibes purchase flow. It receives the cart items and shipping address from the frontend and creates a sale record in the backend. Prices are calculated server-side — the frontend does not send prices. Authentication is always required; unauthenticated requests are rejected immediately with a 401 response.

POST /checkout

Authentication: Required — Authorization: Bearer <token> Creates a new order from the current cart contents and shipping address. On success, the backend returns the new order ID and a confirmation message.

Request Body

items
array
required
Array of cart items to purchase. Each element must include the Discogs release ID and the quantity ordered. Prices are not included — the backend looks them up server-side.
envio
object
required
Shipping address for the order. All fields except numero_int and referencias are required.

Request Example

{
  "items": [
    { "discogs_id": "12345", "cantidad": 1 },
    { "discogs_id": "67890", "cantidad": 2 }
  ],
  "envio": {
    "nombre_receptor": "Ana García",
    "calle": "Av. Insurgentes Sur",
    "numero_ext": "1602",
    "numero_int": "8B",
    "colonia": "Crédito Constructor",
    "codigo_postal": "03940",
    "ciudad": "Ciudad de México",
    "estado": "CDMX",
    "referencias": "Edificio azul, timbre 8B"
  }
}

cURL Example

curl -X POST https://api-tienda-vinilos.onrender.com/checkout \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <token>' \
  -d '{"items":[{"discogs_id":"12345","cantidad":1}],"envio":{"nombre_receptor":"Ana García","calle":"Insurgentes","numero_ext":"1602","colonia":"Crédito Constructor","codigo_postal":"03940","ciudad":"Ciudad de México","estado":"CDMX"}}'

Responses

200 — Success
{ "message": "Compra realizada con éxito", "venta_id": 42 }
401 — Unauthorized
{ "error": "No autorizado" }
The frontend includes a card data collection form (number, name, expiry, CVV) for UX validation only. Card data is NOT sent to the backend. No real payment processing occurs at this endpoint.
After a successful checkout, the frontend clears vv_carrito from localStorage and shows a success toast notification. The new order appears in GET /mis-compras immediately.

How the Frontend Calls This Endpoint

The following code is taken directly from script.js (procesarPago function). Each item includes discogs_id, titulo, artista, cantidad, and precio. The shipping address object (_datosEnvio) is built from the form and uses the field names shown above.
const res = await fetch(`${API}/checkout`, {
    method:  'POST',
    headers: authHeaders(),
    body:    JSON.stringify({ items, envio: _datosEnvio }),
});
Where items for a cart checkout is constructed as:
items = carrito.map(item => ({
    discogs_id: item.discogs_id,
    titulo:     item.titulo,
    artista:    item.artista,
    cantidad:   item.cantidad,
    precio:     item.precio,
}));
And _datosEnvio is assembled from the shipping form as:
_datosEnvio = {
    nombre_receptor: nombre,
    calle,
    numero_ext:   numExt,
    numero_int:   get('envio-num-int') || null,
    colonia,
    codigo_postal: cp,
    ciudad,
    estado,
    referencias:  get('envio-referencias') || null,
};

Build docs developers (and LLMs) love