Esempio n. 1
0
        public virtual void OnProductsRetrieved(string json)
        {
            // NB: AppleStoreImpl overrides this completely and does not call the base.
            unity.OnProductsRetrieved(JSONSerializer.DeserializeProductDescriptions(json));

            Promo.ProvideProductsToAds(this, unity);
        }
Esempio n. 2
0
        public virtual void OnProductsRetrieved(string json)
        {
            // NB: AppleStoreImpl overrides this completely and does not call the base.
            unity.OnProductsRetrieved(JSONSerializer.DeserializeProductDescriptions(json));

            // The shouldLogPromoInitialization flag determines if we should log a message from ProvideProductsToAds
            // We would like to log this message only once when we successfully retrieved products, so we reset
            // shouldLogPromoInitialization to false once we call ProvideProductsToAds.
            Promo.ProvideProductsToAds(this, unity, shouldLogPromoInitialization);
            shouldLogPromoInitialization = false;
        }
        public override void OnProductsRetrieved(string json)
        {
            // base.OnProductsRetrieved (json); // Don't call this, because we want to enrich the products first

            // get product list
            var productDescriptions = JSONSerializer.DeserializeProductDescriptions(json);
            List <ProductDescription> finalProductDescriptions = null;

            this.products_json = json;

            // parse app receipt
            if (m_Native != null)
            {
                var base64AppReceipt = m_Native.appReceipt;
                if (!string.IsNullOrEmpty(base64AppReceipt))
                {
                    AppleReceipt appleReceipt = getAppleReceiptFromBase64String(base64AppReceipt);
                    if (appleReceipt != null &&
                        appleReceipt.inAppPurchaseReceipts != null &&
                        appleReceipt.inAppPurchaseReceipts.Length > 0)
                    {
                        // Enrich the product descriptions with parsed receipt data
                        finalProductDescriptions = new List <ProductDescription> ();
                        foreach (var productDescription in productDescriptions)
                        {
                            // JDRjr this Find may not be sufficient for subsciptions (or even multiple non-consumables?)
                            var foundReceipts = Array.FindAll(appleReceipt.inAppPurchaseReceipts, (r) => r.productID == productDescription.storeSpecificId);
                            if (foundReceipts == null || foundReceipts.Length == 0)
                            {
                                finalProductDescriptions.Add(productDescription);
                            }
                            else
                            {
                                Array.Sort(foundReceipts, (b, a) => (a.purchaseDate.CompareTo(b.purchaseDate)));
                                var mostRecentReceipt = foundReceipts[0];
                                var productType       = (AppleStoreProductType)Enum.Parse(typeof(AppleStoreProductType), mostRecentReceipt.productType.ToString());
                                if (productType == AppleStoreProductType.AutoRenewingSubscription)
                                {
                                    // if the product is auto-renewing subscription, filter the expired products
                                    if (new SubscriptionInfo(mostRecentReceipt, null).isExpired() == Result.True)
                                    {
                                        finalProductDescriptions.Add(productDescription);
                                    }
                                    else
                                    {
                                        finalProductDescriptions.Add(
                                            new ProductDescription(
                                                productDescription.storeSpecificId,
                                                productDescription.metadata,
                                                base64AppReceipt,
                                                mostRecentReceipt.transactionID));
                                    }
                                }
                                else if (productType == AppleStoreProductType.Consumable)
                                {
                                    finalProductDescriptions.Add(productDescription);
                                }
                                else
                                {
                                    finalProductDescriptions.Add(
                                        new ProductDescription(
                                            productDescription.storeSpecificId,
                                            productDescription.metadata,
                                            base64AppReceipt,
                                            mostRecentReceipt.transactionID));
                                }
                            }
                        }
                    }
                }
            }

            // Pass along the enriched product descriptions
            unity.OnProductsRetrieved(finalProductDescriptions ?? productDescriptions);

            // Set up IAP promo product list (since we bypassed the JSON store here)
            Promo.ProvideProductsToAds(this, unity, shouldLogPromoInitialization);
            shouldLogPromoInitialization = false;

            // If there is a promotional purchase callback, tell the store to intercept those purchases.
            if (m_PromotionalPurchaseCallback != null)
            {
                m_Native.InterceptPromotionalPurchases();
            }

            // Indicate we are ready to start receiving payments.
            m_Native.AddTransactionObserver();
        }