Skip to content

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 ​

ItemRequirement
SDK@kuvex/web 1.0.4 or later (current: 1.1.0). receipt_status polling requires 1.0.6 or later
RuntimeKuvex Runtime 162 or later, with the matching Kuvex server release
EnvironmentA 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 methodsCovered by the local payment grant, including its per-transaction amount limit
Commerce methodsRequire the corresponding permissions, off by default
Live modeEach 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 ​

js
// 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

ParameterTypeRequiredDescription
transportStringYesAlways local

Result: a client object. Repeated calls on the same page return the same client.

FieldTypeDescription
transportStringAlways local
terminalIdStringID 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_expired the SDK reconnects once and resends the same call at most once.
  • A call without a reply within 30 seconds (scan: 45 seconds) fails with local_response_timeout.
  • At most 16 calls can be outstanding; further calls fail with local_bridge_busy.

Payment flow ​

  1. Generate an idempotency key for the order and store it durably before calling pay().
  2. Call pay({amount_cents, idempotency_key}). Runtime shows a native confirmation dialog on the terminal; the card is then read on the terminal.
  3. On resolve, the payment is succeeded and its collection is paid: release the order.
  4. On payment_not_completed, read error.payment.status and handle it per Payment status.
  5. On local_response_timeout, payment_timeout, or after a page reload, query with getPaymentByRequest(key) or getPayment(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 ​

js
local.pay({ amount_cents, idempotency_key, currency, wait, timeout_ms })

Starts a payment on this terminal and, by default, waits for its final status.

ParameterTypeRequiredDescription
amount_centsintYesAmount in cents; a positive integer not above the grant's per-transaction limit
idempotency_keyStringYesRequest key; non-empty, at most 160 characters, no control characters
currencyStringNoOnly usd
waitbooleanNofalse returns the payment object as soon as Runtime accepts the request. Default true
timeout_msintNoMaximum 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.

ErrorConditionHandling
payment_not_completedFinal status other than succeeded; error.payment holds the paymentHandle per status
payment_timeoutStatus still pending / processing at the wait deadline; error.payment holds the paymentKeep 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 keyQuery the original key; do not charge again
local_idempotency_conflictThe key already belongs to a payment with a different amountUse 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 ​

MethodParameterResult
getPayment(paymentId)paymentId String, requiredPayment 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 ​

FieldTypeDescription
idStringPayment ID
attempt_idStringAttempt ID on the terminal
amount_centsintRequested amount in cents
currencyStringusd
statusStringSee below
revisionintRevision of this snapshot
result_sourceStringdevice_callback: result from the card module on the terminal; cloud_resolution: result confirmed by Kuvex; pending: no result yet
resolution_idStringID of the Kuvex resolution; null without one
sync_statusStringsynced: delivered to Kuvex; pending: not yet delivered
collectionObjectid, status (paid when the payment succeeded, otherwise open)
receipt_statusStringAutomatic receipt status, see Receipt status
statusMeaningFinalRecommended handling
pending / processingNot yet completed on the terminalNoWait; pay() keeps polling
succeededApproved and chargedYesRelease the order
partially_approvedPartial approval: only part of the amount was chargedYesDo not release the full order
failedDeclined or not completed; nothing chargedYesMay retry with a new idempotency key
canceledCanceled; nothing chargedYes—
reviewUnknown outcome, including an offline approval not yet confirmedNoDo 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_statusMeaning
noneNo receipt is expected: payment not successful, partially approved, automatic receipts off, or no printer
printingPrinting in progress, including a printer waiting for paper or a closed cover; can take seconds to minutes
printedThe terminal confirmed the receipt was printed
not_printedPrinting failed, or the terminal cannot confirm a complete print

Handling:

  • While receipt_status is printing, poll getPayment(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_status is not_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 ​

PermissionMethods
readgetCloudPayment, getTerminal
refundrefund, getRefundByRequest
voidvoid
printprint, getPrintJob
scanscan
displaygetCartDisplay, setCartDisplay

Grant rules:

  • The grant field commerce_operations accepts 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_conflict instead of an unrelated result.

Common argument rules:

  • Arguments may not exceed 24 KB and may contain only the documented fields.
  • payment_id must be a payment taken locally by this application on this terminal binding and synchronized to Kuvex; any other ID returns local_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_timeout or local_cloud_unavailable, the error carries outcome: 'unknown', idempotency_key and payment_id. Query with the original key; never generate a new key for the same intent.

refund, getRefundByRequest ​

js
local.refund({ payment_id, amount_cents, idempotency_key })
local.getRefundByRequest(idempotencyKey)

refund refunds a payment after a native confirmation on the terminal. Permission: refund.

ParameterTypeRequiredDescription
payment_idStringYesOriginal payment ID
amount_centsintYesRefund amount in cents, stated explicitly; a positive integer not above the grant's per-transaction limit
idempotency_keyStringYesRequest 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 ​

js
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.

ParameterTypeRequiredDescription
payment_idStringYesOriginal payment ID. Its amount may not exceed the grant's per-transaction limit
idempotency_keyStringYesRequest key

After the call, check the result with getCloudPayment(paymentId). Never convert a void with an unknown outcome into a refund automatically.

print, getPrintJob ​

js
local.print(receipt, paymentId, idempotencyKey)
local.getPrintJob(idempotencyKey)

Prints a structured document on this terminal. Permission: print.

ParameterTypeRequiredDescription
receiptObjectYesStructured content, fields as in Print. Printer commands and card data are rejected (local_arguments_invalid)
paymentIdStringNoRelated payment ID; pass undefined for none
idempotencyKeyStringYesRequest 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.

statusMeaningFinal
dispatchingBeing sent to the terminal; whether it arrived is not yet knownNo
dispatchedSent to the terminalNo
acceptedAccepted by the terminalNo
blockedWaiting for paper or a closed cover; resumes automaticallyNo
printedPrinting confirmed by the terminalYes
failedKnown failure, including a failed sendYes
delivery_unknownThe terminal lost power or crashed while printing; output unknownYes
skippedThe terminal has no printerYes

scan ​

js
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 ​

js
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.

MethodParameterResult
getCartDisplay()—Cart state, as in Retrieve the cart
setCartDisplay(snapshot)snapshot Object, required: the complete cart with the next revision, as in Push the cartCart state

pending means stored, neither displayed nor paid.

getCloudPayment, getTerminal ​

Permission: read.

MethodParameterResult
getCloudPayment(paymentId)paymentId String, requiredPayment 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 ​

  1. The page calls a method; the native bridge accepts it only from the registered application and origin.
  2. For pay, refund and void, Runtime shows a native confirmation dialog.
  3. Commerce methods: Runtime calls Kuvex over HTTPS with the terminal's device credentials.
  4. 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.
  5. 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 byCodeDescriptionRetriable
SDKtransport_unsupportedconnect() called without transport: 'local'No
SDKlocal_bridge_unavailableNot running in a Kuvex Runtime WebViewNo
SDKlocal_handshake_invalidInvalid handshake reply from RuntimeNo
SDKlocal_bridge_busy16 calls already outstandingYes, after outstanding calls complete
SDKlocal_response_timeoutNo reply within 30 seconds (scan: 45 seconds); outcome unknownNo; query the original request
SDKlocal_bridge_errorUnrecognized error from RuntimeNo
SDK, Kuvexlocal_idempotency_key_requiredIdempotency key missing or invalidNo
SDK, Runtime, Kuvexlocal_amount_invalidAmount not a positive integer, above the grant limit, or currency not usdNo
SDK, Kuvexlocal_idempotency_conflictKey already used with different argumentsNo
SDKpayment_not_completedpay() ended in a status other than succeeded; see error.paymentNo
SDKpayment_timeoutpay() wait deadline reached; see error.paymentNo; query the payment
Runtimelocal_session_expiredThe page navigated; the SDK reconnects and resends onceHandled by the SDK
Runtimelocal_authorization_unavailableNo valid grant for this page and origin, or the terminal clock is not synchronizedNo
Runtimelocal_live_release_pendingCapability not yet approved for live modeNo
Runtime, Kuvexlocal_operation_not_authorizedPermission not granted to this applicationNo
Runtimelocal_request_invalidpay() idempotency key longer than 160 characters or containing control charactersNo
Runtimelocal_confirmation_busyAnother confirmation dialog is openYes
Runtimelocal_confirmation_canceledThe confirmation dialog was canceled; nothing was executedNo
Kuvexlocal_method_unsupportedUnknown methodNo
Kuvexlocal_arguments_invalidUndocumented field, arguments over 24 KB, malformed payment_id, receipt or snapshot not an object, or card data in receiptNo
Kuvexlocal_payment_not_foundNo synchronized payment of this application bindingNo
Kuvexlocal_operation_not_foundNo print job or refund for this keyNo
Kuvexlocal_cloud_unavailableKuvex unreachable or no answer; outcome unknownYes; 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.

  1. Enter the ID of a payment taken by this application on this terminal and synchronized to Kuvex, and query it.
  2. Start a refund and cancel the native confirmation dialog once (local_confirmation_canceled).
  3. Start the refund again and confirm it in the dialog, which is marked as test mode.
  4. Query the refund with the original key.
  5. 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.