Skip to content

Diagnostic Bank transfers and statement matching

RF creditor reference for WooCommerce orders: what check digits buy you

A customer types your order number into their banking app and gets one digit wrong. With a plain number, that is a different, real order. With an RF creditor reference built from the order number, it is an invalid reference, and you know to look. Here is how the check digits are made, what they provably catch, what they do not, and a small script that makes and checks references and tries every single-digit error and adjacent swap.

Python and Node.js Read only No network
An official receipt on a white surface
Photo by Michael Walter on Unsplash
The short answer

An ISO 11649 RF reference is RF, two check digits and up to 21 letters or digits (25 characters at most), printed in groups of four. The check digits are ISO 7064 MOD 97-10, the IBAN algorithm: append RF00, turn letters into numbers, take the remainder modulo 97 and subtract it from 98. They catch every single wrong digit and every swap of two neighbouring different digits, so a typo becomes invalid instead of another order. They do not catch every two-digit error or every letter slip. The script makes references and demonstrates all of this.

The problem in plain words

Order 1042 and order 1043 differ by one digit. A customer who types 1043 by mistake has not made an error you can detect: they have named a different order. The statement reads 1043, which is an open order, and a matcher that trusts it credits the wrong one.

A reference with check digits makes the same slip detectable. RF97 1042 is valid; RF97 1043 is not.

Order 1042customer owes 49.90Typed 1043one digit offPlain numbera real, other orderWrong ordercredited
With check digits the same slip is invalid, and a person looks.

Why it happens

Check digits are redundancy: a few extra digits computed from the rest, so that most changes break the relationship. For an RF reference the recipe is ISO 7064 MOD 97-10, the one behind IBANs:

The key insight

Check digits do not stop the typo; they change what the typo means. A wrong plain number is a wrong answer you cannot see. A wrong RF reference is a question a person can answer.

The fix, as a flow

The script builds a reference from an order number (symbols dropped, uppercase, none when more than 21 characters remain), checks any reference you give it, and can run the demonstration: every digit of a reference replaced by every other digit, every swap of two different neighbouring digits, and every pair of digits wrong at once, counting how many still validate.

Order numbersymbols droppedAppend RF00letters to numbers98 minus mod 97two check digitsCheckrearranged, remainder 1
Pure: no network, no store, nothing written.

Build it step by step

1

Nothing to install

Run it on any order number. It needs no network, no credentials and no store.

setup (shell)
# Python 3.8 or later. Standard library only: nothing to install, no keys, no network.
setup (shell)
# Node 18 or later. Built-in modules only: nothing to install, no keys, no network.
2

Check with one pure function

mod97 turns letters into numbers and takes the remainder seven digits at a time, so a 25-character reference never needs a big-integer library. is_valid moves the first four characters to the end and wants a remainder of 1.

rf_reference.py
def mod97(text):
    """ISO 7064 MOD 97-10 over letters and digits (A=10 ... Z=35), seven digits at a time."""
    digits = "".join(c if c.isdigit() else str(ord(c) - 55) for c in text)
    rem = 0
    for i in range(0, len(digits), 7):
        rem = int(str(rem) + digits[i:i + 7]) % 97
    return rem


def is_valid(reference):
    """Well formed, with check digits that hold. Spaces and case do not matter."""
    r = compact(reference)
    return bool(re.fullmatch(r"RF\d{2}[A-Z0-9]{1,21}", r)) and mod97(r[4:] + r[:4]) == 1
rf-reference.mjs
export function mod97(text) {
  const digits = [...text].map((c) => (/\d/.test(c) ? c : String(c.charCodeAt(0) - 55))).join("");
  let rem = 0;
  for (let i = 0; i < digits.length; i += 7) rem = Number(String(rem) + digits.slice(i, i + 7)) % 97;
  return rem;
}


export function isValid(reference) {
  const r = compact(reference);
  return /^RF\d{2}[A-Z0-9]{1,21}$/.test(r) && mod97(r.slice(4) + r.slice(0, 4)) === 1;
}
3

