Skip to main content
In this tutorial you build a daily payment reconciliation. The procedure compares the payments your policy system recorded for one day with your payment processor’s settlement report for that day. For each mismatch it checks whether the processor’s webhook to your policy system failed. If it did, the procedure resends the event once, waits until the payment is recorded and checks the recorded amount. Mismatches it can’t explain go to a person. When nothing is on hold, it pays out the day’s balance.

What this does for your team

Every day, the payments your processor settled should match the payments your policy system recorded. The procedure does that comparison for one day. When a payment is missing because the processor’s notification never reached your policy system, it resends that notification and checks the amount that arrives. Finance operations sees only the mismatches the procedure can’t explain, with both amounts in front of them. The day’s payout goes out only when nothing is on hold, under a key built from the date, so reconciling the same day twice doesn’t pay it out twice with a processor that honours the key. The run records each mismatch, what was done about it, and who explained it. The example carrier is Northwind Mutual. Its hosts, policy numbers, payments and amounts are made up; replace them with your own.

Before you start

You need:
  • An API key for a member who is not read-only, and curl and jq. See Run procedures from your system, which also covers publishing and starting runs. A draft also needs permission to create procedures, or to publish this one once it exists. Resource-scoped and app API keys can’t start drafts.
  • A group in Effective for the people who look into payment mismatches. The procedure assigns its task to group:finance-operations; replace that with your group.
  • HTTPS APIs for your payment processor and policy system. The procedure’s code calls these endpoints; change the hosts, paths and field names to match yours:
Two behaviors keep a repeated write from applying twice. Your policy system must record at most one payment per webhook event ID, however many times the event arrives. Your processor’s payout endpoint must accept an Idempotency-Key header and answer a repeated key with its first payout.

The procedure

Save this as reconcile-payments.procedure.md. The sections after it walk through each part.
reconcile-payments.procedure.md

How it works

Input and output

The procedure takes one input, settlement_date, a YYYY-MM-DD date. Its output, reconciliation, says whether the day was paid-out or held, how many payments matched, the day’s balance in payoutCents, and one outcome for each mismatch.

Read both sides

read-settlement and read-recorded-payments are call nodes. Each runs a local effect, a ts effect you write and publish with the procedure. Each effect declares the one secret it uses, payments-token or policy-system-token; the values are never in the source. Both effects check the shape of what they read and return it in a fixed shape, so the rest of the procedure works on typed data. See Functions and effects. A 4xx answer other than 429 throws FatalError and fails the run at once, because another attempt can’t change it. A 429, a 5xx answer or a network error throws an ordinary error, which is retried. Reads change nothing, so retrying them is always safe. When an effect fails the run, the run’s failure names the step and its code, but not the message the effect threw: Effective doesn’t show thrown messages, because they could hold secret values. Look in the system that answered for why it refused. Anything the procedure has to act on belongs in a typed result instead, as get-webhook-delivery returns cause.

Compare them

compare-payments calls match-payments, a pure ts function. It gets only its input, with no network, secrets or clock, so the same two lists always give the same comparison. It matches payments by ID and returns the count that matched, plus one entry for each mismatch:
  • not-recorded: the processor settled the payment, but your policy system has no record of it.
  • amount-differs: both have it, with different amounts.
  • not-settled: your policy system recorded it, but it isn’t in the settlement report.
Amounts stay in whole cents. Each mismatch carries the settled amount as settledCents, or null when the processor didn’t settle the payment. It also carries the two amounts as text, such as 412.50, for the person who may have to read them. For the illustrative day, 2026-11-27, the processor settled four payments for $922.75 in all. Your policy system recorded three of them: The comparison finds three matches and one mismatch: pay_1003, not-recorded, a $412.50 gap.

Investigate each mismatch

