#nullable enable
using System;
using UnityEngine.Purchasing.Extension;
using UnityEngine.Purchasing.Interfaces;
using UnityEngine.Purchasing.Models;
namespace UnityEngine.Purchasing
{
///
/// Access Google Play store specific configurations.
///
class GooglePlayConfiguration : IGooglePlayConfiguration, IGooglePlayConfigurationInternal
{
Action? m_InitializationConnectionLister;
readonly IGooglePlayStoreService m_GooglePlayStoreService;
Action? m_DeferredPurchaseAction;
Action? m_DeferredProrationUpgradeDowngradeSubscriptionAction;
Action? m_QueryProductDetailsFailedListener;
bool m_FetchPurchasesAtInitialize = true;
bool m_FetchPurchasesExcludeDeferred = true;
public GooglePlayConfiguration(IGooglePlayStoreService googlePlayStoreService)
{
m_GooglePlayStoreService = googlePlayStoreService;
}
///
/// Set an optional listener for failures when connecting to the base Google Play Billing service. This may be called
/// after if a user does not have a Google account added to their
/// Android device.
///
/// Will be called when
/// is interrupted by a disconnection from the Google Play Billing service.
public void SetServiceDisconnectAtInitializeListener(Action action)
{
m_InitializationConnectionLister = action;
}
///
/// Internal API, do not use.
///
public void NotifyInitializationConnectionFailed()
{
m_InitializationConnectionLister?.Invoke();
}
public void SetQueryProductDetailsFailedListener(Action action)
{
m_QueryProductDetailsFailedListener = action;
}
public void NotifyQueryProductDetailsFailed(int retryCount)
{
m_QueryProductDetailsFailedListener?.Invoke(retryCount);
}
///
/// Set listener for deferred purchasing events.
/// Deferred purchasing is enabled by default and cannot be changed.
///
/// Deferred purchasing successful events. Do not grant the item here. Instead, record the purchase and remind the user to complete the transaction in the Play Store.
public void SetDeferredPurchaseListener(Action action)
{
m_DeferredPurchaseAction = action;
}
public void NotifyDeferredProrationUpgradeDowngradeSubscription(IStoreCallback? storeCallback, string productId)
{
var product = storeCallback.FindProductById(productId);
if (product != null)
{
m_DeferredProrationUpgradeDowngradeSubscriptionAction?.Invoke(product);
}
}
public bool IsFetchPurchasesAtInitializeSkipped()
{
return !m_FetchPurchasesAtInitialize;
}
public bool DoesRetrievePurchasesExcludeDeferred()
{
return m_FetchPurchasesExcludeDeferred;
}
public void NotifyDeferredPurchase(IStoreCallback? storeCallback, IGooglePurchase? purchase, string? receipt, string? transactionId)
{
var product = storeCallback?.FindProductById(purchase?.sku);
if (product != null)
{
ProductPurchaseUpdater.UpdateProductReceiptAndTransactionID(product, receipt, transactionId, GooglePlay.Name);
m_DeferredPurchaseAction?.Invoke(product);
}
}
///
/// Set listener for deferred subscription change events.
/// Deferred subscription changes only take effect at the renewal cycle and no transaction is done immediately, therefore there is no receipt nor token.
///
/// Deferred subscription change event. No payout is granted here. Instead, notify the user that the subscription change will take effect at the next renewal cycle.
public void SetDeferredProrationUpgradeDowngradeSubscriptionListener(Action action)
{
m_DeferredProrationUpgradeDowngradeSubscriptionAction = action;
}
///
/// Optional obfuscation string to detect irregular activities when making a purchase.
/// For more information please visit https://developer.android.com/google/play/billing/security
///
/// The obfuscated account id
public void SetObfuscatedAccountId(string accountId)
{
m_GooglePlayStoreService.SetObfuscatedAccountId(accountId);
}
///
/// Optional obfuscation string to detect irregular activities when making a purchase
/// For more information please visit https://developer.android.com/google/play/billing/security
///
/// The obfuscated profile id
public void SetObfuscatedProfileId(string? profileId)
{
m_GooglePlayStoreService.SetObfuscatedProfileId(profileId);
}
public void SetFetchPurchasesAtInitialize(bool enable)
{
m_FetchPurchasesAtInitialize = enable;
}
public void SetFetchPurchasesExcludeDeferred(bool exclude)
{
m_FetchPurchasesExcludeDeferred = exclude;
}
}
}