{"object":"doc","slug":"troubleshoot-terminal-integration","title":"Troubleshoot a terminal integration safely","summary":"Read checkout snapshots, webhook receiver responses, and order-evidence dispositions without retrying an uncertain payment.","tags":["guide","payments","terminals","webhooks","troubleshooting"],"body":"# Troubleshoot a terminal integration safely\n\nUse this guide with the reviewed Node terminal checkout, webhook receiver, and\norder-payment evidence bundles. They have different jobs and different result shapes:\n\n- Terminal checkout methods return a payment **snapshot** or throw a static local error.\n- The webhook receiver returns an HTTP status and a static response code after checking the\n  exact raw request.\n- `processBatch()` returns disposition **counts**. Detailed reasons remain in its local\n  evidence tables; `getOrder()` returns the conservative order projection.\n\nDo not treat a code from one layer as a code from another. None of these components cancels,\nvoids, refunds, retries a create request, or fulfills an order automatically. Checkout sends\na new create only when the host calls `begin()` again after one of the two definite answers\nbelow (`not_submitted`, `processor_unavailable`).\n\n## Check the installation first\n\nRun these components server-side on Node.js 24.21.0 or newer in the Node 24 line. Use one\nprocess on one host and durable local SQLite storage, not an ephemeral function or shared\nnetwork filesystem. Keep each bundle complete and use the versions declared by its manifest.\n\nThe checkout needs a sandbox key with `payments:write` and `payments:read`, an HTTPS API\norigin (plain HTTP is only for a loopback test bridge), and fixed merchant and terminal IDs.\nKeep one checkout database per API origin, merchant, and terminal binding.\n\nThe receiver needs the endpoint signing secret, a stable trusted receiver ID, the expected\nmerchant allowlist, and its durable database. It must receive the original bytes before any\nJSON parser. The evidence component uses that same database and receiver ID. Register the\nimmutable binding returned by checkout `getBinding(orderId)` before applying events. Never\nconstruct a binding from webhook fields.\n\n## Read a checkout result\n\nThe application owns the order, price, user authorization, CSRF protection, rate limits,\nand fulfillment deduplication. The operator owns uncertain-outcome review and storage\nrecovery.\n\n| Snapshot status and code | Plain meaning | Safe next read or action | Stop when |\n|---|---|---|---|\n| `unknown` / `not_submitted` | The binding was durably prepared but the create send has not been confirmed. This is normally only visible around local failure. | Preserve the database and order ID. Check storage health and the saved row. | Stop automated payment and fulfillment work until the local record is understood. |\n| `pending` / `payment_pending` or `payment_processing` | A matching sandbox terminal payment is still in progress. | Wait for authenticated webhook evidence or call `refresh(orderId)`, which performs GETs only. A simulated terminal with `sim_behavior` `manual` (the REST default) stays pending until you call `POST /v1/sandbox/terminals/{id}/simulate` or the MCP tool `simulate_terminal`. | Stop polling aggressively; a timeout does not authorize another create. |\n| `paid` / `payment_succeeded` | A validated matching API response says `succeeded` with zero known refunded cents. | Record the observation and let the application apply its own idempotent fulfillment policy. Continue to process later authenticated evidence. | Stop if later checkout or evidence state requires review. |\n| `not_paid` / `card_declined`, `payment_canceled`, or `payment_expired` | The API returned one of the component's known final nonpayment combinations. | Show the known outcome. A new attempt requires a separately authorized application flow and order decision. | Do not change this order ID or delete its database row to force a retry. |\n| `not_submitted` / `terminal_busy`, `terminal_offline`, `physical_terminal_unavailable`, `parameter_invalid`, `resource_missing`, `api_key_missing`, `api_key_malformed`, `api_key_invalid`, `insufficient_scope`, `live_mode_unavailable`, or `idempotency_key_required` | The server refused the create with that catalogued error before writing any payment. | Fix the cause (wait for or cancel the running payment, ping the terminal, use a simulated terminal, correct the IDs or key), then call `begin()` again with the same order ID and amount. It records the refused attempt and sends a new one with a fresh reference and Idempotency-Key. | Do not change the order ID or delete the database; `begin()` is the sanctioned path. |\n| `review_required` / `processor_unavailable` | The server wrote the payment but its push to the terminal failed (502). | Call `begin()` again: it resends the identical request with the same Idempotency-Key and the server resumes the push. At most two resends. | If it stays `processor_unavailable`, call `refresh(orderId)`; never create a new reference for this order. |\n| `review_required` / `create_outcome_unknown` | The create attempt had no trustworthy final response (timeout, lost response, 5xx other than the 502 above, 408, 429, a 409 with `Retry-After`, an unrecognized error, or a malformed body). It may or may not have reached the API. | Call `refresh(orderId)` for exact reference/payment lookup and preserve the identity for an operator. | If lookup stays empty, incomplete, ambiguous, or unavailable, stop. Never issue another POST for this order. |\n| `review_required` / `lookup_inconclusive` or `refresh_failed` | A read-only lookup could not establish current truth. | Check API availability and retry only the authorized read later. Capture the order ID, time, snapshot code, and whether lookup was by payment ID or reference. | Stop all automated fulfillment and payment creation while truth is inconclusive. |\n| `review_required` / `payment_mismatch` | The response failed a bound identity, amount, mode, method, state, timestamp, receipt, or ownership check. | Escalate with nonsecret expected-versus-observed field names. Preserve both databases. | Do not accept the response, rewrite the binding, or infer a processor outcome. |\n| `review_required` / `payment_state_conflict` | Equal-time or newer evidence contradicts an already saved final state. | Compare authenticated event history and authorized API reads; keep the historical identity. | Stop until a human resolves the application consequence. |\n| `review_required` / `payment_failure_unknown` | A final failure was not one of the known decline, cancellation, or expiry combinations. | Escalate the state and failure code as bounded metadata. | Do not translate it to declined or safe-to-retry. |\n| `review_required` / `payment_refund_inconsistent`, `payment_refunded`, or `payment_partially_refunded` | A positive refunded counter was observed. The counter is a high-water warning, not proof of a completed refund. | Inspect authenticated refund events and application records. | Stop fulfillment automation; never create a compensating refund or void from this snapshot. |\n\nA later valid read can recover the checkout status from a failed refresh, including returning\nto the saved final state when the new read agrees with it. Stale reads cannot regress that\nsaved final state, and lower refund counters cannot erase the saved refund high-water\nevidence. Repeated `begin()` returns the durable snapshot and never creates a retry escape,\nexcept the new attempt after `not_submitted` and the bounded same-key resend after\n`processor_unavailable`.\n\nCheckout can instead throw `configuration_invalid`, `request_invalid`, `order_missing`,\n`order_binding_mismatch`, `payment_unbound`, `checkout_closed`, or\n`terminal_checkout_storage_error`. These are local exceptions, not payment outcomes.\nCorrect configuration or caller input only when the trusted source is known. For\n`payment_unbound`, use the existing read-only recovery path. For storage errors, stop and\nrepair storage before continuing; raw SQLite or transport errors are intentionally hidden.\n\n## Read a webhook receiver response\n\nOnly HTTP `200` means the authenticated event was durably received. It means durable inbox\nreceipt only: it does not mean the payment succeeded, the order is paid, evidence was\napplied, or fulfillment ran. `{received:true, duplicate:true}` is a committed identical\nreplay, not a new business event.\n\n| HTTP / response code | Plain meaning | Owner and safe action |\n|---|---|---|\n| `400 invalid_event`, `ambiguous_headers`, or `request_aborted` | The envelope, UTF-8/JSON, event-ID agreement, headers, or request stream was invalid. | Integration owner: compare the sender contract and raw-body adapter without logging the raw payload. Do not retry malformed content locally. |\n| `401 invalid_signature` | No configured current/previous secret verified the exact bytes within the five-minute tolerance. | Receiver operator: check clock, secret rotation, and raw-byte handling. Never weaken verification or paste the secret into evidence. |\n| `403 mode_mismatch` or `merchant_mismatch` | The event is live or outside the trusted merchant allowlist. The environment allowlist is read once at startup, so a merchant created afterwards is refused until its ID is configured and the receiver restarts. | Security/application owner: reject it and check endpoint/environment routing. For a merchant your platform created, add it from your own records and restart, or use the receiver's trusted `isAllowedMerchant` lookup; redeliver dead deliveries afterwards. Do not add an ID from request input to the allowlist. |\n| `404 not_found` / `405 method_not_allowed` / `415 unsupported_content` | The path, method, media type, or content encoding is unsupported. | Integration owner: correct the sender/adapter to the documented POST endpoint and JSON content type. |\n| `408 request_timeout` / `413 body_too_large` | The request exceeded the five-second or 1 MiB receiver bound. | Receiver operator: investigate sender and capacity. Do not raise bounds casually or process the partial body. |\n| `409 event_identity_conflict` | The same event ID arrived with different authenticated bytes. | Security/application owner: preserve the original receipt and escalate. Never overwrite it or treat the second body as a replay. |\n| `503 storage_unavailable` or `receiver_unavailable` | Durable receipt did not complete, the bounded receiver failed, or the optional merchant lookup threw. | Operator: restore local storage/service health. Sender redelivery is safe because event identity is durable once committed. |\n\nReceiver construction can throw `Invalid receiver configuration.` or verifier configuration\ncan throw `Provide one or two nonempty signing secrets and a clock.` These startup errors are\nnot HTTP event results. Fix trusted configuration before accepting traffic.\n\n## Read evidence processing\n\n`processBatch()` reports `applied`, `held`, `blocked`, and `ignored` counts:\n\n| Disposition | Plain meaning | Owner and stopping condition |\n|---|---|---|\n| `applied` / `evidence_applied` | Valid evidence matched a registered immutable order binding and was committed atomically. | Application owner: read `getOrder()` and the semantic outbox. Do not equate application with fulfillment. |\n| `held` / `order_unbound` | A valid payment/refund identity has no registered trusted order yet. The inbox row remains pending for fair retry. | Application owner: recover the existing checkout identity, authorize the order, and register its exact binding. Never bind from the event. |\n| `blocked` / `event_invalid`, `event_unsupported`, `payment_invalid`, or `refund_invalid` | The saved event, supported type, or nested object failed strict validation. | Integration/security owner: inspect bounded metadata and the protected inbox locally. Stop; do not edit the raw row or mark it applied. |\n| `ignored` / `unrelated_event` | A recognized merchant, terminal, or `webhook.test` event has no order-payment effect. | No payment action. Retain normal receipt/deduplication policy. |\n\nAn order projection of `awaiting_evidence` means no accepted payment conclusion yet.\n`success_observed` means authenticated success evidence was seen; it deliberately does not\nmean paid or authorize fulfillment. `not_paid_observed` is limited to known decline,\ncancel, or expiry evidence. `review_required` is sticky after uncertain failure,\ncontradictory finals, any refund signal, attention, reversal, or refund event. There is no\nreview-resolution API. Preserve the record and require an application/operator decision.\n\nOutbox kinds are `payment_success_observed`, `payment_review_required`, and\n`refund_completion_observed`. They are deduplicated observations for a future dispatcher,\nnot commands. `listOutbox()` does not acknowledge delivery. A refund completion event still\nleaves the order in review; never trigger another refund or void from the outbox.\n\nEvidence methods can throw `order_evidence_configuration_invalid`, `order_binding_invalid`,\n`receiver_inbox_missing`, `receiver_inbox_incompatible`, `order_binding_mismatch`,\n`payment_already_bound`, `reference_already_bound`, `batch_limit_invalid`,\n`order_id_invalid`, `order_missing`, `order_evidence_closed`, or\n`order_evidence_storage_error`. Treat them as local integration/storage faults, not remote\npayment results. Restore the compatible receiver inbox and immutable binding; do not create\na replacement payment identity.\n\n## Escalate without secrets\n\nRecord the component name and version, UTC time window, application order ID, snapshot\nstatus/code or HTTP status/static code or evidence disposition/reason, API origin hostname,\nand whether the failure occurred before receipt, after durable receipt, or during evidence\napplication. Include bounded nonsecret ownership field names, counts, and revision numbers.\n\nNever include API keys, webhook secrets, authorization or signature headers, raw webhook\nbodies, database files or paths, idempotency keys, receipt bearer URLs, processor IDs, card\ndata, or customer payloads. Keep the original order/payment/reference identity and durable\ndatabases available to the authorized operator. An unknown outcome remains unknown until an\nauthorized read or authenticated evidence establishes otherwise.","updated":1790213661}