Prove it on your own numbers

The demo command tries every single-digit error and adjacent swap on a reference built from your order number, and tells you plainly how many two-digit errors still validate.

run it
python3 rf_reference.py demo 1042
run it
node rf-reference.mjs demo 1042
Read only, on purpose

The script never writes anything and never touches the network: it reads the files or numbers you give it and prints. Confirming a payment against an order is a decision for a person.

The full code

The complete script in one file for each language. It makes, checks and demonstrates references.

Get this script on GitHub Follow @allanninal Python and Node.js, with tests. Read only. One of 148 WooCommerce fixes, free and open source.
rf_reference.py
"""Make and check ISO 11649 RF creditor references, and show what the check digits catch.

An RF reference is "RF", two check digits and up to 21 letters or digits (25
characters at most), shown in groups of four. The check digits are ISO 7064 MOD
97-10, the algorithm behind IBAN check digits. Built from an order number, a
mistyped digit or two swapped digits make the reference invalid instead of
pointing at another order. Pure: no network, no store, no writes.

    python3 rf_reference.py make 1042        RF97 1042
    python3 rf_reference.py check "RF97 1042"
    python3 rf_reference.py demo 1042

Guide: https://www.allanninal.dev/woocommerce/rf-creditor-reference-check-digits/
"""
import re
import sys

MAX_BODY = 21


def body_of(order_number):
    """An order number reduced to what an RF body may hold: A-Z and 0-9, uppercase."""
    return re.sub(r"[^A-Z0-9]", "", str(order_number).upper())


def mod97(text):
    """ISO 7064 MOD 97-10 over letters and digits (A=10 ... Z=35), seven digits at a time."""
    digits = "".join(c if c.isdigit() else str(ord(c) - 55) for c in text)
    rem = 0
    for i in range(0, len(digits), 7):
        rem = int(str(rem) + digits[i:i + 7]) % 97
    return rem


def make(order_number):
    """The compact reference for an order number, or None when there cannot be one."""
    body = body_of(order_number)
    if not body or len(body) > MAX_BODY:
        return None
    return "RF" + str(98 - mod97(body + "RF00")).zfill(2) + body


def compact(reference):
    return re.sub(r"\s+", "", str(reference)).upper()


def is_valid(reference):
    """Well formed, with check digits that hold. Spaces and case do not matter."""
    r = compact(reference)
    return bool(re.fullmatch(r"RF\d{2}[A-Z0-9]{1,21}", r)) and mod97(r[4:] + r[:4]) == 1


def display(reference):
    """Grouped in fours: RF97 1042."""
    r = compact(reference)
    return " ".join(r[i:i + 4] for i in range(0, len(r), 4))


def demonstrate(order_number):
    """Try every single-digit error and every adjacent swap on a reference; count what still validates."""
    ref = make(order_number)
    digit_at = [i for i in range(2, len(ref)) if ref[i].isdigit()]
    errors = caught_errors = 0
    for i in digit_at:
        for d in "0123456789":
            if d != ref[i]:
                errors += 1
                caught_errors += not is_valid(ref[:i] + d + ref[i + 1:])
    swaps = caught_swaps = 0
    for i in range(2, len(ref) - 1):
        if ref[i].isdigit() and ref[i + 1].isdigit() and ref[i] != ref[i + 1]:
            swaps += 1
            caught_swaps += not is_valid(ref[:i] + ref[i + 1] + ref[i] + ref[i + 2:])
    pairs = missed_pairs = 0
    for a in range(len(digit_at)):
        for b in range(a + 1, len(digit_at)):
            for x in "0123456789":
                for y in "0123456789":
                    i, j = digit_at[a], digit_at[b]
                    if x != ref[i] and y != ref[j]:
                        pairs += 1
                        t = ref[:i] + x + ref[i + 1:j] + y + ref[j + 1:]
                        missed_pairs += is_valid(t)
    return {"reference": ref, "single_digit_errors": errors, "caught_errors": caught_errors,
            "adjacent_swaps": swaps, "caught_swaps": caught_swaps,
            "two_digit_errors": pairs, "two_digit_errors_missed": missed_pairs}


