Skip to content

Overweights Chargeback API

API for applying chargeback from the Overweights screen. The existing PUT /overweights/ticket/:id is unchanged and is not used for chargeback.

POST /overweights/chargeback

Applies chargeback to one or more compensations (provisional refunds). For each compensation: debits the client balance, sets the ticket to Rejected, adds comment and history with the reason, updates the compensation to CHARGEBACK and carrier_payment_status to UNPAID, and creates an audit record.

Authentication

  • Strategy: token_admin

Payload

FieldTypeRequiredDescription
compensation_idsnumber[]YesList of compensation ids. Each must exist, belong to a ticket with status Solved (ACCEPTED), and have compensation status ACCEPTED.
review_commentstringYesReason for the chargeback (stored in ticket comment and history).

Request example

Bulk chargeback:

json
{
  "compensation_ids": [101, 102, 103],
  "review_comment": "Carrier confirmed refund incorrect; reversing per report."
}

Individual chargeback: send a single-element array, e.g. "compensation_ids": [101].

Validation (backend)

  • compensation_ids: required, non-empty array of numbers.
  • review_comment: required, non-empty string.
  • For each compensation_id:
    • Compensation must exist.
    • Associated ticket must have ticket_status_id === TICKET_STATUS.ACCEPTED (Solved).
    • Compensation must have status === REFUNDS_STATUS.ACCEPTED.
  • If any validation fails for an id, return 400 with a clear message (e.g. "Compensation not found or not eligible for chargeback").

Success response

  • Status: 200
  • Body: { "data": true } (or, if implementation returns per-item results, an object with success/failure counts or per-id status).

Error responses

StatusCondition
400Missing or invalid payload; or one or more compensation_ids not found / not eligible (ticket not Solved or compensation not ACCEPTED).
401Missing or invalid auth.

Behavior summary

For each valid compensation_id:

  1. Debit client balance by the compensation's approved amount (via existing chargeback logic).
  2. Create surcharge (NEGATIVE) for the chargeback.
  3. Update compensation: status → CHARGEBACK, carrier_payment_status → UNPAID, and chargeback fields.
  4. Update ticket: ticket_status_id → DECLINED.
  5. Insert ticket comment and ticket history with review_comment.
  6. Create audit record (e.g. compensations_history or adjustments module).

GET /overweights (response change)

To support chargeback in the UI, the overweights list may include per-row data when the ticket is Solved:

FieldTypeDescription
compensation_idnumberPresent when the row's ticket has status ACCEPTED and there is an accepted compensation for that ticket. Frontend uses this to build compensation_ids for POST /overweights/chargeback.
compensation_statusstringOptional; if needed for UI to show only ACCEPTED rows as eligible.

Envia Admin