> 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-ios/ja/implement-nfc-wallet/make-payments/replenish-payment-keys.md).

# 支払いキーを補充する

## 概要

非接触決済の EMV クリプトグラムを計算するには、決済キーが必要です。

Host Card Emulation（HCE）モデルでは、決済キーは一時的なものです。決済が中断されないよう、キーがなくなる前に補充してください。

このガイドでは、補充が必要になるタイミングと、その実行方法について説明します。

{% hint style="info" %}
NFC Wallet SDK は、次の種類の決済キーに対応しています。

* **SUK（単回使用キー）**：各取引で使用する1回限りの決済キーです。Mastercard および Thales EMV White Label（PURE）に適用されます。
* **LUK（限定使用キー）**：有効期限が切れるまで複数の取引で使用できる決済キーです。Visa に適用されます。
  {% endhint %}

## 前提条件

### 補充しきい値を設定する（オンボーディング）

オンボーディング時に、 **Thales のデリバリーチーム**.

{% hint style="info" %}
しきい値を設定する際は、次の点を考慮してください。

* **SUK**：補充を開始する残りの SUK 数です。
* **LUK**：残りの取引可能回数と LUK の有効期限です。
  {% endhint %}

## SDK の統合

### 補充が必要なタイミングを検出する

次のシグナルのいずれか（または両方）を使用します。

* **事前チェック**： `DigitalCard.PaymentKeyInfo.needsReplenishment`.
* **リアクティブプッシュ（TSP によるトリガー）**： `MG:ReplenishmentNeededNotification` からのプッシュ通知を処理します。 **TSP**.

プッシュ通知の配信とルーティングについては、 [プッシュ通知を処理する](https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/get-started/configuration/4.-push-notifications/handle-push-notifications.md).

#### 事前チェック

各デジタルカードについて定期的に確認します。たとえば、各決済の後やアプリの起動時に確認してください。

```swift
func checkReplenishment(digitalCard: DigitalCard) async throws -> Bool {
    return try await digitalCard.paymentKeyInfo.needsReplenishment
}
```

次のタイミングで事前チェックを実行してください。

* NFC Wallet SDK の   初期化後。
* 決済後。
* カードをデフォルトに設定したとき。
* 接続が復旧したとき（オフライン → オンライン）。

{% hint style="info" %}
SDK が必要と示したら、すぐに補充を開始してください。補充中にアプリを終了しないでください。
{% endhint %}

### 補充を開始する

補充すると判断したら、 `ReplenishmentService.replenish(digitalCardID:)` を呼び出します。

{% code expandable="true" %}

```swift
func replenishment(digitalCard: DigitalCard) async {
    do {
        if try await digitalCard.paymentKeyInfo.needsReplenishment {
            let replenishmentService = ReplenishmentService()
            try await replenishmentService.replenish(digitalCardID: digitalCard.digitalCardID)
         
            // NFC Wallet バックエンドは、操作を確認するためにプッシュ通知を送信します。
            // アプリで処理する必要があります。詳しくは「プッシュ通知を処理する」を参照してください。
        }
    } catch let error {
        switch (error as? ReplenishmentService.Error) {
            case .networkError:
                break
            case .missingWalletSecureEnrollment:
                break
            case .deviceEnvironmentUnsafe(let error):
                break
            case .clientError(let message):
                break
            case .serverError(let message):
                break
            case .unknown(let underlying):
                break
            @unknown default:
                break
        }
    }
}
```

{% endcode %}

チャージリクエストを送信すると、 **NFC Walletバックエンド** からプッシュ通知が送信されます。アプリケーションが通知を処理し、SDKが新しい決済キーを取得します。

{% hint style="info" %}
**TSPトリガー** を受信したら、 `MG:ReplenishmentNeededNotification`を呼び出します。 `ReplenishmentService.replenish(digitalCardID:isForced:)` に `isForced: true`.

詳しくは、 [MG通知を処理する（チャージ）](https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/get-started/configuration/4.-push-notifications/handle-push-notifications.md#process-mg-notifications-replenishment).
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/implement-nfc-wallet/make-payments/replenish-payment-keys.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