def main(argv):
    if len(argv) != 3 or argv[1] not in ("make", "check", "demo"):
        print('usage: rf_reference.py make ORDER | check "RF.." | demo ORDER', file=sys.stderr)
        return 2
    if argv[1] == "check":
        ok = is_valid(argv[2])
        print(("valid: " if ok else "INVALID: ") + display(argv[2]))
        return 0 if ok else 1
    ref = make(argv[2])
    if ref is None:
        print(f"no reference: {argv[2]!r} is empty or longer than {MAX_BODY} letters and digits once symbols are dropped.")
        return 1
    if argv[1] == "make":
        print(display(ref))
        return 0
    r = demonstrate(argv[2])
    print(f"reference {display(ref)}")
    print(f"single-digit errors: {r['caught_errors']} of {r['single_digit_errors']} caught")
    print(f"adjacent swaps of two different digits: {r['caught_swaps']} of {r['adjacent_swaps']} caught")
    print(f"two digits wrong at once: {r['two_digit_errors_missed']} of {r['two_digit_errors']} still validate ({100 * r['two_digit_errors_missed'] / max(1, r['two_digit_errors']):.2f}%)")
    return 0 if r["caught_errors"] == r["single_digit_errors"] and r["caught_swaps"] == r["adjacent_swaps"] else 1


if __name__ == "__main__":
    sys.exit(main(sys.argv))
rf-reference.mjs
/**
 * Make and check ISO 11649 RF creditor references, and show what the check digits catch.
 *
 * An RF reference is "RF", two check digits and up to 21 letters or digits (25 characters at
 * most), shown in groups of four. The check digits are ISO 7064 MOD 97-10, the algorithm behind
 * IBAN check digits. Built from an order number, a mistyped digit or two swapped digits make the
 * reference invalid instead of pointing at another order. Pure: no network, no store, no writes.
 *
 *     node rf-reference.mjs make 1042        RF97 1042
 *     node rf-reference.mjs check "RF97 1042"
 *     node rf-reference.mjs demo 1042
 *
 * Guide: https://www.allanninal.dev/woocommerce/rf-creditor-reference-check-digits/
 */
import { pathToFileURL } from "node:url";



export const MAX_BODY = 21;

/** An order number reduced to what an RF body may hold: A-Z and 0-9, uppercase. */
export const bodyOf = (orderNumber) => String(orderNumber).toUpperCase().replace(/[^A-Z0-9]/g, "");

/** ISO 7064 MOD 97-10 over letters and digits (A=10 ... Z=35), seven digits at a time. */
export function mod97(text) {
  const digits = [...text].map((c) => (/\d/.test(c) ? c : String(c.charCodeAt(0) - 55))).join("");
  let rem = 0;
  for (let i = 0; i < digits.length; i += 7) rem = Number(String(rem) + digits.slice(i, i + 7)) % 97;
  return rem;
}

/** The compact reference for an order number, or null when there cannot be one. */
export function make(orderNumber) {
  const body = bodyOf(orderNumber);
  if (!body || body.length > MAX_BODY) return null;
  return "RF" + String(98 - mod97(body + "RF00")).padStart(2, "0") + body;
}

export const compact = (reference) => String(reference).replace(/\s+/g, "").toUpperCase();

/** Well formed, with check digits that hold. Spaces and case do not matter. */
export function isValid(reference) {
  const r = compact(reference);
  return /^RF\d{2}[A-Z0-9]{1,21}$/.test(r) && mod97(r.slice(4) + r.slice(0, 4)) === 1;
}

/** Grouped in fours: RF97 1042. */
export const display = (reference) => compact(reference).match(/.{1,4}/g).join(" ");

