# Repayments, refunds and write-offs

After disbursal, everything that changes what a borrower owes is a transaction on the loan. You post one with a command, and you read them back the same way you read any list.

## Before you start

- A disbursed loan: Transactions are posted against a loan that has been approved and disbursed. (https://developer.lokta.ai/guides/quickstart/)
- A user: With permission to post and adjust loan transactions. (https://developer.lokta.ai/api/roles-permissions/)
- The loan id: The commands below call it $LOAN_ID. It is the `loanId` returned when the loan was created.

## Set your environment

Every request authenticates with HTTP Basic and names its tenant in a header. Set these once and the commands below work as written.

```bash
export LOKTA_API="https://default.lokta.tech"
export LOKTA_USER="your-username"
export LOKTA_PASS="your-password"
```

## 1. Post a transaction

Send the command as a query parameter. The body carries the transactionDate and the transactionAmount, with dateFormat and locale.

[POST /v1/loans/{loanId}/transactions](https://developer.lokta.ai/api/loan-transactions/handle-commands-loan-transaction.md)

```bash
curl -X POST "$LOKTA_API/lokta-lms/api/v1/loans/$LOAN_ID/transactions?command=repayment" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "transactionDate": "03 October 2026",
    "transactionAmount": 1000,
    "dateFormat": "dd MMMM yyyy",
    "locale": "en"
  }'
```

## 2. Choose the command

These are the most used commands. The endpoint page lists every command it accepts.

- `repayment`: Make a repayment.
- `downPayment`: Record a down payment.
- `recoverypayment`: Make a recovery payment.
- `merchantIssuedRefund`: Merchant issued refund.
- `payoutRefund`: Payout refund.
- `goodwillCredit`: Goodwill credit.
- `chargeRefund`: Charge refund.
- `refundByCash`: Refund an active loan by cash.
- `creditBalanceRefund`: Refund a credit balance.
- `waiveinterest`: Waive interest.
- `writeoff`: Write off the loan.
- `undowriteoff`: Undo a write-off.
- `foreclosure`: Foreclose an active loan.
- `close`: Close the loan.
- `close-rescheduled`: Close a rescheduled loan.

## 3. List and inspect transactions

List a loan's transactions, then retrieve one to see its detail.

[GET /v1/loans/{loanId}/transactions](https://developer.lokta.ai/api/loan-transactions/retrieve-all-loan-transactions.md)

```bash
curl -X GET "$LOKTA_API/lokta-lms/api/v1/loans/$LOAN_ID/transactions" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default"
```

Note the id of the transaction you want to change. The next step calls it $TRANSACTION_ID.

## 4. Adjust a transaction

Post to the transaction itself with the corrected date and amount. There is no need to send a command parameter.

- `transactionDate`: Mandatory. The corrected date, sent with dateFormat and locale.
- `transactionAmount`: Mandatory. The corrected amount.

[POST /v1/loans/{loanId}/transactions/{transactionId}](https://developer.lokta.ai/api/loan-transactions/adjust-loan-transaction.md)

```bash
curl -X POST "$LOKTA_API/lokta-lms/api/v1/loans/$LOAN_ID/transactions/$TRANSACTION_ID" \
  -u "$LOKTA_USER:$LOKTA_PASS" \
  -H "Tenant-Identifier: default" \
  -H "Content-Type: application/json" \
  -d '{
    "transactionDate": "03 October 2026",
    "transactionAmount": 900,
    "dateFormat": "dd MMMM yyyy",
    "locale": "en"
  }'
```

## Where to go next

- [Quickstart](https://developer.lokta.ai/guides/quickstart/)
- [Handle errors](https://developer.lokta.ai/guides/handle-errors/)
