> 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-android/ja/get-started/configuration/5.-push-notifications/handle-push-notifications.md).

# プッシュ通知を処理する

NFC Wallet はプッシュ通知を使用して、お客様に通知します **デジタルウォレットアプリケーション**。通知は NFC Wallet のバックエンドから送信されます。

{% hint style="info" %}
NFC Wallet のプッシュ通知の処理は、サポートするために必要です **LCM**、トランザクション通知、およびデジタルカードが発行者によって直接有効化されるカード登録フロー。
{% endhint %}

### 通知のルーティングには次を使用します `sender`

読み取り `sender` メッセージペイロードからキーを `データ` そして通知を適切なハンドラーに振り分けます:

* `CPS`：デジタルカード操作（**LCM**)
* `TNS`：トランザクション通知
* `MG`：によってトリガーされる支払いキーの補充 **TSP**

<pre class="language-java" data-expandable="true"><code class="lang-java">private static final String KEY_SENDER = "sender";

public void processIncomingMessage(@NonNull final Context context,
                                   @NonNull final Map&#x3C;String, String> data) {
     
    String sender = "";
    if (!data.isEmpty()) {
        for (String key : data.keySet()) {
            if (KEY_SENDER.equalsIgnoreCase( key )) {
                sender = data.get(key);
            }
        }
    }
     
    switch (sender) {
    case "CPS":
        // デジタルカード操作（LCM）。
        // `ProvisioningBusinessService.processIncomingMessage` を参照
        break;
  
    case "TNS":
<strong>         // トランザクション通知。
</strong>         // トランザクション履歴を更新します。API リファレンスの `MGTransactionHistoryService` を参照してください。
         break;
                  
    case "MG":
         // TSP によってトリガーされるキー補充。
         // 補充をトリガーします。API リファレンスの `ReplenishmentService` を参照してください。
        break;

    default:
        // 非 SDK 通知
<strong>        break;
</strong>    }     
}
</code></pre>

### CPS 通知（デジタルカード操作）を処理します <a href="#process-cps-notifications-digital-card-operations" id="process-cps-notifications-digital-card-operations"></a>

転送 **CPS** 通知を次を使用して `ProvisioningBusinessService`.`processIncomingMessage()`.

