> 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/implement-contactless-payments/6.-display-transaction-context.md).

# 6. Mostrar el contexto de la transacción

## Resumen

Después de cada transacción, tu **aplicación de cartera digital** puede mostrar los detalles de la transacción.

NFC Wallet SDK proporciona un `TransactionContext` en estas devoluciones de llamada:

* `ContactlessPaymentServiceListener.onTransactionCompleted()`
* `ContactlessPaymentServiceListener.onError()`

{% hint style="warning" %}
Trata `TransactionContext` como datos sensibles.

Llamar a `TransactionContext.wipe()` después de terminar de usarlo.
{% endhint %}

## Integración del SDK

### Leer y formatear los detalles de la transacción

Lee los valores que necesitas del contexto y luego fórmalos para mostrarlos.

{% code title="MyPaymentListener.java" expandable="true" %}

```java
@Override
public void onTransactionCompleted(TransactionContext ctx) {
    try {
        TransactionData data = TransactionData.from(ctx);
        // Muestra los datos en tu interfaz de usuario.
    } finally {
        ctx.wipe();
    }
}

@Override
public void onError(
        TransactionContext ctx,
        PaymentServiceErrorCode errorCode,
        String message) {

    if (ctx == null) {
        // Maneja el error cuando no hay un contexto de transacción disponible.
        return;
    }

    try {
        TransactionData data = TransactionData.from(ctx);
        // Muestra los datos y los detalles del error en tu interfaz de usuario.
    } finally {
        ctx.wipe();
    }
}

/**
 * Clase de datos auxiliar para mostrar transacciones.
 */
public class TransactionData {

    private final String currencyCode;
    private final double amount;
    private final String transactionDate;
    private final String transactionType;
    private final String transactionId;

    private TransactionData(
            String currencyCode,
            double amount,
            String transactionDate,
            String transactionType,
            String transactionId) {
        this.currencyCode = currencyCode;
        this.amount = amount;
        this.transactionDate = transactionDate;
        this.transactionType = transactionType;
        this.transactionId = transactionId;
    }

    public static TransactionData from(TransactionContext ctx) {
        String currencyCode = TransactionDisplayUtils.bcdToString(ctx.getCurrencyCode());
        String transactionDate = TransactionDisplayUtils.bcdToString(ctx.getTrxDate());
        String transactionType = TransactionDisplayUtils.getTransactionType(ctx.getTrxType());

        return new TransactionData(
                currencyCode,
                ctx.getAmount(),
                transactionDate,
                transactionType,
                ctx.getTrxId());
    }

    public String getCurrencyCode() {
        return currencyCode;
    }

    public double getAmount() {
        return amount;
    }

    public String getTransactionDate() {
        return transactionDate;
    }

    public String getTransactionType() {
        return transactionType;
    }

    public String getTransactionId() {
        return transactionId;
    }
}
```

{% endcode %}

### Convertir valores BCD para mostrar (utilidad)

La siguiente utilidad convierte valores codificados en BCD a cadenas.

Ajusta el formato para que coincida con tu interfaz de usuario y con los requisitos de tu red de pagos.

{% code title="TransactionDisplayUtils.java" expandable="true" %}

```java
public final class TransactionDisplayUtils {

    private TransactionDisplayUtils() {
        // Clase de utilidad.
    }

    public static String bcdToString(byte[] bcd) {
        if (bcd == null) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (byte b : bcd) {
            sb.append(bcdToString(b));
        }
        return sb.toString();
    }

    public static String bcdToString(byte bcd) {
        int high = (bcd & 0xF0) >>> 4;
        int low = (bcd & 0x0F);
        return String.valueOf(high) + low;
    }

    public static String getTransactionType(byte trxType) {
        switch (trxType) {
            case 0:
                return "PAGO";
            case 32:
                return "REEMBOLSO";
            default:
                return "TRANSACCIÓN";
        }
    }
}
```

{% endcode %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/es/implement-nfc-wallet/make-payment/implement-contactless-payments/6.-display-transaction-context.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
