using System.Collections.ObjectModel; using Uniject; using UnityEngine.Purchasing.Extension; using UnityEngine.Purchasing.Interfaces; namespace UnityEngine.Purchasing { class GooglePlayStore : AbstractStore { readonly IGooglePlayStoreRetrieveProductsService m_RetrieveProductsService; readonly IGooglePlayStorePurchaseService m_StorePurchaseService; readonly IGoogleFetchPurchases m_FetchPurchases; readonly IGooglePlayStoreFinishTransactionService m_FinishTransactionService; readonly IGooglePurchaseCallback m_GooglePurchaseCallback; readonly IGooglePlayStoreExtensionsInternal m_GooglePlayStoreExtensions; readonly IGooglePlayConfigurationInternal m_GooglePlayConfigurationInternal; readonly IUtil m_Util; public GooglePlayStore(IGooglePlayStoreRetrieveProductsService retrieveProductsService, IGooglePlayStorePurchaseService storePurchaseService, IGoogleFetchPurchases fetchPurchases, IGooglePlayStoreFinishTransactionService transactionService, IGooglePurchaseCallback googlePurchaseCallback, IGooglePlayConfigurationInternal googlePlayConfigurationInternal, IGooglePlayStoreExtensionsInternal googlePlayStoreExtensions, IUtil util) { m_Util = util; m_RetrieveProductsService = retrieveProductsService; m_StorePurchaseService = storePurchaseService; m_FetchPurchases = fetchPurchases; m_FinishTransactionService = transactionService; m_GooglePurchaseCallback = googlePurchaseCallback; m_GooglePlayConfigurationInternal = googlePlayConfigurationInternal; m_GooglePlayStoreExtensions = googlePlayStoreExtensions; } /// /// Init GooglePlayStore /// /// The `IStoreCallback` will be call when receiving events from the google store public override void Initialize(IStoreCallback callback) { var scriptingStoreCallback = new ScriptingStoreCallback(callback, m_Util); m_RetrieveProductsService.SetStoreCallback(scriptingStoreCallback); m_FetchPurchases.SetStoreCallback(scriptingStoreCallback); m_FinishTransactionService.SetStoreCallback(scriptingStoreCallback); m_GooglePurchaseCallback.SetStoreCallback(scriptingStoreCallback); m_GooglePlayStoreExtensions.SetStoreCallback(scriptingStoreCallback); } /// /// Call the Google Play Store to retrieve the store products. The `IStoreCallback` will be call with the retrieved products. /// /// The catalog of products to retrieve the store information from public override void RetrieveProducts(ReadOnlyCollection products) { var shouldFetchPurchases = ShouldFetchPurchasesNext(); m_RetrieveProductsService.RetrieveProducts(products, shouldFetchPurchases); } bool HasInitiallyRetrievedProducts() { return m_RetrieveProductsService.HasInitiallyRetrievedProducts(); } bool ShouldFetchPurchasesNext() { var shouldFetchPurchases = true; if (!HasInitiallyRetrievedProducts()) { shouldFetchPurchases = !m_GooglePlayConfigurationInternal.IsFetchPurchasesAtInitializeSkipped(); } return shouldFetchPurchases; } /// /// Call the Google Play Store to purchase a product. The `IStoreCallback` will be call when the purchase is successful. /// /// The product to buy /// No longer used / required, since fraud prevention is handled by the Google SDK now public override void Purchase(ProductDefinition product, string dummy) { m_StorePurchaseService.Purchase(product); } /// /// Call the Google Play Store to consume a product. /// /// Product to consume /// Transaction / order id public override void FinishTransaction(ProductDefinition product, string transactionId) { m_FinishTransactionService.FinishTransaction(product, transactionId); } public void OnPause(bool isPaused) { if (!isPaused) { m_RetrieveProductsService.ResumeConnection(); m_FetchPurchases.FetchPurchases(); } } } }