> For the complete documentation index, see [llms.txt](https://cde-inc.gitbook.io/cde-cad-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cde-inc.gitbook.io/cde-cad-documentation/rest-api/banking-api.md). Agents can also search and read this documentation through its [MCP server](https://cde-inc.gitbook.io/cde-cad-documentation/~gitbook/mcp).

# Banking API

The Banking API manages civilian bank accounts, transactions, and fund transfers within your community. All banking endpoints require authentication and a valid community context.

***

{% hint style="info" %}
**Required Headers**

```
Authorization: Bearer <token>
x-community-id: <communityId>
```

{% endhint %}

## Get Bank Account

Retrieve the bank account details and current balance for a civilian.

{% hint style="success" %}
**GET →** /banking/account/:civilianId
{% endhint %}

|               |                |                          |
| ------------- | -------------- | ------------------------ |
| **Parameter** | **Type**       | **Description**          |
| `civilianId`  | URL param      | The civilian's unique ID |
| `communityId` | Query / Header | Community scope          |

**Response:**

```
{
  "balance": 12500.00,
  "civilianId": "abc123",
  "communityId": "comm456",
  "createdAt": "2025-06-15T10:30:00Z"
}
```

## Deposit Funds

Add funds to a civilian's bank account. Requires a description for the transaction record.

{% hint style="info" %}
**POST →** /banking/deposit
{% endhint %}

**Request Body:**

```
{
  "civilianId": "abc123",
  "amount": 5000.00,
  "description": "Paycheck - Los Santos PD",
  "communityId": "comm456"
}
```

|               |          |              |                                |
| ------------- | -------- | ------------ | ------------------------------ |
| **Field**     | **Type** | **Required** | **Description**                |
| `civilianId`  | string   | Yes          | Target civilian ID             |
| `amount`      | number   | Yes          | Deposit amount (must be > 0)   |
| `description` | string   | Yes          | Transaction description / memo |
| `communityId` | string   | Yes          | Community scope                |

## Withdraw Funds

Withdraw funds from a civilian's bank account. Returns an error if insufficient balance.

{% hint style="info" %}
**POST →** /banking/withdraw
{% endhint %}

**Request Body:**

```
{
  "civilianId": "abc123",
  "amount": 250.00,
  "description": "ATM withdrawal",
  "communityId": "comm456"
}
```

## Transfer Funds

Transfer money between two civilian accounts within the same community.

{% hint style="info" %}
**POST →** /banking/transfer
{% endhint %}

**Request Body:**

```
{
  "fromCivilianId": "abc123",
  "toCivilianId": "def789",
  "amount": 1000.00,
  "description": "Rent payment",
  "communityId": "comm456"
}
```

|                  |          |              |                               |
| ---------------- | -------- | ------------ | ----------------------------- |
| **Field**        | **Type** | **Required** | **Description**               |
| `fromCivilianId` | string   | Yes          | Sender's civilian ID          |
| `toCivilianId`   | string   | Yes          | Recipient's civilian ID       |
| `amount`         | number   | Yes          | Transfer amount (must be > 0) |
| `description`    | string   | Yes          | Transaction memo              |
| `communityId`    | string   | Yes          | Community scope               |

{% hint style="info" %}
**Transfer Validation**

Transfers validate that the sender has sufficient funds and that both civilians belong to the same community. The sender and recipient cannot be the same civilian.
{% endhint %}

## Get Transaction History

Retrieve the full transaction history for a civilian's bank account, ordered by most recent first.

{% hint style="success" %}
**GET →** /banking/transactions/:civilianId
{% endhint %}

**Response:**

```
{
  "transactions": [
    {
      "type": "deposit",
      "amount": 5000.00,
      "description": "Paycheck - Los Santos PD",
      "balanceAfter": 12500.00,
      "createdAt": "2025-06-15T10:30:00Z"
    },
    {
      "type": "transfer_out",
      "amount": 1000.00,
      "description": "Rent payment",
      "balanceAfter": 7500.00,
      "createdAt": "2025-06-14T18:00:00Z"
    }
  ]
}
```

|                      |                                         |
| -------------------- | --------------------------------------- |
| **Transaction Type** | **Description**                         |
| `deposit`            | Funds added to account                  |
| `withdrawal`         | Funds removed from account              |
| `transfer_in`        | Incoming transfer from another civilian |
| `transfer_out`       | Outgoing transfer to another civilian   |
| `fine`               | Judicial fine deduction                 |

{% hint style="warning" %}
**Security Note**

Banking operations are scoped to the authenticated user's permissions. Civilians can only access their own accounts. Administrative operations such as issuing fines require appropriate judicial or admin roles.
{% endhint %}
