> 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/create-device-binding.md).

# デバイスバインディングを作成

Mastercard Token Authentication Framework (TAF) は、デバイスバインディングから始まります。

前提条件:

* カードはすでにトークン化を完了しています。加盟店はすでに `srcDigitalTokenId` を Thales バックエンドから取得しています。
* デバイスは、指紋認証や Face ID などのデバイス認証をサポートしています。

トークンをデバイスにバインドする前に、イシュア側バックエンドがエンドユーザーを認証します（ID\&V）。イシュア側バックエンドはエンドユーザーに OTP を送信します。エンドユーザーは加盟店アプリケーションで OTP を入力します。

## 加盟店アプリケーションがバインディング作成フローを開始します

<figure><img src="/files/dab75244baa107702ed8f63d0ba75be40102b414" alt=""><figcaption><p>バインディングフローを開始します。</p></figcaption></figure>

<table><thead><tr><th width="100">ステップ</th><th>説明</th></tr></thead><tbody><tr><td>1-2</td><td>エンドユーザーは（加盟店アプリケーションを通じて）、Thales SDK を呼び出すことで ID&#x26;V フローを開始します。 <code>tokenId</code> と新しい <code>correlationId</code> （トラブルシューティング用）。</td></tr><tr><td>3-7</td><td>Thales SDK は Thales バックエンドを呼び出し、そこから Mastercard にアクセスして利用可能な ID&#x26;V メソッドを取得します。</td></tr><tr><td>8-9</td><td>加盟店アプリケーションは利用可能な ID&#x26;V メソッドを表示し、エンドユーザーに 1 つ選択するよう求めます。選択肢は SMS またはメールです。</td></tr></tbody></table>

ID\&V メソッドの一覧は `IDVSession` オブジェクトから取得できます。

{% tabs %}
{% tab title="Android" %}
次を使用して `IDVSession` オブジェクトを使って `getIdvMethods` 対応している `ID&V` メソッドの一覧を取得します。

```java
public void createBinding(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID) {

    mastercardTAFHelper.createBinding(tokenID,
            correlationID,
            new TokenBindingListener() {

                @Override
                public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {

                }

                @Override
                public void onIssuerAuthenticationRequired(IDVSession idvSession) {
                    // idv メソッドの一覧を取得
                    List<IDVMethod> idvMethods = idvSession.getIdvMethods();
                }

                @Override
                public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
                    // エラーを確認するか再試行します
                }

                @Override
                public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
                    // 生体認証を使用してデバイス認証を実行
                }

                @Override
                public void onSuccess() {
                    // バインディング作成成功時の UI を処理
                }

                @Override
                public void onError(TMGClientException exception) {
                    // エラーがあるか確認
                }
            });
}
```

{% endtab %}

{% tab title="iOS" %}
次を使用して `IDVSession` オブジェクトを使って `idvMethods` 対応している `ID&V` メソッドの一覧を取得します。

```swift
// Mastercard フローに必要なプロパティを保持するシングルトンクラス
class MastercardService {
    static var shared = MastercardService()
    var idvSession: MastercardTAFHelper.IDVSession? = nil
    var completionHandler: ((MastercardTAFHelper.IDVSession?, TMGError?) -> Void)? = nil
}

let tokenID: String = ""
let correlationID: String = ""
// バインディング作成を開始
mastercardTAFHelper.createBinding(forTokenID: tokenID, correlationID: correlationID, 
    idvSessionHandler: { idvSession in
        // idv セッションをローカルに保持
        MastercardService.shared.idvSession = idvSession
        // idv メソッドの一覧
        let methods = idvSession.idvMethods
        // idv メソッドをユーザーに表示
    },
    deviceAuthenticationHandler: { auth in
        // Face ID
        let customMessage = "" // カスタムメッセージを渡します。例: "Face ID で認証"
        auth.startAuthentication(withMessage: customMessage)
    }, 
    completionHandler: { session, error in
        // completion ハンドラーをローカルに保持
        MastercardService.shared.completionHandler?(session, error)
        // バインディング成功
        if error == nil {
            
        }
        // 失敗時はエラーを処理するか idv セッションを再試行
    }
)
```

{% endtab %}
{% endtabs %}

## エンドユーザーの選択と OTP 送信 <a href="#end-user-selection-and-otp-sending" id="end-user-selection-and-otp-sending"></a>

<figure><img src="/files/ae4bced15c280e145fdbe483a1910fd629846760" alt=""><figcaption><p>エンドユーザーは ID&#x26;V メソッドを選択し、OTP を受け取ります。</p></figcaption></figure>

| ステップ | 説明                                                                                                              |
| ---- | --------------------------------------------------------------------------------------------------------------- |
| 1-2  | エンドユーザーが ID\&V メソッドを選択し、加盟店アプリケーションはその選択を Thales SDK に渡します。                                                     |
| 3-7  | Thales SDK は Thales バックエンドを呼び出して Mastercard にアクセスし、OTP を生成します。その後、イシュア側バックエンドが選択されたチャネルを通じてエンドユーザーに OTP を送信します。 |

