Local JS SDK
kuvex-local.js is the SDK for web applications that run inside an authorized Kuvex Runtime WebView on the terminal. It calls Kuvex Runtime through the native bridge; no secret key or device secret is present in the page. To drive a terminal from a POS on another machine, use companion mode.
Requirements
| Item | Requirement |
|---|---|
| SDK | @kuvex/web 1.0.4 or later (current: 1.1.0). receipt_status polling requires 1.0.6 or later |
| Runtime | Kuvex Runtime 162 or later, with the matching Kuvex server release |
| Environment | A Kuvex Runtime WebView. The application and its origin must be registered and covered by the terminal's current grant; Runtime matches both on every call. Ordinary browsers return local_bridge_unavailable |
| Payment methods | Covered by the local payment grant, including its per-transaction amount limit |
| Commerce methods | Require the corresponding permissions, off by default |
| Live mode | Each requested capability requires release approval by Kuvex; until then calls return local_live_release_pending. This page grants no live access and authorizes no refund |
Connect
// In an authorized Kuvex Runtime WebView, not an ordinary browser.
const connect = require('@kuvex/web/local');
const local = await connect({transport: 'local'});CDN: load /sdk/web/1.1.0/kuvex-local.js, then call Kuvex.connect({transport: 'local'}).
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
transport | String | Yes | Always local |
Result: a client object. Repeated calls on the same page return the same client.
| Field | Type | Description |
|---|---|---|
transport | String | Always local |
terminalId | String | ID of the terminal the page runs on |
Bridge behavior:
- Runtime issues a session per page load. When the page navigates, the session changes; on
local_session_expiredthe SDK reconnects once and resends the same call at most once. - A call without a reply within 30 seconds (
scan: 45 seconds) fails withlocal_response_timeout. - At most 16 calls can be outstanding; further calls fail with
local_bridge_busy.
Payment flow
- Generate an idempotency key for the order and store it durably before calling
pay(). - Call
pay({amount_cents, idempotency_key}). Runtime shows a native confirmation dialog on the terminal; the card is then read on the terminal. - On resolve, the payment is
succeededand its collection ispaid: release the order. - On
payment_not_completed, readerror.payment.statusand handle it per Payment status. - On
local_response_timeout,payment_timeout, or after a page reload, query withgetPaymentByRequest(key)orgetPayment(id)using the stored key or ID. A missing result means the outcome is unknown: do not charge again and do not switch transport.
Payment methods
pay
local.pay({ amount_cents, idempotency_key, currency, wait, timeout_ms })Starts a payment on this terminal and, by default, waits for its final status.
| Parameter | Type | Required | Description |
|---|---|---|---|
amount_cents | int | Yes | Amount in cents; a positive integer not above the grant's per-transaction limit |
idempotency_key | String | Yes | Request key; non-empty, at most 160 characters, no control characters |
currency | String | No | Only usd |
wait | boolean | No | false returns the payment object as soon as Runtime accepts the request. Default true |
timeout_ms | int | No | Maximum wait for a final status, 1000–300000. Default 120000 |
Result: the payment object, only when status is succeeded and collection.status is paid. pay() resolves as soon as the payment succeeds; it does not wait for the receipt.
| Error | Condition | Handling |
|---|---|---|
payment_not_completed | Final status other than succeeded; error.payment holds the payment | Handle per status |
payment_timeout | Status still pending / processing at the wait deadline; error.payment holds the payment | Keep querying the same payment |
local_response_timeout with error.outcome = 'unknown' | No reply from Runtime and no payment found for the key; error.idempotency_key holds the key | Query the original key; do not charge again |
local_idempotency_conflict | The key already belongs to a payment with a different amount | Use a new key for a different amount |
On local_response_timeout the SDK queries getPaymentByRequest once before failing; it never resubmits the payment. While waiting, the SDK polls the payment every 500 ms and passes each snapshot to listeners registered with local.on('payment.changed', fn). Exceptions thrown by listeners are ignored.
getPayment, getPaymentByRequest, cancelPayment
| Method | Parameter | Result |
|---|---|---|
getPayment(paymentId) | paymentId String, required | Payment object |
getPaymentByRequest(idempotencyKey) | idempotencyKey String, required: the key of the original pay() | Payment object, or null if none was found |
cancelPayment(paymentId) | paymentId String, required | { requested: boolean } |
cancelPayment requests cancellation of a payment in progress. It is neither a refund nor an approved void.
Payment object
| Field | Type | Description |
|---|---|---|
id | String | Payment ID |
attempt_id | String | Attempt ID on the terminal |
amount_cents | int | Requested amount in cents |
currency | String | usd |
status | String | See below |
revision | int | Revision of this snapshot |
result_source | String | device_callback: result from the card module on the terminal; cloud_resolution: result confirmed by Kuvex; pending: no result yet |
resolution_id | String | ID of the Kuvex resolution; null without one |
sync_status | String | synced: delivered to Kuvex; pending: not yet delivered |
collection | Object | id, status (paid when the payment succeeded, otherwise open) |
receipt_status | String | Automatic receipt status, see Receipt status |
status | Meaning | Final | Recommended handling |
|---|---|---|---|
pending / processing | Not yet completed on the terminal | No | Wait; pay() keeps polling |
succeeded | Approved and charged | Yes | Release the order |
partially_approved | Partial approval: only part of the amount was charged | Yes | Do not release the full order |
failed | Declined or not completed; nothing charged | Yes | May retry with a new idempotency key |
canceled | Canceled; nothing charged | Yes | — |
review | Unknown outcome, including an offline approval not yet confirmed | No | Do not charge again; keep querying the same payment |
getCloudPayment returns the Kuvex payment object, whose status values (including offline_approved and requires_capture) are listed under Transaction status.
Receipt status
receipt_status reports only whether the terminal's automatic receipt was printed. It never changes the payment result.
receipt_status | Meaning |
|---|---|
none | No receipt is expected: payment not successful, partially approved, automatic receipts off, or no printer |
printing | Printing in progress, including a printer waiting for paper or a closed cover; can take seconds to minutes |
printed | The terminal confirmed the receipt was printed |
not_printed | Printing failed, or the terminal cannot confirm a complete print |
Handling:
- While
receipt_statusisprinting, pollgetPayment(paymentId)at a bounded rate (for example every 2 seconds, for up to 10 minutes). Requires SDK 1.0.6 or later. - If the payment succeeded and
receipt_statusisnot_printed, keep the success screen and inform the customer, for example "Your receipt did not print. Please ask staff for a copy." Do not offer to pay again and do not show an error screen. Staff can reprint from the payment details on the terminal.
Commerce methods
Commerce methods are executed by Kuvex and require a connection from the terminal to Kuvex; they are not available offline.
Permissions
| Permission | Methods |
|---|---|
read | getCloudPayment, getTerminal |
refund | refund, getRefundByRequest |
void | void |
print | print, getPrintJob |
scan | scan |
display | getCartDisplay, setCartDisplay |
Grant rules:
- The grant field
commerce_operationsaccepts only the six permissions above. Grants issued without it confer none of them. - In live mode each requested permission additionally requires release approval by Kuvex.
- Hidden or unassigned applications cannot start operations. A page that is still open may query its own payments, refunds and print jobs while its grant is valid.
- Idempotency keys are scoped to the account, terminal, merchant binding and application. Renewing a grant keeps the scope; changing the application or the terminal's merchant binding starts a new scope, in which earlier keys are not found.
- Reusing a refund or void key for a different payment, or changing the amount or print content of an existing request, returns
local_idempotency_conflictinstead of an unrelated result.
Common argument rules:
- Arguments may not exceed 24 KB and may contain only the documented fields.
payment_idmust be a payment taken locally by this application on this terminal binding and synchronized to Kuvex; any other ID returnslocal_payment_not_found. Commerce methods cannot search other payments of the account.- Idempotency keys: 1–128 characters.
- When a commerce call fails with
local_response_timeoutorlocal_cloud_unavailable, the error carriesoutcome: 'unknown',idempotency_keyandpayment_id. Query with the original key; never generate a new key for the same intent.
refund, getRefundByRequest
local.refund({ payment_id, amount_cents, idempotency_key })
local.getRefundByRequest(idempotencyKey)refund refunds a payment after a native confirmation on the terminal. Permission: refund.
| Parameter | Type | Required | Description |
|---|---|---|---|
payment_id | String | Yes | Original payment ID |
amount_cents | int | Yes | Refund amount in cents, stated explicitly; a positive integer not above the grant's per-transaction limit |
idempotency_key | String | Yes | Request key; reuse the exact key for the same refund intent |
Result: { refund_id, payment_id, amount_cents, status }. pending means reserved or queued, not refunded.
getRefundByRequest(idempotencyKey) returns the stored refund { id, object: 'refund', payment_id, amount_cents, status }, or fails with local_operation_not_found. Poll it at a bounded rate, or rely on the webhooks received by the ISV server (refund events). Do not infer success from HTTP 202.
void
local.void({ payment_id, idempotency_key })Voids a payment after a native confirmation on the terminal. Permission: void. The acquirer decides eligibility; see Cancel / void.
| Parameter | Type | Required | Description |
|---|---|---|---|
payment_id | String | Yes | Original payment ID. Its amount may not exceed the grant's per-transaction limit |
idempotency_key | String | Yes | Request key |
After the call, check the result with getCloudPayment(paymentId). Never convert a void with an unknown outcome into a refund automatically.
print, getPrintJob
local.print(receipt, paymentId, idempotencyKey)
local.getPrintJob(idempotencyKey)Prints a structured document on this terminal. Permission: print.
| Parameter | Type | Required | Description |
|---|---|---|---|
receipt | Object | Yes | Structured content, fields as in Print. Printer commands and card data are rejected (local_arguments_invalid) |
paymentId | String | No | Related payment ID; pass undefined for none |
idempotencyKey | String | Yes | Request key |
Result: { id, object: 'print_job', terminal_id, status }. Repeating the same key with the same content returns the existing job with replay: true and never prints twice; different content returns local_idempotency_conflict.
getPrintJob(idempotencyKey) returns { id, object: 'print_job', terminal_id, status } of the original request, or fails with local_operation_not_found.
status | Meaning | Final |
|---|---|---|
dispatching | Being sent to the terminal; whether it arrived is not yet known | No |
dispatched | Sent to the terminal | No |
accepted | Accepted by the terminal | No |
blocked | Waiting for paper or a closed cover; resumes automatically | No |
printed | Printing confirmed by the terminal | Yes |
failed | Known failure, including a failed send | Yes |
delivery_unknown | The terminal lost power or crashed while printing; output unknown | Yes |
skipped | The terminal has no printer | Yes |
scan
local.scan()Reads one barcode or QR code. Permission: scan. Result: { id, object: 'scan', status, data }. Only status: 'completed' with non-empty data is a code; timeout is not an empty successful scan.
getCartDisplay, setCartDisplay
const current = await local.getCartDisplay();
await local.setCartDisplay({
revision: current.revision + 1, session_id: 'register-1', currency: 'usd',
lines: [{ id: 'l1', name: 'Latte', quantity: 1, amount_cents: 450 }],
subtotal_cents: 450, tax_cents: 0, total_cents: 450,
});Permission: display.
| Method | Parameter | Result |
|---|---|---|
getCartDisplay() | — | Cart state, as in Retrieve the cart |
setCartDisplay(snapshot) | snapshot Object, required: the complete cart with the next revision, as in Push the cart | Cart state |
pending means stored, neither displayed nor paid.
getCloudPayment, getTerminal
Permission: read.
| Method | Parameter | Result |
|---|---|---|
getCloudPayment(paymentId) | paymentId String, required | Payment object as stored by Kuvex; only for payments covered by the argument rules above |
getTerminal() | — | Terminal object of this terminal; contains no credentials |
Request path and outages
- The page calls a method; the native bridge accepts it only from the registered application and origin.
- For
pay,refundandvoid, Runtime shows a native confirmation dialog. - Commerce methods: Runtime calls Kuvex over HTTPS with the terminal's device credentials.
- Kuvex checks the grant, permission and arguments, then executes through the same transaction and command ledger as the REST API; the terminal executes the command received over MQTT.
- Kuvex stores the result and sends a signed webhook to the ISV server.
Outage behavior:
- Local payment execution and recovery run on the terminal. Commerce methods depend on Kuvex and do not work offline.
- An HTTP or network failure leaves the outcome unknown. Kuvex performs no local fallback refund, no transport switch, no new payment and no automatic reprint.
- Credentials never enter the WebView. The page cannot specify a URL, target terminal or account; all are taken from the grant.
Error codes
Methods reject with an Error whose code property holds the error code. Error codes of the REST API returned by the forwarded call (for example terminal_offline, display_revision_conflict, not_refundable) are passed through unchanged; see Errors.
| Raised by | Code | Description | Retriable |
|---|---|---|---|
| SDK | transport_unsupported | connect() called without transport: 'local' | No |
| SDK | local_bridge_unavailable | Not running in a Kuvex Runtime WebView | No |
| SDK | local_handshake_invalid | Invalid handshake reply from Runtime | No |
| SDK | local_bridge_busy | 16 calls already outstanding | Yes, after outstanding calls complete |
| SDK | local_response_timeout | No reply within 30 seconds (scan: 45 seconds); outcome unknown | No; query the original request |
| SDK | local_bridge_error | Unrecognized error from Runtime | No |
| SDK, Kuvex | local_idempotency_key_required | Idempotency key missing or invalid | No |
| SDK, Runtime, Kuvex | local_amount_invalid | Amount not a positive integer, above the grant limit, or currency not usd | No |
| SDK, Kuvex | local_idempotency_conflict | Key already used with different arguments | No |
| SDK | payment_not_completed | pay() ended in a status other than succeeded; see error.payment | No |
| SDK | payment_timeout | pay() wait deadline reached; see error.payment | No; query the payment |
| Runtime | local_session_expired | The page navigated; the SDK reconnects and resends once | Handled by the SDK |
| Runtime | local_authorization_unavailable | No valid grant for this page and origin, or the terminal clock is not synchronized | No |
| Runtime | local_live_release_pending | Capability not yet approved for live mode | No |
| Runtime, Kuvex | local_operation_not_authorized | Permission not granted to this application | No |
| Runtime | local_request_invalid | pay() idempotency key longer than 160 characters or containing control characters | No |
| Runtime | local_confirmation_busy | Another confirmation dialog is open | Yes |
| Runtime | local_confirmation_canceled | The confirmation dialog was canceled; nothing was executed | No |
| Kuvex | local_method_unsupported | Unknown method | No |
| Kuvex | local_arguments_invalid | Undocumented field, arguments over 24 KB, malformed payment_id, receipt or snapshot not an object, or card data in receipt | No |
| Kuvex | local_payment_not_found | No synchronized payment of this application binding | No |
| Kuvex | local_operation_not_found | No print job or refund for this key | No |
| Kuvex | local_cloud_unavailable | Kuvex unreachable or no answer; outcome unknown | Yes; query the original request |
Test in the sandbox
The sandbox lab runs as a registered, authorized test-mode application. It refuses live terminals and performs no operation on load; in an ordinary browser it reports local_bridge_unavailable and keeps its operation buttons disabled.
- Enter the ID of a payment taken by this application on this terminal and synchronized to Kuvex, and query it.
- Start a refund and cancel the native confirmation dialog once (
local_confirmation_canceled). - Start the refund again and confirm it in the dialog, which is marked as test mode.
- Query the refund with the original key.
- Check the print job and the cart revision separately.
Hardware output, actual refunds and voids at the acquirer, and live-mode webhooks require a separately approved merchant and device test window. A passing sandbox test does not prove that money was returned.