investigate-mismatches is a for-each. It runs the nodes under Investigate one mismatch once for each entry in comparison.mismatches, with the entry as $mismatch. Each item has its own names: a value one item binds is invisible to the others. collect gathers each item’s mismatch_outcome into outcomes, in the order of the mismatches, whatever order they finish in. Items run one at a time, because concurrency defaults to 1. With no mismatches, outcomes is empty and the run goes straight on. A run that stops partway resumes at the item it was on. Items that already finished keep their recorded results.

Find the cause

For each mismatch, check-webhook asks the processor how it delivered the payment’s event. The get-webhook-delivery effect returns webhook-failed only for a not-recorded payment whose last delivery to your policy system failed. Every other case is unexplained, with a detail line saying what it found. route-cause is a choice on diagnosis.cause, with a case for each value. Its outputs declare mismatch_outcome, and each case’s heading binds it, so the item always ends with an outcome whichever way it went. That is what collect reads.

Resend the event once

For pay_1003, the processor’s delivery log shows that the event evt_503 failed with a 503, so the run takes Resend the event. resend-event asks the processor to deliver the event again. The run records that the call finished. If the run is interrupted and resumes later, it doesn’t resend: it uses the recorded result. That is the sense in which the event is resent once. A retry is different. If the resend’s reply is lost, the effect’s default retry may send the request again. That’s safe here for two reasons: the effect passes operation.idempotencyKey, which is the same on every attempt of this call, and your policy system records a payment once per event ID. A second delivery of evt_503 changes nothing. If your processor has no idempotency key for resends, the event ID still protects you, as long as your policy system deduplicates on it. confirm-recorded is a polling wait. It reads the payment from your policy system every minute until status is recorded, for up to 30 minutes. If it’s still not recorded by then, the run fails before any payout. Its failure.code is poll_timeout, and its message is resent-payment-not-recorded. Someone then looks at why your policy system rejected the event. A recorded payment isn’t yet a resolved one: the policy system could record the resent event with the wrong amount. check-resent-amount calls the pure function compare-resent-amount, which compares the amount the policy system recorded, recorded_payment.amountCents, with the mismatch’s settledCents. It returns matches, and a detail line that gives both amounts when they differ. route-resent-amount is a choice on resent_amount.matches, nested in Resend the event. Its cases claim the two headings under it, and it declares mismatch_outcome as its own output. When it finishes, that output is the outcome the enclosing route-cause reads, so every path through Resend the event still ends with an outcome:
  • 'true' runs record-resend, which binds resolution: resent.
  • 'false' runs record-resent-hold, which binds resolution: hold, with the two amounts in the note. The day’s payout is held, as when finance answers hold.
A nested choice can only claim headings under its own section, so this path can’t send the mismatch to Ask finance operations. It holds the payout instead, and the run’s outcomes show which payment to look at.

Ask a person about the rest

Suppose your policy system had recorded pay_1004 as $220.00 instead of $230.00. That mismatch is amount-differs, which the procedure can’t explain, so the run takes Ask finance operations. explain-mismatch is a task for the finance-operations group. Its instructions show both amounts and the procedure’s finding. The person answers with a resolution, explained or hold, and a note; the mismatch-decision schema requires both. The run waits for the answer without holding anything. record-explanation binds the outcome from the answer. Only unexplained mismatches create a task. A day with nothing but failed webhooks needs no person.

Pay out the balance

summarize calls the pure function summarize-reconciliation. It releases the payout only if no outcome is hold. The payout is the settlement report’s netCents: once every mismatch is resent with the settled amount or explained, the two sides agree, and the processor’s balance for the day is the amount to pay out. route-payout is a choice on summary.releasePayout:
  • 'true' runs Release the payout. pay-out asks the processor for the payout and the run completes with status: paid-out and the payoutId.
  • 'false' runs Hold the payout. The run completes with status: held. Nothing is paid out: payoutCents is the balance held back, not an amount paid. The outcomes show which mismatch is on hold and why.
