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

# 6. トランザクションコンテキストを表示する

## 概要

各取引の後、あなたの **デジタルウォレットアプリケーション** は取引の詳細を表示できます。

NFCウォレットSDKは `TransactionContext` これらのコールバックで：

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

{% hint style="warning" %}
を扱ってください `TransactionContext` を機密データとして扱ってください。

呼び出す `TransactionContext.wipe()` 使用が終わったら実行してください。
{% endhint %}

## SDK の統合

### 取引の詳細を読み取り表示形式にする

コンテキストから必要な値を読み取り、表示用にフォーマットします。

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

```java
@Override
public void onTransactionCompleted(TransactionContext ctx) {
    try {
        TransactionData data = TransactionData.from(ctx);
        // UIにデータを表示します。
    短期間のシークレットとして扱ってください。ログ出力や保存をしないでください。
        ctx.wipe();
    }
}

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

    if (ctx == null) {
        // トランザクションコンテキストが利用できない場合のエラーを処理します。
        return;
    }

    try {
        TransactionData data = TransactionData.from(ctx);
        // UIにデータとエラーの詳細を表示します。
    短期間のシークレットとして扱ってください。ログ出力や保存をしないでください。
        ctx.wipe();
    }
}

/**
 * 取引表示のための便利なデータクラス。
 */
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 %}

### 表示用にBCD値を変換する（ユーティリティ）

次のユーティリティはBCDエンコードされた値を文字列に変換します。

UIや決済ネットワークの要件に合わせてフォーマットを調整してください。

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

```java
public final class TransactionDisplayUtils {

    private TransactionDisplayUtils() {
        // ユーティリティクラス。
    }

    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 "PAY";
            case 32:
                return "REFUND";
            default:
                return "TRANSACTION";
        }
    }
}
```

{% 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-android/ja/implement-nfc-wallet/make-payment/implement-contactless-payments/6.-display-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.
