使用 Google Play 计费扩展
了解如何将特定于 Google Play 的扩展与 Unity IAP 集成以增强购买处理和订阅管理。
阅读时间1 分钟最后更新于 20 天前
访问特定于 Google Play 的 Unity IAP 扩展。使用混淆的帐户和配置文件 ID 进行欺诈预防和帐户关联,并在用户修改订阅层级时监听延迟订阅付款更改。
扩展功能
了解如何将特定于 Google Play 的功能与 Unity IAP 结合使用。设置和读取混淆的 ID
使用混淆的帐户和配置文件 ID 将购买与用户帐户关联,同时保护用户隐私。这些标识符有助于欺诈检测,并可将购买关联到您的后端用户系统。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; }}
监听延迟订阅更改
当用户使用延迟付款更改其订阅层级(升级或降级)时,更改将在下一个续订日期生效。使用此监听器可在发生此类更改时收到通知,以便您可以更新 UI 或通知用户他们即将进行的订阅更改。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; //... }}