> 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`: 支払いに使用されたデジタルカード識別子。
* `scheme`: 支払いネットワーク（例：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:

```
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>
```

The question should be specific, self-contained, and written in natural language.
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.
