# From Provider to Ledger

Source: https://docs.formance.com/v4.0/modules/connectivity/from-provider-to-ledger

Stack: v4.0

This page follows one payment from a provider into Ledger, one stage at a time. Activity happens at the provider on its own schedule. The connection only reads it, and the connector's profile (its rules for turning provider records into Ledger entries) decides what each record becomes.

The example is fictional. It follows one pay-in from created to succeeded, then a balance that the provider reports. The accounts, Numscript, and fields are simplified to show the stages. To see what a real connector reads and records, open its [catalog entry](https://docs.formance.com/v4.0/modules/connectivity/connectors).

## Walkthrough

The connector profile tries these match rules in order; the first true rule selects the template.

- `PAYIN_CREATED` (transaction): `kind == "transition" && flow == "payin" && state == "created"`
- `PAYIN_AUTHORIZED` (transaction): `kind == "transition" && flow == "payin" && state == "authorized"`
- `PAYIN_SUCCEEDED` (transaction): `kind == "transition" && flow == "payin" && state == "succeeded"`
- `PAYIN_RELEASED` (transaction): `kind == "transition" && flow == "payin" && (state == "failed" || state == "cancelled")`
- `BALANCE_REPORTED` (metadata): `kind == "balance"`

### Pay-in created

- At the provider: Something happens in the provider's own systems. Formance is not part of it, and does not know yet what changed.
- Observe: The connection reads the provider's new objects. This one comes back as an observation: a pay-in of 1,250.00. The amount reads 125000 because USD/2 counts in cents.
- Match: Each template in the connector profile carries a match rule. The first rule that is true for the observation selects the template: here, PAYIN\_CREATED.
- Transform: The inputs are expressions over the observation. They build the amount, the addresses, a reference for this step, and metadata: provider facts, Formance's reading of the event, and values the connector derives.
- Record: The pay-in is not settled yet, so the money moves from the counterparty into a hold account. Holds are ephemeral: once their input equals their output, Ledger removes them.

Observation:

```text
kind = transition
flow = payin
state = created
previous_state = none
state_index = 0
transaction_id = pi-7f3a
account_id = acct-07
payment_method = card
asset = USD/2
amount = 125000
current_hold_position = 1
```

Selected template: `PAYIN_CREATED`. Reference: `pi-7f3a:0:created`.

```numscript
// the counterparty holds the offsetting balance
send [USD/2 125000] (
  source = @provider:acct-07:counterparty:main
  destination = @provider:acct-07:payin:pi-7f3a:hold:1
)
set_tx_meta("provider.example/payin-id", "pi-7f3a")
set_tx_meta("provider.example/payment-method", "card")
set_tx_meta("formance.com/observation.event-type", "provider.payin.created")
set_tx_meta("formance.com/accounting.transition", "to_transitional")
set_tx_meta("plugins.connectivity.formance.com/provider/derived.direction", "inbound")
```

### Pay-in authorized

- At the provider: The provider's systems change again. Until the connection reads, Formance cannot tell what changed or whether it matters.
- Observe: The read returns a new state for the same pay-in. Real lifecycles often pass through more states, each with its own template.
- Match: state == "authorized" now selects PAYIN\_AUTHORIZED. The created rule is tried first and no longer matches.
- Transform: The previous and current hold positions place the money: out of the first hold, into the second.
- Record: The whole hold balance moves to the second hold. In equals out on the first hold, so its balance is 0 and Ledger removes it. Its transactions stay in the history.

Observation:

```text
kind = transition
flow = payin
state = authorized
previous_state = created
state_index = 1
transaction_id = pi-7f3a
account_id = acct-07
payment_method = card
asset = USD/2
amount = 125000
current_hold_position = 2
```

Selected template: `PAYIN_AUTHORIZED`. Reference: `pi-7f3a:1:authorized`.

```numscript
send [USD/2 *] (
  source = @provider:acct-07:payin:pi-7f3a:hold:1
  destination = @provider:acct-07:payin:pi-7f3a:hold:2
)
set_tx_meta("provider.example/payin-id", "pi-7f3a")
set_tx_meta("provider.example/payment-method", "card")
set_tx_meta("formance.com/observation.event-type", "provider.payin.authorized")
set_tx_meta("formance.com/accounting.transition", "transition")
set_tx_meta("plugins.connectivity.formance.com/provider/derived.direction", "inbound")
```

### Pay-in succeeded

- At the provider: More activity at the provider. The connection only learns about it on its next read.
- Observe: The pay-in has succeeded.
- Match: PAYIN\_SUCCEEDED is the final step for a successful pay-in. A failed or cancelled one would select PAYIN\_RELEASED and return the money to the counterparty instead.
- Transform: The receiving account comes from the observation, so the funds land on acct-07.
- Record: The second hold drains into the provider account and is removed in turn. Every step is a transaction you can trace by its reference and metadata.

Observation:

```text
kind = transition
flow = payin
state = succeeded
previous_state = authorized
state_index = 2
transaction_id = pi-7f3a
account_id = acct-07
payment_method = card
asset = USD/2
amount = 125000
current_hold_position = 3
```

Selected template: `PAYIN_SUCCEEDED`. Reference: `pi-7f3a:2:succeeded`.

```numscript
send [USD/2 *] (
  source = @provider:acct-07:payin:pi-7f3a:hold:2
  destination = @provider:acct-07:main
)
set_tx_meta("provider.example/payin-id", "pi-7f3a")
set_tx_meta("provider.example/payment-method", "card")
set_tx_meta("formance.com/observation.event-type", "provider.payin.succeeded")
set_tx_meta("formance.com/accounting.transition", "to_final")
set_tx_meta("plugins.connectivity.formance.com/provider/derived.direction", "inbound")
```

### Balance reported

- At the provider: The provider updates its own view of the account. Again, Formance only finds out by reading.
- Observe: The provider reports an available balance of 4,980.00 on acct-07. Compare the matching Ledger position using the same scope, time, sign convention, and reporting precision.
- Match: No transaction template matches, so the profile tries its metadata rules, and BALANCE\_REPORTED matches.
- Transform: This balance observation creates no postings. The illustrative fields record its amount, asset, and provider time. Later observations refresh these values.
- Record: The provider reports 3,730.00 more than the postings add up to. Ledger does not adjust for the gap. To explain it, check the opening position, the recorded activity, and how recent each value is.

Observation:

```text
kind = balance
account_id = acct-07
asset = USD/2
available = 498000
reported_at = 2026-10-08T09:00:00Z
```

Selected template: `BALANCE_REPORTED`.

Account metadata:

```json
{
  "address": "provider:acct-07:main",
  "reportedBalance": 498000,
  "entries": [
    [
      "provider.example/balance.reported-amount",
      "498000"
    ],
    [
      "provider.example/balance.reported-asset",
      "USD/2"
    ],
    [
      "provider.example/balance.reported-at",
      "2026-10-08T09:00:00Z"
    ]
  ]
}
```

## What happens at each stage

At the provider

A payment is created, a status changes, a statement is issued. All of this happens in the provider's systems without Formance taking part. Formance learns about it only when the connection reads.

Observe

The connection reads new activity with the access you configured: API resources, events, files, or snapshots. Each item it reads is an observation, one provider fact such as a status change or a reported balance. The connection never writes to the provider.

Match

The profile works out what kind of fact the observation is, such as a payment status change or a reported balance, and picks the rule that handles it.

Transform

The rule computes what Ledger needs: the amount in the asset's smallest unit, the account addresses, a unique reference, and the metadata to attach.

Record

Ledger writes the result as a transaction or as account metadata. Each transaction carries its unique reference, so a retry never records the same step twice.

## What a connector profile holds

A profile has three parts: a chart of accounts, transaction templates for records that move value, and metadata rules for records that only add information.

How this example is mapped

A profile can create a transaction, update metadata, or do both for one observation. In this example, each payment status is handled by the first transaction template whose rule matches. The reported balance is handled by a separate metadata rule, which runs no Numscript.

Input expressions read the observation's fields and build exact integer amounts, account addresses, a unique reference, and metadata. The chart of accounts defines the addresses that templates and metadata rules can use.

```mermaid
flowchart LR
  Profile["Connector profile"] --> Templates["Transaction templates"]
  Templates --> TMatch["Match rule"] --> Inputs["Inputs"] --> Numscript["Numscript"]
  Profile --> Rules["Metadata rules"]
  Rules --> RMatch["Match rule"] --> AccountMetadata["Account metadata"]
  Profile --> Chart["Chart of accounts"]
```

Ledger applies each batch atomically. A posting moves an asset between two accounts and updates their input and output volumes. An account's balance is its input minus its output. Money still in flight sits in hold accounts of an ephemeral type. When a hold's input equals its output, Ledger removes the account and keeps its transactions in the history.

The example labels each metadata value by who stands behind it: the provider, the connector's reading of the event, or the recording itself. [What metadata tells you](https://docs.formance.com/v4.0/modules/connectivity/what-it-models#what-metadata-tells-you) describes these categories and what to expect from your own connection.

## Reported balances

The last observation in the example is a balance that the provider reports. The connection stores it as account metadata and posts nothing. The reported figure sits next to the balance Ledger builds from postings without changing it, and each later report replaces the stored value.

In the example the two figures differ by 3,730.00. Ledger does not adjust for a gap like this one. Before you draw a conclusion, check that both figures cover the same accounts at the same point in time, that Ledger has the opening position, and that the reported value is recent. A read that failed leaves the previous value in place. It does not mean the balance is zero.

[Two views of a balance](https://docs.formance.com/v4.0/modules/connectivity/what-it-models#two-views-of-a-balance) walks through the comparison.

## The same stages for every provider

Every connector runs these stages. What changes from one connector to the next is what it reads and the Ledger model it builds. The catalog documents both.

[What Connectivity Models](https://docs.formance.com/v4.0/modules/connectivity/what-it-models)

How accounts, transactions, and metadata represent provider activity.

[How Connectivity Works](https://docs.formance.com/v4.0/modules/connectivity/how-it-works)

Saved progress, retries, and what happens when you restart or change a connection.

[Connector Catalog](https://docs.formance.com/v4.0/modules/connectivity/connectors)

Each connector's coverage, Ledger model, and configuration.
