> 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/classic-push-provisioning/ja/ysuksu/to/apuri/apple-pay.md).

# Apple Pay

#### スキームTSP構成 <a href="#scheme-tsp-configuration" id="scheme-tsp-configuration"></a>

リダイレクト情報は以下の通りです：

* `contactName`：イシュア名の識別子（上の図を参照）。
* `bank_app`：アプリ内認証で使用されるiOSアプリの名前。
* `appLaunchURL`：イシュアアプリケーション専用のディープリンクURLスキーム。Apple Payはこれを使用してアプリ内認証のためにイシュアアプリを起動します。イシュアアプリはURLスキームの値に基づいてウォレットアプリから起動されたことを判別できます。
* `associatedStoreIdentifiers`：App Storeにおけるイシュアアプリケーションの識別子。Apple Payは、インストールされていない場合にエンドユーザーにイシュアアプリのダウンロードを促すためにこれらを使用します。
* `associatedApplicationIdentifiers`：イシュアアプリケーションの識別子。開発者アカウントのTeam IDとアプリのバンドルIDに一致する必要があります。

**カスタムURLスキームの設定と処理**

1. Xcodeで、Project Settings > Targets > あなたのアプリケーション に移動し、次を選択します `Info` ターゲットのタブ。
   * に設定します `identifier` を一意の識別子にします。推奨値はアプリケーションのバンドルIDです。
   * に設定します `URL Schemes` をあなたのカスタムスキームに。
   * に設定します `役割` に `Editor`.

<br>

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

2. ウォレットアプリがエンドユーザーをイシュアアプリにリダイレクトする場合、イシュアアプリはウォレットアプリによって起動されたことを検証する必要があります。ウォレットアプリはURLにクエリパラメータを追加します。これらのパラメータはパス（デジタルカード）を一意に識別します。例えば、 `myscheme://mypath?passTypeIdentifier=paymentpass.com.apple&serialNumber=123&action=verify`.

詳細については、 [Appleのドキュメント](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app).

#### カードおよびトークンの識別 <a href="#card-and-token-identification" id="card-and-token-identification"></a>

有効化するカードとトークンを識別するために、イシュアアプリはiOSのPassKit APIを使用する必要があります。特に、これらのパラメータを使用します：

* passTypeIdentifier
* serialNumber

iOSの用語では、これらのパラメータにより `Pass`を識別できます。このフローでは、 `Pass` は有効化するトークンです。

以下は、このデータを使用してを識別する方法を示すサンプルSwiftコードです。 `Pass`.

> <i class="fa-exclamation-circle">:exclamation-circle:</i>
>
> **警告**
>
> このサンプルコードは現状のままで提供されています。最新のApple仕様を使用する責任はあなたにあります。ThalesはPassKit APIに対してAppleが導入する可能性のある変更について責任を負いません。

```swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
        // エラーを処理します。例：ログ記録
        return false
    }
    
    guard let queryItems = components.queryItems else {
        // エラーを処理します。例：ログ記録
        return false
    }

    // クエリ項目をチェックする例
    let containsPassTypeIdentifier = queryItems.contains(where: { $0.name == "passTypeIdentifier" && $0.value == "paymentpass.com.apple" })
    let indexSerialNumber = queryItems.firstIndex(where: { $0.name == "serialNumber" })
    let containsAction = queryItems.contains(where: { $0.name == "action" })
    let validated = containsPassTypeIdentifier && indexSerialNumber != nil && containsAction

    guard validated, let indexSerialNumber = indexSerialNumber else {
        // エラーを処理します。例：エラーUIを表示
        return false
    }

    var serialNumber = queryItems[indexSerialNumber].value
    let tokenRequestorId = "40010030273" // VISAの場合のみ、それ以外は空文字列
    let scheme = "SCHEME" // VISA、MASTERCARD、AMEX
    let authorizationCode = "<JWT>" // 特定のカードに関連するJWT値を、イシュアのバックエンドから取得して提供

    if let serialNumber = serialNumber {
        let tokenInput = GetTokenInput(serialNumber: serialNumber)
        TPCSDK.getToken(input: tokenInput) {
            (localPass, remotePass, error) in
            if let error = error {
                // TPCエラーを処理
                return
            }
            
            var tokenId: String? = nil
            var last4: String? = nil
            if let localPass = localPass {
                last4 = localPass.secureElementPass?.primaryAccountNumberSuffix
                tokenId = localPass.secureElementPass?.deviceAccountIdentifier
            } else if let remotePass = remotePass {
                last4 = remotePass.secureElementPass?.primaryAccountNumberSuffix
                tokenId = remotePass.secureElementPass?.deviceAccountIdentifier
            }

            if let last4 = last4,
                let tokenId = tokenId {

                // 確認用UIにlast4を表示

                TPCSDK.updateTokenState(tokenId: tokenId,
                                        tokenRequestorId: tokenRequestorId,
                                        schemeString: scheme,
                                        authorizationCode: authorizationCode,
                                        action: .Activate) { success, error in
                    if let error = error {
                        // TPCエラーを処理
                    } else if success {
                        // todo: カードのデジタル化状態を示すようにUIを更新
                    }
                }
            }
        }
    } else {
        // エラーを処理します。例：エラーUIを表示
        return false
    }
    return true
}
```

\
**注意：**

その `deviceAccountIdentifier` は `トークンID` に対応します（TSP内）。それを使用してデジタル化されたカードのトークンを有効化できます。 `primaryAccountNumberSuffix` はトークン化されたPANの下4桁です。認証要求中にカードアートを取得してエンドユーザーに表示するために使用できます。


---

# 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/classic-push-provisioning/ja/ysuksu/to/apuri/apple-pay.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.
