Alipay+ DocsAlipay+ Docs

Token status

Each token status value indicates the current state of a user's card. The following APIs return a token status:

  • isPaymentAvailable
  • activatePayment (via callback)
  • activatePaymentInSlientMode (via ActivateStatusListener)

isPaymentAvailable evaluates the following conditions in order and returns immediately when the first condition is met:

  1. Returns -3 if the white-box cryptography module failed to initialize.
  2. Returns -2 if the SDK is not connected.
  3. Returns 11 if a credential replenishment is in progress.
  4. Otherwise, returns the token status retrieved from the local query.

Checking whether a card can pay

Call isPaymentAvailable before displaying a tap-to-pay entry point, and handle the result as shown below.

copy
void prepareForTap(String userId) {
    ACTapManager manager = ACTapManager.getInstance(getApplication());

    switch (manager.isPaymentAvailable()) {
        case TokenStatus.TOKEN_STATUS_READY_TO_TAP:
            // The card can pay. Nothing to do.
            break;

        case TokenStatus.TOKEN_STATUS_ACTIVATED_WITH_NO_CREDENTIALS:
            manager.replenish(null);
            break;

        case TokenStatus.TOKEN_STATUS_LOCKED:
            manager.unlock();
            break;

        case TokenStatus.TOKEN_NOT_CONNECTED:
            manager.connect(userId, null);
            break;

        case TokenStatus.TOKEN_STATUS_NOT_EXIST:
        case TokenStatus.TOKEN_STATUS_NOT_CONFIRMED:
            // Start activation. For TOKEN_STATUS_NOT_CONFIRMED, call
            // NFCActivateParams.setDoConfirm(true) first so the user confirms the card.
            break;

        case TokenStatus.TOKEN_WB_UNAVAILABLE:
            // This device cannot support tap payment. Do not retry on it.
            break;

        case TokenStatus.TOKEN_STATUS_IN_PROGRESS:
        case TokenStatus.TOKEN_STATUS_UNKNOWN:
            // Wait and check again. Do not start a second activation or replenish.
            break;
    }
}

Token status values

Code

Value

Description

Further action

Returned by

-3

TOKEN_WB_UNAVAILABLE

The white-box cryptography module required by this SDK is not available on this device. Evaluated first; all other states are hidden when this applies.

This device does not support tap-to-pay payment. Do not retry on this device.

isPaymentAvailable only

-2

TOKEN_NOT_CONNECTED

No user is connected, or the user has already disconnected.

Call connect with the user ID.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

-1

TOKEN_STATUS_UNKNOWN

The token status could not be determined. Possible causes: an invalid input parameter (errorCode 10011), a card read or sync failure, or an activation failure.

Check the errorCode returned with this value to identify the cause.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

0

TOKEN_STATUS_NOT_EXIST

No card exists for this user, or the card is not activated, is marked for deletion, or is in an unresolvable state.

Call activatePayment. If errorCode 10010 is also returned, an activation is already in progress. Wait for it to complete instead of starting another.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

1

TOKEN_STATUS_ACTIVATED_WITH_NO_CREDENTIALS

The card is active but has no credentials available for payment.

Call replenish.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

2

TOKEN_STATUS_READY_TO_TAP

The card is active and has at least one valid credential. This is the only value that confirms a tap can succeed.

No action required.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

3

TOKEN_STATUS_LOCKED

The card is suspended by the server.

Call unlock.

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

11

TOKEN_STATUS_IN_PROGRESS

A replenishment or activation is already running.

Wait and check again. Do not start a second replenishment or activation.

isPaymentAvailable only

21

TOKEN_STATUS_NOT_CONFIRMED

The card is active but the user has not yet confirmed it.

Call activatePayment with NFCActivateParams.setDoConfirm(true).

isPaymentAvailable, activatePayment, and activatePaymentInSlientMode

deleteToken and token status

deleteToken does not return a token status. It calls isPaymentAvailable internally and proceeds only if the result is 1, 2, or 3. For any other value, it returns false with errorCode 10004.

APIs that return similar-looking values

The following APIs return integer values that resemble token status codes but represent different things. Do not use their return values as token status inputs.

  • replenish callback: Returns 1 for success and 0 for failure. The -2 value is an exception and does indicate TOKEN_NOT_CONNECTED.
  • getAvailableCredentialsCounts: Returns the number of available credentials, or -2 when the SDK is not connected.