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

# 5. 取引コンテキストを表示する

処理 `ContactlessPaymentSession.Event.transactionCompleted` 最終ユーザーに支払い状況を表示するために。

このイベントには `TransactionContext` 取引の重要な詳細を含んでいます。

### 完了イベントを処理する

あなたの `ContactlessPaymentSession.eventStream` ループで、次を処理します：

* `.transactionCompleted(let transactionContext)`

使用する `transactionContext` UIを更新し、必要な後続アクションをトリガーするために。

### TransactionContext のフィールド

`TransactionContext` 通常は次を含みます：

* `aid`: EMVアプリケーション識別子（AID）。
* `amount`: 取引金額（UI表示用に整形済み）。
* `rawAmount`: 端末から受け取った生の金額値。
* `currencyCode`: ISO-4217の数値通貨コード。
* `transactionDate`: 取引日（YYMMDD、BCDエンコード）。
* `transactionType`: 取引タイプコード（例：購入、返金など）。
* `digitalCardID`: 支払いに使用されたデジタルカード識別子。
* `スキーム`: 支払いネットワーク（例：Visa や Mastercard）。
* `isTransit`: その取引が交通系取引かどうかを示します。
* `transactionID`: 取引識別子。

実装手順については、以下のサンプルコードをご参照ください：

{% code title="取引コンテキストを整形して表示する" %}

```swift
func displayTransactionContext(_ context: TransactionContext) {
    // これをロケールに設定します。
    let locale = Locale(identifier: "en_US")

    // ISO-4217の数値コードをアルファベットコードにマッピングします。
    // サポートする通貨に応じて、このマッピングを拡張してください。
    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 {
        // フォールバック：解析に失敗した場合は日付の表示を省略します。
        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":
        // 購入
        break
    case "20":
        // 返金 / 修正
        break
    default:
        // 不明な取引タイプ
        break
    }

    // amountStr、dateStr、scheme、isTransit、transactionID を使用して UI を更新します。
}
```

{% 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/ja/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.
