A comprehensive payment processing simulator with full EMV (Europay, MasterCard, Visa) tag support and ISO 8583 message format implementation for testing and development.
The lab/ folder turns the simulator into an end-to-end payments QA environment. It runs in Docker, and the simulator code is unchanged.
| Area | What it does | Tests |
|---|---|---|
| Event pipeline | Transactions stream through Kafka (keyed by card) to separate Postgres and Splunk consumer groups, with at-least-once, idempotent delivery | Source-to-target reconciliation (verify): 12 checks; crash-recovery test with no loss or duplicates |
| Fraud & chargebacks | Rules engine (velocity, high amount, lost/stolen auto-block, approvals on blocked cards), analyst review, and the full dispute lifecycle through arbitration with Visa / Mastercard / Amex / Discover reason codes | fraud-scenarios: 39 checks + 12 unit tests |
| Java test suite | REST Assured API and JSON Schema contract tests, Cucumber BDD chargeback scenarios, Selenium Page Object UI tests verified against the API | 54 tests, all passing |
| Monitoring | Splunk dashboards for approval rate, declines by DE39, fraud alerts, rule precision and chargeback outcomes | SQL data-quality checks |
API testing uncovered 8 defects in the simulator, each with steps, expected vs. actual, root cause and fix, plus an automated test that fails until it's fixed. See lab/java-tests/DEFECTS.md.
| ID | Defect | Severity |
|---|---|---|
| DEF-001 | ISO 8583 DE4 loses a cent on amounts like $19.99 (fixed: rounds instead of floors) | High |
| DEF-002 | DE39 is always 00, even on declined transactions (fixed: DE39 and tag 8A carry the decision) |
High |
| DEF-003 | Full PAN returned by the API and stored unmasked (fixed: DE2 truncated to first 6 / last 4) | Critical (PCI DSS) |
| DEF-004 | Invalid expiry month accepted (fixed: month must be 01–12) | Medium |
| DEF-005 | Expired card approved (fixed: declined 54; set SIM_NOW to pin the date) |
High |
| DEF-006 | Negative amount approved (fixed: amount must be positive, at most 2 decimals) | High |
| DEF-007 | Declined transaction can be refunded (fixed: APPROVED only, recorded, capped at the original) | High |
| DEF-008 | ISO 8583 primary bitmap wrong for data elements 9 and up (fixed) | High |
cd lab
.\Start-Lab.ps1 # Kafka, Postgres, Splunk, risk service
docker compose run --rm java-tests # REST Assured + Cucumber + Selenium (54 tests)
docker compose run --rm --build fraud-scenarios # fraud & chargeback suite (39 checks)
docker compose run --rm verify # pipeline source-to-target checkFull guide: lab/README.md · Java suite: lab/java-tests/README.md
- ✅ EMV TLV - 28-tag dictionary; 18 tags plus 8A emitted in DE55, including everything commonly required for an online auth (82, 9F02, 9F03, 9F27, 9F36); TVR/TSI match the APDU trace at 1st GENERATE AC (simulated values, no real cryptogram)
- ✅ ISO 8583 - 0100 request and 0110 response, 0200 refund and 0400 reversal messages, plus a 24-field reference dictionary
- ✅ Test Cards - 4 approval brands and 4 decline codes (05, 41, 51, 54)
- ✅ RESTful API - Transaction processing, history, refunds, EMV and ISO 8583 inspection
- ✅ APDU trace + decoder - Every transaction gets a contact EMV kernel trace (C-APDU / R-APDU, status words, TVR/TSI/CVM/CID explained, logcat-style log);
tools/emv-decode.jsdecodes TVR, TSI, CVM, CID, SW, TLV, DE55 and raw APDU logs - ✅ Fault injection - Opt-in
faulton/process: app not found (6A82), PIN try limit (6983), malformed DE55, host timeout with timeout reversal, issuer 91/96, issuer authentication failure (6300), card removed before 2nd GENERATE AC. Each maps to an SDK-style error code (ERR_*) - ✅ Entry modes - Opt-in
entry_mode(chip, contactless, swipe, fallback) sets DE22 / 9F39 and picks the trace: contact, contactless (C-2/C-3 style: PPSE, TTQ, ARQC in GPO, CVM limit) or magnetic stripe - ✅ Terminal profile -
GET/PUT/DELETE /api/terminal/config(TID, MID, country, AIDs, CAPKs, floor and contactless limits) for TMS-style support scenarios - ✅ Device log - Any transaction as an Android logcat (threadtime) log, ready for
tools/emv-decode.js log - ✅ Interactive UI - Terminal simulator with EMV and ISO 8583 tabs
- ✅ Automated Tests - Playwright API specs plus a page-object UI suite with a visual baseline
- ✅ Agentic test kit - Claude Code planner, generator and locator-only healer, held in check by hook guards (see below)
- ✅ QA Lab - Kafka/Postgres/Splunk pipeline, fraud & chargeback engine, and Java test suite (see above)
- Node.js 18+ (
node --version) - Ports 3000 and 3001 available
.\START_POS_SIMULATOR.bat # backend, UI and a tests window
.\START_POS_SIMULATOR.bat test # same, then runs the ready test suiteThe launcher checks Node and the ports, then opens three windows: backend (:3001), UI (:3000) and tests.
cd backend && npm install && npm start # terminal 1: API on :3001
node scripts/serve-ui.js # terminal 2: UI on :3000The UI is served by a small Node static server. python -m http.server is not used, because on Windows it can send index.html with the wrong content type.
Navigate to: http://localhost:3000
- Enter test card:
4111 1111 1111 1111 - Exp:
12/28 - CVV:
123 - Amount:
99.99 - Click PROCESS TRANSACTION
- View EMV Tags and ISO 8583 tabs
pos-simulator/
├── backend/
│ ├── package.json # Dependencies (Express, SQLite, uuid, cors)
│ ├── server.js # Express API server
│ ├── emv-iso8583.js # Core EMV/ISO 8583 classes
│ └── node_modules/ # Installed packages
│
├── frontend/
│ └── index.html # Interactive terminal UI
│
├── scripts/ # serve-ui.js (UI on :3000) and the launcher's run-*.ps1 windows
│
├── tests/
│ ├── *.spec.js # API specs (EMV, ISO 8583, transactions, history)
│ ├── support/cards.js # Shared test data (card expiry)
│ ├── ui/pages/ # TerminalPage page object (all UI locators)
│ ├── ui/agent/ # Agent-built UI specs + visual baseline
│ └── playwright.config.js # Test configuration
│
├── specs/ # Test plans written by the planner agent
├── .claude/ # Agents and guard hooks (see Agentic test kit)
├── CLAUDE.md # Rules every agent follows
│
└── lab/ # QA lab (Docker): Kafka, Postgres, Splunk,
├── services/ # pipeline producer/consumers, traffic, verify
├── risk/ # fraud engine, chargeback API, risk console
└── java-tests/ # REST Assured, Cucumber, Selenium, DEFECTS.md
- server.js - RESTful API with 14 endpoints
- emv-iso8583.js - Core payment processing module
EMVTagsclass - 27-tag dictionary with TLV encode/decodeISO8583Messageclass - Builds ISO 8583 messages with hex outputEMVTransactionclass - Complete transaction processing
- SQLite - In-memory transaction database
- Single-page application (no build step required)
- Card processing form with test card selector
- Real-time EMV tag and ISO 8583 field display
- Transaction history viewer
- Copy-to-clipboard functionality
- API layer: EMV tags, ISO 8583 fields, Field 55 inspection, approvals, declines, history, health
- UI layer: page object (
tests/ui/pages/TerminalPage.js) plus specs for sales, every test card, form validation, backend-down and timeout handling, and a visual baseline npm run test:readyfromtests/runs the ready suite
- Agents: a test planner (writes
specs/), a generator (builds page objects and specs) and a healer that may fix locators only. It classifies each failure as LOCATOR, TIMING, ASSERTION or ENVIRONMENT, and ASSERTION failures are reported, never "fixed". - Guard hooks (
.claude/hooks/) enforce this in the harness, not in a prompt:- Agents can write only to
tests/,specs/andheal-log/. - Existing
expect()lines can't change. - No skips, retries or timeouts.
- No shell writes to
backend/orfrontend/. - No destructive git.
- Visual baselines update only after a one-time human approval.
- Agents can write only to
- Audit: every healer edit is logged to
heal-log/heals.jsonl. The guards have 25 self-tests (npm run test:guard) and were verified live in Claude Code.
GET /api/emv-tags
# Response: { tags: {...}, total: 24 }GET /api/iso8583-fields
# Response: { fields: {...}, total: 24 }POST /api/transactions/process
# Body: { card_number, exp_date, cvv, amount, currency, merchant_id, description }
# Response: { success, transaction_id, status, emv, iso8583 (0100), iso8583_response (0110), ... }currency: USD (default), EUR, GBP, CAD, AUD or MXN; drives DE49 and tag5F2A. Anything else is 400.- The 0100 carries DE2 (truncated), 3, 4, 11, 12, 13 (local time), 39, 41, 42 (
merchant_id), 49, 55. - The 0110 echoes DE2/3/4/11/12/13/41/42/49 and adds DE38 (approvals), DE39 and tag
8Ain DE55. - DE11 (STAN) is sequential per backend process.
POST /api/transactions/{id}/refund
# Body (optional): { amount } -- omit to refund whatever is still refundable
# 200: { success, original_transaction_id, refund_id, amount, remaining_amount,
# status: REFUNDED | PARTIALLY_REFUNDED, timestamp }
# 404 unknown id | 422 original not APPROVED | 400 invalid amount
# 409 over the remaining refundable amount (body includes remaining_amount)
GET /api/transactions/{id}/refunds
# Response: { transaction_id, refunds: [...], total_refunded, remaining_amount }Refunds are capped at the original amount (summed in integer minor units) and serialized
in-process, so concurrent refunds can't both pass the cap. Each refund builds a 0200
(DE3 200000, DE37 = the original's retrieval reference), returned as iso8583.
POST /api/transactions/{id}/reversal
# 200: { success, original_transaction_id, reversal_id, amount, status: REVERSED, timestamp, iso8583 (0400) }
# 404 unknown id | 422 not APPROVED (incl. already reversed) | 409 the transaction has refundsA reversed transaction can't be refunded.
GET /api/transactions/{id}/apdu-trace
# Response: { transaction_id, interface, scheme, aid, fault, outcome, summary { tvr, tsi, cvm_results,
# cid_first, cid_final, explained }, steps [...], log [...], de55_check }The trace simulates the card/terminal dialogue around the simulator's host decision: PSE and AID
selection, GPO, READ RECORD, DDA, CVM (No CVM under 50.00, else offline PIN), terminal risk
management (floor limit 0), 1st GENERATE AC (ARQC), the 0100/0110, EXTERNAL AUTHENTICATE and
2nd GENERATE AC (TC or AAC). Without a fault it never changes the result. The PAN is masked with
F nibbles and PIN blocks are never logged in clear. Cryptograms, ARPCs and SDAD are placeholders.
de55_check checks the 0100's DE55 against the tags commonly required for an online auth (all present
since B1). DE55 95/9B are the TVR/TSI at 1st GENERATE AC, so they match the trace; the trace's
final TSI adds issuer authentication (F800), and post-online TVR bits (e.g. issuer auth failed) appear only in the trace.
GET /api/faults # catalogue: name, stage, description, expected
POST /api/transactions/process { ..., "fault": "host_timeout" }
# Extra keys on fault requests only: fault { name, applied, description, note }, apdu_trace,
# and reversal { reversal_id, reason, iso8583 (0400) } when the terminal must reverse.| Fault | Result |
|---|---|
app_not_found |
SELECT 6A82, TERMINATED, no host messages (iso8583 null) |
pin_try_limit |
VERIFY 6983, TVR byte 3, DE39 75 (only above the 50.00 No-CVM limit) |
malformed_tlv |
DE55 truncated by 2 bytes, DE39 30; emv.tlv_hex stays intact |
host_timeout |
no 0110, ARC Z3, AAC, TIMEOUT_REVERSED + 0400 |
issuer_91 / issuer_96 |
DE39 91 / 96, AAC |
issuer_auth_failed |
DE39 00, EXTERNAL AUTHENTICATE 6300, AAC, DECLINED_BY_CARD + 0400 |
card_removed |
DE39 00, no response to 2nd GENERATE AC, CARD_REMOVED_REVERSED + 0400 |
A fault that can't apply (PIN fault under 50.00, post-approval fault on a declined card) returns
applied: false with a note. Requests without fault return exactly the same response as before.
POST /api/tools/emv-decode { tvr, tsi, cvm_results, cid, sw, cvm_list, tlv_hex, de55, log } # any subset
node tools/emv-decode.js tvr 0000208040
node tools/emv-decode.js tlv 770F9F2701409F360200019F3403410302
node tools/emv-decode.js de55 <hex>
node tools/emv-decode.js log customer-logcat.txt # finds non-9000 SWs, missing responses, TVR bits
node tools/emv-decode.js trace <transaction_id> --save trace.logPOST /api/transactions/process { ..., "entry_mode": "contactless" } # chip | contactless | swipe | fallbackentry_mode |
DE22 | DE55 | Trace |
|---|---|---|---|
| (none) | not sent | as before | contact |
chip |
051 |
+ 9F39 05 |
contact |
contactless |
071 |
+ 9F39 07, 9F66 TTQ 36004000; TSI 0000 |
contactless: PPSE, GPO (ARQC in the response), READ RECORD, fDDA, CVM limit, online; no 2nd GENERATE AC |
fallback |
801 |
none (emv null, DE55 removed from 0100/0110) |
3 failed ICC power-ons, then swipe |
swipe |
— | — | chip card swiped → TERMINATED, ERR_CHIP_CARD_SWIPED |
Responses to requests with entry_mode echo it, and add apdu_trace / device_log links.
Contactless kernel by scheme: Visa C-3, Mastercard C-2, Amex C-4, Discover C-6. Above the
contactless CVM limit (default 100.00) the trace records online PIN (TVR byte 3 bit 3, CVMR 420300).
GET /api/terminal/config # { config, defaults, terminal_errors }
PUT /api/terminal/config # partial update, validated all-or-nothing (400 + details)
DELETE /api/terminal/config # restore defaults (POST /api/admin/reset does too)Defaults equal the old constants (TERM0001, MERCHANT01, 0840, the 4 AIDs, CAPK 09, floor 0).
Support scenarios: remove an AID → TERMINATED ERR_AID_NOT_SUPPORTED; remove CAPK 09 → DDA/fDDA
failed in TVR (still approved); contactless_transaction_limit_minor → ERR_CTLS_LIMIT_EXCEEDED;
contactless_cvm_limit_minor → online PIN; floor_limit_minor above the amount → TVR byte 4 clear.
The profile is global server state: tests that change it restore it in afterEach.
GET /api/transactions/{id}/device-log # text/plain, logcat threadtime
GET /api/transactions/{id}/device-log?format=json # { transaction_id, lines }Tags: SystemInfo, TermConfig, CardReader, EmvKernel, PinPad, Comm; applied faults end
with E EmvKernel: SDK error ERR_*. APDU lines keep C-APDU / R-APDU, so
node tools/emv-decode.js log device.log decodes it.
Expiry checks (DE14 / exp_date) use the current UTC month. Set SIM_NOW before starting the
backend to pin "now" to any Date-parsable value; invalid values are ignored.
$env:SIM_NOW = '2028-12-31T23:59:59Z'; node server.js # logs "SIM_NOW set: ..."
Remove-Item Env:SIM_NOW # back to the real clockThe test cards expire 12/28; from Jan 2029 they decline 54 unless SIM_NOW is set. The
test suites assume SIM_NOW is unset.
GET /api/transactions/{id}/emv
# Response: { transaction_id, emv: { tags, tlv_hex } }GET /api/transactions/{id}/iso8583
# Response: { transaction_id, iso8583: { mti, fields, hex_message } }# Reference Data
GET /api/emv-tags # 24 EMV tags
GET /api/iso8583-fields # 24 ISO 8583 fields
GET /api/test-cards # Test card definitions
# Transaction Processing
POST /api/transactions/process # Process payment
GET /api/transactions/history # Transaction list
GET /api/transactions/:id # Transaction details
GET /api/transactions/:id/emv # EMV tag data
GET /api/transactions/:id/iso8583 # ISO 8583 data
POST /api/transactions/:id/refund # Refund (full or partial)
GET /api/transactions/:id/refunds # Refunds recorded + remaining amount
POST /api/transactions/:id/reversal # Reverse an APPROVED auth with no refunds (0400)
GET /api/transactions/:id/apdu-trace # Card/terminal APDU trace, TVR/TSI/CVM/CID explained
GET /api/transactions/:id/device-log # Trace as a logcat (threadtime) device log
GET /api/field55/inspect?scheme=visa # Sample DE55 / ISO message, no transaction
# Support tools
GET /api/faults # Fault catalogue (opt-in "fault" on /process)
POST /api/tools/emv-decode # Decode TVR/TSI/CVM/CID/SW/TLV/DE55/APDU log
GET /api/terminal/config # Terminal profile; PUT updates, DELETE restores defaults
# Utilities
GET /api/health # Health check
POST /api/admin/reset # Reset database| Card | Status | Use Case |
|---|---|---|
| 4111 1111 1111 1111 | ✓ Approved | Standard VISA |
| 5555 5555 5555 4444 | ✓ Approved | MasterCard |
| 3782 822463 10005 | ✓ Approved | American Express |
| 6011 1111 1111 1117 | ✓ Approved | Discover |
| 4000 0000 0000 0002 | ✗ Declined | Insufficient Funds |
| 4000 0000 0000 9987 | ✗ Declined | Lost Card |
| 4000 0000 0000 0010 | ✗ Declined | Expired Card |
| 5105 1051 0510 5100 | ✗ Declined | Generic Decline |
cd tests
npm installnpm testnpm run test:headednpm test -- --grep "EMV Tags"npm run test:debugnpx playwright show-report| Tag | Name | Category | Length |
|---|---|---|---|
| 9F06 | Application Dedicated File (AID) | Application | Variable |
| 9F26 | Cryptogram | Cryptography | 8 bytes |
| 95 | Terminal Verification Results (TVR) | Security | 5 bytes |
| 9B | Transaction Status Information (TSI) | Security | 2 bytes |
| 9F27 | Cryptogram Information Data | Cryptography | 1 byte |
| ... | ... | ... | ... |
24 tags in the dictionary; 13 are emitted in DE55, plus 8A once the decision is set. Values are simulated: the cryptogram and unpredictable number are fixed samples.
| Field | Name | Type | Length | Category |
|---|---|---|---|---|
| 0 | Message Type Indicator (MTI) | numeric | 4 | Control |
| 2 | Primary Account Number (PAN) | numeric | 19 | Card |
| 4 | Amount, Transaction | numeric | 12 | Transaction |
| 11 | System Trace Audit Number (STAN) | numeric | 6 | Transaction |
| 39 | Response Code | numeric | 2 | Response |
| ... | ... | ... | ... | ... |
24 fields in the reference dictionary. The 0100 message sets DE2 (truncated), 3, 4, 11, 12, 13, 39, 41, 42, 49 and 55 (bitmap 7038000002C08200). Defects are tracked in the defect log.
- ✅ Luhn Algorithm - Card number validation
- ✅ TLV Format - Tag-Length-Value encoding and decoding for DE55
- ✅ Hex Output - EMV TLV and ISO 8583 message shown in hex
- ℹ️ Simulator only - Not EMV- or network-certified; cryptograms are not real. STAN is sequential per backend process and wraps after 999999
- ✅ PCI - Test cards only; the PAN is truncated to first 6 / last 4 in DE2,
hex_messageand storage (DEF-003, fixed)
# Check if port 3001 is in use
netstat -ano | findstr :3001
# If port is blocked, change PORT:
PORT=3002 npm start# Verify backend is running
curl http://localhost:3001/api/health
# Check CORS is enabled (it is by default)# Install Playwright browsers
cd tests
npx playwright install
# Try running tests again
npm test- The in-memory database is single-process
- Close other instances and restart backend
| Document | Purpose | Time |
|---|---|---|
| README.md | Overview & quick start | 5 min |
| INSTALL.md | Installation | 5 min |
| SETUP_GUIDE.md | Detailed setup guide | 10 min |
| ARCHITECTURE.txt | Architecture notes | 10 min |
| lab/README.md | QA lab: pipeline, fraud module, exercises | 15 min |
| lab/java-tests/DEFECTS.md | Defect log | 10 min |
- Review test cases in
tests/emv-iso8583.spec.js - Run full test suite:
npm test - Add custom decline rules to
backend/server.js - Create test scenarios for edge cases
- Modify EMV tags in
backend/emv-iso8583.js - Add new ISO 8583 fields
- Extend API endpoints in
backend/server.js - Enhance frontend UI in
frontend/index.html
- Export database transactions via API
- Integrate with your payment gateway
- Customize decline rules based on business logic
- Add additional security validations
- Check the documentation listed above
- Review test cases for usage examples
- Verify backend is running on port 3001
- Check browser console for errors
Test/Development Use Only - Do not use with real card data
Version: 1.0.0
Last Updated: 2026-11-17
Status: Test/development tool. See the defect log