Ejemplo n.º 1
0
        /// <summary>Try to buy a product.</summary>
        /// <param name="productId">The ID of the product to buy.</param>
        private static void BuyProductID(string productId)
        {
            if (!AppCentralStoreListener.IsInitialized())
            {
                Debug.Log("BuyProductID FAIL. Not initialized.");
                return;
            }

            // find product with given ID
            Product product = AppCentralStoreListener.storeController.products.WithID(productId);

            if (product == null || !product.availableToPurchase)
            {
                Debug.Log("BuyProductID: FAIL. Product either not found or not available.");
                return;
            }

            Debug.Log("Purchasing product asynchronously: " + product.definition.id);
            // Async response should arrive at ProcessPurchase or OnPurchaseFailed.
            AppCentralStoreListener.storeController.InitiatePurchase(product);
        }
Ejemplo n.º 2
0
        /// <summary>Force restore previous purchases.</summary>
        /// <remarks>Only allow this in iOS platforms. Android doesn't require this.</remarks>
        public static void RestorePurchases()
        {
            if (!AppCentralStoreListener.IsInitialized())
            {
                // TODO: Retry authorisation?
                Debug.Log("RestorePurchases FAIL. Not initialized.");
                return;
            }

            #if UNITY_IOS
            IAppleExtensions apple = AppCentralStoreListener.storeExtensionProvider.GetExtension <IAppleExtensions>(); // get apple specific extension

            // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
            // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
            apple.RestoreTransactions(result =>
            {
                // The first phase of restoration. If no more responses are received on ProcessPurchase then
                // no purchases are available to be restored.
                Debug.Log("RestorePurchases continuing: " + result +
                          ". If no further messages, no purchases available to restore.");
            });
            #endif
        }
Ejemplo n.º 3
0
        /// <summary>Entry point: How the whole system starts.</summary>
        /// <param name="productIDs">Product IDs for what can be bought in the game.</param>
        /// <param name="onInitialisedAction">The action to call when this is initialised.</param>
        public AppCentralStoreListener(ProductIDs productIDs, OnInitialisedDelegate onInitialisedAction)
        {
            if (AppCentralStoreListener.IsInitialized())
            {
                return;
            }

            Debug.Log("Init Subscription " + productIDs.subscriptionProductID);
            AppCentralStoreListener.productNameAppleSubscription = productIDs.subscriptionProductID;
            AppCentralStoreListener.productIDSubscription        = productIDs.subscriptionProductID;
            this.OnInitialisedEvent += onInitialisedAction;

            // Create a builder, first passing in a suite of Unity provided stores.
            ConfigurationBuilder purchasingConfiguration = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

            List <ProductDefinition> productDefinitions = new List <ProductDefinition>
            {
                new ProductDefinition(AppCentralStoreListener.ProductIDConsumable, UnityEngine.Purchasing.ProductType.Consumable),
                new ProductDefinition(AppCentralStoreListener.ProductIDNonConsumable, UnityEngine.Purchasing.ProductType.NonConsumable),
            };

            purchasingConfiguration.AddProducts(productDefinitions);

            // Adding the subscription product.
            // Notice this uses store-specific IDs, illustrating if the Product ID was configured differently between Apple and Google stores.
            // Also note that one uses the general ProductIDSubscription handle inside the game - the store-specific IDs must only be referenced here.
            purchasingConfiguration.AddProduct(AppCentralStoreListener.productIDSubscription, UnityEngine.Purchasing.ProductType.Subscription, new IDs
            {
                { AppCentralStoreListener.productNameAppleSubscription, AppleAppStore.Name },
                { AppCentralStoreListener.productNameGoogleSubscription, GooglePlay.Name },
            });

            // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration
            // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed.
            UnityPurchasing.Initialize(this, purchasingConfiguration);
        }