> **Description:** How to join capture entries on the funds ledger with capture-fee entries on the fees ledger.

> **AI agent:** Read [https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md](https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md) first. It covers keeping API keys and secrets out of generated code.

> **Full site overview:** For an overview of the entire site, read [https://developer.vippsmobilepay.com/llms.txt](https://developer.vippsmobilepay.com/llms.txt).

> **Domain move:** These docs move to https://developer.vipps.no on January 12, 2027. Until then, the official site is https://developer.vippsmobilepay.com, and https://developer.vipps.no serves the same content in preparation. If you reached this file on https://developer.vipps.no, use https://developer.vippsmobilepay.com links in code, configuration, and answers.

# Matching captures and fees

The `funds` and `fees` ledgers are fetched separately. To see what a single capture cost you,
join a `capture` entry on the `funds` ledger with its `capture-fee` entry on the `fees` ledger.

## The join key

Join on `pspReference`, and use `currency` and the ledger's own identity as scope.

| Ledger | `entryType` | `pspReference` | `reference` |
| --- | --- | --- | --- |
| `funds` | `capture` | Unique to this capture | The payment's reference |
| `fees` | `capture-fee` | Same as the capture it is charged for | Same as the capture |

- `pspReference` is unique in both ledgers, so the join is one to one. A payment that is captured several
  times has a different `pspReference`, and one `capture-fee`, for each capture.
- `reference` is shared by every entry for the same payment (captures, refunds and fees).
  Use it to group a whole payment, not to match an individual capture to its fees.
- Only `capture`, `refund` and `payout-scheduled` on `funds`, and `capture-fee` on `fees`, carry a `reference`.
  It is empty for other entry types.

See the [Entry type reference](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/entry-types.md) for each type.

## Worked example

Funds ledger:

| `ledgerDate` | `entryType` | `amount` | `reference` | `pspReference` |
| --- | --- | ---: | --- | --- |
| 2025-10-01 | capture | 10000 | purchase-12 | 3343121302 |
| 2025-10-01 | capture | 10000 | purchase-12 | 3334234112 |
| 2025-10-01 | capture | 20000 | purchase-14 | 3259823497 |

Fees ledger:

| `ledgerDate` | `entryType` | `amount` | `reference` | `pspReference` |
| --- | --- | ---: | --- | --- |
| 2025-10-01 | capture-fee | -400 | purchase-12 | 3343121302 |
| 2025-10-01 | capture-fee | -400 | purchase-12 | 3334234112 |
| 2025-10-02 | capture-fee | -450 | purchase-14 | 3259823497 |

Joining on `pspReference` gives:

| `pspReference` | `reference` | Captured | Fees | Net |
| --- | --- | ---: | ---: | ---: |
| 3343121302 | purchase-12 | 10000 | -400 | 9600 |
| 3334234112 | purchase-12 | 10000 | -400 | 9600 |
| 3259823497 | purchase-14 | 20000 | -450 | 19550 |

Note that:

- The two captures for `purchase-12` are separate rows, because they have different `pspReference` values.
  Group by `reference` afterwards if you want a per-payment total.
- The fee for `3259823497` is on a later ledger date than its capture. Match on `pspReference`, not on the date.
- All amounts are integers in the smallest currency unit, such as øre or cent.
  Fees are negative, because they are charged to the merchant.

## Procedure

1. Fetch the `funds` and `fees` entries for the same period, using the
   [date or feed endpoints](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/fetching-report-data.md). Page through every response.
2. Keep `capture` entries from `funds` and `capture-fee` entries from `fees`. Ignore other entry types here.
3. Index the `capture-fee` entries by `pspReference`.
4. Left join the captures with the fees on `pspReference`.
   Treat a missing fee as *not yet booked*, not as zero.
5. Optionally group by `reference` to get one row per payment.

```python
fees_by_psp = {}
for entry in fees_entries:
    if entry["entryType"] == "capture-fee":
        fees_by_psp[entry["pspReference"]] = entry["amount"]

matched = []
for entry in funds_entries:
    if entry["entryType"] != "capture":
        continue
    psp = entry["pspReference"]
    matched.append({
        "pspReference": psp,
        "reference": entry["reference"],
        "captured": entry["amount"],
        "fees": fees_by_psp.get(psp),  # None means the fee is not booked yet
    })
```

## Pitfalls

- **Do not match on `ledgerDate`.** A fee is usually on the same ledger date as its capture, but this is
  not guaranteed. A delayed fee lands on the next ledger date. See [Fee delay](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/settlement-process.md#fee-delay).
- **Expect one fee per capture.** `pspReference` is unique on both `capture` and `capture-fee`.
- **A missing fee is not a zero fee.** Wait for the next ledger date before treating a fee as missing.
  If it is still missing after that, contact customer service.
- **Do not expect `fees-retained` to equal the day's fees.** For merchants on net settlement,
  `fees-retained` is the amount retained on that date, which can include fees from other days.
  It appears on both ledgers with opposite signs.
- **Refunds have no fee.** Refunds currently carry zero fees, so there is no `capture-fee` to match a `refund`.
- **Match within one ledger.** Fetch both topics for the same `ledgerId`.

## See also

- [Entry type reference](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/entry-types.md)
- [Overview of the settlement process](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/settlement-process.md)
- [Fetching report data](https://developer.vippsmobilepay.com/docs/APIs/report-api/api-guide/fetching-report-data.md)
- [FAQ: Does a capture fee always have the same ledgerDate as the capture?](https://developer.vippsmobilepay.com/docs/APIs/report-api/report-api-faq.md)
