Skip to content

A stateful issuer

A simulated host usually answers from rules: amounts over a limit decline, a card prefix times out. A stateful issuer answers the way a real one does, from balances, holds, limits and card status that move with every message. An authorization holds funds, a completion posts them, a reversal gives them back, and the same request sent twice gets the same answer and changes nothing.

In the host form, tick Stateful issuer and add:

  • Accounts: an id, the currency (ISO 4217 numeric), the balance, and any limits: an overdraft, a most-per-transaction, a daily amount and count, and how much stand-in may approve.
  • Cards: a test card number, the account it draws on, an expiry (YYMM, optional) and a status.

Card numbers go through the test-data guard like everything else, so use published test cards or your own test ranges. Tick Approve part of an amount for partial approvals (response code 10, the approved amount in field 4).

Rules still come first: a host’s rules answer what they match (a timeout, a malformed response), and the issuer answers the rest.

The host page shows each account’s balance, what’s held and what’s available, each card’s use today, open holds, and the latest decisions with their reason. Approved responses carry the balances in field 54.

The answers follow the state:

Code When
00 Approved
10 Part of the amount approved (when allowed)
51 Not enough available
61 Over the per-transaction or daily amount limit
65 Over the daily count
54 The card has expired
55, 75 A wrong PIN; the card’s PIN tries are used up (when the host checks PINs)
41, 43, 57, 62 The card is lost, stolen, blocked or restricted
14 No such card
12, 25 A currency the account isn’t in; a reversal or completion of something the issuer never approved
91 The issuer’s state couldn’t be written (the host answers again once it has caught up)
96 The host already holds 500,000 open authorizations; complete, reverse or reset

Editors can set a balance, change a card’s status, put the host in stand-in (it approves within each account’s stand-in limit without looking at balances, and catches up when stand-in ends) and reset it to its configured accounts and cards. Every change is kept like a message’s: the state survives restarts and redeploys.

A stateful host can verify the PIN in field 52 the way an issuer does: by asking its HSM. On the HSM page, add a ZPK (the zone PIN key acquirers encrypt PINs under) and a PVK (the PIN verification key). In the host form, tick Check PINs through the HSM, choose the two keys, the method (Visa PVV or IBM 3624 offset) and how many wrong tries lock a PIN, then give each card a test PIN.

The HSM turns each test PIN into what verifies it, a PVV or an offset, and that’s all the host keeps; the PIN itself is never stored. For every request with a PIN block, the host sends the HSM an EC or EA command over TCP, exactly as an issuer’s host application does:

  • the right PIN goes on to the balance checks;
  • a wrong PIN answers 55 and counts a try;
  • the try that reaches the limit answers 75, and so does every request after it, right PIN or not, until you Clear the tries on the host’s page;
  • a card without a PIN on file answers 55, and when the HSM doesn’t answer the host answers 91 and counts nothing.

Requests without field 52 (signature or contactless purchases) aren’t PIN checked. The HSM’s keys are named, not copied, so replacing the LMK doesn’t break the host.

The host can also verify the values a card carries, through the same HSM. Add a CVK pair on the HSM page, tick Check CVVs, iCVVs and CVV2s through the HSM in the host form, and choose it:

  • CVV in track 2 (field 35): the host reads the card number, expiry and service code from the track, and the CVV from the issuer’s discretionary data at the CVV position (5 by default: after a 1-digit PVKI and a 4-digit PVV, a common layout; your issuer’s may differ). The track’s card number must be field 2’s, or the request answers 14.
  • iCVV: when field 22 says the track came from the chip (entry modes 05 and 07 by default), the value is an iCVV, which the HSM checks with service code 999.
  • CVV2: name where your network carries it, as a field number or a sub-element path from the host’s dialect (126.10, 48.92). It’s checked with service code 000 and the expiry in field 14.

The HSM verifies each value with CY. A wrong one answers 05 (our default: set your network’s code), and live activity says which value it was. The check comes after the card’s status and expiry and before the PIN: a stolen card answers 43 whatever its CVV, and a wrong CVV costs no PIN try. Requests without a value aren’t checked, and when the HSM doesn’t answer the host answers 91. Scenarios make valid values with hsm steps (examples/scenarios/hsm-card-values.yaml); the host never stores a CVV.

The host can verify chip cards’ cryptograms too, and answer them as an issuer does. Add an MK-AC (the issuer master key for application cryptograms) on the HSM page, tick Check chip cryptograms through the HSM in the host form, choose the key, and give cards a chip: the cryptogram version they compute and their PAN sequence number.

