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

# Test and go live with fundings

> Know your fundings integration is ready before your first production funding

Use this page twice: once while you test fundings in sandbox, and again before your first real funding. The calls that move a funding in sandbox are on [Move objects and trigger events in sandbox](https://docs.lead.bank/v2/get-started/sandbox/advance-and-simulate.md). [Program launch](https://docs.lead.bank/get-started/program-launch.md) has the milestones for the whole program, and the [Fundings overview](https://docs.lead.bank/v2/products/fundings/overview.md) explains what a funding is.

## What sandbox can do for fundings

In sandbox, a funding has one transition, and you make it yourself with the advance call, `POST /v2/simulate/fundings/{funding_id}/advance`, which moves one of your own objects to the status you name.

| From | `next_status` | To | Webhook |
| - | - | - | - |
| `processing` | `posted` | `posted` | `funding.posted` |

The advance call moves the funding to `posted`, and Lead posts the `funding` user credit transaction, as it would in production. To see the result, retrieve the funding. If funding events are enabled for your program (your Technical Account Manager can tell you), Lead also sends `funding.posted`. The event names the funding without carrying it, so you still retrieve it to read the result. See [Webhooks & Events](https://docs.lead.bank/api-reference/using-the-api/webhooks-v2.md).

There are no outside events to trigger for a funding (no simulate scenarios), because nothing outside Lead acts on one.

## What sandbox doesn't do for fundings

Three things a posted funding does in production don't happen in sandbox:

* Move money. A funding posted in sandbox has no `core_transaction_id`. In production it names the core transaction that moved the money.
* Change core balances. Core balances and core transactions return fixed sample data in sandbox. See [Core objects in sandbox](https://docs.lead.bank/products/banking-infrastructure/sandbox.md), in the shared API section.
* Post a funding on its own. A new funding stays `processing` until you move it.

## Test run

Run these in order against `https://api.sandbox.lead.bank`. Each item ends with what to check before you move on.

1. Get an access token with `entity/read_write`, `application/read_write`, `user_account/read_write`, `user_credit_balance/read_write`, and `funding/read_write`. Each scope is listed on [Authentication](https://docs.lead.bank/api-reference/using-the-api/authentication.md#available-scopes).

   **Confirm:** the response is `200` with an `access_token`. If your program isn't set up for one of the scopes, the request fails with `insufficient_scope` instead.

2. Create an entity, an application, and a user account with a credit feature. Then create a `non_revolving` user credit balance. [Originate your first loan](https://docs.lead.bank/v2/get-started/quickstart/originate-your-first-loan.md) has each payload.

   **Confirm:** the user credit balance is `active`, and you have the ID of the account number Lead enabled for fundings.

3. Create a funding with `POST /v2/fundings` and an `Idempotency-Key` header. Store the funding ID.

   **Confirm:** `status` is `processing`.

4. Move it to `posted` with the advance call, `POST /v2/simulate/fundings/{funding_id}/advance`, a new `Idempotency-Key`, and `{"next_status": "posted"}`.

   **Confirm:** `200` with an empty object.

5. Retrieve the funding.

   **Confirm:** `status` is `posted`. If funding events are enabled for your program, a `funding.posted` webhook arrived too.

6. Retrieve the user credit balance. The `funding` user credit transaction can post a few seconds after the funding does, so retry if `amount_breakdown.principal` hasn't changed yet.

   **Confirm:** `amount_breakdown.principal` includes the funding's `amount`.

7. Call advance on the same funding again, with a new `Idempotency-Key`.

   **Confirm:** `422` with `object_state_mismatched`, and the funding doesn't change.

8. Repeat item 3 with the same `Idempotency-Key` and the same body.

   **Confirm:** the response is the one from item 3, with `status` still `processing` and the header `Idempotency-Replayed: true`. The funding itself is still `posted`.

9. Create a second funding on the same balance with an `amount` larger than the remaining room under `terms.max_funding_amount`.

   **Confirm:** `422` with `limit_exceeded`, and no funding is created.

## Before you go live

Before your first production funding, make sure that:

* Know which account number Lead has enabled to receive your fundings. Your Technical Account Manager can tell you.
* Get a production token with the `funding/read_write` scope.
* Store every funding ID when you create it. There's no endpoint to list fundings. To reconcile later, use the stored IDs, or list the user credit transactions with a `funding_id`.
* Retrieve the funding and confirm `status` is `posted` before you send the money on to the borrower. A `200` on create means Lead accepted the funding, not that the money moved. The `funding` user credit transaction can arrive a few seconds later.

The rest of the go-live checklist is on [Program launch](https://docs.lead.bank/get-started/program-launch.md).

## Related

* [Move objects and trigger events in sandbox](https://docs.lead.bank/v2/get-started/sandbox/advance-and-simulate.md): the two sandbox-only calls, their rules, and their errors
* [Fundings overview](https://docs.lead.bank/v2/products/fundings/overview.md): what a funding is and where it fits in a lending integration
* [Funding statuses](https://docs.lead.bank/v2/products/fundings/statuses.md): the two statuses and how to tell when money moved
* [Originate and service an on-sheet loan](https://docs.lead.bank/v2/guides/lend/on-sheet-loan-origination-and-servicing.md): the full lending flow a funding belongs to
* [Program launch](https://docs.lead.bank/get-started/program-launch.md): the milestones from kickoff through sandbox testing to go-live
