Skip to main content

Matching captures and fees

View as Markdown (opens in a new tab)
Install AI tools

Give your assistant up-to-date guidance for our APIs, with our plugin or without it.

The plugin is still under development. See the AI tools page for details.

Run both commands, in order.

claude plugin marketplace add vippsas/agent-toolkit
claude plugin install vipps-developer@agent-toolkit

For troubleshooting, see the full instructions.

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.

LedgerentryTypepspReferencereference
fundscaptureUnique to this captureThe payment's reference
feescapture-feeSame as the capture it is charged forSame 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 for each type.

Worked example​

Funds ledger:

ledgerDateentryTypeamountreferencepspReference
2025-10-01capture10000purchase-123343121302
2025-10-01capture10000purchase-123334234112
2025-10-01capture20000purchase-143259823497

Fees ledger:

ledgerDateentryTypeamountreferencepspReference
2025-10-01capture-fee-400purchase-123343121302
2025-10-01capture-fee-400purchase-123334234112
2025-10-02capture-fee-450purchase-143259823497

Joining on pspReference gives:

pspReferencereferenceCapturedFeesNet
3343121302purchase-1210000-4009600
3334234112purchase-1210000-4009600
3259823497purchase-1420000-45019550

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. 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.
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.
  • 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​