# リモートカタログの取得

> 支払いプロバイダーストアのリモートカタログを取得します。

[リモートカタログ](./configure-remote-catalog.md)を明示的にフェッチするために、`StoreController`に接続するスクリプトを作成する必要があります。このスクリプトを[初期化スクリプト](./initialize-services.md)と同じゲームオブジェクトにアタッチ、設定、添付します。

支払いプロバイダー ストアのリモート カタログを取得するには、 をインスタンス化し`RemoteCatalogProvider`てから、`FetchRemoteCatalog` を呼び出して Unity Iap バックエンドからプロダクトを取得する必要があります。

その後、`RemoteCatalogProvider` を使用して直接 `FetchProducts` を呼び出すか、`IProductService` または `StoreController` から製品リストを`FetchProducts` に渡します。

## リファレンス情報##reference-information

以下の要素は、支払いプロバイダーのリモートカタログを取得するときに関連します。

| **パラメーター**              | **説明**                                                                                                                            |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `RemoteCatalogProvider` | IAP とともに使用するリモートカタログを取得するために使用するクラスです。リモートカタログは IAP バックエンドから取得されます。                                                               |
| `UnityIAPServices`      | これは IAP との通信の出発点です。以下のサービスを受ける必要があります。 `StoreService` `ProductService` `PurchaseService`                                          |
| `StoreController`       | これは `UnityIAPServices` 上のラッパーです。1 つのクラスと相互作用する場合は、その`storeName`をコンストラクタに渡します。                                                     |
| `PaymentProvider.Name`  | これは、D2C(ダイレクト ツー コンシューマー)支払いプロバイダーを`UnityIAPServices`と`StoreController`に登録するために使用する識別子です。このフィールドは設定のために使用され、プロバイダーのディスプレイ名を返しません。 |

> **Important:**
>
> `RemoteCatalogProvider`に電話をかけるときは、正しいストア名(D2C 支払いプロバイダーの場合は `PaymentProvider.Name`)を指定してください。

## リモートカタログの取得スクリプト例##fetch-remote-catalog-example-script

以下のスクリプト例を参照してください。

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Purchasing;

public class PurchaseManager :MonoBehaviour
{
    StoreController m_StoreController;  


    // Called by the ServiceOrchestrator after Auth is complete
    public async Task InitializeIAP()  
    {  
        m_StoreController = UnityIAPServices.StoreController(PaymentProvider.Name);


        m_StoreController.OnPurchasePending += OnPurchasePending;  


        await m_StoreController.Connect();  


        m_StoreController.OnProductsFetched += OnProductsFetched;


        // 1.RemoteCatalogProvider の初期化
        RemoteCatalogProvider catalogProvider = new RemoteCatalogProvider();

        // 2.支払いプロバイダーのカタログを明示的に取得します
        var fetchRemoteCatalogResult = await catalogProvider.FetchRemoteCatalog();

        if (!fetchRemoteCatalogResult.Success)
            throw fetchRemoteCatalogResult.例外!;

        // 3.StoreController にリモート定義を渡す
        var productDefinitions = catalogProvider.GetProducts();
        m_StoreController.FetchProducts(productDefinitions);
    }

    private void OnPurchasePending(PendingOrder order)
    {
        // Handle purchase validation and rewarding before confirming the order
        Debug.Log($"Order pending: {order.Info}");
    }

    void OnProductsFetched(List<Product> products)  
    {
        // Handle fetched products (e.g., populate UI)
        Debug.Log("Fetched products:");
        Foreach (製品の var product)
        {
            Foreach (product.catalogListings.Values の var catalogListing)
            {
                Debug.Log($"ID: {catalogListing.definition.id} - Price: {catalogListing.metadata.localizedPriceString}");
            }
        }
    }
}
```

## 次のステップ##next-steps

このページは、IAPでD2C支払いプロバイダーを設定するワークフローの一部です。このワークフローを続行するには、以下のオプションのいずれかを選択します。

[Integrate D2C payment providers](./workflow.md#fetch-your-remote-catalog): Integrate D2C payment provider with IAP ワークフロー (D2C 支払いプロバイダーと IAP ワークフローの統合) ページに戻ります。
[Configure a webhook for purchase fulfillment](./configure-fulfilment.md): ワークフローの次のステップ(任意)に進み、D2C支払いプロバイダーを設定します。
