> 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/sdk-tong-he/ios-api/migrate-from-2.x-to-3.0.md).

# 2.x から 3.0 に移行

TMG SDK 3.0.0以降、いくつかのパブリックAPIが簡素化されました。

## SDKを初期化する <a href="#initialisation-of-sdk" id="initialisation-of-sdk"></a>

SDKは次を削除します `TMGClientConfiguration.Builder` および設定をに移動します `TMGClientConfiguration` イニシャライザ：

* 削除されたもの： [`TMGClientConfiguration.Builder`](https://thalesgroup.github.io/d1sdk-docs/tmg-sdk/ios/2.1.0/Classes/TMGClientConfiguration/Builder.html)
* 代わりに使用： [`TMGClientConfiguration`](https://thalesgroup.github.io/d1sdk-docs/tmg-sdk/ios/3.0.0/Classes/TMGClientConfiguration.html)

### 何が変わったか

* 非推奨 `certificatePins`。SDKは現在証明書ピンニングを内部で管理します。
* 名前が変更されました `serverUrl` から `serverURL`.
* 名前が変更されました `serverKeyId` から `serverKeyID`.

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
let serverUrl;
let serverCertificate;
let keyIdentifier;
let configurationBuilder = TMGClientConfiguration.Builder(serverUrl: serverUrl, 
                                                          serverCertificate: Data(serverCertificate.utf8), 
                                                          serverKeyId: keyIdentifier)
let configuration: TMGClientConfiguration = TMGClientConfiguration(builder: configurationBuilder)
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
let serverURL = ""
let serverCertificate = ""
let serverKeyID = ""
let configuration = TMGClientConfiguration(serverURL: serverURL,
                                           serverCertificate: Data(serverCertificate.utf8),
                                           serverKeyID: serverKeyID)
```

{% endtab %}
{% endtabs %}

### 初期化 `VisaCTFHelper` <a href="#initialisation-of-visactfhelper" id="initialisation-of-visactfhelper"></a>

TMG SDK 3.0.0では、 `createVisaCTFHelper` は非同期から同期に変わります。これによりエラーハンドリングと制御フローが簡素化されます。

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
let tmgClient = TMGClient.sharedInstance
tmgClient.createVisaCTFHelper(tmgClientConfiguration: configuration,
                              completion: { (visaCTFHelper, error) in
  // VisaCTFHelperオブジェクトを取得します
  // エラーを確認します
})
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
do {
    let visaCTFHelper = try TMGClient.sharedInstance.createVisaCTFHelper(withConfiguration: configuration)
} catch let error {
    // エラーを処理します
}
```

{% endtab %}
{% endtabs %}

### デバイスバインディングフロー（グリーンおよびイエロー）を更新する <a href="#device-binding-in-green-and-yellow-flow" id="device-binding-in-green-and-yellow-flow"></a>

デバイスバインディングはデバイス認証、識別および検証（ID\&V）、およびバインディング完了をカバーします。TMG SDK 3.0.0では、フローは：

* の使用を標準化しました `completionHandler`.
* の混在を削除しました `delegate` です。難読化の詳細は、 `completionHandler`.
* バインディング成功を複数箇所でハンドルする必要を削除しました。
* 制御フローを簡素化しました。

{% hint style="info" %}
旧バージョンのSDKから移行する際は、これらのAPI名変更に注意してください：

* `PendingBindingSession` は現在 `VisaCTFHelper.IDVSession`.
* `DeviceAuthenticationDelegate` は現在 `DeviceAuthentication`.
* `IdvMethod` は現在 `IDVMethod`.
* `IdvType` は現在 `IDVType`.
* `OtpActivationStatus` は現在 `OTPActivationStatus`.
  * `maxOtpRequestsAllowed` は現在 `maxOTPRequestsAllowed`.
  * `maxOtpVerificationAllowed` は現在 `maxOTPVerificationAllowed`.
    {% endhint %}

デバイスバインディング統合を更新するには、以下のコードを使用してください：

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
// 1. DeviceAuthenticationDelegateに準拠する（これはデバイス認証のため）
class DeviceAuthenticationDelegateImplementation: DeviceAuthenticationDelegate {

    let authenticationMessage

    func shouldStartAuthentication(startHandler: (String?, Bool) -> Void) {
        //3. ユーザー認証を開始する 
        startHandler(authenticationMessage, YES)
    }
}

var pendingBindingSession: PendingBindingSession?
let deviceId
let correlationId
let deviceAuthenticationDelegate = DeviceAuthenticationDelegateImplementation()
// 2. バインディング作成を開始する
visaCTFHelper.createBinding(vProvisionedTokenId: vProvisionedTokenId,
                            correlationId: correlationId,
                            deviceAuthenticationDelegate: deviceAuthenticationDelegate) { session, error in
    // 4. バインド成功 [シナリオ 1]
    if error == nil && session == nil {

    }
    // 5. イエローフローのためにセッションをローカルに保存する
    pendingBindingSession = session
}
// MARK: idv フロー
// 6. idvメソッドのリストを取得する（イエローフロー）
pendingBindingSession.idvMethods(completion: { idvMethods, error in
    if error == nil {
        let listOfIdvMethod = idvMethods
    }
})

//7. 選択したidvメソッドを送信する（OTPフロー）
let selectedIdvMethod
pendingBindingSession.submitIdvMethod(idvMethod: selectedIdvMethod,
                                      completion: { otpActivationStatus, error in
     // エラーがないことを確認する
    if error == nil {
        let maxOtpVerificationAllowed = otpActivationStatus.maxOtpRequestsAllowed
        let maxOtpRequestsAllowed = otpActivationStatus.maxOtpVerificationAllowed
        let otpExpiration = otpActivationStatus.maxOtpVerificationAllowed
    }
    // 8. エラーの場合は再試行
    
})

//9. バインディングを有効化する
let otp
pendingBindingSession.activateBinding(otp: otp, 
                                      completion: { error in
    // 4.1 バインド成功 [シナリオ 2]
    if error == nil {

    }
    // 10. エラーの場合は再試行
})
```

{% endtab %}

{% tab title="3.0.0" %}

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

let vProvisionedTokenID: String = ""
let correlationID: String = ""
// 1. バインディング作成を開始する
visaCTFHelper.createBinding(forVProvisionedTokenID: vProvisionedTokenID,
                            correlationID: correlationID,
    deviceAuthenticationHandler: { auth in
        // 2. ユーザー認証を開始する
        let customMessage = "" // カスタムメッセージを渡します。例: "Authenticate with Face ID"
        auth.startAuthentication(withMessage: customMessage)
    }, idvSessionHandler: { session in
        // 3. イエローフローのためにセッションをローカルに保存する
        VisaService.shared.idvSession = session

    }, completionHandler: { session, error in
        // 4. completion handlerをローカルに保持する
        VisaService.shared.completionHandler?(session, error)
    })

// MARK: idv フロー
do {
    guard let session = VisaService.shared.idvSession else {
        return
    }
    // 5. idvメソッドのリストを取得する（イエローフロー）
    let idvMethods = try session.idvMethods
    // 6. 選択したidvメソッドを送信する（OTPフロー）
    session.selectIDVMethod(idvMethods[0]) { otp in
        // otpアクティベーションステータスを確認する
    }
} catch let error {
    // idvメソッドのリストでのエラー
}

// 7. バインディングを有効化する
let otp = ""
VisaService.shared.idvSession?.activateBinding(withValue: otp)

// 8. 成功またはエラーを処理する。
// 成功またはエラーについてはcompletionHandlerを監視できます
VisaService.shared.completionHandler = {(session, error) in
    // 9. バインド成功
    if error == nil {
        
    } else if let error, let session {
        // 10. エラーの場合は再試行
        if error.description == TMGError.invalidOTPMessage.description {
            VisaService.shared.idvSession = session
        }
    } else {
        // 11. エラーを処理する
    }
}
```

{% endtab %}
{% endtabs %}

### バインディングを再開する（`resumeBinding`) <a href="#resumebinding-api" id="resumebinding-api"></a>

この `resumeBinding` フローは以前のバージョンから変更されていません。変更されるのは `IDVSession` （ID\&V）ステップのみです。

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
var pendingBindingSession: PendingBindingSession?
// 1. バインディングの再開を開始する
visaCTFHelper.resumeBinding(vProvisionedTokenId: vProvisionedTokenId) { session, error in
    // 2. イエローフローのためにセッションをローカルに保存する
    if error == nil { 
        pendingBindingSession = session
    }
    // エラーを確認する
}

// 3. MARK: idv フロー（コードスニペットのcreate binding idvフローを参照）
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
// Visaフローに必要なプロパティを保持するシングルトンクラス
class VisaService {
    static var shared = VisaService()
    var idvSession: VisaCTFHelper.IDVSession? = nil
    var completionHandler: ((VisaCTFHelper.IDVSession?, TMGError?) -> Void)? = nil
}
let vProvisionedTokenID: String = ""
// 1. バインディングの再開を開始する
visaCTFHelper.resumeBinding(forVProvisionedTokenID: vProvisionedTokenID,
                            idvSessionHandler: { session in
        // 2. イエローフローのためにセッションをローカルに保存する
        VisaService.shared.idvSession = session        
    }, completionHandler: { session, error in
        // 3. completion handlerをローカルに保持する
        VisaService.shared.completionHandler?(session, error)
    })
// 4. MARK: idv フロー（コードスニペットのcreate binding idvフローを参照）
```

{% endtab %}
{% endtabs %}

### バインディング状態を取得する（`bindingState`) <a href="#bindingstate-api" id="bindingstate-api"></a>

TMG SDK 3.0.0では、 `bindingState` は非同期から同期に変わります。これによりエラーハンドリングと制御フローが簡素化されます。

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
let vProvisionedTokenId = ""
visaCTFHelper.bindingState(vProvisionedTokenId: vProvisionedTokenId) { (bindingState, error) in 
}
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
let vProvisionedTokenID = ""
do {
    let state = try visaCTFHelper.bindingState(forVProvisionedTokenID: vProvisionedTokenID)
} catch let error {
    // エラーを処理します
}
```

{% endtab %}
{% endtabs %}

### トランザクションを認証する <a href="#transaction-flow" id="transaction-flow"></a>

トランザクション認証はデバイス認証とVisaペイロードの返却をカバーします。TMG SDK 3.0.0では、フローは：

* の使用を標準化しました `completionHandler`.
* の混在を削除しました `delegate` です。難読化の詳細は、 `completionHandler`.

トランザクション認証の統合を更新するには、以下のコードを使用してください：

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
// 1. DeviceAuthenticationDelegateに準拠する（これはデバイス認証のため）
class DeviceAuthenticationDelegateImplementation: DeviceAuthenticationDelegate {

    let authenticationMessage

    func shouldStartAuthentication(startHandler: (String?, Bool) -> Void) {
        //3. ユーザー認証を開始する 
        startHandler(authenticationMessage, YES)
    }
}

let deviceAuthenticationDelegate = DeviceAuthenticationDelegateImplementation()

// 2. トランザクション認証を開始する
visaCTFHelper.authenticateTransaction(vProvisionedTokenId: vProvisionedTokenID,
                                      deviceAuthenticationDelegate: deviceAuthenticationDelegate,
                                      completion: { visaPayload, error in
    // 4. ペイロードの生成に成功
    if error == nil {
    
    } else {
        // エラーを処理する
    } 
})
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
let vProvisionedTokenID: String = ""
        
// 1. トランザクション認証を開始する
visaCTFHelper.authenticateTransaction(forVProvisionedTokenID: vProvisionedTokenID,
                                        deviceAuthenticationHandler: { auth in
        // 2. ユーザー認証を開始する 
        let customMessage = "" // カスタムメッセージを渡します。例: "Authenticate with Face ID"
        auth.startAuthentication(withMessage: customMessage)
    }, completionHandler: { (visaPayload, error) in
        // 3. ペイロード生成に成功
        if error == nil {
            
        } else {
            // エラーを処理する
        }    
})
```

{% endtab %}
{% endtabs %}

### バインディングを削除する（`removeBinding`) <a href="#removebinding-api" id="removebinding-api"></a>

`removeBinding` は現在追加の `correlationID`.

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
を必要とします
// 1. バインディング削除を開始する
                            completion: { error in
    visaCTFHelper.removeBinding(vProvisionedTokenId: vProvisionedTokenID,
    if error == nil {
        
    } else {
        // エラーを処理する
    }
})
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
let vProvisionedTokenID: String = ""
let correlationID: String = ""

を必要とします
// 2. バインディング削除に成功
                            visaCTFHelper.removeBinding(forVProvisionedTokenID: vProvisionedTokenID,
    visaCTFHelper.removeBinding(vProvisionedTokenId: vProvisionedTokenID,
    if error == nil {
        
    } else {
        // エラーを処理する
    } 
}
```

{% endtab %}
{% endtabs %}

### correlationID: correlationID) { error in`バインディング状態を同期する（`) <a href="#syncbindingstate-api" id="syncbindingstate-api"></a>

`バインディング状態を同期する（` は現在追加の `correlationID`.

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
syncBindingState
// 1. バインディング状態の同期を開始する
                               visaCTFHelper.syncBindingState(vProvisionedTokenId: vProvisionedTokenID,
    completion: { bindingState, error in
    if error == nil {
        
    } else {
        // エラーを処理する
    }  
})
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
let vProvisionedTokenID: String = ""
let correlationID: String = ""

syncBindingState
// 2. バインディング状態の同期に成功
                                visaCTFHelper.syncBindingState(forVProvisionedTokenID: vProvisionedTokenID,
    completion: { bindingState, error in
    if error == nil {
        
    } else {
        // エラーを処理する
    }   
}
```

{% endtab %}
{% endtabs %}

### correlationID: correlationID) { (state, error) in <a href="#previouslyselectedidvmethod-in-idvsession" id="previouslyselectedidvmethod-in-idvsession"></a>

以前に選択されたID\&Vメソッドを読み取る `IDVSession` に加えて、 `createBinding` フローで使用される関数、以前に選択されたID\&Vメソッドを読み取ることができます。TMG SDK 3.0.0では、 `previouslySelectedIDVMethod` は非同期から同期に変わります。これによりエラーハンドリングと制御フローが簡素化されます。

{% tabs %}
{% tab title="3.0.0より前" %}

```swift
// 1. 以前に選択されたidvメソッドを取得する
pendingBindingSession.previouslySelectedIdvMethod(completion: { idvMethod, error in
    // 2. 以前に選択されたidvメソッドを正常に取得する
    if error == nil {
        let prevIDVMethod = idvMethod
    } else {
        // エラーを処理する
    } 
})
```

{% endtab %}

{% tab title="3.0.0" %}

```swift
guard let idvSession = VisaService.shared.idvSession else {
    // idv セッションがありません
    return
}
// 1. 以前に選択されたidvメソッドを取得する
do {
    let prevIDVMethod = try idvSession.previouslySelectedIDVMethod
} catch let error {
    // 2. エラーを処理する
}
```

{% 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/sdk-tong-he/ios-api/migrate-from-2.x-to-3.0.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.
