# Google Play 課金拡張機能の使用

> google play固有の拡張機能をUnity Iapと統合して、購入処理とサブスクリプション管理を強化する方法を説明します。

Unity Iap 用の google play 固有の拡張にアクセスします。難読化されたアカウント ID とプロファイル ID を詐欺防止とアカウントリンクに使用し、ユーザーがサブスクリプション契約条件を変更したときに、ディファードサブスクリプションの支払いの変更をリッスンします。

## 拡張機能##extended-functionality

Unity Iapでgoogle play固有の機能を使用する方法を説明します。

### 難読化された ID の設定と読み取り##set-and-read-obfuscated-ids

ユーザー プライバシーを保護しながら、難読化されたアカウントIDとプロファイルIDを使用して購入をユーザー アカウントに関連付けます。これらの識別子は不正の検出にヘルプし、購入をバックエンド ユーザー システムにリンクできます。

> **Note:**
>
> 難読化された ID は [`IGooglePlayStoreExtendedService`](https://docs.unity3d.com/Packages/com.unity.purchasing@latest?subfolder=/api/UnityEngine.Purchasing.IGooglePlayStoreExtendedService.html) を使用して設定されますが、[`IGooglePlayStoreExtendedPurchaseService`](https://docs.unity3d.com/Packages/com.unity.purchasing@latest?subfolder=/api/UnityEngine.Purchasing.IGooglePlayStoreExtendedPurchaseService.html) を使用して注文から読み取ります。

```cs
using UnityEngine.Purchasing;

class GooglePlayObfuscatedIdsSample
{
    静的 void SetObfuscatedIds(StoreController storeController, 文字列 profileId, 文字列 accountId)
    {
        var googlePlayStoreService = storeController.GooglePlayStoreExtendedService;
        if (googlePlayStoreService != null)
        {
            googlePlayStoreService.SetObfuscatedProfileId(profileId);
            googlePlayStoreService.SetObfuscatedAccountId(accountId);
        }
    }
    
    static void ReadObfuscatedIdsUsingConvenienceFunction(StoreController storeController, Order order)
    {
        var googlePlayPurchasingService = storeController.GooglePlayStoreExtendedPurchaseService;
        if (googlePlayPurchasingService != null)
        {
            var obfuscatedProfileId = googlePlayPurchasingService.GetObfuscatedProfileId(order);
            var obfuscatedAccountId = googlePlayPurchasingService.GetObfuscatedAccountId(order);
            //...
        }
    }

    static void ReadObfuscatedIdsFromOrder(Order order)
    {
        var profileId = order.Info.Google?.ObfuscatedProfileId;
        var accountId = order.Info.Google?.ObfuscatedAccountId;
    }
}
```

### ディファード サブスクリプション変更のリッスン##listen-for-deferred-subscription-changes

ユーザーがディファードでサブスクリプションのティアを変更 (アップグレードまたはダウングレード) すると、変更は次の更新日に効果になります。このリスナーを使用して、このような変更が発生したときに通知され、UI を更新したり、保留中のサブスクリプション変更をユーザーに通知したりできます。

```cs
using UnityEngine.Purchasing;

class AddGoogleEventListenersSample
{
    void AddGoogleEventListeners(StoreController storeController)
    {
        var googlePlayPurchasingService = storeController.GooglePlayStoreExtendedPurchaseService;
        if (googlePlayPurchasingService != null)
        {
            googlePlayPurchasingService.OnDeferredPaymentUntilRenewalDate += OnDeferredPaymentUntilRenewalDate;
        }
    }

    void OnDeferredPaymentUntilRenewalDate(DeferredPaymentUntilRenewalDateOrder deferredPaymentOrder)
    {
        var currentOrder = deferredPaymentOrder.CurrentOrder;
        var nextSubscriptionProduct = deferredPaymentOrder.SubscriptionOrdered;
        //...
    }
}
```
