> 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**.

プッシュ配信とルーティングについては、次を参照してください [プッシュ通知の処理](/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通知を処理する（補充）](/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 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/nfc-wallet-sdk-ios/ja/implement-nfc-wallet/make-payments/replenish-payment-keys.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.
