> 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/implement-click-to-pay-issuers/enroll-cards-in-click-to-pay/enroll-cards-by-d1-sdk.md).

# Enroll cards by D1 SDK

## Overview

This page explains how the issuer application can enroll a card and its end user in Click to Pay by using the D1 SDK.

The issuer application calls `enrol`, which triggers the same backend Click to Pay enrollment operation as the issuer backend calling the [D1 API](/click-to-pay/integrate-the-d1-api/d1-api-summary.md).

Use this SDK flow when you want the end user to initiate Click to Pay enrollment directly in the issuer application user interface while D1 orchestrates the backend interactions with the Click to Pay directories and the payment network.

## Flow

The following diagram illustrates the main steps of the SDK Click to Pay enrollment flow:

<figure><img src="/files/NxjHM0ILOP8O76vZjMSF" alt=""><figcaption></figcaption></figure>

## Sequence diagram

Since D1 SDK 4.2.0, with the addition of the backend flow, the `enrol` ([Android](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/com/thalesgroup/gemalto/d1/clicktopay/ClickToPayService.html#enrol\(java.lang.String,com.thalesgroup.gemalto.d1.clicktopay.ConsumerInfo,java.lang.String,com.thalesgroup.gemalto.d1.clicktopay.BillingAddress,com.thalesgroup.gemalto.d1.D1Task.Callback\)) / [iOS](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/4.3.0/ios/documentation/d1/clicktopayservice/enrol\(_:consumerinfo:name:billingaddress:\))) API is also available through [D1 SDK](/click-to-pay/integrate-the-d1-sdk/api-reference.md).

### Prerequites

The SDK flow has the same prerequisites and limitations as the backend flow. Please refer to [prerequisites](/click-to-pay/implement-click-to-pay-issuers/enroll-cards-in-click-to-pay.md#prerequisites).

The following sequence diagram shows the flow initiated from the issuer application:

<figure><img src="/files/kEYDJUXpy8ctxQ1PnrdX" alt=""><figcaption></figcaption></figure>

### Key points

* The issuer application must provide the consumer information. See `ConsumerInfo` ([SDK API](/click-to-pay/integrate-the-d1-sdk/api-reference.md)).
* The enrollment is an asynchronous operation. The final result can be retrieved by:
  * using the callback status (`SUCCESSFUL` or `PENDING`),
  * calling the `Get Operation` endpoint available in the [D1 API](/click-to-pay/integrate-the-d1-api/d1-api-summary.md), or
  * activating D1 notifications. In the SDK flow, the issuer can also activate [in-app push notifications](/click-to-pay/integrate-d1-notifications.md) in addition to issuer backend notifications.
* The TSP associated with the payment network triggers a typical digitization flow.

### Handle Click to Pay push notifications

Before the issuer application can receive Click to Pay enrollment notifications from the D1 backend, ensure that push notifications are set up as follows:

{% stepper %}
{% step %}
**Configure push notifications**

Perform the necessary actions as outlined in [push notification configuration](https://gitlab.sre.ops.gcloud.thalescloud.io/bps/gitbook/d1-gitbook-docs/-/blob/main/Products/Click-to-Pay/integrate-the-d1-sdk/getting-started/configuration/4.-push-notifications).
{% endstep %}

{% step %}
**Register push notification token**

Register the [push notification token](https://gitlab.sre.ops.gcloud.thalescloud.io/bps/gitbook/d1-gitbook-docs/-/blob/main/Products/Click-to-Pay/integrate-the-d1-sdk/getting-started/configuration/4.-push-notifications).
{% endstep %}

{% step %}
**Register for message notifications**

Register for [message notifications](/click-to-pay/integrate-d1-notifications/in-app-notifications-and-messaging.md).
{% endstep %}
{% endstepper %}

Once these steps are completed, the issuer application can start receiving push notifications such as `clickToPayEnrolment` and `clickToPayOptOutCard`.

When D1 SDK receives a push notification of type `clickToPayEnrolment` ([Android](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/com/thalesgroup/gemalto/d1/messaging/MessageType.html#CLICKTOPAY_ENROLMENT) / [iOS](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/4.3.0/ios/documentation/d1/messagetype/clicktopayenrolment)) or `clickToPayOptOutCard` ([Android](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/com/thalesgroup/gemalto/d1/messaging/MessageType.html#CLICKTOPAY_OPTOUT_CARD) / [iOS](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/4.3.0/ios/documentation/d1/messagetype/clicktopayoptoutcard)), the issuer application checks the notification to determine whether the Click to Pay enrollment operation or opt-out is successful.

## SDK API

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

```kotlin
fun enrolClick2Pay(d1Task: D1Task, cardID: String) {
    // Consumer info received from user input or backend.
    val consumerInfo = ConsumerInfo(
        "Bella",
        "middle name",
        "Lin",
        "en-US",
        "+65",
        "99998888",
        "email@thalesgroup.com"
    )
    val billingAddress = BillingAddress("CZ")

    val callback: D1Task.Callback<Status?> =
        object : D1Task.Callback<Status?> {
            override fun onSuccess(data: Status?) {
                // Enrol to Click to Pay success
                val status: Status? = data
                val operationID = data?.operationID
            }

            override fun onError(exception: D1Exception) {
                // Refer to D1 SDK Integration – Error Management section.
            }
        }
    d1Task.getClickToPayService().enrol(
        cardID,
        consumerInfo,
        "Bella Lin",
        billingAddress,
        callback
    )
}
```

{% endtab %}

{% tab title="Android - JAVA" %}

```java
public void enrolClick2Pay(@NonNull D1Task d1Task, @NonNull String cardID) {
    // Consumer info received from user input or backend.
    ConsumerInfo consumerInfo = new ConsumerInfo(
        "Bella", 
        "middle name", 
        "Lin", 
        "en-US", 
        "+65", 
        "99998888", 
        "email@thalesgroup.com"
    );
    BillingAddress billingAddress = new BillingAddress("CZ");

    D1Task.Callback<Status> callback = new D1Task.Callback<Status>() {
        @Override
        public void onSuccess(Status data) {
            // Enrol to Click to Pay success
            Status status = data;
            String operationID = data.operationID;
        }

        @Override
        public void onError(D1Exception exception) {
            // Refer to D1 SDK Integration – Error Management section.
        }
    };
    d1Task.getClickToPayService().enrol(
            cardID,
            consumerInfo,
            "Bella Lin",
            billingAddress,
            callback);
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
let cardID = ""
let name = "Bella Lin"
let consumerInfo = ConsumerInfo(firstName: "Bella",
                                middleName: nil,
                                lastName: "Lin",
                                language: "en-US",
                                phoneNumberCountryCode: "+65",
                                phoneNumber: "99998888",
                                email: "email@thalesgroup.com")

let billingAddress = BillingAddress(line1: "1230 Rue de Rivoli",
                                    line2: nil,
                                    line3: nil,
                                    city: "Paris",
                                    state: "75",
                                    zipCode: "75000",
                                    countryCode: "FR")
do {
    let status = try await d1Task.clickToPayService().enrol(cardID,
                                                            consumerInfo: consumerInfo,
                                                            name: name,
                                                            billingAddress: billingAddress)
    switch status {
    case .pending(let operationID):
        // Enrol to Click to Pay is pending.
        print(operationID)
    case .successful(let operationID):
        // Enrol to Click to Pay successfully.
        print(operationID)
    }
} catch {
    // Handle the error.
}
```

{% 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, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/click-to-pay/implement-click-to-pay-issuers/enroll-cards-in-click-to-pay/enroll-cards-by-d1-sdk.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.
