SEPA returns check
A returned SEPA Direct Debit comes back with a four-character reason code. The code decides what the merchant may do next: collect again later, fix something first, talk to the customer, or stop. This skill reads a whole file of returns and gives that answer per debit, with the earliest date a new attempt may go out.
What you need
- Python 3.9 or newer. The script uses the standard library only and opens no network connection.
- The merchant's return file, or one reason code.
Run it
Paths here are relative to this skill's folder, the one that holds this file.
A file:
python scripts/returns_check.py <path-to-file> --today <YYYY-MM-DD>
One code:
python scripts/returns_check.py --code AM04
Options:
| Option | What it does | Default |
|---|---|---|
--today | The day a new advance notice to the customer would go out | today |
--fee-failed | What the merchant's bank or provider charges per failed debit, in euros | 3.50 |
--fee-refund | What it charges per refund claim (code MD06), in euros | 15.00 |
--no-rows | Leaves out the per-debit list, for a very large file | off |
--no-references | Leaves each debit's reference out of the list | off |
The fee defaults are Stripe's published prices for Ireland, read on 30 October 2026. If the merchant gives one fee or
both, pass what they gave. feesUsed in the output says where each fee came from; say so in the answer.
To try it without a real file, use examples/returns-october.xml or examples/returns-october.csv.
What the output holds
One JSON object:
returns,amount,fees: how many debits came back, what they total, and the fees charged for them. The amount is money that was not collected, not money lost: report it and the fees as two figures, never as one sum.buckets: the returns with a known code, sorted into four groups.retry: collect again later.fix: correct the account, the mandate or the file first.contact: talk to the customer before any new collection.stop: do not collect again on this mandate.
unknown: debits whose code is outside the 25 that the scheme's guidance covers. They sit in no group and carry no fee, so the four groups andunknowntogether add up toreturns. Do not guess what such a code means; tell the merchant to ask their bank or provider.byCode: each code in the file with its name, meaning, who caused it, the collect-again answer, a message for the customer, and a page with the full explanation.retryCalendar: theretrydebits totalled per day: how many may go out again on each date, and their amount.rows: each debit with its reference, its date, its decision and, for aretrydebit,retryOn, the earliest date for that debit.dateis the collection date in a pain.002 or CSV file and the booking date in a camt file.
How to answer
- Lead with the count and the money: how many debits came back, what they total, the fees, and how the groups split.
- Then one short table, a row per code: code, what it means in plain words, how many, the amount, what to do.
- Give the retry dates as dates. Say what they assume (see the rules below).
- Offer the customer messages for the codes in the file. Each has the placeholders
[amount],[date]and[link]. Fill the first two fromrows. Leave[link]for the merchant: it is a page of their own shop. - For a single code, answer in three parts: what it means, who caused it, whether to collect again.
--codegives no date. If the merchant asks when, say the earliest is the day the advance notice period ends, and work out a date only if they tell you when the notice goes out.
Rules that keep the answer right
- Scheme facts and defaults are different things. Keep them apart. The code names, how a code arrives and which scheme it belongs to come from the European Payments Council's guidance (EPC173-14, version 8.1, 30 September 2026). Whether to collect again, how long to wait and how many times are Waverunner's defaults. The EPC sets no retry rule. When the data says "our 5-day wait", write "a default wait of 5 days".
- A retry date assumes a new advance notice. The Core scheme asks the merchant to tell the customer about a debit
at least 14 calendar days ahead, unless the two agreed a different period. Each retry date is the later of that
notice, counted from
--today, and the default wait, moved to Monday when it falls on a weekend. If the merchant agreed a different notice period with the customer, say the date changes with it and do not invent one. - MS03 hides the real reason. A bank may send MS03 ("reason not specified") in place of the true code. Any code
with
canArriveAsMs03: truemay be behind it. So an MS03 is never retried blind: the merchant asks the customer or the provider which reason applies first. - Never retry a
stoporcontactdebit to see what happens. With MD01 no valid mandate covers the debit. With MD06 the customer had the debit refunded; the merchant talks to them before any new debit. - Provider notes apply only to that provider. Some texts say what Stripe or Mollie does. Pass such a note on only when the merchant uses that provider, or say plainly that it applies to that provider.
- Add nothing the output does not say. No meaning for an unknown code, no extra legal step, no timing rule from
memory. If the merchant needs more, the code's page (
page) is the place to send them. - Read nothing beyond the script's output. The script takes only the code, amount, date and the debit's own
reference from the file. Do not open the file yourself to pull out names or account numbers, and do not repeat any
that the merchant pastes. A reference is whatever the merchant put in it; if their references hold customer names,
run with
--no-references. - This is not legal advice. A merchant with a dispute over a mandate should ask their bank or a lawyer.
If it fails
The script exits with code 2 and prints {"error": "..."} in words meant for the merchant. Pass that message on. The
usual causes: the file is a statement with no returns in it, the CSV has no column of reason codes, or the export is
not valid XML.
Where the data comes from
data/codes.json is a copy of the open file at https://waverunner.ai/tools/sepa-return-codes/codes.json. Waverunner's
defaults and text in it are under CC BY 4.0; the codes, names and types are the EPC's and ISO 20022's. The same decoder
runs in the browser at https://waverunner.ai/tools/sepa-return-codes/ for anyone who would rather not use a terminal.