> 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ウォレットはプッシュ通知を使用してあなたの〜に通知します **デジタルウォレットアプリケーション**。通知はNFCウォレットのバックエンドによって送信されます。

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

### 通知をルーティングするには `送信者`

読み取り  `送信者` メッセージペイロードからのキー `データ` および通知を正しいハンドラーにルーティングします：

* `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送信者処理
<strong>    // 1 - プッシュペイロードデータからバンドルを構築する
</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送信の処理
</strong><strong>    My_PushServiceListener pushListener = new My_PushServiceListener();
</strong>    final ProvisioningBusinessService provService 
                = ProvisioningServiceManager.getProvisioningBusinessService();                
    provService.processIncomingMessage( bundle, pushListener );
</code></pre>

NFCウォレットSDKはプッシュを処理し、NFCウォレットのバックエンドとやり取りします。

#### 実装する `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:
              // カードインストールのための最初のプッシュ通知
          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` を使用してトランザクション記録を取得します。

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

* キー `送信者`: `TNS`.
* キー `アクション`: `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送信者処理
    // 1 - TNS送信者通知のために値を抽出する
    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通知（補充）を処理する

The **TSP** は支払いキーの補充を要求できます。使用してください `ProvisioningServiceManager.sendRequestForReplenishment` でキーを補充します。

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

* `送信者`: `MG`.
* `アクション`: `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送信者処理
    // 1 - TNS送信者通知のために値を抽出する
    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）カードでは、これは補充リクエストを送信したことを意味し、バックエンドからSU Kが取得準備できるまでプッシュメッセージを待つ必要があることを意味します。
            // 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.
