> ## Documentation Index
> Fetch the complete documentation index at: https://docs.confidolegal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Confido Core

## Setup & Configuration

### 1. Confido Settings (Custom Setting)

`Settings__c` — Hierarchy Custom Setting. Configure at **Setup → Custom Settings → Confido Settings → Manage**.

| Field                  | API Name                   | Description                                                                               |
| :--------------------- | :------------------------- | :---------------------------------------------------------------------------------------- |
| Confido API Token      | `ApiToken__c`              | Your Confido API key. Required for all API calls.                                         |
| Confido Webhook Secret | `WebhookSecret__c`         | HMAC secret for verifying incoming webhooks.                                              |
| Production Environment | `ProductionEnvironment__c` | Checkbox. Checked = `api.gravity-legal.com`; unchecked = `api.sandbox.gravity-legal.com`. |

### 2. Remote Site Settings

Pre-configured; both active by default:

* **production** → `https://api.gravity-legal.com`
* **sandbox** → `https://api.sandbox.gravity-legal.com`

### 3. Webhook Configuration

Point your Confido webhook to:

```
https://<your-salesforce-domain>/services/apexrest/confido_core/webhook
```

The endpoint verifies the `X-SIGNATURE` header using HMAC-SHA512 with your `WebhookSecret__c`. Must be exposed via a Salesforce Site or Community (public REST resource).

### 4. Sync Bank Accounts

Bank accounts are managed in Confido, not Salesforce. Sync them before creating payment links using the LWC button or the invocable action.

***

### Client\_\_c

| Field                 | Description                                  |
| :-------------------- | :------------------------------------------- |
| `Name`                | Client name (synced to Confido)              |
| `ConfidoId__c`        | Text(36), unique external ID, auto-populated |
| `SyncErrorMessage__c` | Long Text, populated if last sync failed     |

### Matter\_\_c

| Field                 | Description          |
| :-------------------- | :------------------- |
| `Name`                | Matter name          |
| `Client__c`           | Lookup → Client\_\_c |
| `ConfidoId__c`        | Text(36), unique     |
| `SyncErrorMessage__c` | Long Text            |

### PaymentLink\_\_c

| Field                  | Description                                            |
| :--------------------- | :----------------------------------------------------- |
| `Name`                 | Descriptive name                                       |
| `BankAccount__c`       | Lookup → BankAccount\_\_c (destination)                |
| `Client__c`            | Lookup → Client\_\_c                                   |
| `Matter__c`            | Lookup → Matter\_\_c (optional)                        |
| `ConfidoId__c`         | Text(36), unique                                       |
| `OutstandingAmount__c` | Currency, amount still owed                            |
| `PaidAmount__c`        | Currency, amount paid so far                           |
| `Status__c`            | Picklist: `unpaid`, `partially_paid`, `paid`, `sealed` |
| `Url__c`               | URL, the shareable payment link                        |
| `SyncErrorMessage__c`  | Long Text                                              |

### Transaction\_\_c (auto-created via webhooks)

