Alur ini bisa dibangun dengan Apache Hop (ambil & jadwalkan data), PostgreSQL (penyimpanan), dbt Core atau SQL (aturan pencocokan), dan Metabase (dashboard). Refund, cicilan, biaya payment gateway, dan settlement bank dibahas sebagai tahap berikutnya.
Lihat skrip Python demo
"""Reproducible synthetic order/payment reconciliation demo for NAFAF.
Run: python3 rekonsiliasi.py --output demo/output
No external packages or customer data are required.
"""
import argparse
import csv
import json
from collections import Counter, defaultdict
from datetime import datetime, timedelta
from pathlib import Path
def write_csv(path, rows, fields):
with path.open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=fields)
writer.writeheader()
writer.writerows(rows)
def read_csv(path):
with path.open(newline="", encoding="utf-8") as handle:
return list(csv.DictReader(handle))
def generate(output):
orders = []
payments = []
day = datetime(2026, 9, 1, 9, 0)
def add_payment(order_id, amount):
index = len(payments) + 1
payments.append({
"payment_id": f"PAY-{index:05d}",
"order_id": order_id,
"paid_at": (day + timedelta(minutes=index)).isoformat(timespec="minutes"),
"amount_idr": amount,
"status": "SUCCESS",
"provider_reference": f"REF-{index:06d}",
})
for index in range(1, 10001):
order_id = f"ORD-{index:05d}"
amount = 50000 + (index * 7919) % 950000
orders.append({
"order_id": order_id,
"order_date": (day + timedelta(minutes=index)).isoformat(timespec="minutes"),
"customer_code": f"CUS-{1 + index % 750:04d}",
"amount_idr": amount,
})
if index <= 9300:
add_payment(order_id, amount)
elif index <= 9600:
continue # No successful payment.
elif index <= 9800:
add_payment(order_id, amount)
add_payment(order_id, amount) # Two distinct successful captures.
else:
add_payment(order_id, amount + 10000)
for index in range(1, 51):
add_payment(f"ORD-X{index:04d}", 75000 + index * 1000)
write_csv(output / "orders.csv", orders, ["order_id", "order_date", "customer_code", "amount_idr"])
write_csv(output / "payments.csv", payments, ["payment_id", "order_id", "paid_at", "amount_idr", "status", "provider_reference"])
def reconcile(output):
orders = read_csv(output / "orders.csv")
payments = read_csv(output / "payments.csv")
by_order = defaultdict(list)
for payment in payments:
if payment["status"] == "SUCCESS":
by_order[payment["order_id"]].append(payment)
results = []
for order in orders:
matched = by_order.pop(order["order_id"], [])
expected = int(order["amount_idr"])
paid = sum(int(payment["amount_idr"]) for payment in matched)
if len(matched) == 0:
status = "BELUM_DIBAYAR"
elif len(matched) > 1:
status = "DIBAYAR_GANDA"
elif paid != expected:
status = "NOMINAL_BERBEDA"
else:
status = "COCOK"
results.append({
"order_id": order["order_id"],
"expected_idr": expected,
"successful_payments": len(matched),
"paid_idr": paid,
"difference_idr": paid - expected,
"status": status,
"payment_ids": "|".join(payment["payment_id"] for payment in matched),
})
unmatched = [payment for matches in by_order.values() for payment in matches]
write_csv(output / "reconciliation.csv", results,
["order_id", "expected_idr", "successful_payments", "paid_idr", "difference_idr", "status", "payment_ids"])
write_csv(output / "unmatched_payments.csv", unmatched,
["payment_id", "order_id", "paid_at", "amount_idr", "status", "provider_reference"])
summary = {
"dataset": "SYNTHETIC_DEMO",
"orders": len(orders),
"payment_rows": len(payments),
"status_counts": dict(sorted(Counter(row["status"] for row in results).items())),
"payments_without_order": len(unmatched),
}
(output / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
return summary
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output", type=Path, default=Path("demo/output"))
args = parser.parse_args()
args.output.mkdir(parents=True, exist_ok=True)
generate(args.output)
print(json.dumps(reconcile(args.output), indent=2))
if __name__ == "__main__":
main()