> 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/opt-out-cards-from-click-to-pay/opt-out-by-d1-sdk.md).

# Opt out by D1 SDK

## Overview

This page explains how the issuer application can opt out from Click to Pay by using the D1 SDK.

D1 SDK provides two opt-out APIs:

* `optOutCard` removes one card from Click to Pay.
* `optOutConsumer` removes all cards for the end user from Click to Pay.

Use these SDK flows when you want the end user to start the opt-out directly from the issuer application while D1 orchestrates the backend interactions with the Click to Pay directories and the payment network.

{% hint style="info" %}
**Quick links**

* [Opt out cards from Click to Pay](/click-to-pay/implement-click-to-pay-issuers/opt-out-cards-from-click-to-pay.md)
* [Retrieve profiles by D1 SDK](/click-to-pay/implement-click-to-pay-issuers/retrieve-click-to-pay-profiles/retrieve-profiles-by-d1-sdk.md)
* [Enroll cards by D1 SDK](/click-to-pay/implement-click-to-pay-issuers/enroll-cards-in-click-to-pay/enroll-cards-by-d1-sdk.md)
* [Update profiles by D1 SDK](/click-to-pay/implement-click-to-pay-issuers/update-click-to-pay-profiles/update-profiles-by-d1-sdk.md)
  {% endhint %}

## Choose the right SDK API

### `optOutCard`

Use `optOutCard` when the end user wants to remove one specific card from Click to Pay.

This option keeps other enrolled cards unchanged.

### `optOutConsumer`

Use `optOutConsumer` when the end user wants to remove the full Click to Pay profile.

This option removes all cards enrolled in Click to Pay for that end user.

## Flow

The diagram below depicts the overall SDK-based opt-out flow:

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

## Sequence diagram

The SDK flow has the same functional behavior as the backend opt-out flow, but it is initiated directly from the issuer application.

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

<figure><img src="/files/2E4B49DtBARDbnejxdxz" alt=""><figcaption></figcaption></figure>

### Key points

* Both operations are asynchronous.
* The immediate result contains a status of `SUCCESSFUL` or `PENDING`, plus an `operationID`.
* Use [Retrieve profiles by D1 SDK](/click-to-pay/implement-click-to-pay-issuers/retrieve-click-to-pay-profiles/retrieve-profiles-by-d1-sdk.md) before opt-out when the issuer application must show the current Click to Pay state.
* `optOutCard` removes one digital card from the payment network side.
* `optOutConsumer` removes the full Click to Pay profile for the end user across enrolled cards.
* The final result can also be tracked through the Get Operation endpoint in the [D1 API summary](/click-to-pay/integrate-the-d1-api/d1-api-summary.md) or through D1 Notifications.

The diagrams illustrate the opt-out flow started from the issuer application.

`optOutConsumer` follows the same SDK pattern as `optOutCard`, but applies to all cards linked to the end user.

## Handle Click to Pay push notifications

Refer to [Handle Click to Pay push notifications](/click-to-pay/implement-click-to-pay-issuers/enroll-cards-in-click-to-pay/enroll-cards-by-d1-sdk.md#handle-click-to-pay-push-notifications) in the enrollment by D1 SDK documentation for the implementation details.

## SDK API for `optOutCard`

Since D1 SDK 4.2.0, `optOutCard` ([Android](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/com/thalesgroup/gemalto/d1/clicktopay/ClickToPayService.html#optOutCard\(java.lang.String,com.thalesgroup.gemalto.d1.D1Task.Callback\)) / [iOS](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/4.3.0/ios/documentation/d1/clicktopayservice/optoutcard\(_:\))) is available through D1 SDK.

Use this API when the end user wants to opt out one specific card only.

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

```kotlin
fun optOutClick2Pay(d1Task: D1Task, cardID: String) {

    val callback: D1Task.Callback<Status?> =
        object : D1Task.Callback<Status?> {
            override fun onSuccess(data: Status?) {
                // Opt out 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().optOutCard(
        cardID,
        callback
    )
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
let cardID = ""
do {
    let status = try await d1Task.clickToPayService().optOutCard(cardID)
    switch status {
    case .pending(let operationID):
        // Opt-out from Click to Pay is pending.
        print(operationID)
    case .successful(let operationID):
        // Opt-out from Click to Pay successfully.
        print(operationID)
    }
} catch {
    // Handle the error.
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Use `optOutCard` when the issuer application presents a card list and the end user selects one card to remove.
{% endhint %}

## SDK API for `optOutConsumer`

Since D1 SDK 4.3.0, `optOutConsumer` ([Android](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/com/thalesgroup/gemalto/d1/clicktopay/ClickToPayService.html#optOutConsumer\(com.thalesgroup.gemalto.d1.D1Task.Callback\)) / [iOS](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/4.3.0/ios/documentation/d1/clicktopayservice/optoutconsumer\(\))) is available through D1 SDK.

Use this API when the end user wants to opt out all cards from Click to Pay in a single action.

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

```kotlin
fun optOutConsumerClick2Pay(d1Task: D1Task) {
    val callback: D1Task.Callback<Status?> =
        object : D1Task.Callback<Status?> {
            override fun onSuccess(data: Status?) {
                // Opt out 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().optOutConsumer(
        callback
    )
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
do {
    let status = try await d1Task.clickToPayService().optOutConsumer()
    switch status {
    case .pending(operationID: let operationID):
        // Handle pending scenario
        print(operationID)
    case .successful(operationID: let operationID):
        // Handle successful scenario
        print(operationID)
    }
} catch let error {
    // Handle the error.
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Use `optOutConsumer` carefully.

This action removes all Click to Pay cards for the end user.
{% 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/click-to-pay/implement-click-to-pay-issuers/opt-out-cards-from-click-to-pay/opt-out-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.