<pre class="language-java" data-expandable="true"><code class="lang-java">public void processIncomingMessage(@NonNull final Context context,
                                   @NonNull final Map&#x3C;String, String> data) {
    // ...
    // CPS sender の処理
<strong>    // 1 - プッシュペイロードデータから Bundle を作成
</strong><strong>    final Bundle bundle = new Bundle();
</strong>    if (!data.isEmpty()) {
        for (String key : data.keySet()) {
            if (null != data.get(key)) {
                 bundle.putString(key, data.get(key));    
            }
        }
    }

<strong>    // 2 - CPS sender のプッシュを処理
</strong><strong>    My_PushServiceListener pushListener = new My_PushServiceListener();
</strong>    final ProvisioningBusinessService provService 
                = ProvisioningServiceManager.getProvisioningBusinessService();                
    provService.processIncomingMessage( bundle, pushListener );
</code></pre>

NFC Wallet SDK はプッシュを処理し、NFC Wallet バックエンドと連携します。

#### 実装する `PushServiceListener`

実装する `PushServiceListener` デジタルカード操作を追跡するためのコールバックを処理するために

サポートされるコールバック:

* `onUnsupportedPushContent`：プッシュペイロードが SDK でサポートされていない場合にトリガーされます。
* `onComplete`：処理が正常に完了したときにトリガーされます（たとえば、カードプロファイルと支払いキーのプロビジョニング後）。
* `serverMessage`：バックエンドがサーバーメッセージを返したときにトリガーされます。SDK は `ProvisioningServiceMessage` オブジェクトと `tokenizedCardId`.

受信したら `ProvisioningServiceMessage`、次を呼び出します `getMsgCode` バックエンドが実行している操作を判定するために使用します:

* `REQUEST_INSTALL_CARD`：このメッセージは、カードのインストール要求を示します。
* `REQUEST_REPLENISH_KEYS`：このメッセージは、補充要求を示します。
* `REQUEST_RESUME_CARD`：このメッセージは、カードを停止状態から有効状態へ移行する要求を示します。
* `REQUEST_SUSPEND_CARD`：このメッセージは、カードを有効状態から停止状態へ移行する要求を示します。
* `REQUEST_DELETE_CARD`：このメッセージは、カードの削除要求を示します。
* `REQUEST_RENEW_CARD`：このメッセージは、カードの更新要求を示します

{% code expandable="true" %}

```java
public class My_PushServiceListener implements PushServiceListener {

  @Override
  public void onServerMessage(String tokenizedCardId, ProvisioningServiceMessage message) {
    /*
    これは、プロビジョニングフローの各ステップ、ライフサイクル管理操作、キー補充の際にトリガーされます。

    実行されたアクションを把握するには、ProvisioningServiceMessage オブジェクトを解析します。
    **/

      //例
    	String messageCode = provisioningServiceMessage.getMsgCode();

      switch (messageCode) {
          case KnownMessageCode.REQUEST_INSTALL_CARD:
              // カードインストール用の1回目のプッシュ通知
          case KnownMessageCode.REQUEST_REPLENISH_KEYS:
              // 支払いキーのインストールおよびその後の補充用の2回目のプッシュ通知
          case KnownMessageCode.REQUEST_RESUME_CARD:
              // 再開されるカード
          case KnownMessageCode.REQUEST_SUSPEND_CARD:
              // 停止されるカード
          case KnownMessageCode.REQUEST_RENEW_CARD:
              // 更新されるトークン（プロファイル更新）
          case KnownMessageCode.REQUEST_DELETE_CARD:
              // 削除されるカード。
              LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_RELOAD_CARDS));
              break;
          default:
      }
  }

  @Override
  public void onUnsupportedPushContent(Bundle pushMessageBundle) {
    /*
    渡されたメッセージが理解できない場合、またはサポートされていない場合にトリガーされます
    **/
  }

  @Override
  public void onComplete() {
    /*
    プロビジョニングセッションが正常に完了するとトリガーされます。カードは支払いに使用できる状態です。
    **/
  }

  @Override
  public void onError(ProvisioningServiceError error) {
    /*
    エラーが発生するとトリガーされます。開発者はエラーを解析し、適切な対応を取る必要があります。
    **/
  }
}
```

{% endcode %}

### TNS 通知（トランザクション）を処理します

トランザクション通知には、完了した支払いトランザクションの詳細が含まれます。次を使用します `MGTransactionHistoryService` トランザクション記録を取得します。

プッシュ通知を通じて、 **デジタルウォレットアプリケーション** 次の情報をメッセージペイロード経由で取得します `データ` :

* キー `sender`: `TNS`.
* キー `action`: `TNS:PaymentTransactionNotification`.
* キー `digitalCardId`：デジタルカード識別子。次とともに使用します `MGTransactionHistoryService.refreshHistory()` トランザクションを取得するために
* キー `transactionRecordType`：共通ブランドカードにのみ存在します。次に渡して `MGTransactionHistoryService.refreshHistory()` 関連するレコード（主カードまたは補助カード）のみを取得します。

{% code expandable="true" %}

```java
private static final String KEY_SENDER = "sender";
private static final String KEY_ACTION = "action";
private static final String KEY_DIGITALIZED_CARD_ID = "digitalCardID";
private static final String KEY_TRANSACTION_RECORD_TYPE = "transactionRecordType";

public void processIncomingMessage(@NonNull final Context context,
                                   @NonNull final Map<String, String> data) {
    
    String action = "";
    String digitalCardID = "";
    String transactionRecordType = "";
    
    // ...
    // TNS sender の処理
    // 1 - TNS sender 通知の値を抽出
    final Bundle bundle = new Bundle();
    if (!data.isEmpty()) {
        for (String key : data.keySet()) {
            if (KEY_DIGITALIZED_CARD_ID.equalsIgnoreCase( key )) {
                 digitalCardID = data.get(key);
            }
            else if (KEY_ACTION.equalsIgnoreCase( key )) {
                 action = data.get(key);
            }
            else if (KEY_TRANSACTION_RECORD_TYPE .equalsIgnoreCase( key )) {
                 transactionRecordType = data.get(key);
            }
        }
    }
    
    // 2 - パラメータを確認
    if( ! "TNS:PaymentTransactionNotification".equals( action ) || digitalCardID == null ) {
         // エラーをログに記録
    }
    else {
         // 3 - MG トランザクション履歴サービスを呼び出す         
         final MGTransactionHistoryService tnsService 
                = MobileGatewayManager.INSTANCE.getTransactionHistoryService();
                
         // 3a - 先にアクセストークンを取得してください
         final ProvisioningBusinessService provService 
                = ProvisioningServiceManager.getProvisioningBusinessService();
         provService.getAccessToken(digitalCardID, 
              GetAccessTokenMode.REFRESH, new AccessTokenListener() {
                 @Override
                 public void onSuccess(String digitalCardId, String accessToken) {
                      // 3b - アクセストークンを使用してトランザクションを取得できます
                      tnsService.refreshHistory(accessToken, 
                                               digitalCardID, null, transactionRecordType , new TransactionHistoryListener() {
                              
                              @Override
                              public void onSuccess(List<MGTransactionRecord> list, String digitalCardId, String timeStamp) {
                                  // 成功
                                  // トランザクションレコードの一覧を解析できます
                              }

                              @Override
                              public void onError(String s, MobileGatewayError mobileGatewayError) {
                                  // エラーをログに記録
                              }
                      });              
                 }
                 
                 @Override
                 public void onError(String digitalCardId, ProvisioningServiceError provisioningServiceError) {
                       // アクセストークンの取得に失敗しました
                       // エラーをログに記録
                  }
             });
      } 
}


```

{% endcode %}

### MG 通知（補充）を処理する

発行者は **TSP** 支払いキーの補充を要求できます。次を使用します `ProvisioningServiceManager.sendRequestForReplenishment` キーを補充するために。

プッシュ通知を通じて、 **デジタルウォレットアプリケーション** 次の情報をメッセージペイロード経由で取得します `データ`

* `sender`: `MG`.
* `action`: `MG:ReplenishmentNeededNotification`.
* `"digitalCardId`：デジタルカード識別子。次とともに使用します `ReplenishmentService.replenish(digitalCardID:isForced:)`.

<pre class="language-java" data-expandable="true"><code class="lang-java">private static final String KEY_SENDER = "sender";
private static final String KEY_ACTION = "action";
private static final String KEY_DIGITALIZED_CARD_ID = "digitalCardID";

public void processIncomingMessage(@NonNull final Context context,
                                   @NonNull final Map&#x3C;String, String> data) {
    
    String action = "";
    String digitalCardID = "";
    String transactionRecordType = "";
    
    // ...
    // MG sender の処理
    // 1 - TNS sender 通知の値を抽出
    final Bundle bundle = new Bundle();
    if (!data.isEmpty()) {
        for (String key : data.keySet()) {
            if (KEY_DIGITALIZED_CARD_ID.equalsIgnoreCase( key )) {
                 digitalCardID = data.get(key);
            }
            else if (KEY_ACTION.equalsIgnoreCase( key )) {
                 action = data.get(key);
            }
        }
    }
    
    // 2 - パラメータを確認
    if( ! "MG:ReplenishmentNeededNotification".equals( action ) || digitalCardID == null ) {
         // エラーをログに記録
    }
    else {
         // 3 - プロビジョニングビジネスサービスを呼び出す
         final ProvisioningBusinessService provService 
                = ProvisioningServiceManager.getProvisioningBusinessService();
         provService.sendRequestForReplenishment( digitalCardID, new ReplenishmentListener(), true);                             
    }
}

/**
 * このリスナーを使用すると、結果のみを監視します
 * ProvisioningBusinessService#sendRequestForReplenishment() API の呼び出し結果を監視します。この API は
 * 同じ PushServiceListener API を使用しますが、プッシュメッセージの処理は含まれません。
 */
private static class ReplenishmentListener implements PushServiceListener {

        public ReplenishmentListener(){
        }


        @Override
        public void onError(final ProvisioningServiceError provisioningServiceError) {
            // エラーをログに記録
        }

        @Override
        public void onUnsupportedPushContent(final Bundle bundle) {
            // 補充のユースケースでは、これは決して起こるべきではありません。なぜなら、私たちは渡していないからです
            // エラーをログに記録
        }

        @Override
        public void onServerMessage(final String tokenizedCardId,
                                    final ProvisioningServiceMessage provisioningServiceMessage) {
            //  補充では、これは決して起こるべきではありません
            // エラーをログに記録
<strong>         }
</strong>
        @Override
        public void onComplete() {

            // Mastercard および PURE（ホワイトラベル EMV）カードの場合、これは補充リクエストを送信済みであり、待機する必要があることを意味するだけです
            // SUK がバックエンドから取得可能になる準備が整ったら、プッシュメッセージが届くのを待ちます。
 
            // Visa カードの場合、これで完了し、カードは新しい LUK で利用可能な状態になります
            // したがって、Visa カードかどうかを確認し、該当する場合はユーザーに通知するためにプッシュメッセージ処理コードを再利用します
        }
    }



</code></pre>


---

# 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-android/ja/get-started/configuration/5.-push-notifications/handle-push-notifications.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.