{% tabs %}
{% tab title="Android" %}

```java
public void selectIDVMethod(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID, @NonNull FragmentActivity activity) {
    mastercardTAFHelper.createBinding(tokenID,
            correlationID,
            new TokenBindingListener() {

                @Override
                public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {
                    // OTP を検証
                }

                @Override
                public void onIssuerAuthenticationRequired(IDVSession idvSession) {
                    // idv メソッドの一覧を取得
                    List<IDVMethod> idvMethods = idvSession.getIdvMethods();

                    // 選択した idv メソッドを送信
                    IDVMethod selectedIdvMethod = idvMethods.get(0);
                    idvSession.selectIDVMethod(selectedIdvMethod);
                }

                @Override
                public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
                    // エラーを確認するか再試行します
                }

                @Override
                public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
                    // 生体認証を使用してデバイス認証を実行
                }

                @Override
                public void onSuccess() {
                    // バインディング作成成功時の UI を処理
                }

                @Override
                public void onError(TMGClientException exception) {
                    // エラーがあるか確認
                }
            });
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
guard let idvSession = MastercardService.shared.idvSession else {
    // idv セッションがありません
    return
}
// 1. idv メソッドの一覧を表示
do {
    let idvMethods = try idvSession.idvMethods
    let selectedIdvMethod = idvMethods[0] // ユーザーは利用可能な idvMethods から 1 つ選択します
    
    // 2. idv メソッドを送信
    idvSession.selectIDVMethod(selectedIdvMethod) {
        // 3. OTP 値を入力するページを表示
    }
} catch let error {
    // エラーを処理
}
        
// 4. ステップ 2 の失敗（selectIDVMethod）は completionHandler で処理されます。
MastercardService.shared.completionHandler = { (session, error) in
    // 5. selectIDVMethod のエラーか確認
    if let session = session,
        let error = error,
        error.description == TMGError.invalidIdvMethod.description {
        MastercardService.shared.idvSession = session
        // 6. IDV フローを再試行
    }
}
```

{% endtab %}
{% endtabs %}

SDK はバインディングの有効化結果を次を通じて返します `onSuccess` または `onIssuerAuthenticationError`。有効化に失敗した場合は、 `IDVSession` で返されたインスタンスを保持してください `onIssuerAuthenticationError`それを使用して ID\&V フローを再試行します。

## OTP 検証

<figure><img src="/files/fe8fa19daa9c83c25d297f682ecb860c4d366f9f" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="100">ステップ</th><th>説明</th></tr></thead><tbody><tr><td>1-2</td><td>エンドユーザーは加盟店アプリケーションで OTP を入力し、アプリケーションはそれを Thales SDK に送信します。</td></tr><tr><td>3-7</td><td>SDK は OTP を安全に Mastercard に渡して検証を行い、その結果を加盟店アプリケーションに返します。</td></tr></tbody></table>

{% tabs %}
{% tab title="Android" %}

```java
public void validateOTP(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID, @NonNull FragmentActivity activity) {
    mastercardTAFHelper.createBinding(tokenID,
            correlationID,
            new TokenBindingListener() {

                @Override
                public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {
                    // バインディングを有効化
                    String otp = "12345";
                    idvSession.validateOTP(otp);

                }

                @Override
                public void onIssuerAuthenticationRequired(IDVSession idvSession) {
                    // idv メソッドの一覧を取得
                }

                @Override
                public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
                    // エラーを確認するか再試行します
                }

                @Override
                public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
                    // 生体認証を使用してデバイス認証を実行
                    CharSequence title = "title"; //生体認証ポップアップに表示する title
                    CharSequence subTitle = "subTitle"; //生体認証ポップアップに表示する subTitle
                    CharSequence description = "description"; // 生体認証ポップアップに表示する description
                    CharSequence negativeButtonText = "negativeButtonText"; // 生体認証ポップアップに表示する拒否ボタンのテキスト
                    deviceAuthentication.startAuthentication(activity,
                            title,
                            subTitle,
                            description,
                            negativeButtonText);
                }

                @Override
                public void onSuccess() {
                    // バインディング作成成功時の UI を処理
                }

                @Override
                public void onError(TMGClientException exception) {
                    // エラーがあるか確認
                }
            });
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
guard let idvSession = MastercardService.shared.idvSession else {
    // idv セッションがありません
    return
}
do {
    let otp = "123456" // ユーザーが入力した OTP 値
    // 1. OTP 値を送信
    idvSession.validateOTP(otp)
} catch let error {
    // エラーを処理
}
        
// 2. ステップ 1 の validateOTP の失敗は completionHandler で処理されます。
MastercardService.shared.completionHandler = { (session, error) in
    // 3. validateOTP のエラーか確認
    if let session = session,
        let error = error,
        error.description == TMGError.invalidOTPMessage.description {
        MastercardService.shared.idvSession = session
        // 4. IDV フローを再試行
    }
}
```

{% 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/create-device-binding.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.
