# reverseIncomingPayment

## Overview

Reverses a **POSTED** incoming payment, transitioning the `IncomingPayment` from POSTED to REVERSED. The native command posts an **exact reversing `JournalEntry`** dated `reversalDate` (resolving the accounting period for that date), releases the payment's settlement allocations so the previously-settled `AccountReceivableDueScheduleLine` items become open again, and stamps the payment REVERSED — all in the same transaction. The original journal entry is never deleted, so the full audit trail is preserved. Use this to undo a payment posted in error. A DRAFT payment cannot be reversed (cancel it with [cancelIncomingPayment](./cancelIncomingPayment.md) instead), and a payment that has already been reversed is rejected.

## Modules Commands Used

- [account-receivable] reverseIncomingPayment

## Exception Handling

| Error Code | Description |
| --- | --- |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_NOT_FOUND | No incoming payment exists for the given ID. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_INVALID_STATUS | The payment is not in POSTED status; only POSTED payments can be reversed. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_ALREADY_REVERSED | The payment has already been reversed. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_REVERSAL_NOT_ALLOWED | The payment cannot be reversed in its current state. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_ACCOUNTING_PERIOD_NOT_FOUND | No accounting period covers the reversal date. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_JOURNAL_ENTRY_CREATE_FAILED | The reversing journal entry could not be created. |
| ACCOUNT_RECEIVABLE_INCOMING_PAYMENT_JOURNAL_ENTRY_POST_FAILED | The reversing journal entry could not be posted. |
