Skip to content
Projetos

Sobre

Local deterministic sandbox simulating Algerian payment, courier, and banking APIs (Chargily Pay v2, SATIM, Yalidine, BaridiMob). Test what fails offline.

Negócios e finanças

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
0
em 15 dias
0
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

dz-sandbox banner

dz-sandbox

Test what fails, not just what succeeds.

A deterministic, 100% offline-first local sandbox that simulates Algerian payment and delivery APIs (Chargily Pay v2, SATIM, Yalidine, and BaridiMob mobile banking) so developers can integrate and test happy paths and real-world failure modes locally without merchant accounts, live credentials, or internet access.

CI Documentation License: MIT Node.js Status: Unofficial Simulator

Live Documentation: https://test-bit-sys.github.io/dz-sandbox/
Languages: English | العربية (Arabic) | Français (French)

Disclaimer

Unofficial. Not affiliated with Chargily, SATIM, Yalidine, or BaridiMob (Algérie Poste). Behavior is simulated and may differ from production. Always test against each provider's real sandbox before going live. See docs/SPEC_STATUS.md for verified versus unverified scope.


Quick Start in 3 Commands

Option A: Docker Compose

docker compose up

Option B: Node.js (20+)

npm install
npm run build
npx dz-sandbox start

Local Service Base URLs

Service Default URL Purpose
Control API & Dashboard http://127.0.0.1:4000 Web dashboard (Arabic RTL default, FR/EN), OpenAPI schema (/__control/openapi.json), virtual clock, scenario switcher
Chargily Pay v2 Mock http://127.0.0.1:4001/api/v2 Checkouts, customers, products, prices, payment links, local hosted payment page, HMAC-SHA256 signed webhooks
SATIM E-Payment Mock http://127.0.0.1:4002/payment/rest Registration (register.do), hosted fake-card form (4000000000000001..05), confirmation, bounded refunds
Yalidine Express Mock http://127.0.0.1:4003/v1 Parcels CRUD, delivery fee calculation, 69 wilayas / 1,541 communes, virtual-clock lifecycle progression
BaridiMob Banking Mock http://127.0.0.1:4004/mobilebank/service Algérie Poste mobile banking: login, SMS OTP, RIP transfers, accounts & cards, bill payments

Point the Official @chargily/chargily-pay SDK to the Sandbox

The official @chargily/[email protected] SDK locks its endpoint URL in the constructor. Redirect it cleanly with one line using @dz-sandbox/client:

import { ChargilyClient } from '@chargily/chargily-pay';
import { pointChargilyClientToSandbox } from '@dz-sandbox/client';

const client = pointChargilyClientToSandbox(
  new ChargilyClient({ api_key: 'test_sk_local', mode: 'test' }),
  process.env.CHARGILY_BASE_URL ?? 'http://127.0.0.1:4001/api/v2',
);

Test What Fails in 15 Lines

Most integrations only test when payments succeed. With dz-sandbox, you can deterministically reproduce race conditions, duplicate callbacks, and network partitions:

import { createSandboxClient } from '@dz-sandbox/client';

const sandbox = createSandboxClient({ controlUrl: 'http://127.0.0.1:4000' });

// 1. Reset state to a clean baseline
await sandbox.reset();

// 2. Set the global scenario to deliver duplicate webhooks
await sandbox.scenario('chargily', 'duplicate_webhook');

// 3. Create & complete a checkout against http://127.0.0.1:4001/api/v2 ...
// 4. Await both webhooks and verify your backend handler is idempotent (processes order once!)
const webhooks = await sandbox.waitForWebhook({ provider: 'chargily', count: 2, timeoutMs: 5000 });

// 5. Instantly trigger time-dependent lifecycle events without waiting in real time
await sandbox.clock.advance('2h');

Prefer Python? A zero-dependency stdlib client is included (packages/python-client):

from dz_sandbox import SandboxClient

client = SandboxClient("http://127.0.0.1:4000")
client.reset()
client.scenario("chargily", "duplicate_webhook")
hooks = client.wait_for_webhook(provider="chargily", count=2)

Prefer PHP / Laravel / Pest? A zero-dependency client is included (packages/php-client):

use DzSandbox\SandboxClient;

$client = new SandboxClient("http://127.0.0.1:4000");
$client->reset();
$client->scenario("chargily", "duplicate_webhook");
$hooks = $client->waitForWebhook(provider: "chargily", count: 2);

🤖 For AI Coding Agents (Cursor / Windsurf / Claude Code)