const isDigit = (c) => c >= "0" && c <= "9";

/** Try every single-digit error and every adjacent swap on a reference; count what still validates. */
export function demonstrate(orderNumber) {
  const ref = make(orderNumber);
  const digitAt = [];
  for (let i = 2; i < ref.length; i++) if (isDigit(ref[i])) digitAt.push(i);
  let errors = 0, caughtErrors = 0;
  for (const i of digitAt) {
    for (const d of "0123456789") {
      if (d === ref[i]) continue;
      errors++;
      if (!isValid(ref.slice(0, i) + d + ref.slice(i + 1))) caughtErrors++;
    }
  }
  let swaps = 0, caughtSwaps = 0;
  for (let i = 2; i < ref.length - 1; i++) {
    if (isDigit(ref[i]) && isDigit(ref[i + 1]) && ref[i] !== ref[i + 1]) {
      swaps++;
      if (!isValid(ref.slice(0, i) + ref[i + 1] + ref[i] + ref.slice(i + 2))) caughtSwaps++;
    }
  }
  let pairs = 0, missedPairs = 0;
  for (let a = 0; a < digitAt.length; a++) {
    for (let b = a + 1; b < digitAt.length; b++) {
      const i = digitAt[a], j = digitAt[b];
      for (const x of "0123456789") {
        for (const y of "0123456789") {
          if (x === ref[i] || y === ref[j]) continue;
          pairs++;
          if (isValid(ref.slice(0, i) + x + ref.slice(i + 1, j) + y + ref.slice(j + 1))) missedPairs++;
        }
      }
    }
  }
  return { reference: ref, single_digit_errors: errors, caught_errors: caughtErrors, adjacent_swaps: swaps, caught_swaps: caughtSwaps, two_digit_errors: pairs, two_digit_errors_missed: missedPairs };
}

export async function run(argv = process.argv.slice(2)) {
  if (argv.length !== 2 || !["make", "check", "demo"].includes(argv[0])) {
    console.error('usage: rf-reference.mjs make ORDER | check "RF.." | demo ORDER');
    return 2;
  }
  const [cmd, arg] = argv;
  if (cmd === "check") {
    const ok = isValid(arg);
    console.log((ok ? "valid: " : "INVALID: ") + display(arg));
    return ok ? 0 : 1;
  }
  const ref = make(arg);
  if (ref === null) {
    console.log(`no reference: "${arg}" is empty or longer than ${MAX_BODY} letters and digits once symbols are dropped.`);
    return 1;
  }
  if (cmd === "make") {
    console.log(display(ref));
    return 0;
  }
  const r = demonstrate(arg);
  console.log(`reference ${display(ref)}`);
  console.log(`single-digit errors: ${r.caught_errors} of ${r.single_digit_errors} caught`);
  console.log(`adjacent swaps of two different digits: ${r.caught_swaps} of ${r.adjacent_swaps} caught`);
  console.log(`two digits wrong at once: ${r.two_digit_errors_missed} of ${r.two_digit_errors} still validate (${((100 * r.two_digit_errors_missed) / Math.max(1, r.two_digit_errors)).toFixed(2)}%)`);
  return r.caught_errors === r.single_digit_errors && r.caught_swaps === r.adjacent_swaps ? 0 : 1;
}

if (import.meta.url === pathToFileURL(process.argv[1]).href) {
  run().then((code) => process.exit(code)).catch((err) => { console.error(err); process.exit(2); });
}

Add a test

The decision is the part most worth testing, and because it is a pure function the tests need no store and no network: they feed in plain objects and check the answer.

test_rf_reference.py
import pytest

from rf_reference import body_of, demonstrate, display, is_valid, make, mod97


def test_the_iso_example_is_valid_and_rebuilt_exactly():
    assert is_valid("RF18539007547034")
    assert is_valid("rf18 5390 0754 7034")
    assert make("539007547034") == "RF18539007547034"
    assert display("RF18539007547034") == "RF18 5390 0754 7034"


