Skip to main content

Debt API

Created: January 27, 2025This documentation provides comprehensive information about the Debt API endpoints, including customer debt tracking, invoice management, and payment processing capabilities.
The Debt API enables optical stores to track customer debt, view invoice details, and process payments for outstanding balances. The API provides endpoints to retrieve customers with debt, view their invoices, and make payments either to specific invoices or distribute payments across all outstanding invoices.
All Debt API endpoints require authentication and store context. Ensure you include the x-store-id header and a valid Bearer token for all requests.

Overview

The Debt API provides comprehensive debt management capabilities:
  • Customer Debt Tracking: Retrieve all customers with outstanding debt amounts and invoice counts
  • Invoice Management: View customer invoices with payment status and outstanding amounts
  • Payment Processing: Make payments to specific invoices or distribute payments across multiple invoices
  • Payment History: Track payment entries and allocations for audit purposes

Endpoint Details

Base URL: https://joptic.jethings.com

Required Headers

All endpoints require store-level access. The x-store-id header must match a store the authenticated user has access to.

Get Customers with Debt

GET /debt/customers Retrieve a list of all customers who have outstanding debt, including their total due amounts and the number of unpaid invoices. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id

Success Response

Status Code: 200 OK

Response Fields

Notes

  • Only customers with at least one invoice that has an outstanding balance are included
  • The totalDueAmount is calculated as the sum of all outstanding amounts across all unpaid invoices
  • Invoices are considered unpaid if totalPaid < ttc (total tax included)
  • Deleted customers and deleted invoices are automatically excluded

Example Requests


Get Customer Invoices

GET /debt/customers/:customerId/invoices Retrieve all invoices for a specific customer, including payment status and outstanding amounts. Optionally filter to show only invoices with outstanding balances. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id

Path Parameters

Query Parameters

Success Response

Status Code: 200 OK

Response Fields

Error Responses

404 Not Found - Customer not found

Notes

  • Invoices are sorted by creation date (oldest first)
  • When onlyOutstanding=true, only invoices where outstandingAmount > 0 are returned
  • The outstandingAmount is calculated as ttc - totalPaid
  • Deleted invoices are automatically excluded

Example Requests


Pay Customer Debt

POST /debt/customers/:customerId/pay Make a payment towards a customer’s total debt. The payment is automatically distributed across the customer’s unpaid invoices, starting with the oldest invoice first. If the payment amount exceeds the total outstanding debt, the remaining amount is returned. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id

Path Parameters

Request Body

Request Body Example

Success Response

Status Code: 200 OK

Response Fields

Special Cases

No Unpaid Invoices:

Error Responses

400 Bad Request - Invalid payment amount

Notes

  • Payments are distributed across invoices in chronological order (oldest first)
  • Each invoice is paid up to its outstanding amount before moving to the next invoice
  • If a payment amount exceeds the total outstanding debt, the remainingAmount field indicates the excess
  • Invoices without a storeId are skipped during payment distribution
  • Each payment creates a paymentEntry and a corresponding paymentAllocation record

Example Requests


Pay Invoice

POST /debt/customers/:customerId/invoices/:invoiceId/pay Make a payment towards a specific invoice. The payment amount cannot exceed the outstanding balance of the invoice. If the invoice is already fully paid, a success response is returned with no payment created. Requires Authentication: Bearer token in Authorization header
Requires Header: x-store-id

Path Parameters

Request Body

Request Body Example

Success Response

Status Code: 200 OK

Response Fields

Special Cases

Invoice Already Fully Paid:
Partial Payment (amount exceeds outstanding): If you request to pay 500.00 but the invoice only has 250.00 outstanding:

Error Responses

400 Bad Request - Invalid payment amount or missing storeId
Or:
404 Not Found - Invoice not found or doesn’t belong to customer

Notes

  • The payment amount is automatically capped at the invoice’s outstanding amount
  • If the requested amount exceeds the outstanding balance, only the outstanding amount is paid
  • The amountPaid field reflects the actual amount applied to the invoice
  • If an invoice is already fully paid, the endpoint returns success with amountPaid: 0 and no payment records created
  • The invoice must have a valid storeId for the payment to be processed

Example Requests


Important Notes

Payment Processing

When paying customer debt (not a specific invoice), payments are distributed across invoices in chronological order (oldest first). Each invoice is paid up to its outstanding amount before moving to the next invoice.
  • Payment amounts are automatically capped at the outstanding balance
  • For customer debt payments, if the amount exceeds total debt, the excess is returned in remainingAmount
  • For invoice payments, if the amount exceeds outstanding, only the outstanding amount is paid
Each successful payment creates:
  • A paymentEntry record tracking the payment transaction
  • A paymentAllocation record linking the payment to the specific invoice
  • Both records are returned in the response for audit purposes
  • Invoices must belong to the specified customer
  • Invoices must have a valid storeId for payments to be processed
  • Deleted invoices are automatically excluded from all operations

Debt Calculation

Outstanding Amount

Calculated as: ttc - totalPaid
outstandingAmount = invoiceTotal - paymentsMade

Total Debt

Sum of all outstanding amounts across all invoices for a customer
totalDebt = Σ(outstandingAmount)

Data Filtering

  • Only non-deleted customers and invoices are included in results
  • Invoices with ttc (total tax included) of null are excluded
  • Customers with no outstanding debt are excluded from the customers list
  • Invoices are sorted by creation date (oldest first) for payment distribution

Summary

1

Get Customers with Debt

Use GET /debt/customers to retrieve all customers who have outstanding balances
2

View Customer Invoices

Use GET /debt/customers/:customerId/invoices to see all invoices and their payment status
3

Make Payment

Choose between:
  • Pay specific invoice: POST /debt/customers/:customerId/invoices/:invoiceId/pay
  • Pay customer debt: POST /debt/customers/:customerId/pay (distributes across invoices)
4

Verify Payment

Check the response to confirm payment amounts and remaining balances
This API provides comprehensive debt management for optical stores, enabling efficient tracking of customer balances, invoice management, and flexible payment processing options.

Customer API

Create and manage optical customers

POS Checkout API

Process point of sale transactions