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
curlandjq. 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 asreconcile-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.
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
Forpay_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'runsrecord-resend, which bindsresolution: resent.'false'runsrecord-resent-hold, which bindsresolution: hold, with the two amounts in the note. The day’s payout is held, as when finance answershold.
Ask a person about the rest
Suppose your policy system had recordedpay_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-outasks the processor for the payout and the run completes withstatus: paid-outand thepayoutId.'false'runs Hold the payout. The run completes withstatus: held. Nothing is paid out:payoutCentsis the balance held back, not an amount paid. The outcomes show which mismatch is on hold and why.
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 sendingreconcile-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:
-
Delete the two
yaml secretblocks under Secrets. -
Replace each
ts effectwith one that returns sample data and declares nouses=orsecrets=. These two give the day from the table above, withpay_1004recorded as $220.00 so that you see both paths:effect id=get-settlement-report input=date-request result=settlement-reportFor the others:effect id=get-recorded-payments input=date-request result=recorded-paymentsget-webhook-deliveryreturnswebhook-failedwhenkindisnot-recordedandunexplainedotherwise;resend-webhook-eventreturns{ eventId: eventId ?? '' };get-paymentreturns{ status: 'recorded', amountCents: 41250 }; andcreate-payoutreturns{ payoutId: 'po_test_1' }. -
Assign the task to yourself, so you can answer it:
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:
Idempotency-Key.
Check the result
Read the run withGET /procedures/runs/{runId} until status is completed. With the answer
above, output looks like this (illustrative):
matchedCountis2andoutcomeshas one entry per mismatch, in the order of the comparison:pay_1003first, thenpay_1004.pay_1003was resent without a task.taskslists only the task forpay_1004.- Answering
holdinstead completes the run withstatus: "held"and nopayoutId. - With
pay_1004recorded as $230.00 in the stand-in, there is one mismatch, no task, and the run pays out on its own. - With
get-paymentreturningamountCents: 40000instead, the resentpay_1003doesn’t match its settled $412.50. Its outcome ishold, with both amounts in the note, and the run completes withstatus: "held"and nopayoutId, whatever you answer forpay_1004.
Run it against your systems
When the flow does what you want, publish the realreconcile-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.
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-eachandwait: concurrency, collections, polling and timeouts.