> 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/merchant-tokenization/ja/mastercard-taf/implement-taf/authenticate-a-transaction.md).

# トランザクションを認証する

Mastercard Token Authentication Framework（TAF）を使用してトランザクションを認証します。

この呼び出しは Mastercard のペイロードを生成します。TAF の対象となるトランザクションクリプトグラムを取得するために使用します。

## 認証フロー

<figure><img src="/files/59c78f387393c9423dd94fb9f2485630e0ab2790" alt=""><figcaption><p>チェックアウト時の Mastercard TAF 認証フロー。</p></figcaption></figure>

## SDK統合

{% tabs %}
{% tab title="Android" %}
呼び出し `MastercardTAFHelper.authenticateTransaction`.

でデバイス認証を開始 `onDeviceAuthentication`.

生体認証UIの文字列をカスタマイズできます。

最終結果を次で処理 `onSuccess` または `onError`.

```java
public void mastercard_AuthenticateTransaction(@NonNull final String tokenID, @NonNull TransactionContext transactionContext, @NonNull MastercardTAFHelper masterCardTAFHelper, @NonNull FragmentActivity fragmentActivity) {
    masterCardTAFHelper.authenticateTransaction(tokenID, transactionContext, new TransactionListener() {
        @Override
        public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
            CharSequence title = "タイトル";
            CharSequence subTitle = "サブタイトル";
            CharSequence description = "説明";
            CharSequence negativeButtonText = "否定ボタン";
            deviceAuthentication.startAuthentication(fragmentActivity,
                    title,
                    subTitle,
                    description,
                    negativeButtonText);
        }

        @Override
        public void onError(TMGClientException exception) {
            // エラーを確認
            int errorCode = exception.getErrorCode();
            String errorMessage = exception.getMessage();
        }

        @Override
        public void onSuccess(String payload) {
            // Mastercard ペイロードをデコードし、トランザクションのアサーションを検証します
        }
    });
}
```

`onSuccess` は Mastercard のペイロードを返します。

`onError` は `TMGClientException` をエラーコードとメッセージ付きで返します。
{% endtab %}

{% tab title="iOS" %}
呼び出し `authenticateTransaction` と `TransactionContext`.

でデバイス認証を開始 `deviceAuthenticationHandler`.

```swift
let tokenID = ""
let transContext = MastercardTAFHelper.TransactionContext(merchantName: "ABC", amount: "100", currencyCode: "USD")
// 1. トランザクション認証を開始
mastercardTAFHelper.authenticateTransaction(forTokenID: tokenID, context: transContext,
    deviceAuthenticationHandler: { auth in
        // 2. ユーザー認証を開始
        let customMessage = "" // カスタムメッセージを渡します。例: "Face IDで認証してください"
        auth.startAuthentication(withMessage: customMessage)
    },
    completionHandler: { (mastercardPayload, error) in
        // ペイロード生成に成功
        if error == nil {
        
        } else {
            // エラーを処理
        }
    }
)
```

{% endtab %}
{% endtabs %}


---

# 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/merchant-tokenization/ja/mastercard-taf/implement-taf/authenticate-a-transaction.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.
