> 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/click-to-pay/integrate-d1-notifications/in-app-notifications-and-messaging.md).

# In-app notifications and messaging

Use the D1 SDK to register the issuer application for in-app notifications. You can also retrieve a message list and mark messages as read.

### Register the issuer application for notifications

D1 requires the issuer application to explicitly register with the messaging service to receive in-app notifications.

You perform this registration using the D1 SDK.

#### Flow

D1 delivers in-app notifications using push notifications.

<figure><img src="/spaces/62lLFDcmLCeqqwmy4Fee/files/U8FespQASKBjiweV3ZJq" alt=""><figcaption><p>In-app notification flow using push notifications.</p></figcaption></figure>

#### Register and unregister

After calling `D1Task.updatePushToken`, register for message notifications by calling `MessagingService.registerMessageNotification`.

To stop receiving message notifications, call `MessagingService.unregisterMessageNotification`.

{% hint style="info" %}
When using Click to Pay and the messaging service, call `D1Task.login()` first. Then call `D1Task.updatePushToken()`. Only then call `MessagingService.registerMessageNotification()`.
{% endhint %}

#### Integration flow

**Prerequisites :**

* SDK is properly initialised.
* Issuer App called D1 SDK login API.
* Issuer App updated the push token.

<figure><img src="/spaces/62lLFDcmLCeqqwmy4Fee/files/W0zAPM9xGdG8HrQw1R6b" alt=""><figcaption><p>Register and unregister for message notifications.</p></figcaption></figure>

{% tabs %}
{% tab title="Android" %}

```java
MessagingService messagingService = d1Task.getMessagingService();
messagingService.registerMessageNotification(new D1Task.Callback<Void>() {
    @Override
    public void onSuccess(Void data){
        // Proceed with the subsequent flows, for example, update UI.
    }
    @Override
    public void onError(@NonNull D1Exception exception){
        // Refer to D1 SDK Integration – Error Management section. 
    }
});

MessagingService messagingService = d1Task.getMessagingService();
messagingService.unregisterMessageNotification(new D1Task.Callback<Void>(){
    @Override
    public void onSuccess(Void unused){
        // Proceed with subsequent flows.
    }
    @Override
    public void onError(@NonNull D1Exception e){
        // Refer to D1 SDK Integration – Error Management section.
    }
});
```

{% endtab %}

{% tab title="iOS" %}

```objective-c
do {
    messagingService = try d1Task.messagingService()
} catch let error {
    // possible error: D1Error.Code.deviceEnvironmentUnsafe
}

messagingService.registerMessageNotification { error in
    if error == nil {
        // Proceed with subsequent flows.
    } else {
        // Refer to D1 SDK Integration – Error Management section.
    }
}

messagingService.unregisterMessageNotification { error in
    if error == nil {
        // Proceed with subsequent flows.
    } else {
        // Refer to D1 SDK Integration – Error Management section.
    }
}
```

{% endtab %}
{% endtabs %}

### Retrieve messages and mark them as read

#### Flow

<figure><img src="/spaces/62lLFDcmLCeqqwmy4Fee/files/12iZMW9znpa9GYen0UiK" alt=""><figcaption></figcaption></figure>

#### Integration flow

**Prerequisites :**

* SDK is properly initialised
* Issuer App called D1 SDK login API

<figure><img src="/spaces/62lLFDcmLCeqqwmy4Fee/files/xZc8Zl3DNOhEdOWndhfn" alt=""><figcaption><p>Retrieve a message list and mark messages as read.</p></figcaption></figure>

You can handle messages from [push notifications](https://thales-dis-dbp.stoplight.io/docs/d1-caas/tx0ctsp29oo0v-message-handling). You can also retrieve a message list by calling `MessagingService.getMessageList`.

{% tabs %}
{% tab title="Android" %}

```java
MessagingService messagingService = d1Task.getMessagingService();
D1Task.Callback<List<Message>> callback = new D1Task.Callback<List<Message>>() {
    @Override
    public void onSuccess(List<Message> messages) {
        // Proceed with subsequent flows. For example, show the list to the end user.
        for(Message message : messages) {
            String id = message.getMessageID();
            String title = message.getTitle();
            String content = message.getMessage();
            boolean isRead = message.isRead();
            String timeStamp = message.getTimeStamp();
        }
    }
    @Override
    public void onError(@NonNull D1Exception e) {
        // Refer to D1 SDK Integration – Error Management section.
    }
};
messagingService.getMessageList(callback);
```

{% endtab %}

{% tab title="iOS" %}

```objective-c
do {
    messagingService = try d1Task.messagingService()
} catch let error {
    // possible error: D1Error.Code.deviceEnvironmentUnsafe
}

messagingService.messageList { messageList, error in
    if let messageList = messageList {
        // Proceed with subsequent flows. For example, show the list to the end user.
        for message in messageList {
            let id = message.id // To be used for marking message as read.
            let title = message.title
            let content = message.message
            let isRead = message.isRead
            let timestamp = message.timestamp
        }
    } else if let error = error {
        // Refer to D1 SDK Integration – Error Management section.
    }
}
```

{% endtab %}
{% endtabs %}

After the end user views the messages, mark them as read by calling `MessagingService.markMessageListAsRead`.

{% tabs %}
{% tab title="Android" %}

```java
ArrayList<String> messageIDs = new ArrayList<>();
messageIDs.add("<#T##messageID1: String#>");
messageIDs.add("<#T##messageID2: String#>");

MessagingService messagingService = d1Task.getMessagingService();
D1Task.Callback<Void> callback = new D1Task.Callback<Void>() {
    @Override
    public void onSuccess(Void unused) {
        // Proceed with subsequent flows. For example, update UI.
    }
    @Override
    public void onError(@NonNull D1Exception e) {
        // Refer to D1 SDK Integration – Error Management section.
    }
};
messagingService.markMessageListAsRead(messageIDs, callback);
```

{% endtab %}

{% tab title="iOS" %}

```objective-c
do {
    messagingService = try d1Task.messagingService()
} catch let error {
    // possible error: D1Error.Code.deviceEnvironmentUnsafe
}

let ids = ["<#T##messageID1: String#>", "<#T##messageID2: String#>"]
messagingService.markMessageListAsRead(ids) { error in
    if error == nil {
        // Proceed with subsequent flows. For example, update UI.
    } else {
        // Refer to D1 SDK Integration – Error Management section.
    }
}
```

{% endtab %}
{% endtabs %}


---

# 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:

```
GET https://docs.payments.thalescloud.io/click-to-pay/integrate-d1-notifications/in-app-notifications-and-messaging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
