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 'NETWORK_ERROR':
        // check the Payment Order on your backend before retrying
        break;
    }
  }
}
PropertyDescription
codeStable error code, listed below.
messageHuman-readable message, in English. Log it; do not show it as is to the merchant.
statusHTTP status, when the PayGreen API answered with an error.
causeOriginal error, for your logs only.

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, for example a refused permission.Remount <LemonwayTerminalRoot> to retry.
CONNECTION_TOKEN_FAILEDtokenProvider failed, timed out (15 s) or returned no secret.Check your connection token endpoint.
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 off or permission refused.Ask the merchant to turn location on and grant it.
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 API refused to authorize the Payment Order. See status below.Usually create a new Payment Order.
PAYMENT_DECLINEDThe card was declined.Create a new Payment Order and ask for another card.
PAYMENT_CANCELEDThe payment was canceled.Create a new Payment Order for the next try.
CARD_READ_ERRORThe card could not be read.Call collectPayment() again with the same authorized object.
PAYMENT_IN_PROGRESSA payment is already running.Wait for it, or cancel it.
NETWORK_ERRORNetwork failure, timeout or server error.Before collectPayment(): retry. During collectPayment(): check the Payment Order on your backend first, the card may have been charged.
UNSUPPORTED_OPERATIONFeature not available with Tap to Pay.—
UNKNOWNAnything else.Same as NETWORK_ERROR. Log error.message.

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, has a buyer, or no usable bank_card config.
5xx, timeoutNETWORK_ERRORRetry. Authorizing the same Payment Order twice is safe.

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.

PERMISSION_REQUIRED or terminal.error at startup

Tap to Pay needs location services on and the precise location permission. If the merchant refused it, they must grant it in the system settings, then you 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?