public void onAppReceiptRetrieved(string receipt)
 {
     if (receipt != null)
     {
         biller.setAppReceipt(receipt);
         if (null != onAppReceiptRefreshed)
         {
             onAppReceiptRefreshed(receipt);
         }
     }
 }
Example #2
0
        public void onProductListReceived(string productListString)
        {
            if (productListString.Length == 0)
            {
                biller.logError(UnibillError.STOREKIT_RETURNED_NO_PRODUCTS);
                biller.onSetupComplete(false);
                return;
            }

            Dictionary <string, object> responseObject = (Dictionary <string, object>)Unibill.Impl.MiniJSON.jsonDecode(productListString);

            this.appReceipt = responseObject.getString("appReceipt");
            Dictionary <string, object> response         = responseObject.getHash("products");
            HashSet <PurchasableItem>   productsReceived = new HashSet <PurchasableItem>();

            foreach (var identifier in response.Keys)
            {
                if (!remapper.canMapProductSpecificId(identifier.ToString()))
                {
                    biller.logError(UnibillError.UNIBILL_UNKNOWN_PRODUCTID, identifier.ToString());
                    continue;
                }

                var item = remapper.getPurchasableItemFromPlatformSpecificId(identifier.ToString());
                Dictionary <string, object> details = (Dictionary <string, object>)response[identifier];

                PurchasableItem.Writer.setAvailable(item, true);
                PurchasableItem.Writer.setLocalizedPrice(item, details["price"].ToString());
                PurchasableItem.Writer.setLocalizedTitle(item, details["localizedTitle"].ToString());
                PurchasableItem.Writer.setLocalizedDescription(item, details["localizedDescription"].ToString());
                if (details.ContainsKey("isoCurrencyCode"))
                {
                    PurchasableItem.Writer.setISOCurrencySymbol(item, details ["isoCurrencyCode"].ToString());
                }

                if (details.ContainsKey("priceDecimal"))
                {
                    PurchasableItem.Writer.setPriceInLocalCurrency(item, decimal.Parse(details ["priceDecimal"].ToString()));
                }
                productsReceived.Add(item);
            }

            HashSet <PurchasableItem> productsNotReceived = new HashSet <PurchasableItem> (products);

            productsNotReceived.ExceptWith(productsReceived);
            if (productsNotReceived.Count > 0)
            {
                foreach (PurchasableItem product in productsNotReceived)
                {
                    biller.logError(UnibillError.STOREKIT_REQUESTPRODUCTS_MISSING_PRODUCT, product.Id, remapper.mapItemIdToPlatformSpecificId(product));
                }
            }

            this.productsNotReturnedByStorekit = new HashSet <string>(productsNotReceived.Select(x => remapper.mapItemIdToPlatformSpecificId(x)));

            // Register our storekit transaction observer.
            // We must wait until we have initialised to do this.
            storekit.addTransactionObserver();

            if (this.appReceipt != null)
            {
                biller.setAppReceipt(this.appReceipt);
            }

            // We should complete so long as we have at least one purchasable product.
            biller.onSetupComplete(true);
        }