Skip to content
بازگشت به پروژه‌ها
02/Developer Tooling & TestingCreator & Lead Developer2024

IPG Sandbox

سندباکس درگاه پرداخت قابل میزبانی شخصی برای شبیه‌سازی زرین‌پال، آیدی‌پی و به‌پرداخت.

استک تکنولوژیDOCKERFASTAPIPYTHONNEXT.JSTESTINGMOCK
مشاهده سورس در گیت‌هاب
IPG Sandbox
مرور کلی

Problem & solution scope

Testing payment workflows in Iranian software development has historically required live test credentials, manual card simulations, or unstable staging endpoints. IPG Sandbox is a zero-setup, self-hosted emulation suite that mirrors the REST and SOAP APIs of major payment gateways (Zarinpal, IDPay, Behpardakht Mellat), allowing developers to test approve, decline, timeout, refund, and verify-fail scenarios deterministically in local dev and CI/CD pipelines.

معماری سیستم

System architecture

Dual-Plane Simulation Engine with Deterministic State Machine

Architected into a high-performance Python FastAPI engine and a Next.js inspection dashboard. The engine intercepts standard gateway endpoints, models transactions through a persistent state machine, and evaluates header-driven scenario rules (X-Sandbox-Scenario) without modifying production code under test.

اجزای سیستم

Emulation Engine

Python 3.11+ / FastAPI / SQLModel

Exposes drop-in compatible REST and SOAP WSDL endpoints imitating real gateway network contracts and error codes.

Deterministic Scenario Evaluator

Header & Rule Engine

Evaluates headers like X-Sandbox-Scenario: decline or timeout to inject predictable failure modes without mocking SDK internals.

Transaction State Machine

SQLModel / SQLite & PostgreSQL

Tracks lifecycle states: INITIATED -> PENDING -> PAID / FAILED -> VERIFIED, enforcing double-verification prevention.

Inspection Web Dashboard

Next.js / Tailwind CSS / Playwright

Real-time UI for viewing live transactions, payload inspection, simulated user payment UI, and callback triggers.

جریان داده و اجرا

01
Base URL Redirection

Application under test points its gateway URL to http://localhost:8080/{gateway} with the test merchant ID.

02
Scenario Injection

Test suite or developer passes optional X-Sandbox-Scenario header (e.g. approve, decline, timeout, verify_fail).

03
Transaction Tracking

Engine persists transaction state, generates reference tokens, and logs the HTTP exchange.

04
Callback Execution

Engine simulates redirect or webhook to merchant's callback URL; merchant verifies transaction against sandbox verification endpoint.

قابلیت‌های کلیدی

Engineered capabilities

[01]

18-Cell Scenario Matrix: 6 realistic outcomes (approve, decline, timeout, refund, pending_settle, verify_fail) across 3 gateway adapters.

[02]

Zero External Dependencies: Runs fully offline via Docker Compose without external internet access or credit cards.

[03]

Fault-Injection via Headers: Non-invasive testing without changing application business logic.

[04]

Real-Time Inspection Dashboard: Live visual inspection of payloads, callbacks, and transaction states.

[05]

Dual SQL Engine: Lightweight SQLite for local dev and fast unit tests (199+ passed tests), PostgreSQL for concurrency testing.

تصمیمات فنی و مصالحه‌ها

Engineering trade-offs

Header-Based Scenario Selection

Using standard HTTP headers (X-Sandbox-Scenario) allows E2E test suites to force error branches without modifying application code or database records.

Documented-Subset SOAP Emulation

Emulated the precise WSDL operations used by mainstream Behpardakht payment SDKs, maintaining high fidelity without full banking mainframe overhead.

نحوه استفاده و راه‌اندازی

Local Docker Compose Launch

// bashsnippet
git clone https://github.com/amirmuha/ipg-sandbox.git
cd ipg-sandbox
cp .env.example .env
docker compose up -d

# Dashboard available on http://localhost:3000
# Gateway engine on http://localhost:8080/api/v1
بازگشت به پروژه‌هامشاهده سورس در گیت‌هاب