Example #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);
        }
Example #2
0
 public virtual void OnPurchaseSucceeded(string id, string receipt, string transactionID)
 {
     if (!eventsDisabled)
     {
         SendPurchaseSucceededEvent(id, receipt, transactionID);
     }
     unity.OnPurchaseSucceeded(id, receipt, transactionID);
     Promo.ProvideProductsToAds(this, unity);
 }
Example #3
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;
        }
        // This is now being used by the INativeStore implementation
        public void StoreRetrieveProducts(ReadOnlyCollection <ProductDefinition> productDefinitions)
        {
            var products = new List <ProductDescription>();

            foreach (var product in productDefinitions)
            {
                if (unavailableProductId != product.id)
                {
                    var            metadata = new ProductMetadata("$0.01", "Fake title for " + product.id, "Fake description", "USD", 0.01m);
                    ProductCatalog catalog  = ProductCatalog.LoadDefaultCatalog();
                    if (catalog != null)
                    {
                        foreach (var item in catalog.allProducts)
                        {
                            if (item.id == product.id)
                            {
                                metadata = new ProductMetadata(item.googlePrice.value.ToString(), item.defaultDescription.Title, item.defaultDescription.Description, "USD", item.googlePrice.value);
                            }
                        }
                    }
                    products.Add(new ProductDescription(product.storeSpecificId, metadata));
                }
            }

            Action <bool, InitializationFailureReason> handleAllowInitializeOrRetrieveProducts =
                (bool allow, InitializationFailureReason failureReason) =>
            {
                if (allow)
                {
                    m_Biller.OnProductsRetrieved(products);

                    // Since iOS is already rigged to work this way might as well just use it...
                    // *** if we want to use this change without Promo then we'll need to use reflection here
                    Promo.ProvideProductsToAds(this, m_Biller);
                }
                else
                {
                    m_Biller.OnSetupFailed(failureReason);
                }
            };

            // To mimic typical store behavior, only display RetrieveProducts dialog for developers
            if (!(UIMode == FakeStoreUIMode.DeveloperUser &&
                  StartUI <InitializationFailureReason> (productDefinitions, DialogType.RetrieveProducts, handleAllowInitializeOrRetrieveProducts)))
            {
                // Default non-UI FakeStore RetrieveProducts behavior is to succeed
                handleAllowInitializeOrRetrieveProducts(true, InitializationFailureReason.AppNotKnown);
            }
        }
        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();
        }