Version Cards The ARPC covers
Visa CVN 10 Visa, card verification results in the cryptogram the response code
Visa CVN 18 and 22 Visa, the whole issuer application data in the cryptogram the card status update
M/Chip CVN 16 and 20 Mastercard the response code
M/Chip CVN 17 and 21 Mastercard, with the card’s counters the response code
Interac CVN 133 Interac the response code
  • Sending chip data: a scenario step sends it with chip: true for the card in field 2. The target can be the host itself, or your own system in front of it, such as a switch or an acquirer: give that target chip_issuer: <the host's name>, and your system passes the chip data on to the host and its answer back. The run plays the card: it takes the card’s next transaction counter (ATC) from the host, which keeps it, builds the tags from the request (amount, currency, date, transaction type, an unpredictable number), and has the HSM compute the cryptogram under the MK-AC. The step sends it all in field 55, and field 22 says the chip was read. chip: contactless reads the card contactless instead (see Contactless below). chip: tc and chip: aac send the card’s own approval (a TC) or decline (an AAC) instead of an ARQC, as advices carry them; the host checks them the same way, and only an ARQC gets an ARPC back. For negative tests, chip: wrong sends a cryptogram that fails, and chip: replay sends the card’s last chip data again, counter and all, which the host declines as a replay.
  • Checking it: the HSM verifies the cryptogram in field 55 with the card’s own key, derived from the MK-AC. A wrong one answers 05 (our default: set your network’s code). The issuer also remembers the counters it has accepted, and declines one it has seen before, as a replayed cryptogram, with the same code. Requests that overtake each other are fine: any counter not seen, up to 1,024 below the highest, is accepted, and anything older is declined as too old to tell.
  • Answering: approvals carry the issuer’s response cryptogram (ARPC) in field 55, tag 91, for the card to check. A run checks it as the card does, through the HSM: an ARPC the issuer’s key didn’t make fails the step.
  • Your product’s profile: each chip card sends its version’s defaults unless it has a profile of its own: open its chip profile under the card (in the host form, or under Chip cards on the HSM page) and set its application id (84), interchange profile (82), issuer application data (9F10), more tags it always sends (such as 5F28=0840) or contactless tags it adds when read contactless. The issuer application data has to carry the card’s cryptogram version; the form says when it doesn’t.
  • Contactless: chip: contactless sets the contactless entry mode and has the card add what its scheme’s contactless cards send: a Visa card its form factor indicator (9F6E, by default a card over ISO 14443), a Mastercard card its third party data (9F6E, by default a card with no proprietary data). The cryptogram is checked as an inserted card’s is. Set your product’s own form factor, device type or customer exclusive data (9F7C) under contactless tags in its chip profile. Only what a public source describes is added: Visa CVN 10 and 18 cards and Mastercard cards get their scheme’s data; a Visa CVN 22 or Interac card is read with the contactless entry mode and adds nothing, as every card did before, unless its profile’s contactless tags say what it sends. Visa’s CVN 17 (the version MSD and some qVSDC cards carry) isn’t simulated, as it has no public known-answer vectors.
  • Issuer scripts: to have the host send a card scripts, give its chip checks a script key (an MK-SMI from the HSM page). Then, on the host page, Send a script next to a chip card queues an application block or unblock, a card block or a PIN unblock: the host sends them with its next answer to that card, MACed in the HSM for that transaction, and clears them. A run checks each script’s MAC as the card would. Issuers make script MACs their own way: by default the session key is Visa’s for Visa cards and the EMV common one for others, and the ATC and cryptogram go into the MAC; set script MACs on the host’s chip checks, or on a Platform card, to match yours. A Platform card checks your issuer’s scripts with your issuer’s MK-SMI and its method. So far that check has been tried against the Platform’s own issuer, not a real one.
  • Your own issuer: when the issuer is yours, its cards can’t be a simulated host’s. Import its MK-AC on the HSM page (from its components or a key block) and add its test cards under Chip cards there: card number, chip and PAN sequence number. A scenario or load that targets your system by its address, without chip_issuer, plays those cards, so your issuer verifies the cryptograms and the run checks your ARPCs. Their counters carry on from run to run, as a real card’s do, so your issuer never sees one twice.
  • Loads: an entry in a load’s mix takes chip: too. Each load generator takes a card’s counters from the host eight at a time, so the host isn’t asked for every request, and the HSM makes each request’s cryptogram. Counters a generator took and didn’t use are skipped, as a real card’s are when a transaction never reaches its issuer.
  • Order: the cryptogram is checked after the card’s status and expiry and before its CVV and PIN, so a wrong one costs no PIN try.

