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;
}
}
}| Property | Description |
|---|---|
code | Stable error code, listed below. |
message | English diagnostic message. Use code to choose translated text for the merchant. |
status | HTTP status, when the PayGreen API answered with an error. |
hint | Suggested next action when available. |
cause | Underlying error. Keep it out of logs and merchant-facing messages because it can contain sensitive details. |
Error codes
Setup
| Code | Cause | What to do |
|---|---|---|
NOT_INITIALIZED | init() not called, <LemonwayTerminalRoot> not mounted, or still initializing. | Call init() first and wait for terminal.ready. |
INVALID_CONFIG | Missing 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_FAILED | The terminal could not start. | Resolve the cause and remount LemonwayTerminalRoot. |
CONNECTION_TOKEN_FAILED | tokenProvider failed, timed out after 15 seconds or returned no token. | Check the connection token request. |
APPLE_ACCOUNT_REQUIRED | iOS requires an Apple Account for setup. | Sign in to an Apple Account in Settings, then retry. |
TERMS_ACCEPTANCE_REQUIRED | The Tap to Pay terms need acceptance. | Have an authorized merchant representative connect with allowTermsAcceptance: true. |
TERMS_ACCEPTANCE_CANCELED | The merchant canceled terms acceptance. | Let the merchant retry when ready. |
TERMS_ACCEPTANCE_FAILED | iOS could not complete terms acceptance. | Check the Apple Account and retry. |
OS_VERSION_NOT_SUPPORTED | The iOS version cannot run Tap to Pay. | Update iOS and retry setup. |
INVALID_PARAMS | Missing parameter, or no location for the connection. | Fix the call. Return locationId from tokenProvider. |
Phone and reader
| Code | Cause | What to do |
|---|---|---|
DEVICE_NOT_SUPPORTED | The phone or its OS version cannot run Tap to Pay. | Use a supported phone. |
INSECURE_ENVIRONMENT | Debug build, Developer options on, or rooted phone. | Use a release build and turn Developer options off. |
PERMISSION_REQUIRED | Location services are disabled or a required permission is missing. | Enable location services and check permissions. |
LOCATION_PERMISSION_DENIED | The merchant denied Android foreground location at startup. | Grant location while in use in Android settings, then remount the root. |
NFC_DISABLED | NFC is off. | Ask the merchant to turn NFC on. |
READER_DISCOVERY_FAILED | The phone could not be found as a reader. | Retry connectTapToPay(). |
READER_CONNECTION_FAILED | Connection refused, for example Tap to Pay not enabled on the account. | Retry. If it persists, contact PayGreen with error.message. |
READER_DISCONNECTED | The reader was disconnected. | Wait for reader.connected or connect again. |
READER_HARDWARE_ERROR | The reader failed. | Retry. |
Payment
| Code | Cause | What to do |
|---|---|---|
PAYMENT_ORDER_FAILED | The Payment Order request failed or the SDK could not prepare collection. | Check status when available and verify the same order before replacing it. |
PAYMENT_DECLINED | The 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_CANCELED | Card reading was canceled. | Collect again with the same authorization. |
CARD_READ_ERROR | The card could not be read. | Call collectPayment() again with the same authorized object. |
PAYMENT_IN_PROGRESS | A payment is running and the requested operation cannot proceed. | Wait for the active payment. Cancellation is available while waiting for the card. |
NETWORK_ERROR | A network call timed out or failed. | Check connectivity and the operation that failed. |
PAYMENT_RESULT_UNKNOWN | The SDK cannot establish the outcome of collection. | Keep the purchase pending and check the same order. |
UNSUPPORTED_OPERATION | Feature not available with Tap to Pay. | — |
UNKNOWN | The 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
| HTTP | Code | Meaning |
|---|---|---|
| 401 | INVALID_CONFIG | Public key rejected, or wrong env. |
| 403 | PAYMENT_ORDER_FAILED | Wrong objectSecret, or Payment Order of another shop. |
| 404 | PAYMENT_ORDER_FAILED | Unknown Payment Order id. |
| 409 | PAYMENT_ORDER_FAILED | The Payment Order is locked by another request. Retry. |
| 422 | PAYMENT_ORDER_FAILED | Business rule: Payment Order expired or not pending, not tap_to_pay, automatic capture disabled, has a buyer, or no usable bank_card config. |
| 5xx, timeout | NETWORK_ERROR | Retry. 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.
| Code | Cause |
|---|---|
INVALID_CONFIG | HTTP 401. Check the shop’s public key and environment. |
NETWORK_ERROR | A network error, the 15-second timeout or HTTP 5xx. |
PAYMENT_ORDER_FAILED | Another 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().
Updated 8 days ago