> 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-ios/es/implement-nfc-wallet/make-payments/implement-contactless-payment/5.-display-the-transaction-context.md).

# 5. Mostrar el contexto de la transacción

Manejar `ContactlessPaymentSession.Event.transactionCompleted` para mostrar el estado del pago al usuario final.

Este evento incluye un `TransactionContext` que contiene detalles clave sobre la transacción.

### Manejar el evento de finalización

En su `ContactlessPaymentSession.eventStream` bucle, manejar:

* `.transactionCompleted(let transactionContext)`

Use `transactionContext` para actualizar su interfaz y desencadenar cualquier acción posterior.

### Campos de TransactionContext

`TransactionContext` normalmente incluye:

* `aid`: Identificador de aplicación EMV (AID).
* `amount`: Importe de la transacción (formateado para mostrar en su interfaz).
* `rawAmount`: Valor bruto del importe tal como se recibió del terminal.
* `currencyCode`: Código numérico de moneda ISO-4217.
* `transactionDate`: Fecha de la transacción (YYMMDD, codificada en BCD).
* `transactionType`: Código del tipo de transacción (por ejemplo, compra vs reembolso).
* `digitalCardID`: Identificador de tarjeta digital utilizado para el pago.
* `esquema`: Red de pago (por ejemplo, Visa o Mastercard).
* `isTransit`: Indica si la transacción es de transporte.
* `transactionID`: Identificador de la transacción.

Consulte el siguiente fragmento de código de ejemplo para instrucciones de implementación:

{% code title="Formatear y mostrar el contexto de la transacción" %}

```swift
func displayTransactionContext(_ context: TransactionContext) {
    // Establezca esto en su configuración regional.
    let locale = Locale(identifier: "en_US")

    // Mapear códigos numéricos ISO-4217 a códigos alfabéticos.
    // Ampliar este mapeo según las monedas que admita.
    let iso4217NumToCode: [Int: String] = [
        978: "EUR",
        840: "USD"
    ]

    let currencyFormatter = NumberFormatter()
    currencyFormatter.locale = locale
    currencyFormatter.numberStyle = .currency

    if let currencyCode = iso4217NumToCode[context.currencyCode.bcdToInt()] {
        currencyFormatter.currencyCode = currencyCode
    }

    let rawDateFormatter = DateFormatter()
    rawDateFormatter.dateFormat = "yyMMdd"

    guard let transactionDate = rawDateFormatter.date(from: context.transactionDate.bcdToString()) else {
        // Alternativa: omitir la representación de la fecha si el análisis falla.
        return
    }

    let displayDateFormatter = DateFormatter()
    displayDateFormatter.locale = locale
    displayDateFormatter.dateStyle = .medium

    let amountStr = currencyFormatter.string(from: context.amount as NSNumber) ?? "-"
    let dateStr = displayDateFormatter.string(from: transactionDate)

    let transactionTypeStr = context.transactionType.bcdToString()
    switch transactionTypeStr {
    case "00":
        // Compra
        break
    case "20":
        // Reembolso / corrección
        break
    default:
        // Tipo de transacción desconocido
        break
    }

    // Actualice su interfaz con amountStr, dateStr, scheme, isTransit y transactionID.
}
```

{% 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 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-ios/es/implement-nfc-wallet/make-payments/implement-contactless-payment/5.-display-the-transaction-context.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.
