Use Google Play billing extensions
Learn how to integrate Google Play-specific extensions with Unity IAP to enhance purchase handling and subscription management.
Read time 2 minutesLast updated 8 days ago
Access Google Play-specific extensions for Unity IAP. Use obfuscated account and profile IDs for fraud prevention and account linking, read the Google Play order ID and purchase token of an order, and listen for deferred subscription payment changes when users modify their subscription tier.
Extended functionality
Learn how to use Google Play-specific features with Unity IAP.
Set and read obfuscated IDs
Use obfuscated account and profile IDs to associate purchases with user accounts while protecting user privacy. These identifiers help with fraud detection and can link purchases to your backend user system.
using UnityEngine.Purchasing;class GooglePlayObfuscatedIdsSample{ static void SetObfuscatedIds(StoreController storeController, string profileId, string 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; }}
Read Google Play order identifiers
In IAP 5.4.3 and later, each Google Play order exposes its Google Play identifiers through . For orders from other stores, is . The following identifiers are available:
order.Info.Googleorder.Info.Googlenull- : The Google Play order ID of the purchase. Use it to match a purchase with the orders in your Google Play reports. For a subscription renewal,
OrderIdreturns the order ID of the initial purchase, not the ID of the renewal. If Google Play doesn't provide an order ID, the property returnsOrderId.null - : The Google Play purchase token of the purchase.
PurchaseTokenhas the same value asPurchaseToken, which contains the purchase token on Google Play, not the order ID.order.Info.TransactionID
using UnityEngine.Purchasing;class GooglePlayOrderIdentifiersSample{ static void ReadOrderIdentifiers(Order order) { var orderId = order.Info.Google?.OrderId; var purchaseToken = order.Info.Google?.PurchaseToken; //... }}
Listen for deferred subscription changes
When a user changes their subscription tier (upgrade or downgrade) with a deferred payment, the change takes effect at the next renewal date. Use this listener to be notified when such changes occur, so you can update your UI or inform the user about their pending subscription change.
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; //... }}