# postOutgoingPayment

## Overview

Posts a **DRAFT** outgoing payment to the general ledger, transitioning the `OutgoingPayment` from DRAFT to POSTED. The native command resolves the accounting period for the payment date, builds a **balanced `JournalEntry`** — debiting the payable control account and crediting the cash/bank payment account for the settled amount, direction-aware when the payment settles credit memos as well as invoices (erp-kit 0.51) — and posts it directly in financial-accounting within the same transaction. The entry carries `sourceDocumentType = OUTGOING_PAYMENT` and `sourceDocumentId` equal to the payment id. Posting also applies each settlement against its target `AccountPayableDueScheduleLine`, reducing that open item's balance. It rejects over-settlement (paying more than a line's open balance), a total that does not reconcile with the settlements, ineligible targets (for example an invoice that is not itself posted), and a payment currency that differs from the company base currency.

## Modules Commands Used

- [account-payable] postOutgoingPayment

## Exception Handling

| Error Code | Description |
| --- | --- |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_NOT_FOUND | No outgoing payment exists for the given ID. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_INVALID_STATUS | The payment is not in DRAFT status; only DRAFT payments can be posted. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_OVER_SETTLEMENT | A settlement exceeds the open balance of its target due-schedule line. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_TOTAL_MISMATCH | The payment total does not reconcile with the sum of its settlements. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_TARGET_INELIGIBLE | A settlement target is not eligible (for example, the invoice is not posted). |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_INVALID_AMOUNT | The payment amount is not a positive value. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_ACCOUNTING_PERIOD_NOT_FOUND | No accounting period covers the payment date. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_JOURNAL_ENTRY_CREATE_FAILED | The journal entry could not be created. |
| ACCOUNT_PAYABLE_OUTGOING_PAYMENT_JOURNAL_ENTRY_POST_FAILED | The journal entry could not be posted to the general ledger. |
