← Back to all products

Payment Retry Logic

$19

Payment retry system with smart scheduling, declining card detection, and recovery workflows.

📁 9 files
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

payment-retry-logic/ ├── LICENSE ├── README.md ├── examples/ │ └── failed_payments.json ├── free-sample.zip ├── guide/ │ ├── 01_features.md │ ├── 02_cli-reference.md │ └── 03_license.md ├── index.html └── src/ └── payment_retry_logic.py

📖 Documentation Preview README excerpt

Payment Retry Logic

Part of the Payment Stack by CodeVault

A smart payment retry system with exponential backoff, failure categorization, and recovery analytics. Knows which failures to retry and when.

Features

  • 20+ error codes classified into 7 failure categories
  • Exponential backoff with configurable jitter
  • Category-aware retry strategies (network vs. decline vs. fraud)
  • Retry task queue with scheduling and execution tracking
  • Recovery rate analytics and statistics
  • Hard decline detection (never retry stolen/expired cards)
  • Human-readable delay formatting
  • Full backoff schedule visualization
  • Python stdlib only — zero dependencies

Quick Start


# Run the full demo
python src/payment_retry_logic.py --action demo

# Classify an error code
python src/payment_retry_logic.py --action classify --error-code insufficient_funds

# Schedule a retry
python src/payment_retry_logic.py --action schedule --payment-id pay_001 --error-code network_error

# View backoff tables
python src/payment_retry_logic.py --action backoff-table

# Process pending retries
python src/payment_retry_logic.py --action process-queue

CLI Reference

FlagDescription
--action, -aAction to perform (required)
--error-codePayment error code to classify
--payment-idPayment ID for retry scheduling
--task-idRetry task ID for execution
--amountPayment amount in cents
--simulate-successSimulate a successful retry
--data-dirData storage directory (default: ./retry_data)
--verbose, -vEnable debug logging

Error Categories

CategoryRetryableStrategy
soft_declineYesRetry after 1-24 hours
hard_declineNoAsk customer to update payment
network_errorYesRetry in 1-15 minutes
fraudNoNever retry
processing_errorYesRetry in 15-60 minutes
authenticationNoRedirect customer to 3DS

... continues with setup instructions, usage examples, and more.

📄 Code Sample .py preview

src/payment_retry_logic.py #!/usr/bin/env python3 """ Payment Retry Logic — Payment Stack by DataNest A smart payment retry system with exponential backoff, failure categorization, retry scheduling, and recovery analytics. Determines which failures are retryable, calculates optimal retry timing, and tracks success rates. Why this exists: Not all payment failures are the same. A "card declined" is different from "insufficient funds" which is different from "network timeout." Each needs a different retry strategy. Retrying a stolen card wastes time. Waiting too long to retry "insufficient funds" means the customer moves on. This tool categorizes failures and applies the right retry strategy for each. Usage: python payment_retry_logic.py --action classify --error-code card_declined python payment_retry_logic.py --action schedule --payment-id pay_001 --error-code insufficient_funds python payment_retry_logic.py --action process-queue --data-dir ./retry_data python payment_retry_logic.py --action demo License: MIT """ from __future__ import annotations import argparse import json import logging import math 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 # --------------------------------------------------------------------------- # Base delay for exponential backoff (in seconds) BASE_DELAY_SECONDS = 3600 # 1 hour # Maximum delay cap (7 days — no point waiting longer) MAX_DELAY_SECONDS = 604800 # Jitter factor: ±20% randomization to avoid thundering herd JITTER_FACTOR = 0.2 # ... 631 more lines ...
Buy Now — $19 Back to Products