def test_published_examples_with_letters():
    assert make("1234") == "RF541234"      # Finance Finland's example "RF54 1234"
    assert make("REF1234") == "RF98REF1234"  # Finance Finland's example "RF98 REF1 234"


def test_the_iso_11649_annex_b_worked_example():
    assert mod97("2348231271500") == 27 and 98 - 27 == 71
    assert make("2348231") == "RF712348231"
    assert display(make("2348231")) == "RF71 2348 231"
    assert is_valid("RF71 2348 231")


def test_the_same_body_with_other_check_digits_is_invalid():
    # RF18 is the only valid pair for this body; any other pair must fail.
    assert not is_valid("RF68 5390 0754 7034")


def test_a_wrong_check_pair_is_invalid():
    assert not is_valid("RF19539007547034")
    assert not is_valid("RF1853900754703")


def test_symbols_in_an_order_number_are_dropped():
    assert body_of("2026-0042") == "20260042"
    assert body_of("wc#42") == "WC42"
    assert is_valid(make("2026-0042"))


def test_no_reference_when_nothing_or_too_much_is_left():
    assert make("#--") is None
    assert make("9" * 22) is None
    assert len(make("9" * 21)) == 25


def test_mod97_is_one_for_a_valid_reference_rearranged():
    assert mod97("539007547034RF18") == 1


def test_every_single_digit_error_and_adjacent_swap_is_caught():
    for n in ("1", "42", "1042", "20260042", "7" * 21):
        r = demonstrate(n)
        assert r["caught_errors"] == r["single_digit_errors"] > 0
        assert r["caught_swaps"] == r["adjacent_swaps"]


def test_two_digit_errors_are_not_all_caught_and_the_script_says_so():
    r = demonstrate("20260042")
    assert 0 < r["two_digit_errors_missed"] < r["two_digit_errors"] * 0.03


def test_a_letter_for_a_digit_can_validate():
    # The gap, stated honestly: letters count as two digits, so a letter typed for a digit can slip through.
    assert make("42") == "RF3442"
    assert is_valid("RF344U")
check-rf-reference.test.mjs
import { test } from "node:test";
import assert from "node:assert/strict";
import { bodyOf, demonstrate, display, isValid, make, mod97 } from "./rf-reference.mjs";

test("the ISO example is valid and rebuilt exactly", () => {
  assert.ok(isValid("RF18539007547034"));
  assert.ok(isValid("rf18 5390 0754 7034"));
  assert.equal(make("539007547034"), "RF18539007547034");
  assert.equal(display("RF18539007547034"), "RF18 5390 0754 7034");
});
test("published examples with letters", () => {
  assert.equal(make("1234"), "RF541234");
  assert.equal(make("REF1234"), "RF98REF1234");
});
test("the ISO 11649 annex B worked example", () => {
  assert.equal(mod97("2348231271500"), 27);
  assert.equal(make("2348231"), "RF712348231");
  assert.equal(display(make("2348231")), "RF71 2348 231");
  assert.ok(isValid("RF71 2348 231"));
});
test("the same body with other check digits is invalid", () => assert.ok(!isValid("RF68 5390 0754 7034")));
test("a wrong check pair is invalid", () => {
  assert.ok(!isValid("RF19539007547034"));
  assert.ok(!isValid("RF1853900754703"));
});
test("symbols in an order number are dropped", () => {
  assert.equal(bodyOf("2026-0042"), "20260042");
  assert.equal(bodyOf("wc#42"), "WC42");
  assert.ok(isValid(make("2026-0042")));
});
test("no reference when nothing or too much is left", () => {
  assert.equal(make("#--"), null);
  assert.equal(make("9".repeat(22)), null);
  assert.equal(make("9".repeat(21)).length, 25);
});
test("mod97 is one for a valid reference rearranged", () => assert.equal(mod97("539007547034RF18"), 1));
test("every single digit error and adjacent swap is caught", () => {
  for (const n of ["1", "42", "1042", "20260042", "7".repeat(21)]) {
    const r = demonstrate(n);
    assert.ok(r.single_digit_errors > 0);
    assert.equal(r.caught_errors, r.single_digit_errors);
    assert.equal(r.caught_swaps, r.adjacent_swaps);
  }
});
test("two digit errors are not all caught and the script says so", () => {
  const r = demonstrate("20260042");
  assert.ok(r.two_digit_errors_missed > 0 && r.two_digit_errors_missed < r.two_digit_errors * 0.03);
});
test("a letter for a digit can validate", () => {
  assert.equal(make("42"), "RF3442");
  assert.ok(isValid("RF344U"));
});