Building your app with an AI coding assistant? Copy and paste this prompt into your project instructions or .cursorrules:

"When testing or integrating Algerian payment and delivery services (Chargily Pay v2, SATIM, Yalidine, BaridiMob), use the local dz-sandbox daemon on http://127.0.0.1:4000. Run npx dz-sandbox start to start local mock servers. Test happy paths and failure edge cases (e.g. declined, insufficient_funds, duplicate_webhook, otp_timeout) using the test clients or the X-DZ-Scenario: <name> request header. Never ask for or commit real credentials or card numbers."

AI context files included in this repo:


Why dz-sandbox?

The Problem

  • No self-serve sandboxes: Getting test merchant accounts for Algerian payment gateways or delivery APIs often takes weeks of administrative review.
  • Untested failure paths: Production e-commerce stores frequently ship with naive webhook handlers that double-fulfill orders on retries, crash on out-of-order events, or miscalculate DZD vs. centimes (2500 DZD charged as 25 DZD on SATIM).
  • Flaky internet in local dev: Offline development and fast, hermetic CI pipelines are impossible when dependent on external test sandboxes.

What Makes It Different

  • Declarative Scenario Engine: Deterministic rule precedence: Request Header (X-DZ-Scenario) > Per-Resource Rule > Sequence Rule > Provider Default > success.
  • Controllable Virtual Clock: Advance time (+2h, +1d) to instantly test webhook retries and multi-day parcel delivery lifecycles (En préparation → Expédié → Livré / Retourné au centre).
  • 100% Offline & Hermetic: Runs completely offline with zero external network requests, zero telemetry, and zero CDN dependencies.
  • Bilingual RTL Dashboard: Embedded zero-dependency web interface with native Arabic (RTL default), French, and English interfaces.
  • Safe Record & Replay: Built-in proxy (dz-sandbox record) that sanitizes API keys and customer PII before saving reproducible test fixtures.

Provider Support & Maturity Ledger

Every endpoint in dz-sandbox is audited against official references and tracked in docs/SPEC_STATUS.md. We never invent unverified behavior without marking it clearly.

Provider Package Maturity Verified vs. Simulated Scope Configuration
Chargily Pay v2 @dz-sandbox/mock-chargily Verified / Partial Customer, product, price, and checkout lifecycles and HMAC-SHA256 signature verified against @chargily/[email protected]. Fee calculation and edge 4xx payloads simulated chargily.spec.ts
SATIM E-Payment @dz-sandbox/mock-satim Unverified (Simulated) SmartVista registration (register.do), hosted test cards (4000000000000001..05), confirmation, and bounded refunds simulated. Exact bank-specific paths and error codes require the official bank technical PDF satim.spec.ts
Yalidine Express @dz-sandbox/mock-yalidine Partial / Unverified All 69 wilayas and 1,541 communes (AR/FR/EN, coordinates excluded) imported from official administrative gazettes. Parcel CRUD, fees, and histories simulated; response envelopes await live captures yalidine.spec.ts
BaridiMob Banking @dz-sandbox/mock-baridimob Simulated / Mock Algérie Poste mobile banking: login, device attachment, SMS OTP, accounts & cards, RIP transfers, and bill payments baridimob.spec.ts
ZR Express @dz-sandbox/mock-zrexpress Scaffold (Unverified) Package skeleton and scenario middleware wired; returns 501 NOT_IMPLEMENTED_AWAITING_SPEC until official specs or sanitized captures are added zrexpress.spec.ts
Maystro Delivery @dz-sandbox/mock-maystro Scaffold (Unverified) Package skeleton and scenario middleware wired; returns 501 NOT_IMPLEMENTED_AWAITING_SPEC until official specs or sanitized captures are added maystro.spec.ts

Full honesty ledger: docs/SPEC_STATUS.md


Built-in Failure Scenarios (33 Scenarios)

Switch scenarios instantly via header (X-DZ-Scenario: <name>), Dashboard, CLI, or test client:

Category Examples Purpose
Payment Failures declined, insufficient_funds, expired_card, invalid_card, amount_mismatch Verify checkout UI handles card declines and currency/amount mismatches gracefully
Mobile Banking otp_timeout, rip_invalid, transfer_limit_exceeded Test SMS OTP expiration, invalid recipient RIP format, and maximum balance transfer caps
Network & Gateway timeout, network_drop, gateway_500, rate_limited Ensure your HTTP clients implement backoff, circuit-breaking, and rate-limit (429) handling
Webhook Delivery duplicate_webhook, delayed_webhook, out_of_order_webhooks, webhook_bad_signature, webhook_never_sent Test idempotent order fulfillment and cryptographic signature rejection
Delivery Lifecycles lifecycle_fast, status_stuck, delivery_failed, returned_to_sender, phone_rejected, invalid_wilaya Test tracking webhooks, commune validation errors, and multi-day parcel returns