The payout’s key is built from the settlement date:
If the reply is lost and the effect runs again, the processor sees payout-2026-11-27 again and returns the payout it already made. The same is true across runs: if someone reconciles 2026-11-27 a second time, the second payout request gets the first payout back. A processor that honours the key pays a day out once; one that ignores it can pay twice, which is why you check this before you go live. If the second run asks for a different amount under the same key, a processor that checks the payload refuses it, and the effect’s FatalError fails the run instead of paying. One that doesn’t check returns the first payout, for the first amount, so if your processor returns the payout’s amount, compare it with amountCents and throw FatalError when they differ.

Try it as a draft

A draft runs source without publishing it. See Try a draft. A draft can’t declare secrets, and this procedure declares two, so sending reconcile-payments.procedure.md as a draft is refused with 422 invalid_procedure and no run starts. To try the flow before you connect your systems, make a stand-in copy that runs without secrets. Save it as reconcile-payments.draft.procedure.md and change three things:
  1. Delete the two yaml secret blocks under Secrets.
  2. Replace each ts effect with one that returns sample data and declares no uses= or secrets=. These two give the day from the table above, with pay_1004 recorded as $220.00 so that you see both paths:
    effect id=get-settlement-report input=date-request result=settlement-report
    effect id=get-recorded-payments input=date-request result=recorded-payments
    For the others: get-webhook-delivery returns webhook-failed when kind is not-recorded and unexplained otherwise; resend-webhook-event returns { eventId: eventId ?? '' }; get-payment returns { status: 'recorded', amountCents: 41250 }; and create-payout returns { payoutId: 'po_test_1' }.
  3. Assign the task to yourself, so you can answer it:
Keep the three functions and everything else as they are. Then start the draft:
An illustrative response, abbreviated; your IDs differ:
The run resends evt_503 for pay_1003, then stops at the task for pay_1004. Find the task with GET /procedures/tasks?status=open&assignedToMe=true and answer it as in Answer a task, using the task ID from your own list:
Each edit to the draft needs a new Idempotency-Key.

Check the result

Read the run with GET /procedures/runs/{runId} until status is completed. With the answer above, output looks like this (illustrative):
Check that:
  • matchedCount is 2 and outcomes has one entry per mismatch, in the order of the comparison: pay_1003 first, then pay_1004.
  • pay_1003 was resent without a task. tasks lists only the task for pay_1004.
  • Answering hold instead completes the run with status: "held" and no payoutId.
  • With pay_1004 recorded as $230.00 in the stand-in, there is one mismatch, no task, and the run pays out on its own.
  • With get-payment returning amountCents: 40000 instead, the resent pay_1003 doesn’t match its settled $412.50. Its outcome is hold, with both amounts in the note, and the run completes with status: "held" and no payoutId, whatever you answer for pay_1004.

Run it against your systems

When the flow does what you want, publish the real reconcile-payments.procedure.md, as in Publish a version. Reading the version lists the two secrets it needs under secrets. Before the first run, set their values on the procedure’s page in the Effective app, under Secrets: a shared default for every run, or a personal override for the runs that run as you. See Give a secret a value. Try it on a test day first. If your processor and policy system have test environments, publish a copy with its own id, such as reconcile-payments-test, whose effects call your test hosts, and give that copy test credentials. Secrets are set for each procedure, so the copy’s values don’t affect the real procedure’s. Then check what only your systems can show:
  • After a resend, your policy system holds the missing payment once, with the settled amount.
  • Run the same day again. The comparison should find no mismatch for the resent payment, and the processor should return the first payout’s ID. If it makes a second payout, its payout endpoint isn’t honoring the key; fix that before you go live.
Start the daily run from your own system after the processor publishes the day’s report. Use a run Idempotency-Key derived from the date, such as reconcile-2026-11-27, as in Start a run.

Next steps

  • Cancel a policy: an approval before three keyed writes, and a run that is safe to start again.
  • Writes to your systems: retries, idempotency keys and what to do when an endpoint has no key.
  • for-each and wait: concurrency, collections, polling and timeouts.