The host page shows each chip card’s counter and the highest the issuer has seen. The keys never leave the HSM. Rotating the MK-AC on the HSM page keeps the previous version for verifying, so cryptograms made just before still verify. Scenario cards take a chip too, in state: (see examples/scenarios/chip-cards.yaml):

state:
accounts:
dana: {balance: 50000}
cards:
dana: {account: dana, chip: {version: visa-18, psn: "01"}}
steps:
- name: A chip purchase, answered with the ARPC
send: {sample: auth, pan: "{{cards.dana.pan}}", amount: 2500, chip: true}
expect: {fields: {39: "00"}, present: [55]}

A scenario against a stateful host can declare the accounts and cards it starts from. Amounts are in minor units, as in send.amount:

name: Spending down a balance
target: {simulated_host: Issuer}
state:
accounts:
alice: {balance: 5000, daily_count_limit: 10}
cards:
alice: {account: alice, expiry: "3012"}
stolen: {account: alice, status: stolen, network: MASTERCARD}
steps:
- name: The first purchase fits
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 3000}
expect: {fields: {39: "00"}}
- name: The second doesn't (with partial approvals, it gets the 20.00 left)
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 3000}
expect: {fields: {39: "51"}}
- name: A stolen card is declined
send: {sample: auth, pan: "{{cards.stolen.pan}}", amount: 100}
expect: {fields: {39: "43"}}

Each run gets card numbers and account ids of its own, so runs side by side, from CI or from teammates, never meet, and every run starts from the balances in the file. In steps, {{cards.<name>.pan}} is a card’s number, {{cards.<name>.expiry}} its expiry, and {{accounts.<name>.id}} an account’s id.

The card numbers fail the Luhn check on purpose: they can never be a real card, so the test-data guard lets them through in every mode. That also means they’re for simulated hosts; your own systems probably reject them before anything else.

On a host that checks PINs, a step sends a PIN with pin: the runner has the HSM encrypt it under the host’s zone PIN key into field 52. A run’s cards can have test PINs too:

state:
accounts: {alice: {balance: 5000}}
cards: {alice: {account: alice, pin: "2468"}}
steps:
- name: The right PIN
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 100, pin: "{{cards.alice.pin}}"}
expect: {fields: {39: "00"}}
- name: A wrong one
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 100, pin: "1111"}
expect: {fields: {39: "55"}}

For your own systems, name the HSM’s zone PIN key on the target (target: {host: ..., port: ..., pin_key: Acquirer ZPK}), and steps’ PINs are encrypted under it.

When the run ends, its accounts and cards are removed, with anything still held on them. Add keep: true under state: to leave them on the host for a day, to look at on its page; they’re marked run there. The run’s page lists what it brought, with card numbers masked.

5. Share state across the scenarios in a suite

Section titled “5. Share state across the scenarios in a suite”

Some flows span files: one scenario authorizes, the next completes or reverses what it left. Add scope: suite under state: and the runs in one suite share accounts and cards by name:

authorize.yaml
state:
scope: suite
accounts: {alice: {balance: 5000}}
cards: {alice: {account: alice}}
steps:
- name: Hold 30.00
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 3000}
expect: {fields: {39: "00"}}
# check.yaml: declares alice too, and finds her as authorize.yaml left her
state:
scope: suite
accounts: {alice: {balance: 5000}}
cards: {alice: {account: alice}}
steps:
- name: Only 20.00 is available
send: {sample: auth, pan: "{{cards.alice.pan}}", amount: 3000}
expect: {fields: {39: "51"}}

The CI client runs its files in order as one suite:

Terminal window
python iso8583sim-run.py --url https://your-platform authorize.yaml check.yaml

The first file to declare an account or card sets it up from its declaration; later files use it as they find it, so declare it the same way in each. When the last file ends, the client removes the suite’s state (--keep-state leaves it for a day, to look at on the host’s page). Each invocation is a new suite, so every CI build starts from the files’ balances, and builds side by side never meet. --suite names it, to find its runs in the Platform. Run on its own from the console, a file with scope: suite gets its own state, as with scope: run.

From your own tooling, pass suite when starting runs (POST /api/runs with {"source": ..., "suite": "build-1234"}), and end it with POST /api/suites/build-1234/end.