Refund rows: separate the selected payment's statuses before totaling
Calculate supplied refund stages without claiming money received.
Immutable revision: 4e0a9a9a9e6fe38081e19bd8c12034c3112cb3e6e0e6e30362b2462938dbb727. Publication and independent validation are separate; inspect metadata and provenance before use.
Refund rows: separate the selected payment's statuses before totaling
Four invented refund rows total $50.00, matching the invented original charge. That does not make the selected payment fully refunded: its supplied rows contain $12.50 marked succeeded, $7.50 pending and $10.00 failed. Another payment contributes the remaining $20.00. Actual receipt and whether another refund is needed remain unknown.
Prepare the selected snapshot
This fictional U.S. direct-merchant snapshot has one account and a fixed USD payment. The existing credit-note guide [cited revision] handles allocation and funding; this calculation leaves that guidance intact.
Stripe's Refund object, Attributes describes integer amounts in the smallest currency unit, the refunded charge relationship and five status labels: succeeded, pending, failed, canceled and requires_action. Its currency guide, Specify amounts uses 1000 for 10 USD; this fixture handles USD only.
| Authored row | Relation to selected payment | Fixture amount/status |
|---|---|---|
| refund-success | Selected charge A | $12.50 / succeeded |
| refund-pending | Selected charge A | $7.50 / pending |
| refund-failed | Selected charge A | $10.00 / failed |
| refund-other | Other charge B | $20.00 / succeeded, excluded |
- Bind account, selected payment and currency before totaling.
- Use one current row per refund ID. Identical duplicates and same-ID histories stop; resolve them before rerunning.
- Keep matching statuses separate and list other-charge exclusions. Missing rows yield zero only in this inventory, without proving no refund exists.
- Hand back stages and unknowns; infer no amount owed, entitlement or permission to refund again.
Positive amounts, nonnull statuses, unexpanded IDs and fixed payment are own subset boundaries, not Stripe API schema. Other currencies/accounts or new fields/evidence need separate evaluation. Stripe's refund guidance, state transitions and reversal/trace sections illustrates why recorded success is not a substitute for receipt evidence: states can change and a reversal need not show a separate credit.
Reproduce the exact calculation
Save the five named fences as UTF-8 files with one final LF each in an empty directory. On CPython 3.12.3 run:
python sum_refunds.py fixture.json 363df99c1d548fd02e022fa61c6286c6ffbf7691f29dc0c701c937138c876b89
python check.py
The first output equals expected.json: 642 bytes, SHA-256 e95ba243ec164accf114b75b8ffcc73f1eb896481f04906e2fce71a3b2af84e6. The checker compares all 10 top-level fields, nested subtotals and full bytes: four positive cases, one wrong-total demonstration and 18 stops, recorded individually. Python JSON documentation, loads and object_pairs_hook supports the standard decoder; no replacement parser or general refund validator is used.
Evidence: Sources read through 2026-10-05T19:48:31.254905Z; no update dates established. Python reference 3.12.15, execution 3.12.3 at 2026-10-05T19:52:06.831189Z, exit 0; expectations authored beforehand. A distinct same-controller checker read the sources, replayed all 23 public cases and checked ten additional executable boundaries; no independent formal coverage. No account/API/payment/refund/bank/contact action. Recheck sources and changed inputs before use and by 2026-11-05T19:52:06.831189Z. Feedback should name a failed public case without private transaction details. Billing standard [current article].
Complete public files and measured results
fixture.json
{
"origin": "fictional-authored",
"fixture_account": "fictional-us-direct-merchant",
"selected_payment": {
"charge": "fictional-charge-A",
"amount": 5000,
"currency": "usd"
},
"refunds": [
{
"fixture_account": "fictional-us-direct-merchant",
"id": "fictional-refund-success",
"charge": "fictional-charge-A",
"amount": 1250,
"currency": "usd",
"status": "succeeded"
},
{
"fixture_account": "fictional-us-direct-merchant",
"id": "fictional-refund-pending",
"charge": "fictional-charge-A",
"amount": 750,
"currency": "usd",
"status": "pending"
},
{
"fixture_account": "fictional-us-direct-merchant",
"id": "fictional-refund-failed",
"charge": "fictional-charge-A",
"amount": 1000,
"currency": "usd",
"status": "failed"
},
{
"fixture_account": "fictional-us-direct-merchant",
"id": "fictional-refund-other",
"charge": "fictional-charge-B",
"amount": 2000,
"currency": "usd",
"status": "succeeded"
}
]
}
sum_refunds.py
"""Own fictional USD snapshot arithmetic; no API validation or financial action."""
import hashlib
import json
import sys
ACCOUNT = "fictional-us-direct-merchant"
PAYMENT = {"charge": "fictional-charge-A", "amount": 5000, "currency": "usd"}
STATES = ("succeeded", "pending", "failed", "canceled", "requires_action")
def require(condition, message):
if not condition:
raise ValueError(message)
def keys(value, names):
require(type(value) is dict and set(value) == set(names.split()), "missing or unsupported fields")
def unique_members(pairs):
result = {}
for name, value in pairs:
require(name not in result, "duplicate JSON member")
result[name] = value
return result
def decode(raw):
return json.loads(raw, object_pairs_hook=unique_members)
def subtotal(data):
keys(data, "origin fixture_account selected_payment refunds")
require(data["origin"] == "fictional-authored" and data["fixture_account"] == ACCOUNT, "outside authored account context")
payment = data["selected_payment"]
keys(payment, "charge amount currency")
require(type(payment["amount"]) is int and payment == PAYMENT, "changed selected payment")
require(type(data["refunds"]) is list, "refund snapshot list required")
totals = dict.fromkeys(STATES, 0)
seen, excluded = set(), []
for row in data["refunds"]:
keys(row, "fixture_account id charge amount currency status")
require(row["fixture_account"] == ACCOUNT, "mixed account context")
require(type(row["id"]) is str and bool(row["id"]) and type(row["charge"]) is str and bool(row["charge"]), "missing relationship or identifier")
require(row["id"] not in seen, "duplicate refund snapshot; select one current record first")
seen.add(row["id"])
require(type(row["amount"]) is int and row["amount"] > 0, "positive integer minor-unit amount required")
require(row["currency"] == "usd", "outside USD-only fixture")
require(row["status"] in STATES, "unknown or unset fixture status")
if row["charge"] != payment["charge"]:
excluded.append(row["id"])
else:
totals[row["status"]] += row["amount"]
return {
"fixture_account": ACCOUNT,
"selected_charge": payment["charge"],
"currency": "usd",
"fixture_original_charge_minor_units": payment["amount"],
"fixture_status_subtotals_minor_units": totals,
"excluded_other_charge_ids": sorted(excluded),
"actual_bank_receipt": None,
"inventory_complete": None,
"additional_refund_needed": None,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
}
def main():
raw = open(sys.argv[1], "rb").read()
require(hashlib.sha256(raw).hexdigest() == sys.argv[2], "fixture bytes changed")
print(json.dumps(subtotal(decode(raw)), indent=2))
if __name__ == "__main__":
try:
main()
except (ValueError, TypeError, KeyError, IndexError) as error:
raise SystemExit("STOP: " + str(error))
expected.json
{
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
}
check.py
"""Replay own declared USD refund-snapshot outputs and local stop boundaries."""
import copy
import datetime
import hashlib
import importlib.util
import json
from pathlib import Path
import platform
import subprocess
import sys
P = Path(__file__).resolve().parent
FIXTURE_HASH = "363df99c1d548fd02e022fa61c6286c6ffbf7691f29dc0c701c937138c876b89"
EXPECTED_HASH = "e95ba243ec164accf114b75b8ffcc73f1eb896481f04906e2fce71a3b2af84e6"
raw, expected_raw = (P / "fixture.json").read_bytes(), (P / "expected.json").read_bytes()
if hashlib.sha256(raw).hexdigest() != FIXTURE_HASH or hashlib.sha256(expected_raw).hexdigest() != EXPECTED_HASH:
raise SystemExit("fixture/expectation bytes changed")
spec = importlib.util.spec_from_file_location("bounded_refunds", P / "sum_refunds.py")
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
base, expected = m.decode(raw), m.decode(expected_raw)
records = []
def good(name, data, wanted):
observed = m.subtotal(data)
if observed != wanted:
raise SystemExit(name + ": full output mismatch")
records.append({"case": name, "expected": wanted, "observed": observed, "pass": True})
good("baseline", base, expected)
wrong = sum(row["amount"] for row in base["refunds"])
if wrong != 5000 or wrong != base["selected_payment"]["amount"]:
raise SystemExit("naive equal-charge total not demonstrated")
records.append({"case": "naive-all-row-total", "expected_wrong_total_minor_units": 5000,
"observed_wrong_total_minor_units": wrong, "matching_succeeded_minor_units": 1250, "pass": True})
reverse = copy.deepcopy(base)
reverse["refunds"].reverse()
good("reversed-row-order", reverse, expected)
more = copy.deepcopy(base)
more["refunds"] += [
{"fixture_account": m.ACCOUNT, "id": "fictional-canceled", "charge": m.PAYMENT["charge"], "amount": 300, "currency": "usd", "status": "canceled"},
{"fixture_account": m.ACCOUNT, "id": "fictional-action", "charge": m.PAYMENT["charge"], "amount": 400, "currency": "usd", "status": "requires_action"}
]
wanted = copy.deepcopy(expected)
wanted["fixture_status_subtotals_minor_units"].update(canceled=300, requires_action=400)
good("all-five-statuses-separate", more, wanted)
missing = copy.deepcopy(base)
missing["refunds"].pop(0)
wanted = copy.deepcopy(expected)
wanted["fixture_status_subtotals_minor_units"]["succeeded"] = 0
good("missing-row-not-actual-no-refund", missing, wanted)
def change(path, value=None, delete=False):
data = copy.deepcopy(base)
target = data
for part in path[:-1]:
target = target[part]
if delete:
del target[path[-1]]
else:
target[path[-1]] = value
return data
negative = [
("identical-duplicate", change(["refunds"], base["refunds"] + [base["refunds"][0]])),
("conflicting-history", change(["refunds"], base["refunds"] + [dict(base["refunds"][0], status="failed")])),
("mixed-account", change(["refunds", 0, "fixture_account"], "fictional-other-account")),
("foreign-currency", change(["refunds", 0, "currency"], "eur")),
("missing-charge", change(["refunds", 0, "charge"], delete=True)),
("missing-status", change(["refunds", 0, "status"], delete=True)),
("unset-status", change(["refunds", 0, "status"], None)),
("unknown-status", change(["refunds", 0, "status"], "posted")),
("boolean-amount", change(["refunds", 0, "amount"], True)),
("decimal-string-amount", change(["refunds", 0, "amount"], "12.50")),
("negative-amount", change(["refunds", 0, "amount"], -1)),
("zero-outside-subset", change(["refunds", 0, "amount"], 0)),
("changed-selected-charge", change(["selected_payment", "charge"], "fictional-charge-B")),
("changed-selected-amount", change(["selected_payment", "amount"], 5001)),
("new-bank-receipt-evidence", change(["actual_bank_receipt"], True)),
("nonlist-refunds", change(["refunds"], {}))
]
for name, data in negative:
try:
m.subtotal(data)
except (ValueError, TypeError, KeyError) as error:
records.append({"case": name, "expected": "stop", "observed": "stop", "reason": str(error), "pass": True})
else:
raise SystemExit(name + ": expected local stop")
try:
m.decode('{"status":"pending","status":"succeeded"}')
except ValueError as error:
records.append({"case": "duplicate-json-member", "expected": "stop", "observed": "stop", "reason": str(error), "pass": True})
else:
raise SystemExit("duplicate JSON member accepted")
good_cli = subprocess.run([sys.executable, str(P / "sum_refunds.py"), str(P / "fixture.json"), FIXTURE_HASH], capture_output=True)
if good_cli.returncode != 0 or good_cli.stdout != expected_raw:
raise SystemExit("reader command/full expected stdout bytes differ")
bad_cli = subprocess.run([sys.executable, str(P / "sum_refunds.py"), str(P / "fixture.json"), "0" * 64], capture_output=True)
if bad_cli.returncode == 0 or b"fixture bytes changed" not in bad_cli.stderr:
raise SystemExit("changed byte pin accepted")
records.append({"case": "changed-byte-pin", "expected": "stop", "observed": "stop", "pass": True})
report = {
"test_status": "offline-reproduced",
"executed_at": datetime.datetime.now(datetime.timezone.utc).isoformat().replace("+00:00", "Z"),
"runtime": {"python": sys.version, "platform": platform.platform(), "optimization": sys.flags.optimize, "external_packages": []},
"fixture_sha256": FIXTURE_HASH,
"expected_sha256": EXPECTED_HASH,
"observed_stdout_sha256": hashlib.sha256(good_cli.stdout).hexdigest(),
"observed_stdout_bytes": len(good_cli.stdout),
"baseline_top_level_fields": len(expected),
"all_expected_fields_equal": True,
"all_expected_bytes_equal": True,
"positive_cases": 4,
"demonstrated_wrong_total": 1,
"stop_cases": len(negative) + 2,
"records": records,
"effects": "Own local files/stdout only; no API/account/payment/refund action or bank receipt observation."
}
print(json.dumps(report, indent=2))
run-record.json
{
"test_status": "offline-reproduced",
"executed_at": "2026-10-05T19:52:06.831189Z",
"runtime": {
"python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]",
"platform": "Linux-6.8.0-146-generic-x86_64-with-glibc2.39",
"optimization": 0,
"external_packages": []
},
"fixture_sha256": "363df99c1d548fd02e022fa61c6286c6ffbf7691f29dc0c701c937138c876b89",
"expected_sha256": "e95ba243ec164accf114b75b8ffcc73f1eb896481f04906e2fce71a3b2af84e6",
"observed_stdout_sha256": "e95ba243ec164accf114b75b8ffcc73f1eb896481f04906e2fce71a3b2af84e6",
"observed_stdout_bytes": 642,
"baseline_top_level_fields": 10,
"all_expected_fields_equal": true,
"all_expected_bytes_equal": true,
"positive_cases": 4,
"demonstrated_wrong_total": 1,
"stop_cases": 18,
"records": [
{
"case": "baseline",
"expected": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"observed": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"pass": true
},
{
"case": "naive-all-row-total",
"expected_wrong_total_minor_units": 5000,
"observed_wrong_total_minor_units": 5000,
"matching_succeeded_minor_units": 1250,
"pass": true
},
{
"case": "reversed-row-order",
"expected": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"observed": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"pass": true
},
{
"case": "all-five-statuses-separate",
"expected": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 300,
"requires_action": 400
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"observed": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 1250,
"pending": 750,
"failed": 1000,
"canceled": 300,
"requires_action": 400
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"pass": true
},
{
"case": "missing-row-not-actual-no-refund",
"expected": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 0,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"observed": {
"fixture_account": "fictional-us-direct-merchant",
"selected_charge": "fictional-charge-A",
"currency": "usd",
"fixture_original_charge_minor_units": 5000,
"fixture_status_subtotals_minor_units": {
"succeeded": 0,
"pending": 750,
"failed": 1000,
"canceled": 0,
"requires_action": 0
},
"excluded_other_charge_ids": [
"fictional-refund-other"
],
"actual_bank_receipt": null,
"inventory_complete": null,
"additional_refund_needed": null,
"next_step": "Verify exact payment, current refund states and customer receipt privately before reporting returned money or deciding a further action."
},
"pass": true
},
{
"case": "identical-duplicate",
"expected": "stop",
"observed": "stop",
"reason": "duplicate refund snapshot; select one current record first",
"pass": true
},
{
"case": "conflicting-history",
"expected": "stop",
"observed": "stop",
"reason": "duplicate refund snapshot; select one current record first",
"pass": true
},
{
"case": "mixed-account",
"expected": "stop",
"observed": "stop",
"reason": "mixed account context",
"pass": true
},
{
"case": "foreign-currency",
"expected": "stop",
"observed": "stop",
"reason": "outside USD-only fixture",
"pass": true
},
{
"case": "missing-charge",
"expected": "stop",
"observed": "stop",
"reason": "missing or unsupported fields",
"pass": true
},
{
"case": "missing-status",
"expected": "stop",
"observed": "stop",
"reason": "missing or unsupported fields",
"pass": true
},
{
"case": "unset-status",
"expected": "stop",
"observed": "stop",
"reason": "unknown or unset fixture status",
"pass": true
},
{
"case": "unknown-status",
"expected": "stop",
"observed": "stop",
"reason": "unknown or unset fixture status",
"pass": true
},
{
"case": "boolean-amount",
"expected": "stop",
"observed": "stop",
"reason": "positive integer minor-unit amount required",
"pass": true
},
{
"case": "decimal-string-amount",
"expected": "stop",
"observed": "stop",
"reason": "positive integer minor-unit amount required",
"pass": true
},
{
"case": "negative-amount",
"expected": "stop",
"observed": "stop",
"reason": "positive integer minor-unit amount required",
"pass": true
},
{
"case": "zero-outside-subset",
"expected": "stop",
"observed": "stop",
"reason": "positive integer minor-unit amount required",
"pass": true
},
{
"case": "changed-selected-charge",
"expected": "stop",
"observed": "stop",
"reason": "changed selected payment",
"pass": true
},
{
"case": "changed-selected-amount",
"expected": "stop",
"observed": "stop",
"reason": "changed selected payment",
"pass": true
},
{
"case": "new-bank-receipt-evidence",
"expected": "stop",
"observed": "stop",
"reason": "missing or unsupported fields",
"pass": true
},
{
"case": "nonlist-refunds",
"expected": "stop",
"observed": "stop",
"reason": "refund snapshot list required",
"pass": true
},
{
"case": "duplicate-json-member",
"expected": "stop",
"observed": "stop",
"reason": "duplicate JSON member",
"pass": true
},
{
"case": "changed-byte-pin",
"expected": "stop",
"observed": "stop",
"pass": true
}
],
"effects": "Own local files/stdout only; no API/account/payment/refund action or bank receipt observation."
}
Exact public file manifest
| File | Bytes | SHA-256 |
|---|---|---|
| fixture.json | 1099 | 363df99c1d548fd02e022fa61c6286c6ffbf7691f29dc0c701c937138c876b89 |
| sum_refunds.py | 3144 | b43057a96afb3fc9b26aa293e8d59597edba1c74cd64fe2084d57563f68cf4dc |
| expected.json | 642 | e95ba243ec164accf114b75b8ffcc73f1eb896481f04906e2fce71a3b2af84e6 |
| check.py | 5974 | bcd3291ca5eb1a57760168f8a3eddc3f9da804d911954a9218fab385ee115b63 |
| run-record.json | 10678 | 89fc6060011d9147177bb8296268c916921099720306772d9f418aeea7056dc5 |
The run report is historical author evidence. A new replay has its own execution clock; compare all nonclock fields. Changed inputs, sources or runtime require a new pinned run. Missing rows do not prove no other refund exists; arithmetic does not establish snapshot authenticity, currentness or completeness. No Connect, tax/fee/conversion, entitlement, processing timetable or bank reconciliation is modeled.