| Field               | Description                                                                                                                                                 |
| :------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Amount__c`         | Currency                                                                                                                                                    |
| `AmountRefunded__c` | Currency                                                                                                                                                    |
| `BankAccount__c`    | Lookup → BankAccount\_\_c                                                                                                                                   |
| `Client__c`         | Lookup → Client\_\_c                                                                                                                                        |
| `Matter__c`         | Lookup → Matter\_\_c                                                                                                                                        |
| `PaymentLink__c`    | Lookup → PaymentLink\_\_c                                                                                                                                   |
| `ConfidoId__c`      | Text(36), unique                                                                                                                                            |
| `CreatedOn__c`      | DateTime                                                                                                                                                    |
| `ErrorMessage__c`   | Text(255)                                                                                                                                                   |
| `LastFour__c`       | Text(255), last 4 of payment method                                                                                                                         |
| `Method__c`         | Picklist: `ACH`, `CARD`, `CREDIT`, `DEBIT`, `MANUAL`, `PUSH_TO_CARD`                                                                                        |
| `PayerEmail__c`     | Email                                                                                                                                                       |
| `PayerName__c`      | Text(255)                                                                                                                                                   |
| `Status__c`         | Picklist: `PENDING`, `SUCCESSFUL`, `DEPOSITED`, `FUNDS_IN_TRANSIT`, `REFUNDED`, `PARTIALLY_REFUNDED`, `RETURNED`, `VOIDED`, `ERROR`, `CHARGED_BACK`, `HELD` |
| `Type__c`           | Text(255), e.g. `payment`, `refund`, `return`                                                                                                               |

### BankAccount\_\_c (read-only from Confido)

| Field          | Description            |
| :------------- | :--------------------- |
| `Name`         | Nickname               |
| `Category__c`  | `operating` or `trust` |
| `ConfidoId__c` | Text(36), unique       |
| `IsDefault__c` | Checkbox               |
| `LastFour__c`  | Text(255)              |

### AggregateLink\_\_c

| Field                 | Description                       |
| :-------------------- | :-------------------------------- |
| `Name`                | Descriptive name                  |
| `ConfidoId__c`        | Text(36), unique                  |
| `PaymentLinkIds__c`   | Long Text, comma-separated SF IDs |
| `Url__c`              | URL                               |
| `SyncErrorMessage__c` | Long Text                         |

### AggregateLinkPaymentLink\_\_c

Junction object (Master-Detail on both sides), managed automatically.

### Platform Events

`WebhookPayload__e` and `TransactionPayload__e` — used internally for async webhook processing.

***

## Invocable Flow Actions

All available in Flow Builder under Action elements. They create/update both the Salesforce record and the corresponding Confido record.

### Create Client (`ClientCreate`)

* **Input:** `name` (String, required)
* **Returns:** `List<Client__c>`

### Update Client (`ClientUpdate`)

* **Input:** `clientId` (String, required), `name` (String, optional)
* **Returns:** `List<Client__c>`

### Create Matter (`MatterCreate`)

* **Input:** `clientId` (String, required), `name` (String, required)
* **Returns:** `List<Matter__c>`

### Update Matter (`MatterUpdate`)

* **Input:** `matterId` (String, required), `name` (String, required)
* **Returns:** `List<Matter__c>`

### Create Payment Link (`PaymentLinkCreate`)

* **Input:** `amount` (Decimal, required), `bankAccountId` (String, required), `clientId` (String, required), `matterId` (String, optional), `paymentLinkName` (String, optional)
* **Returns:** `List<PaymentLink__c>`

### Update Payment Link (`PaymentLinkUpdate`)

* **Input:** `paymentLinkId` (String, required), `amount` (Decimal), `bankAccountId` (String), `clientId` (String), `matterId` (String) — all optional except ID
* **Returns:** `List<PaymentLink__c>`

### Create Aggregate Link (`AggregateLinkCreate`)

* **Input:** `paymentLinkIds` (List\<String>, required), `aggregateLinkName` (String, optional)
* **Returns:** `List<AggregateLink__c>`

### Update Aggregate Link (`AggregateLinkUpdate`)

* **Input:** `aggregateLinkId` (String, required), `paymentLinkIds` (List\<String>, required — pass empty to delete)
* **Returns:** `List<AggregateLink__c>`

### Sync Bank Accounts (`BankAccountsSync`)

* **Input:** None
* Fetches all bank accounts from Confido and upserts/deletes `BankAccount__c` records to match.

***

## Lightning Web Components

All exposed to App Pages, Home Pages, and Flow Screens.

| Component                    | Description                                                                                  |
| :--------------------------- | :------------------------------------------------------------------------------------------- |
| `confidoSettings`            | Settings card                                                                                |
| `confidoClientCreate`        | Client creation form (Client Name)                                                           |
| `confidoMatterCreate`        | Matter creation form (Client picker + Matter Name)                                           |
| `confidoPaymentLinkCreate`   | Full payment link form (Name, Bank Account, Client, Matter, Amount). Displays resulting URL. |
| `confidoAggregateLinkCreate` | Aggregate link from multiple payment links (multi-select with pill container)                |
| `confidoAggregateLinkUpdate` | Update an aggregate link's payment links                                                     |
| `confidoBankAccountsSync`    | "Sync Bank Accounts" button, shows count of synced accounts                                  |
| `confidoTransactionsList`    | Read-only table of 10 most recent transactions                                               |

***

## Webhooks & Automatic Transaction Sync

### Flow

```
Confido webhook
  → WebhookListener (HMAC verify)
  → WebhookPayload__e
  → Handler fetches full transaction from API
  → TransactionPayload__e
  → Upserts Transaction__c + auto-creates related Client/Matter/PaymentLink if needed
```

### Supported Events

| Event                            | Behavior                              |
| :------------------------------- | :------------------------------------ |
| `transaction.created`            | Creates/updates the transaction       |
| `transaction.deposited`          | Updates status                        |
| `transaction.funds_in_transit`   | Updates status                        |
| `transaction.ach_returned`       | Updates original + creates return txn |
| `transaction.refunded`           | Updates original + creates refund txn |
| `transaction.partially_refunded` | Updates original + creates refund txn |
| `transaction.voided`             | Updates status                        |

> **Note:** Payout-type transactions and zero-amount transactions (e.g., trust surcharging) are auto-skipped.

***

## Trigger Sync Behavior

| Object             | Behavior                                                                                                                                               |
| :----------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Client__c`        | After Insert/Update: auto-syncs to Confido if no `ConfidoId` or Name changed                                                                           |
| `Matter__c`        | After Insert/Update: same pattern                                                                                                                      |
| `PaymentLink__c`   | After Insert/Update: syncs if no `ConfidoId` or amount/bank/client/matter changed. Before/After Delete: removes from aggregate links then from Confido |
| `AggregateLink__c` | After Insert/Update: syncs + re-creates junction records                                                                                               |

Sync errors are stored in `SyncErrorMessage__c` and cleared on the next successful sync.

***

## Quick Start Checklist

1. ☐ Install `confido_core` package
2. ☐ Set API Token in Custom Settings
3. ☐ Set Webhook Secret in Custom Settings
4. ☐ Check/uncheck Production Environment
5. ☐ Verify Remote Site Settings are active
6. ☐ Configure webhook URL in Confido
7. ☐ Expose `/webhook` endpoint via SF Site or Experience Cloud
8. ☐ Run Sync Bank Accounts
9. ☐ Create first Client, Matter, and Payment Link
10. ☐ Verify transactions flow in via webhooks

***

## Dependencies

* **Nebula Logger** — Package uses `Nebula.Logger` for logging. Install from: [https://github.com/jongpie/NebulaLogger](https://github.com/jongpie/NebulaLogger)
