> 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/transaction-control/ja/implement-transaction-control/implement-domain-controls/manage-in-app-card-controls.md).

# アプリ内のカード制御を管理する

エンドユーザーがドメインコントロールを表示および更新できるように、次から操作します： **イシュアアプリケーション** を取得できます **D1 SDK**.

## シーケンス図

D1 SDK を使用して現在の設定を取得し、UI を描画してから更新を送信します。

**前提条件**

* 消費者とカードが既に D1 に作成／登録されていること。
* SDK が適切に初期化されていること。
* イシュアアプリが D1 SDK のログイン API を呼び出していること。
* updateCardControlSettings または updateCardLimitSettings API を呼び出す前に、まず getCardSettings API を呼び出してください。

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

## D1 SDK 統合

D1 SDK は D1 で管理されているカードに対して以下の公開 API を使用します：

* `CardService.getCardSettings()`：カード設定を取得するため。
* `CardService.updateCardControlSettings()`：カードのコントロール設定を更新するため。

### 現在の設定を取得する

`CardService.getCardSettings()` は 2 グループの設定を返します：

* カードコントロール設定（ドメインコントロール）
* カード上限設定（支出限度）は次を参照してください： [API ドキュメント](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/index.html) fまたはカードコントロールおよびカード上限設定の詳細なフィールドレベル情報。

