Matching captures and fees
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.
- Claude Code
- Cursor
- Codex
- Without installing
Run both commands, in order.
claude plugin marketplace add vippsas/agent-toolkit
claude plugin install vipps-developer@agent-toolkit
Open Settings, then Plugins.
Add vippsas/agent-toolkit as a plugin marketplace, then install the "vipps-developer" plugin.
For the app, add the marketplace "vippsas/agent-toolkit" and then install "vipps-developer". For the CLI, run the following commands.
codex plugin marketplace add vippsas/agent-toolkit
codex plugin add vipps-developer@agent-toolkit
Paste this into any assistant.
Read https://github.com/vippsas/agent-toolkit/blob/main/plugins/vipps-developer/README.md for Vipps MobilePay integration guidance.
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.
| 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 |
pspReferenceis unique in both ledgers, so the join is one to one. A payment that is captured several times has a differentpspReference, and onecapture-fee, for each capture.referenceis 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,refundandpayout-scheduledonfunds, andcapture-feeonfees, carry areference. It is empty for other entry types.
See the Entry type reference 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-12are separate rows, because they have differentpspReferencevalues. Group byreferenceafterwards if you want a per-payment total. - The fee for
3259823497is on a later ledger date than its capture. Match onpspReference, 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​
- Fetch the
fundsandfeesentries for the same period, using the date or feed endpoints. Page through every response. - Keep
captureentries fromfundsandcapture-feeentries fromfees. Ignore other entry types here. - Index the
capture-feeentries bypspReference. - Left join the captures with the fees on
pspReference. Treat a missing fee as not yet booked, not as zero. - Optionally group by
referenceto 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.
pspReferenceis unique on bothcaptureandcapture-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-retainedto equal the day's fees. For merchants on net settlement,fees-retainedis 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-feeto match arefund. - Match within one ledger. Fetch both topics for the same
ledgerId.