Sub topic 15
Reconciling with PSP and bank reports
This chapter assumes you know the payment lifecycle, the double-entry ledger, and basic SQL and Python from earlier chapters.
Why reconciliation exists
Reconciliation is the process of comparing your internal records with reports from outside parties and investigating every difference. Your ledger says what you believe happened. The PSP (payment service provider) and the bank say what they believe happened. Timeouts, dropped webhooks, bugs, and manual operations can make these views diverge. Reconciliation finds the divergence before a merchant or an auditor does.
The three sources
| Source | Question it answers | Typical format |
|---|---|---|
| Internal ledger | What do we think happened? | Database tables |
| PSP settlement report | What did the PSP process and how much does it owe us? | CSV or API, usually daily |
| Bank statement | What money actually arrived? | CAMT.053, MT940, or CSV |
Matching internal records to the PSP report is the first step. Matching the PSP's payout totals to bank deposits is the second. Together they form a three-way reconciliation.
Matching transactions
Match on a stable identifier, such as the PSP's transaction reference that you stored when you called the PSP. Never match on amount and time alone, because many payments share both. Then classify each difference:
- Missing at the PSP: you recorded a capture the PSP has no record of.
- Missing internally: the PSP captured money you never recorded, often after a lost response.
- Amount or currency mismatch: the two sides disagree on the value.
- Status mismatch: for example, you show
capturedand the PSP showsvoided.
def reconcile(internal, psp):
"""Both arguments map psp_ref -> (amount_minor, currency)."""
exceptions = []
for ref, record in internal.items():
if ref not in psp:
exceptions.append((ref, "missing_at_psp"))
elif psp[ref] != record:
exceptions.append((ref, "value_mismatch"))
for ref in psp.keys() - internal.keys():
exceptions.append((ref, "missing_internally"))
return sorted(exceptions)
internal = {"ch_1": (1999, "USD"), "ch_2": (500, "USD")}
psp = {"ch_1": (1999, "USD"), "ch_2": (550, "USD"), "ch_3": (700, "USD")}
print(reconcile(internal, psp))This prints [('ch_2', 'value_mismatch'), ('ch_3', 'missing_internally')].
Matching payouts
A PSP pays you in batches, net of fees and refunds. For each payout, check that gross captures minus fees minus refunds equals the payout amount, then find a bank deposit with that amount. Settlement takes days, so a payment can be correctly absent from today's report. Track expected settlement dates and flag only items that are overdue.
Handling exceptions
- Do not edit or delete ledger entries to make numbers agree. Post a correcting entry that references the original.
- Retry the transition when a status mismatch comes from a missed webhook. Fetch the PSP's current state and apply it through the state machine.
- Send unresolved items to a queue with an owner and an age, and alert when items grow old.
- Make the job idempotent and keyed by report date, so you can rerun it safely.
Exercise
Your ledger shows a captured payment, but the PSP report lists no matching reference two days later. Name two possible causes and the first action to take.
Show answer
The capture request may have timed out before the PSP processed it, or the payment may still be within the PSP's settlement delay. First query the PSP's API for the payment's current status using your stored reference. Apply the result through the state machine, and post a correcting ledger entry if the capture never happened.