Worked example

From a real run

What it proved

make turned order 1042 into RF97 1042. Checking RF97 1043, one digit off, came back INVALID, and RF97 1042 came back valid. The demo tried all 54 single-digit errors (six digits, nine wrong values each) and all 5 swaps of two different neighbouring digits: every one was caught. It also tried 1,215 cases of two digits wrong at once, and 9 of them still validate.

output (Python)
RF97 1042
INVALID: RF97 1043
valid: RF97 1042
reference RF97 1042
single-digit errors: 54 of 54 caught
adjacent swaps of two different digits: 5 of 5 caught
two digits wrong at once: 9 of 1215 still validate (0.74%)
(exit status 0)
output (Node.js)
RF97 1042
INVALID: RF97 1043
valid: RF97 1042
reference RF97 1042
single-digit errors: 54 of 54 caught
adjacent swaps of two different digits: 5 of 5 caught
two digits wrong at once: 9 of 1215 still validate (0.74%)
(exit status 0)

That is 0.74% here, against the roughly one in 97 the arithmetic allows. The check digits are strong against the common typo and honest about the rare one.

FAQ

Does my customer have to type the RF part?

No. People often drop the prefix and type the order number alone. The check digits only protect references that include the RF part, so a plain number is weaker evidence and is best treated that way.

Can an order number with letters work?

Yes, up to 21 letters and digits. But letters are the weak spot: a letter typed for a digit can validate. A numeric order number is safer.

Is a valid RF reference proof the right order was paid?

No. It proves the characters were typed as issued. It does not prove the payer meant this order, or that the amount is right. It is strong evidence for a match, not the whole match.

Related field notes

Citations

  1. ISO 11649:2009, Structured creditor reference to remittance information (preview copy): structure, check digits and the worked example in Annex B. standards.iteh.ai/catalog/standards/sist/a4c0fe42-a793-480d-974a-9a2e5d0c7fe4/iso-11649-2009
  2. Finance Finland: Structure of the RF Creditor Reference (ISO 11649), with examples and the printed layout. www.finanssiala.fi/wp-content/uploads/2024/04/structure-of-the-rf-creditor-reference-iso-11649.pdf
  3. European Payments Council, EPC069-12 v3.0: the QR code guidelines, whose example carries the RF reference RF18539007547034. europeanpaymentscouncil.eu/sites/default/files/kb/file/2022-09/EPC069-12%20v3.0%20Quick%20Response%20Code%20-%20Guidelines%20to%20Enable%20the%20Data%20Capture%20for%20the%20Initiation%20of%20an%20SCT_0.pdf
  4. Deutsche Kreditwirtschaft, DFU agreement Anlage 3, version 26.11 (valid from 15 November 2026): chapter 7 on camt statements; chapter 8 (MT940/MT942) reads "removed". www.ebics.de/de/datenformate
Built from the order number, read back safely

Transferproof builds the reference from the order number (RF, check digits, the number with symbols dropped, grouped in fours) and reads it back from statement text only when exactly one reading validates. A reference whose check digits fail finds nothing, instead of finding another order.

Did this save you a morning with the bank statement?

If it did, you can buy me a coffee. It is the best way to keep these field notes free and growing.

Buy me a coffee on Ko-fi

Back to all WooCommerce and Stripe field notes