参照： [D1 SDK API リファレンス](https://thalesgroup.github.io/d1sdk-docs/d1-sdk/latest/android/index.html) フィールドレベルの詳細について。

支出限度も実装する場合は、次を参照してください： [支出限度の実装](/transaction-control/ja/implement-transaction-control/implement-spending-limits-controls.md).

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

```java
// カード設定を取得
String cardID = ""; // バックエンドから受け取った cardID。
final CardSettings[] cardSettingsCached = new CardSettings[0];

CardService cardService = d1Task.getCardService();
D1Task.Callback<CardSettings> callback = new D1Task.Callback<CardSettings>() {
    @Override
    public void onSuccess(CardSettings cardSettings) {
        // アプリ内で設定をキャッシュする
        cardSettingsCached[0] = cardSettings;
    }

    @Override
    public void onError(D1Exception exception) {
        // D1 SDK 統合 – エラー管理 セクションを参照してください。
    }
};
cardService.getCardSettings(cardID, callback);
```

{% endtab %}

{% tab title="iOS" %}

```swift
let cardID = "" // 例：サーバーから取得
let cardService = d1Task.cardService()
cardService.cardSettings(cardID) { [weak self] cardSettings, error in
    if let error = error {
       // エラーを処理する
    } else if let cardSettings = cardSettings {
        cardSettingsCached = cardSettings
        // 続くフローを実行（例：カードコントロール／上限設定の UI を表示）
    }
}
```

{% endtab %}
{% endtabs %}

### UI にカードコントロール設定をレンダリングする

カードコントロールは次の `CardSettings` オブジェクトから読み取り、存在するコントロールのみをレンダリングします。

一部のコントロールはカードプロダクトレベルでオプションです。D1 はそれらを次のように返します： `null`。それらのコントロールは非表示にしてください。

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

```java
// カード設定を取得
String cardID = ""; // バックエンドから受け取った cardID。
final static CardSettings cardSettingsCached;// キャッシュされたカード設定、または `Cardservice.getCardSettings()` API から取得したもの
CardControlSettings cardControlSettings = cardSettingsCached.getControl();    
        

//
// ==== 支払いステータス セクション =====
//
// オンライン支払いの有効/無効
Switch onlinePaymentSwitch;
onlinePaymentSwitch.setChecked(cardControlSettings.isOnlinePaymentEnabled());

// 海外支払いの有効/無効
Switch abroadPaymentSwitch;
abroadPaymentSwitch.setChecked(cardControlSettings.isAbroadPaymentEnabled());

// 非接触支払いの有効/無効。
if(cardControlSettings.isContactlessEnabled() != null) {
    // 注：`CardService.getCardSettings()` API レスポンスに isContactlessEnabled 属性がある場合のみこの設定を表示してください。
    Switch contactlessSwitch;
    contactlessSwitch.setChecked(cardControlSettings.isContactlessEnabled());
}

// 磁気ストライプ支払いの有効/無効
if(cardControlSettings.isMagneticStripeEnabled() != null) {
    // 注：`CardService.getCardSettings()` API レスポンスに isMagneticStripeEnabled 属性がある場合のみこの設定を表示してください。
    Switch magneticStripeSwitch;
    magneticStripeSwitch.setChecked(cardControlSettings.isMagneticStripeEnabled());
}

// ATM 引き出しの有効/無効
if(cardControlSettings.isATMWithdrawalEnabled() != null) {
    // 注：`CardService.getCardSettings()` API レスポンスに isATMWithdrawalEnabled 属性がある場合のみこの設定を表示してください。
    Switch atmWithdrawalSwitch;
    atmWithdrawalSwitch.setChecked(cardControlSettings.isATMWithdrawalEnabled());
}

//
// ==== 禁止通貨リスト セクション =====
//
// 禁止通貨リストセクションを表示
List<String> deniedCurrencies = cardControlSettings.getDeniedCurrencyList();
RecyclerView deniedCurrencyListRecyclerview;
DeniedCurrencyListAdapter deniedCurrencyAdapter = new DeniedCurrencyListAdapter(deniedCurrencies);
deniedCurrencyListRecyclerview.setAdapter(deniedCurrencyAdapter);


//
// ==== 地理（ジオグラフィ）セクション =====
//
// 地理設定セクションを表示
CardControlSettings.Geography geography = cardControlSettings.getGeography();
List<CardControlSettings.Region> regionList = geography.getRegionList();
RecyclerView regionListRecyclerview;
RegionListAdapter regionAdapter = new RegionListAdapter(regionList);
regionListRecyclerview.setAdapter(regionAdapter);


List<String> countryList = geography.getCountryList();
RecyclerView countryListRecyclerview;
CountryListAdapter countryAdapter = new CountryListAdapter(countryList);
countryListRecyclerview.setAdapter(countryAdapter);

//
// ==== マーチャント（加盟店）セクション =====
//
// マーチャントセクションを表示
CardControlSettings.Merchant merchant = cardControlSettings.getMerchant();
// ギャンブル関連マーチャントでの支払いの有効/無効
Switch gamblingMerchantSwitch;
gamblingMerchantSwitch.setChecked(merchant.isGamblingMerchantEnabled());

// アダルト関連マーチャントでの支払いの有効/無効
Switch adultMerchantSwitch;
adultMerchantSwitch.setChecked(merchant.isAdultMerchantEnabled());

// リスキー（危険）なマーチャントでの支払いの有効/無効
Switch riskyMerchantSwitch;
riskyMerchantSwitch.setChecked(merchant.isRiskyMerchantEnabled());
```

{% endtab %}

{% tab title="iOS" %}

```swift
// UI 表示の例
let onlinePaymentSwitch = UISwitch()
let contactlessSwitch = UISwitch()
let magneticStripeSwitch = UISwitch()
let atmWithdrawalSwitch = UISwitch()
let abroadPaymenSwitch = UISwitch()
let deniedCurrencyListTextView = UITextView()
let countryListTextView = UITextView()
let regionListTextView = UITextView()
let gamblingMerchantSwitch = UISwitch()
let adultMerchantSwitch = UISwitch()
let riskyMerchantSwitch = UISwitch()

let cardControlSettings = cardSettingsCached.control

//
// ===== 支払いステータス セクション =====
//

// オンライン支払いの有効/無効
onlinePaymentSwitch.isOn = cardControlSettings.isOnlinePaymentEnabled

// 非接触支払いの有効/無効
if let isContactlessEnabled = cardControlSettings.isContactlessEnabled {
    contactlessSwitch.isOn = isContactlessEnabled
} else {
    // 注：値が nil でない場合にのみ設定を表示してください
    contactlessSwitch.isHidden = true
}

// 磁気ストライプの有効/無効
if let isMagneticStripeEnabled = cardControlSettings.isMagneticStripeEnabled {
    magneticStripeSwitch.isOn = isMagneticStripeEnabled
} else {
    // 注：値が nil でない場合にのみ設定を表示してください
    magneticStripeSwitch.isHidden = true
}

// ATM 引き出しの有効/無効
if let isATMWithdrawalEnabled = cardControlSettings.isATMWithdrawalEnabled {
    atmWithdrawalSwitch.isOn = isATMWithdrawalEnabled
} else {
    // 注：値が nil でない場合にのみ設定を表示してください
    atmWithdrawalSwitch.isHidden = true
}

// 海外支払いの有効/無効
abroadPaymenSwitch.isOn = cardControlSettings.isAbroadPaymentEnabled

//
// ===== 禁止通貨リスト セクション =====
//

// 禁止通貨リストセクションを表示（例：UITextView または UITableView）
for currency in cardControlSettings.deniedCurrencyList {
    deniedCurrencyListTextView.text = "\(deniedCurrencyListTextView.text)\n\(currency)"
}

//
// ===== 地理（ジオグラフィ）セクション =====
//

// 地理設定セクションを表示（例：UITextView または UITableView）
for country in cardControlSettings.geography.countryList {
    countryListTextView.text = "\(countryListTextView.text)\n\(country)"
}
for region in cardControlSettings.geography.regionList {
    regionListTextView.text = "\(countryListTextView.text)\n\(region)"
}

//
// ===== マーチャント（加盟店）セクション =====
//

// マーチャントセクションを表示
// ギャンブル関連マーチャントでの支払いの有効/無効
gamblingMerchantSwitch.isOn = cardControlSettings.merchant.isGamblingMerchantEnabled
// アダルト関連マーチャントでの支払いの有効/無効
adultMerchantSwitch.isOn = cardControlSettings.merchant.isAdultMerchantEnabled
// リスキー（危険）なマーチャントでの支払いの有効/無効
riskyMerchantSwitch.isOn = cardControlSettings.merchant.isRiskyMerchantEnabled
```

{% endtab %}
{% endtabs %}

### カードコントロール設定を更新する

{% hint style="warning" %}
カードコントロールの更新は機密操作として扱ってください。

* カード設定を変更する前に追加の認証を実行してください。
* 常に、次の `CardSettings` が返すオブジェクトから開始してください： `CardService.getCardSettings()`.
* 自分でオブジェクトを作成しないでください。 `CardSettings` オブジェクトを自分で初期化して送信すると、

既存の値を上書きする可能性があります。 `CardService.updateCardControlSettings()`D1 バックエンド上の既存の値を上書きすることがあります。 **また、次のようなエラーを引き起こす可能性があります：**&#x45;RROR\_CARD\_SETTINGS\_OPERATION\_NOT\_ALLOWED `ERROR_CARD_SETTINGS_INVALID_FORMAT`, `、または`ERROR\_CARD\_SETTINGS\_INVALID\_VALUE `前提条件と許可される更新`.
{% endhint %}

#### コントロールを更新する前に、D1 が getCardSettings() で対応する属性を返していることを確認してください。

getCardSettings() `D1 SDK は、エンドユーザーが利用できないコントロールを更新しようとした場合に 次を返します：`.

D1 SDK returns `ERROR_CARD_SETTINGS_INVALID_FORMAT` 以下の表は各コントロール設定に対する前提条件を示します：

カードコントロール設定

| 前提条件                                                            | CardControlSettings.setOnlinePaymentEnabled(true)                                                                                                               |
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `該当なし`                                                          | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `CardControlSettings.setDeniedCurrencyList()`                   | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `CardControlSettings.Merchant.setGamblingMerchantEnabled(true)` | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `CardControlSettings.Merchant.setAdultMerchantEnabled(true)`    | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `CardControlSettings.Merchant.setRiskyMerchantEnabled(true)`    | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `CardControlSettings.setContactlessEnabled(true)`               | CardControlSettings.setAbroadPaymentEnabled(true)                                                                                                               |
| `もし`                                                            | isContactlessEnabled `属性が API から取得されていれば、更新操作が許可されます。` API `CardService.getCardSettings()` CardControlSettings.setMagneticStripeEnabled(true)                   |
| `isMagneticStripeEnabled`                                       | isContactlessEnabled `CardControlSettings.setATMWithdrawalEnabled(true)` API `CardService.getCardSettings()` CardControlSettings.setMagneticStripeEnabled(true) |
| `isATMWithdrawalEnabled`                                        | isContactlessEnabled `入力検証とエラー` API `CardService.getCardSettings()` CardControlSettings.setMagneticStripeEnabled(true)                                          |

#### D1 SDK は次のものを返すことがあります：

エラーコード：エンドユーザーが無効な形式の入力でカードコントロール設定を更新しようとしたとき、イシュアアプリケーションに返されます。

* カウンターを維持します。承認時にカウンターを更新し、次と照合します `、または` エラーコード：エンドユーザーが形式は正しいが入力値が不正確なカードコントロール設定を更新しようとしたときに返されます。
* カウンターを維持します。承認時にカウンターを更新し、次と照合します `前提条件と許可される更新` リストベースのコントロールには次の形式を使用してください：

形式

| 前提条件                                                            | CardControlSettings.getGeography().setCountryList()                                                                                                                                                                                                                     |
| --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `参照：`                                                           | ISO 3166-1 alpha-2 形式 [国コードの許容される形式について。形式が無効な場合、D1 SDK はそのエラーをイシュアアプリケーションに伝播します。次を参照してください：](https://www.iban.com/country-codes) Android Country API [そのようなエラーが発生しないように。](https://developer.android.com/reference/java/util/Locale#getCountry\(\)) ISO 4217 アルファコード形式 |
| `CardControlSettings.Merchant.setGamblingMerchantEnabled(true)` | ISO 3166-1 alpha-2 形式 [許容される通貨コード形式について。形式が無効な場合、D1 SDK はそのエラーをイシュアアプリケーションに伝播します。参照：](https://www.iban.com/currency-codes) Android Currency API [更新を送信するための例を次に示します：](https://developer.android.com/reference/android/icu/util/Currency) ISO 4217 アルファコード形式            |

CardSettings cardSettings = null; // API からカード設定を取得するか、キャッシュから使用する

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

```java
String cardID = ""; // バックエンドから受け取った cardID。

CardService cardService = d1Task.getCardService();
CardControlSettings cardControlSettings = cardSettings.getControl();

cardControlSettings.setOnlinePaymentEnabled(true); // または false

// オンライン支払いの有効/無効
// 非接触支払いの有効/無効

// `CardService.getCardSettings()` API から isContactlessEnabled 属性が取得されている場合、以下の操作は許可されます
if (cardControlSettings.isContactlessEnabled() != null) {       
cardControlSettings.setContactlessEnabled(true); // または false
    // `CardService.getCardSettings()` API から isMagneticStripeEnabled 属性が取得されている場合、以下の操作は許可されます
}

// 磁気ストライプ支払いの有効/無効
if (cardControlSettings.isMagneticStripeEnabled() != null) {        
cardControlSettings.setMagneticStripeEnabled(true); // または false
    // ATM 引き出しの有効/無効
}

// `CardService.getCardSettings()` API から isATMWithdrawalEnabled 属性が取得されている場合、以下の操作は許可されます
if (cardControlSettings.isATMWithdrawalEnabled() != null) {        
cardControlSettings.setATMWithdrawalEnabled(true); // または false
    cardControlSettings.setAbroadPaymentEnabled(true);     // または false
}

// 海外支払いの有効/無効
// 禁止通貨リストを更新

ArrayList<String> deniedCurrencies = new ArrayList<>();
// 例については Android Currency API [Android Currency API](https://developer.android.com/reference/android/icu/util/Currency) を参照してください

// 例えば：
// Currency currency = Currency.getInstance(Locale.CANADA);         
// String currencyCode = currency.getCurrencyCode();
deniedCurrencies.add("USD"); 
        
deniedCurrencies.add("GBP");
cardControlSettings.setDeniedCurrencyList(deniedCurrencies);
// 地理設定

// 地域リストを更新
CardControlSettings.Geography geography = cardControlSettings.getGeography();
ArrayList<CardControlSettings.Region> regionList = new ArrayList<>();
regionList.add(CardControlSettings.Region.ASIA);
regionList.add(CardControlSettings.Region.SCHENGEN_AREA);
geography.setRegionList(regionList);
// 国リストを更新

ArrayList<String> countryList = new ArrayList<>();
// 参照：Android Country API [Android Country API](https://developer.android.com/reference/java/util/Locale#getCountry())
// または以下の例を参照できます：
// String[] countries = Locale.getISOCountries();
countryList.add("SG");        
countryList.add("FR");
geography.setCountryList(countryList);
// マーチャント設定

merchant.setGamblingMerchantEnabled(true);          // または false
CardControlSettings.Merchant merchant = cardControlSettings.getMerchant();
// ギャンブル関連マーチャントでの支払いの有効/無効
merchant.setAdultMerchantEnabled(true);             // または false
// アダルト関連マーチャントでの支払いの有効/無効
merchant.setRiskyMerchantEnabled(true);             // または false
// リスキー（危険）なマーチャントでの支払いの有効/無効
cardService.updateCardControlSettings(cardID, cardControlSettings, new D1Task.Callback<Void>() {

public void onSuccess(Void data) {
    @Override
    // 続くフローを実行、例：UI を更新。
            public void onError(@NonNull D1Exception exception) {
    }
    @Override
    // 例：更新でエラーが発生した場合の処理
            // D1 SDK 統合 – エラー管理 セクションを参照してください。
    }
});
```

{% endtab %}

{% tab title="iOS" %}

```swift
cardService.updateCardControlSettings(cardID, settings: cardControlSettings) { error in
let cardService = d1Task.cardService()
let cardID = "" // 例：サーバーから取得
// 更新前の初期状態に設定を復元する
    if let error = error {
        cardControlSettings.restore()
        // 続くフローを実行、例：UI を更新
    } else {
        次のステップ
    }
}
```

{% endtab %}
{% endtabs %}

### 地域（リージョン）で地理を使用する場合は、次を参照してください：

* サポートされている地域 [デフォルトの MCC グループが必要な場合は、次を参照してください：](/transaction-control/ja/implement-transaction-control/implement-domain-controls/supported-regions.md).
* デフォルトのマーチャントタイプ（加盟店タイプ） [デフォルトのマーチャントタイプ](/transaction-control/ja/implement-transaction-control/implement-domain-controls/default-merchant-types.md).


---

# 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/transaction-control/ja/implement-transaction-control/implement-domain-controls/manage-in-app-card-controls.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.