Complete scenario catalog: docs/scenarios.md


Dashboard & CLI Reference

The dashboard is served by the control plane at http://127.0.0.1:4000:

  • Native Arabic RTL Default: Full bilingual Arabic, French, and English toggle.
  • Live Stream Auto-Refresh: Real-time polling mode (2.5s) to watch incoming requests and webhooks without manual refresh.
  • Scenario Matrix: View live test coverage across all 33 scenarios per provider.
  • Live Request & Webhook Inspector: Inspect HTTP headers and bodies with automatic secret redaction.
  • Hosted Payment Previews: Complete test checkouts directly in an embedded iframe.

CLI Commands

npx dz-sandbox doctor                         # Diagnose Node, ports 4000-4003, and output .env
npx dz-sandbox start                          # Start local mock servers and web dashboard
npx dz-sandbox stop                           # Stop running sandbox daemon
npx dz-sandbox status                         # Check health and active scenarios
npx dz-sandbox reset                          # Reset store, logs, and virtual clock
npx dz-sandbox scenario set chargily declined # Set global scenario for a provider
npx dz-sandbox logs --provider chargily       # Inspect redacted request log
npx dz-sandbox export repro.json              # Export deterministic state bundle for bug reports
npx dz-sandbox import repro.json              # Replay exported state bundle locally
npx dz-sandbox record --provider yalidine --upstream https://api.yalidine.app/v1 --out ./fixtures/yalidine/captured
npx dz-sandbox replay --provider yalidine --fixtures ./fixtures/yalidine/captured
npx dz-sandbox fixtures validate ./fixtures   # Assert zero unredacted secrets or PII in fixtures
npx dz-sandbox generate --openapi ./spec.yaml --name custom-courier # Experimental OpenAPI mock generator
npx dz-sandbox listen --forward-to http://localhost:8000/api/webhooks/chargily # Forward webhooks locally (Stripe-CLI style)

Examples & Framework Integrations

  • Express Checkout: Minimal Node.js / Express checkout flow demonstrating naive vs. idempotent webhook handling.
  • Next.js COD Store: Next.js App Router e-commerce cart with Yalidine Cash-on-Delivery (COD) shipping calculator.
  • Laravel 11+ Checkout: Full Laravel integration with HMAC signature verification, SATIM CIB payment, and Yalidine parcel creation.
  • Vitest Integration Tests: Automated test suite against hermetic local mock servers.

Common Integration Bug Guides

Real-world guides documenting bugs commonly found in Algerian payment and courier implementations, paired with exact reproducing scenarios:

  1. Duplicate Webhooks & Double Fulfillment (duplicate_webhook)
  2. Out-of-Order Webhooks (out_of_order_webhooks)
  3. Missing Webhook Signature Verification (webhook_bad_signature)
  4. Non-Idempotent Fulfillment Race Conditions (delayed_webhook)
  5. Network Timeouts Without Retry (timeout, gateway_500)
  6. Amount Units: DZD vs. Centimes Mixups (amount_mismatch)
  7. Double Charges on Browser Refresh / Back Button (double_charge_attempt)
  8. Parcel Stuck States & Polling Deadlocks (status_stuck, lifecycle_fast)
  9. Invalid Wilaya / Commune Names & Phone Formats (invalid_wilaya, phone_rejected)

Full guide index: docs/guides/common-integration-bugs.md


Contributing

We welcome contributions! The most valuable way to contribute does not even require writing TypeScript:


Security

  • Binds to 127.0.0.1 by default; requires explicit DZ_CONTROL_TOKEN when exposed on external interfaces.
  • Blocks private-range and metadata SSRF on outbound webhooks (DZ_WEBHOOK_ALLOWLIST).
  • Automatically redacts API keys, passwords, bearer tokens, and payment card numbers from logs.
  • For vulnerability disclosure instructions, see SECURITY.md and docs/THREAT_MODEL.md.

License

MIT © 2026 test-bit-sys and dz-sandbox contributors. See LICENSE.

Explore projetos relacionados

Carregando…