{"object":"doc","slug":"accept-a-terminal-payment","title":"Accept a card-present payment in five calls","summary":"Create a merchant and a simulated terminal, push a payment, choose the outcome, and read the result, with no hardware.","tags":["guide","payments","terminals","sandbox"],"body":"# Accept a card-present payment in five calls\n\nEverything below runs with a `zp_test_` key and never moves money. `$B` is the base URL and `$KEY` your key. Every POST that creates something needs an `Idempotency-Key` header (any unique string).\n\n## 1. Create a merchant\n\n```\nPOST /v1/merchants\n{\"display_name\": \"Corner Gym\"}\n```\nResponse `201`:\n```json\n{\"object\":\"merchant\",\"id\":\"mch_01j...\",\"created\":1757100000,\"livemode\":false,\"display_name\":\"Corner Gym\",\"state\":\"active\",\"processor_connected\":true,\"metadata\":{}}\n```\n\n## 2. Create a simulated terminal\n\n```\nPOST /v1/merchants/{merchant_id}/terminals\n{\"kind\": \"simulated\", \"label\": \"Front desk\"}\n```\nResponse `201` includes `\"status\":\"online\"` and `\"sim_behavior\":\"manual\"`. Use `\"sim_behavior\":\"auto_approve\"` if you want the terminal to answer by itself after `sim_delay_s` seconds, which is closer to how a real terminal behaves.\n\n## 3. Create the payment\n\n```\nPOST /v1/payments\n{\"merchant_id\":\"mch_01j...\",\"amount_cents\":1250,\"currency\":\"usd\",\"platform_reference\":\"order-1001\",\"method\":\"terminal\",\"terminal_id\":\"term_01j...\",\"description\":\"Day pass\"}\n```\nResponse `202`:\n```json\n{\"object\":\"payment\",\"id\":\"pay_01j...\",\"state\":\"pending\",\"expires\":1757100180,\"terminal_id\":\"term_01j...\",\"amount_cents\":1250,\"failure_code\":null,\"receipt_url\":null, \"...\": \"...\"}\n```\n`platform_reference` is your own order id and must be unique per merchant. Reusing one returns `409 platform_reference_in_use` with the existing payment id, which is exactly what you want after a crash.\n\n## 4. Be the customer (sandbox only)\n\n```\nPOST /v1/sandbox/terminals/{terminal_id}/simulate\n{\"payment_id\":\"pay_01j...\",\"outcome\":\"approve\"}\n```\n`outcome` is `approve`, `decline`, `cancel`, or `timeout`. The response is the payment in its new state. The same `payment.processing` and `payment.succeeded` events fire as with a real terminal, so your webhook code sees the real thing. This endpoint does not take an `Idempotency-Key`: it is meant to be called once per outcome you want to try, not replayed.\n\n## 5. Read the result\n\n```\nGET /v1/payments/{payment_id}\n```\n`state` is `succeeded`, `card_last4` is `4242`, and `receipt_url` points at a hosted receipt you can show the customer. If you registered a webhook, you already received `payment.succeeded` with the same object under `data.object`.\n\n## What to do with each state\n\n`pending` and `processing` mean keep waiting (poll or wait for the webhook). Before fulfilling a succeeded payment, match its merchant, reference, currency and amount to the trusted order and inspect its refunded balance. A failed local state is not always proof of no charge: `processor_unverified`, `amount_mismatch`, unknown failure codes and attention events require review. Cancellation and expiry still need late-authorization handling. The handle-every-payment-state guide has the full table. To request stopping a pending or processing terminal payment, use the separately authorized `POST /v1/payments/{payment_id}/cancel` operation.\n\n## With a physical terminal\n\nThe same five calls, with the customer instead of the simulate endpoint. Nothing is installed on the device: the sale is pushed to the terminal's built-in payment bridge over the processor's cloud.\n\n1. `POST /v1/merchants/{merchant_id}/terminals/discover` lists the activated card readers on the merchant's processor account (`device_id`, `serial`, `store_name`).\n2. `POST /v1/merchants/{merchant_id}/terminals` with `{\"kind\":\"physical\",\"device_id\":\"urn:tid:...\",\"label\":\"Counter\"}` registers one. The terminal object carries `store_id`.\n3. `POST /v1/payments` as above, plus `\"terminal_options\": {\"tip\": true, \"receipt_screen\": false}` if the customer may tip or should see the device's receipt screen (both default false). Response `202` with `state: pending` and `expires` three minutes out. The screen shows the amount at once.\n4. The customer taps, inserts, or swipes. About a minute later the payment is `succeeded` (with `card_last4`, `card_brand`, `tip_cents`, `receipt_url`), `failed` (`card_declined`), or `canceled` (`canceled_on_terminal`). Poll `GET /v1/payments/{payment_id}` or take the webhook.\n5. `POST /v1/payments/{payment_id}/cancel` clears the screen and ends the payment `canceled_by_platform`. A payment nobody answers clears the screen at `expires` and ends `expired`.\n\nOne payment at a time per physical terminal: a second `POST /v1/payments` on a busy terminal answers `409 terminal_busy` and names the payment in flight. If the processor refuses the push, the answer is `502 processor_unavailable` and the payment stays `pending`: retry the same request (same `platform_reference`, same amount) and it resumes. That retry pushes the sale to the device again, so retry only after a `502`, never as a way to poll: to follow a payment that is already on the screen, use `GET /v1/payments/{payment_id}` or the webhook.\n\nWe never trust the terminal's report alone: every result is re-read from the processor and its reference, currency, and amounts must match what you asked for. An authorization that does not match, or arrives after a failed, canceled or expired payment, triggers an automatic void attempt (`failure_code: amount_mismatch`, or the `payment.reversed_late` event). An additional authorization on an already succeeded payment is left standing and raises `payment.needs_attention` with reason `additional_authorization`; it requires operator review. A partial approval (the card approved only part of the amount) is never accepted: it is voided the same way and the payment ends `failed` / `partial_approval`, not `amount_mismatch`; ask for another card. A tip the terminal added and the payment allowed is never read as a partial approval. On a terminal sale with an on-screen tip the processor reports the approved amount as order plus tip (VERIFIED on the sandbox 11/17/2026: a 1.00 order tipped 0.18 read `approvedAmount` 118, `amounts.orderAmount` 100, `tipAmount` 18, `transactionAmount` 118, `statusCode` \"1\", `partiallyApproved` false; with no tip, 100 and 100); the shape of a real terminal partial approval is not yet verified. For an amount mismatch, if the processor refuses the void, the authorization stays standing while the payment ends `failed` / `amount_mismatch`. A refused late void preserves the existing failed, canceled or expired state. We log and reconcile these cases; neither local failure nor cancellation is proof that nothing was charged.\n\nTest mode shares a sandbox processor account, so physical terminals are reserved for approved platforms: otherwise registration answers `400 physical_terminal_unavailable`. Start with simulated terminals; physical device behavior requires a separately authorized hardware trial. Live merchant onboarding, live terminal registration and live payment writes are not available in this release.\n\n## Next\n\nRegister a webhook (guide: webhooks), refund the payment (guide: refunds-and-voids), then run the `integration_checklist` tool.","updated":1795030444}