> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/es/implement-nfc-wallet/make-payment/replenish-payment-keys.md).

# Reponer claves de pago

## Resumen

Se requieren claves de pago (SUK o LUK) para calcular criptogramas EMV para pagos sin contacto.

En un modelo Host Card Emulation (HCE), las claves de pago son temporales. Reabastécelas antes de que se agoten. Esto previene interrupciones en los pagos.

Esta guía cubre cuándo reabastecer y cómo activarlo.

{% hint style="info" %}
El SDK de billetera NFC admite estos tipos de claves de pago:

* **SUK (Clave de un solo uso)**: Usar una clave por transacción. Se usa para Mastercard y PURE (EMV de etiqueta blanca).
* **LUK (Clave de uso limitado)**: Usar una clave para múltiples transacciones. Se usa para Visa.
  {% endhint %}

## Prerrequisitos

### Configurar umbrales de reabastecimiento (onboarding)

Configure los umbrales de reabastecimiento durante el onboarding con el **equipo de entrega de Thales**.

{% hint style="info" %}
Al definir los umbrales, considere:

* **SUK**: Conteo restante de SUK que desencadena el reabastecimiento.
* **LUK**: Conteo restante de transacciones y tiempo de expiración del LUK.
  {% endhint %}

## Integración del SDK

### Detectar cuándo se requiere reabastecimiento

Use una (o ambas) de estas señales:

* **Verificación proactiva**: Leer el estado de la tarjeta digital.
* **Push reactivo (activado por TSP)**: Procesar `MG:ReplenishmentNeededNotification` desde el **TSP**.

Para la entrega por push y el enrutamiento, vea [Manejar notificaciones push](/nfc-wallet-sdk-android/es/get-started/configuration/5.-push-notifications/handle-push-notifications.md).

#### Verificación proactiva

Ejecute esta verificación para cada tarjeta digital. Ejecútela al iniciar la aplicación o después de un pago.

1. Obtener `DigitalizedCardStatus` de `DigitalizedCard`.
2. Llamar `DigitalizedCardStatus.needsReplenishment()`.

Vea [Mostrar tarjetas digitales](/nfc-wallet-sdk-android/es/implement-nfc-wallet/manage-digital-cards/display-digital-cards.md).

{% code title="Comprobar si una tarjeta digital necesita reabastecimiento" %}

```java
public static boolean needsReplenishment(final DigitalizedCard card) {
    AsyncResult<DigitalizedCardStatus> result =
            card.getCardState(null).waitToComplete();

    if (!result.isSuccessful()) {
        // TODO: manejar error
        return false;
    }

    DigitalizedCardStatus status = result.getResult();
    return status != null && status.needsReplenishment();
}
```

{% endcode %}

Realice esta verificación proactiva:

* En el inicio regular de la aplicación
  * No realice la verificación si la aplicación está iniciada para un pago - vea la advertencia abajo
* Después de un pago
  * En un evento `onNextTransactionReady` - ver [implementar callbacks de pago sin contacto](/nfc-wallet-sdk-android/es/implement-nfc-wallet/make-payment/implement-contactless-payments/2.-implement-contactless-payment-callbacks.md).
* Cuando la tarjeta se establece como predeterminada.
* Después de que la conectividad regresa (offline → online).

{% hint style="warning" %}
Ejecute esta verificación al iniciar la aplicación, después de **inicialización del SDK de billetera NFC** inicialización.

No ejecute esta verificación cuando el usuario final inicie la aplicación para realizar un pago sin contacto. Puede retrasar la ejecución del pago.
{% endhint %}

### Activar reabastecimiento

Llamar `ProvisioningBusinessService.sendRequestForReplenishment(...)` para solicitar nuevas claves de pago.

1. Obtener el identificador de la tarjeta.

   Use el **ID de tarjeta tokenizada** - ver [Mostrar tarjeta digital](/nfc-wallet-sdk-android/es/implement-nfc-wallet/manage-digital-cards/display-digital-cards.md#tokenized-card-id-versus-digital-card-id).
2. Enviar la solicitud de reabastecimiento.

   Llamar `sendRequestForReplenishment(...)` e implementar `PushServiceListener`:

   * `onComplete`: La solicitud es aceptada.
   * `onError`: El SDK no puede enviar la solicitud. Inspeccione `ProvisioningServiceError`.

   <pre class="language-java" data-title="Enviar una solicitud de reabastecimiento"><code class="lang-java">public void replenish(final String tokenizedCardId, final boolean forced) {
       ProvisioningBusinessService service =
               ProvisioningServiceManager.getProvisioningBusinessService();

       service.sendRequestForReplenishment(
               tokenizedCardId,
               new ReplenishmentListener(),
               forced
       );
   }

   private static class ReplenishmentListener implements PushServiceListener {
       @Override
       public void onComplete() {
           // TODO: registrar éxito
       }

       @Override
       public void onError(final ProvisioningServiceError error) {
           // TODO: registrar error
       }

       @Override
       public void onUnsupportedPushContent(final Bundle bundle) {
           // No se usa para esta llamada.
       }

       @Override
       public void onServerMessage(final String tokenizedCardId,
                                   final ProvisioningServiceMessage message) {
           // No se usa para esta llamada.
       }
   }
   </code></pre>
3. Procesar el push de reabastecimiento.

   Después de enviar la solicitud, el backend de la billetera NFC envía una notificación push. Su **aplicación de billetera digital** debe procesarla. El SDK entonces recupera las nuevas claves de pago.

{% hint style="info" %}
Evite terminar la **aplicación de billetera digital** mientras el reabastecimiento está en progreso.
{% endhint %}

{% hint style="info" %}
**Reabastecimiento activado por TSP**

Cuando reciba `MG:ReplenishmentNeededNotification`, active el reabastecimiento con `forced = true`.

Vea [Procesar notificaciones MG (reabastecimiento)](/nfc-wallet-sdk-android/es/get-started/configuration/5.-push-notifications/handle-push-notifications.md#process-mg-notifications-replenishment).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/es/implement-nfc-wallet/make-payment/replenish-payment-keys.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
