Overview
Registers a payment (pago) or collection (cobro) to settle account balances. Supports idempotency and returns updated statement.
Authentication
Requires JWT authentication:
- VENDEDOR: Not authorized
- VENTANA: Can register payments for own window or sellers
- ADMIN: Can register payments for any entity
Request Body
Payment date in YYYY-MM-DD format (cannot be future)
Payment time in HH:MM 24-hour format (default: 00:00). Cannot be future if date is today.
Window ID (required for window-level payments). Mutually exclusive with vendedorId and bancaId.
Seller ID (required for seller-level payments). Mutually exclusive with ventanaId and bancaId.
Banca ID (admin only, required for banca-level payments). Mutually exclusive with ventanaId and vendedorId.
Payment amount (must be > 0)
Payment type: payment (pago) or collection (cobro)
Payment method: cash, check, transfer, system
Optional notes (max 500 characters)
Mark day as settled (saldado)
Unique key for idempotency (min 8 characters). If key exists, returns cached payment.
Response
Created payment record
Type: payment or collection
User who registered payment
Updated account statement for the day
Present if payment returned from idempotency cache (status 200 instead of 201)
Status Codes
201: Payment created successfully
200: Cached payment returned (idempotency)
400: Invalid date/time or missing dimension
403: RBAC violation
Example Request
{
"date": "2024-03-15",
"time": "14:30",
"ventanaId": "ventana-001",
"amount": 100000,
"type": "payment",
"method": "cash",
"notes": "Pago parcial de ventas del día",
"isFinal": false,
"idempotencyKey": "payment-2024-03-15-001"
}
Example Response
{
"success": true,
"data": {
"payment": {
"id": "pay-abc-123",
"date": "2024-03-15",
"time": "14:30",
"amount": 100000,
"type": "payment",
"method": "cash",
"notes": "Pago parcial de ventas del día",
"isReversed": false,
"isFinal": false,
"paidById": "user-123",
"createdAt": "2024-03-15T20:30:00.000Z"
},
"statement": {
"id": "stmt-001",
"date": "2024-03-15",
"totalSales": 500000,
"totalPayouts": 250000,
"totalPaid": 100000,
"remainingBalance": 132500,
"isSaldado": false
}
}
}
Validation Rules
- Date: Cannot be future date
- Time: Cannot be future if date is today (Costa Rica time)
- Dimension: Must provide exactly one of
bancaId, ventanaId, or vendedorId
- Amount: Must be positive number
- RBAC: VENTANA users can only register payments for their window/sellers
Activity Logging
Logs action ACCOUNT_PAYMENT_CREATE with payment details.