curl --request GET \
--url https://api.example.com/api/sales/debts{
"debt_id": "<string>",
"user_id": "<string>",
"user": {
"name": "<string>",
"surname": "<string>",
"phone": "<string>"
},
"cart_id": "<string>",
"cart": {
"total": 123,
"created_at": "<string>"
},
"amount": 123,
"remaining": 123,
"status": "<string>",
"due_date": "<string>",
"notes": "<string>",
"created_at": "<string>",
"updated_at": "<string>"
}Manage customer payment debts and installment plans
curl --request GET \
--url https://api.example.com/api/sales/debts{
"debt_id": "<string>",
"user_id": "<string>",
"user": {
"name": "<string>",
"surname": "<string>",
"phone": "<string>"
},
"cart_id": "<string>",
"cart": {
"total": 123,
"created_at": "<string>"
},
"amount": 123,
"remaining": 123,
"status": "<string>",
"due_date": "<string>",
"notes": "<string>",
"created_at": "<string>",
"updated_at": "<string>"
}pending - Returns both ‘pending’ and ‘partial’ status debtspartial - Returns debts with partial payments madepaid - Returns fully paid debtspending, partial, or paid# Get all pending debts
curl -X GET "https://api.example.com/api/sales/debts?status=pending" \
-H "Authorization: Bearer YOUR_TOKEN"
[
{
"debt_id": "debt123",
"user_id": "user456",
"user": {
"name": "María",
"surname": "González",
"phone": "+34 612 345 678"
},
"cart_id": "cart789",
"cart": {
"total": 150.00,
"created_at": "2024-01-15T10:00:00Z"
},
"amount": 150.00,
"remaining": 100.00,
"status": "partial",
"due_date": "2024-02-15T00:00:00Z",
"notes": "Pago en 2 cuotas acordado",
"created_at": "2024-01-15T10:00:00Z",
"updated_at": "2024-01-20T14:30:00Z"
}
]
remaining field is automatically set to equal amount when creating a debt. The status defaults to pending.curl -X POST "https://api.example.com/api/sales/debts" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user456",
"cart_id": "cart789",
"amount": 150.00,
"due_date": "2024-02-15T00:00:00Z",
"notes": "Pago en 2 cuotas de 75€"
}'
curl -X GET "https://api.example.com/api/sales/debts/debt123" \
-H "Authorization: Bearer YOUR_TOKEN"
paidpending, partial, or paid# Record a partial payment of 50€
curl -X PUT "https://api.example.com/api/sales/debts/debt123" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"remaining": 50.00,
"status": "partial",
"notes": "Primera cuota de 50€ pagada el 20/01/2024"
}'
curl -X PUT "https://api.example.com/api/sales/debts/debt123" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"remaining": 0,
"notes": "Deuda saldada completamente"
}'
curl -X DELETE "https://api.example.com/api/sales/debts/debt123" \
-H "Authorization: Bearer YOUR_TOKEN"
{
"success": true
}
// Record a payment installment
const recordPayment = async (debtId, paymentAmount) => {
const debt = await fetch(`/api/sales/debts/${debtId}`).then(r => r.json());
const newRemaining = debt.remaining - paymentAmount;
await fetch(`/api/sales/debts/${debtId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
remaining: newRemaining,
status: newRemaining > 0 ? 'partial' : 'paid',
notes: `Pago de ${paymentAmount}€ recibido. ${debt.notes || ''}`
})
});
};
// Get overdue debts
const overdueDebts = debts.filter(debt => {
if (!debt.due_date || debt.status === 'paid') return false;
return new Date(debt.due_date) < new Date();
});
// Calculate debt statistics
const debtSummary = {
totalOutstanding: debts
.filter(d => d.status !== 'paid')
.reduce((sum, d) => sum + d.remaining, 0),
totalDebts: debts.length,
paidDebts: debts.filter(d => d.status === 'paid').length,
pendingDebts: debts.filter(d => d.status === 'pending').length,
partialDebts: debts.filter(d => d.status === 'partial').length
};