Error handling

Error codes, what causes them and what to do.

Every function of the SDK throws a LemonwayTerminalError. Branch on its code: codes are stable across versions.

import { LemonwayTerminalError } from '@lemonway/terminal';

try {
  await LemonwayTerminal.collectPayment(authorized);
} catch (error) {
  if (error instanceof LemonwayTerminalError) {
    switch (error.code) {
      case 'PAYMENT_DECLINED':
        // ask for another card, with a new Payment Order
        break;
      case 'PAYMENT_RESULT_UNKNOWN':
        showPendingPayment(authorized.paymentOrderId);
        break;
    }
  }
}
PropertyDescription
codeStable error code, listed below.
messageEnglish diagnostic message. Use code to choose translated text for the merchant.
statusHTTP status, when the PayGreen API answered with an error.
hintSuggested next action when available.
causeUnderlying error. Keep it out of logs and merchant-facing messages because it can contain sensitive details.

Error codes

Setup

CodeCauseWhat to do
NOT_INITIALIZEDinit() not called, <LemonwayTerminalRoot> not mounted, or still initializing.Call init() first and wait for terminal.ready.
INVALID_CONFIGMissing or invalid option in init(), or public key rejected by the API (HTTP 401).Check env, publicKey and tokenProvider. Keys and env must match.
INITIALIZATION_FAILEDThe terminal could not start.Resolve the cause and remount LemonwayTerminalRoot.
CONNECTION_TOKEN_FAILEDtokenProvider failed, timed out after 15 seconds or returned no token.Check the connection token request.
APPLE_ACCOUNT_REQUIREDiOS requires an Apple Account for setup.Sign in to an Apple Account in Settings, then retry.
TERMS_ACCEPTANCE_REQUIREDThe Tap to Pay terms need acceptance.Have an authorized merchant representative connect with allowTermsAcceptance: true.
TERMS_ACCEPTANCE_CANCELEDThe merchant canceled terms acceptance.Let the merchant retry when ready.
TERMS_ACCEPTANCE_FAILEDiOS could not complete terms acceptance.Check the Apple Account and retry.
OS_VERSION_NOT_SUPPORTEDThe iOS version cannot run Tap to Pay.Update iOS and retry setup.
INVALID_PARAMSMissing parameter, or no location for the connection.Fix the call. Return locationId from tokenProvider.

Phone and reader

CodeCauseWhat to do
DEVICE_NOT_SUPPORTEDThe phone or its OS version cannot run Tap to Pay.Use a supported phone.
INSECURE_ENVIRONMENTDebug build, Developer options on, or rooted phone.Use a release build and turn Developer options off.
PERMISSION_REQUIREDLocation services are disabled or a required permission is missing.Enable location services and check permissions.
LOCATION_PERMISSION_DENIEDThe merchant denied Android foreground location at startup.Grant location while in use in Android settings, then remount the root.
NFC_DISABLEDNFC is off.Ask the merchant to turn NFC on.
READER_DISCOVERY_FAILEDThe phone could not be found as a reader.Retry connectTapToPay().
READER_CONNECTION_FAILEDConnection refused, for example Tap to Pay not enabled on the account.Retry. If it persists, contact PayGreen with error.message.
READER_DISCONNECTEDThe reader was disconnected.Wait for reader.connected or connect again.
READER_HARDWARE_ERRORThe reader failed.Retry.

Payment

CodeCauseWhat to do
PAYMENT_ORDER_FAILEDThe Payment Order request failed or the SDK could not prepare collection.Check status when available and verify the same order before replacing it.
PAYMENT_DECLINEDThe card was declined or the current intent previously failed.Check the order before starting a new attempt. Use a new order after a confirmed refusal.
PAYMENT_CANCELEDCard reading was canceled.Collect again with the same authorization.
CARD_READ_ERRORThe card could not be read.Call collectPayment() again with the same authorized object.
PAYMENT_IN_PROGRESSA payment is running and the requested operation cannot proceed.Wait for the active payment. Cancellation is available while waiting for the card.
NETWORK_ERRORA network call timed out or failed.Check connectivity and the operation that failed.
PAYMENT_RESULT_UNKNOWNThe SDK cannot establish the outcome of collection.Keep the purchase pending and check the same order.
UNSUPPORTED_OPERATIONFeature not available with Tap to Pay.—
UNKNOWNThe SDK could not categorize the failure.Check the operation and keep the order associated with the purchase until its status is resolved.

authorizePaymentOrder() HTTP errors

HTTPCodeMeaning
401INVALID_CONFIGPublic key rejected, or wrong env.
403PAYMENT_ORDER_FAILEDWrong objectSecret, or Payment Order of another shop.
404PAYMENT_ORDER_FAILEDUnknown Payment Order id.
409PAYMENT_ORDER_FAILEDThe Payment Order is locked by another request. Retry.
422PAYMENT_ORDER_FAILEDBusiness rule: Payment Order expired or not pending, not tap_to_pay, automatic capture disabled, has a buyer, or no usable bank_card config.
5xx, timeoutNETWORK_ERRORRetry. Authorizing the same Payment Order twice is safe.

Sandbox detection errors

The SDK determines the sandbox simulation mode before collecting. If detection fails, fix the cause and retry with the same authorization.

CodeCause
INVALID_CONFIGHTTP 401. Check the shop’s public key and environment.
NETWORK_ERRORA network error, the 15-second timeout or HTTP 5xx.
PAYMENT_ORDER_FAILEDAnother HTTP error, including HTTP 404, or an invalid detection response.

Troubleshooting the first setup

INSECURE_ENVIRONMENT on Android

Tap to Pay refuses debuggable builds and phones with Developer options on. Build a release APK, install it with USB debugging on, then turn Developer options off and open the app from its icon.

Android location setup

Keep location services enabled. Grant approximate foreground location on Android 12 and later. For LOCATION_PERMISSION_DENIED, grant access while in use in Android settings, then remount LemonwayTerminalRoot.

iOS build fails to sign

The Tap to Pay entitlement is not enabled on your App ID yet. Request it from Apple, or set iosTapToPayEntitlement to false in the Expo plugin until then.

INVALID_PARAMS: locationId is required

Your connection token endpoint does not return locationId. Return location_id from the API as locationId, or pass it to init().


Did this page help you?