← Back to all products
$19
Refund Processor
Refund processing toolkit with partial/full refunds, reason tracking, and reconciliation.
JSONMarkdownPython
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 9 files
refund-processor/
├── LICENSE
├── README.md
├── examples/
│ └── refund_scenarios.json
├── free-sample.zip
├── guide/
│ ├── 01_features.md
│ ├── 02_cli-reference.md
│ └── 03_policy-rules.md
├── index.html
└── src/
└── refund_processor.py
📖 Documentation Preview README excerpt
Refund Processor
Part of the Payment Stack by CodeVault
A comprehensive payment refund management system with support for full and partial refunds, reason tracking, balance adjustments, policy enforcement, and complete audit trails.
Features
- Full and partial refund support with balance tracking
- 8 standardized refund reason codes with policy rules
- Auto-approval for duplicate, fraudulent, and pricing error refunds
- Refund policy engine (window limits, amount validation, partial refund caps)
- Complete audit trail on every refund action
- Payment balance adjustment and status tracking
- Aggregate refund reporting with reason breakdowns
- Multi-currency amount formatting (USD, EUR, GBP, JPY)
- JSON file persistence for payments and refunds
- Python stdlib only — zero dependencies
Quick Start
# Run the full demo
python src/refund_processor.py --action demo
# Create a full refund
python src/refund_processor.py --action create --payment-id pay_001 --amount 4999 --reason duplicate
# Create a partial refund
python src/refund_processor.py --action create --payment-id pay_002 --amount 1500 --reason customer --notes "Feature not working"
# Check refund status
python src/refund_processor.py --action status --refund-id ref_abc123
# List all refunds
python src/refund_processor.py --action list
# Generate refund report
python src/refund_processor.py --action report
CLI Reference
| Flag | Description |
|---|---|
--action, -a | Action to perform (required) |
--payment-id | Payment ID to refund |
--refund-id | Refund ID to look up |
--amount | Refund amount in cents |
--reason | Refund reason code |
--notes | Additional notes (required for 'other' reason) |
--data-dir | Data storage directory (default: ./refund_data) |
--verbose, -v | Enable debug logging |
Refund Reasons
| Code | Auto-Approve | Full Only | Description |
|---|---|---|---|
duplicate | Yes | Yes | Duplicate charge — always approve full refund |
fraudulent | Yes | Yes | Unauthorized charge — approve immediately |
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
src/refund_processor.py
#!/usr/bin/env python3
"""
Refund Processor — Payment Stack by DataNest
A comprehensive payment refund management system with support for full and
partial refunds, reason tracking, balance adjustments, and complete audit
trails. Enforces refund policies and generates refund reports.
Why this exists:
Refunds are one of the most error-prone parts of payment processing.
A partial refund on an already-partially-refunded payment can exceed the
original amount. Refund windows expire. Some items are non-refundable.
This tool enforces business rules, tracks every dollar, and maintains an
audit trail that satisfies both your accountant and your support team.
Usage:
python refund_processor.py --action demo
python refund_processor.py --action create --payment-id pay_001 --amount 2500 --reason duplicate
python refund_processor.py --action status --refund-id ref_abc123
python refund_processor.py --action report
License: MIT
"""
from __future__ import annotations
import argparse
import json
import logging
import sys
import uuid
from dataclasses import dataclass, field, asdict
from datetime import datetime, timedelta, timezone
from enum import Enum
from pathlib import Path
from typing import Any, Optional
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
# Maximum age of a payment eligible for refund (180 days is typical)
REFUND_WINDOW_DAYS = 180
# Minimum refund amount in cents (most processors require >= $0.50)
MIN_REFUND_CENTS = 50
# Maximum number of partial refunds per payment
MAX_PARTIAL_REFUNDS = 10
# ... 603 more lines ...