Ejemplo n.º 1
0
        IEnumerator OnPressNew()
        {
            UILoader.Instance.StartLoader();

            List <Item> newItems = new List <Item>();
            var         today    = DateTimeExtensions.GetCurrentUnixTime().ToString();

            if (CategorySystemInfo.AllItems.Any())
            {
                foreach (var item in CategorySystemInfo.AllItems)
                {
                    //new Contents are now considered only if they are a t most 7 days old...more than that, it will ignore
                    if (DateTimeExtensions.DifferenceBetweenTwoUnixTime(today, item.UploadDate) <
                        new TimeSpan(7, 0, 0, 0).TotalSeconds)
                    {
                        newItems.Add(item);
                    }

                    yield return(true);
                }

                yield return(StartCoroutine(CategorySystemInfo.PopulateContents(JArray.FromObject(newItems), parentName: "New Arrivals")));
            }

            UILoader.Instance.StopLoader(true);
            yield return(new WaitForEndOfFrame());
        }
Ejemplo n.º 2
0
        void RevalidateSubscription()
        {
            Debug.Log("Re-validating After Initialization");
            try
            {
#if UNITY_ANDROID
                var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
                                                           null, Application.identifier);

                _isRestoreAllowed = false;
                LocalDataManager.Instance.SaveData.NonConsumableBuy.Clear();

                foreach (var product in StoreController.products.all.ToList())
                {
                    var result = validator.Validate(product.receipt);

                    if (product.hasReceipt)
                    {
                        _isRestoreAllowed = true;

                        switch (product.definition.type)
                        {
                        case ProductType.Consumable:
                            //no need to store consumable values
                            break;

                        case ProductType.NonConsumable:
                        {
                            LocalDataManager.Instance.SaveData.NonConsumableBuy.AddUnique(product.metadata.localizedTitle);
                        }
                        break;

                        case ProductType.Subscription:
                        {
                            /*LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Title", product.metadata.localizedTitle);
                             * LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Date", result[0].purchaseDate.ToShortDateString());*/
                        }
                        break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }

                //todo: refactor as above for ios
#elif UNITY_IOS
                Debug.Log("Revalidating After iOS receipt");
                var validator = new CrossPlatformValidator(null,
                                                           AppleTangle.Data(), Application.identifier);
                string appReceipt      = appleConfig.appReceipt;
                string unityIAPReceipt = "{ \"Store\": \"AppleAppStore\", \"Payload\": \"" + appReceipt + "\" }";
                var    result          = validator.Validate(unityIAPReceipt);

                _isRestoreAllowed = false;
                LocalDataManager.Instance.SaveData.NonConsumableBuy.Clear();
                Debug.Log("  LocalDataManager.Instance.SaveData.NonConsumableBuy Cleared");

                foreach (IPurchaseReceipt productReceipt in result)
                {
                    var prodReceipt = productReceipt as AppleInAppPurchaseReceipt;
                    var difference  =
                        DateTimeExtensions.DifferenceBetweenTwoUnixTime(
                            prodReceipt.subscriptionExpirationDate.ToUnixTime(),
                            DateTimeExtensions.GetCurrentUnixTime());

                    /*if (difference > 0)
                     * {
                     *  _isRestoreAllowed = true;
                     *  LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Title", GetProduct(prodReceipt.productID).metadata.localizedTitle);
                     *  LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Date", productReceipt.purchaseDate.ToShortDateString());
                     *  Debug.Log("  LocalDataManager.Instance.SaveData.NonConsumableBuy Added");
                     *  break;
                     * }*/

                    LocalDataManager.Instance.SaveData.NonConsumableBuy.AddUnique(GetProduct(prodReceipt.productID).metadata.localizedTitle);
                    Debug.Log("  LocalDataManager.Instance.SaveData.NonConsumableBuy Added");
                }
#endif
            }
            catch (IAPSecurityException e)
            {
                Debug.Log("Error on Re-validating " + e.Message);

                //clear all saved purchased ids, if there is validator error
                LocalDataManager.Instance.SaveData.NonConsumableBuy.Clear();
            }
        }
Ejemplo n.º 3
0
        public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
        {
            Debug.Log("ProcessPurchase");
            try
            {
                var product = StoreController.products.WithID(args.purchasedProduct.definition.id);
#if UNITY_ANDROID
                Debug.Log(" Validating Google Receipt");
                var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
                                                           null, Application.identifier);
                var result = validator.Validate(args.purchasedProduct.receipt);

                switch (product.definition.type)
                {
                case ProductType.Consumable:
                    //no need to store consumable values
                    break;

                case ProductType.NonConsumable:
                {
                    if (product.hasReceipt)
                    {
                        _isRestoreAllowed = true;
                        LocalDataManager.Instance.SaveData.NonConsumableBuy.AddUnique(product.metadata.localizedTitle);
                    }
                    else
                    {
                        _isRestoreAllowed = false;
                        LocalDataManager.Instance.SaveData.NonConsumableBuy.Remove(product.metadata.localizedTitle);
                    }
                }
                break;

                case ProductType.Subscription:
                {
                    //todo: if there is subscription, use subscription date too

                    /*if (product.hasReceipt)
                     * {
                     * _isRestoreAllowed = true;
                     * LocalDataManager.Instance.SaveData.NonConsumableBuy.AddUnique(product.metadata.localizedTitle);
                     * }
                     * else
                     * {
                     * _isRestoreAllowed = false;
                     * LocalDataManager.Instance.SaveData.NonConsumableBuy.Remove(product.metadata.localizedTitle);
                     * }*/
                }
                break;
                }

                //todo: refactor for ios, as above
#elif UNITY_IOS
                Debug.Log(" Validating iOS Receipt");
                var validator = new CrossPlatformValidator(null,
                                                           AppleTangle.Data(), Application.identifier);
                string appReceipt      = appleConfig.appReceipt;
                string unityIAPReceipt = "{ \"Store\": \"AppleAppStore\", \"Payload\": \"" + appReceipt + "\" }";
                var    result          = validator.Validate(unityIAPReceipt);

                _isRestoreAllowed = false;
                LocalDataManager.Instance.SaveData.NonConsumableBuy.Clear();
                Debug.Log("  LocalDataManager.Instance.SaveData.NonConsumableBuy Cleared");

                foreach (IPurchaseReceipt productReceipt in result)
                {
                    var prodReceipt = productReceipt as AppleInAppPurchaseReceipt;
                    var difference  =
                        DateTimeExtensions.DifferenceBetweenTwoUnixTime(
                            prodReceipt.subscriptionExpirationDate.ToUnixTime(),
                            DateTimeExtensions.GetCurrentUnixTime());

                    /*if (difference > 0)
                     * {
                     *  LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Title", product.metadata.localizedTitle);
                     *  LocalDataManager.Instance.SaveData.SubscriptionDetails.SafeAdd("Date", productReceipt.purchaseDate.ToShortDateString());
                     *  Debug.Log(" LocalDataManager.Instance.SaveData.SubscriptionDetails Added");
                     *  break;
                     * }*/

                    _isRestoreAllowed = true;
                    LocalDataManager.Instance.SaveData.NonConsumableBuy.AddUnique(GetProduct(prodReceipt.productID).metadata.localizedTitle);
                    Debug.Log("LocalDataManager.Instance.SaveData.NonConsumableBuy Added");
                }
#endif
            }
            catch (IAPSecurityException)
            {
                Debug.Log("Invalid receipt for " + args.purchasedProduct.definition.id + ", not unlocking content");
                LocalDataManager.Instance.SaveData.NonConsumableBuy.Clear();
            }

            OnPurchaseSuccess.SafeInvoke(args.purchasedProduct);
            UILoader.Instance.StopLoader(true);
            return(PurchaseProcessingResult.Complete);
        }