Beispiel #1
0
        public Inventory(string json)
        {
            var j = new JSON(json);

            foreach (var entry in (List <object>)j.fields["purchaseMap"])
            {
                List <object> pair = (List <object>)entry;
#if UNITY_IOS
                string key = OpenIAB_iOS.StoreSku2Sku(pair[0].ToString());
                // TODO: use same cotr on all platforms. Test why it works on Android json
                Purchase value = new Purchase((JSON)pair[1]);
#else
                string   key   = pair[0].ToString();
                Purchase value = new Purchase(pair[1].ToString());
#endif
                _purchaseMap.Add(key, value);
            }
            foreach (var entry in (List <object>)j.fields["skuMap"])
            {
                List <object> pair = (List <object>)entry;
#if UNITY_IOS
                string     key   = OpenIAB_iOS.StoreSku2Sku(pair[0].ToString());
                SkuDetails value = new SkuDetails((JSON)pair[1]);
#else
                string     key   = pair[0].ToString();
                SkuDetails value = new SkuDetails(pair[1].ToString());
#endif
                _skuMap.Add(key, value);
            }
        }
        public SkuDetails(JSON json)
        {
            ItemType    = json.ToString("itemType");
            Sku         = json.ToString("sku");
            Type        = json.ToString("type");
            Price       = json.ToString("price");
            Title       = json.ToString("title");
            Description = json.ToString("description");
            Json        = json.ToString("json");

            Sku = OpenIAB_iOS.StoreSku2Sku(Sku);
        }
Beispiel #3
0
 public Inventory(StoreKitProduct[] products)
 {
     foreach (var product in products)
     {
         string sku = OpenIAB_iOS.StoreSku2Sku(product.identifier);
         _skuMap.Add(sku, new SkuDetails(product));
         if (OpenIAB_iOS.IsProductPurchased(product.identifier))
         {
             _purchaseMap.Add(sku, Purchase.CreateFromSku(sku));
         }
     }
 }
        public SkuDetails(JSON json)
        {
            ItemType     = json.ToString("itemType");
            Sku          = json.ToString("sku");
            Type         = json.ToString("type");
            Price        = json.ToString("price");
            Title        = json.ToString("title");
            Description  = json.ToString("description");
            Json         = json.ToString("json");
            CurrencyCode = json.ToString("currencyCode");
            StoreCountry = json.ToString("storeCountry");

            PriceValue = json.ToString("priceValue");
            Sku        = OpenIAB_iOS.StoreSku2Sku(Sku);
        }
Beispiel #5
0
        public SkuDetails(StoreKitProduct storeKitProduct)
        {
            //Debug.Log(storeKitProduct);

            Sku = OpenIAB_iOS.StoreSku2Sku(storeKitProduct.identifier);
            //Debug.Log(storeKitProduct.identifier);

            Price = storeKitProduct.localPrice + storeKitProduct.priceSymbol;
            //Debug.Log(storeKitProduct.localPrice);

            Title = storeKitProduct.localizedTitle;
            //Debug.Log(storeKitProduct.localizedTitle);

            Description = storeKitProduct.localizedDescription;
            //Debug.Log(storeKitProduct.localizedDescription);
        }
Beispiel #6
0
        public Purchase(JSON json)
        {
            if (json != null)
            {
                ItemType         = json.ToString("itemType");
                OrderId          = json.ToString("orderId");
                PackageName      = json.ToString("packageName");
                Sku              = json.ToString("sku");
                PurchaseTime     = json.ToLong("purchaseTime");
                PurchaseState    = json.ToInt("purchaseState");
                DeveloperPayload = json.ToString("developerPayload");
                Token            = json.ToString("token");
                OriginalJson     = json.ToString("originalJson");
                Signature        = json.ToString("signature");
                AppstoreName     = json.ToString("appstoreName");
                Receipt          = json.ToString("receipt");

                // Catch will be hit if the Sku is already a product id
                try
                {
                    Sku = OpenIAB_iOS.StoreSku2Sku(Sku);
                } catch (System.Collections.Generic.KeyNotFoundException) {}

                JSON receiptJson = AppleArrayToJSON(Receipt);

                if (receiptJson != null)
                {
                    string purchaseInfo = receiptJson.ToString("purchase-info");

                    if (!string.IsNullOrEmpty(purchaseInfo))
                    {
                        JSON purchaseInfoJson = AppleArrayToJSON(purchaseInfo);

                        if (purchaseInfoJson != null)
                        {
                            string transactionId = purchaseInfoJson.ToString("original-transaction-id");

                            if (!string.IsNullOrEmpty(transactionId))
                            {
                                Token = transactionId;
                            }
                            else
                            {
                                Debug.LogError("Failed to get transaction id");
                            }
                        }
                        else
                        {
                            Debug.LogError("Failed to get purchaseInfo JSON!");
                        }
                    }
                    else
                    {
                        Debug.LogError("Failed to get purchase info");
                    }
                }
                else
                {
                    Debug.LogError("Failed to get receipt JSON!");
                }
            }
            else
            {
                Debug.LogError("Null json!");
            }
        }
Beispiel #7
0
        /**
         * Create purchase from json string
         * @param jsonString data serialized to json
         */
        public Purchase(string jsonString)
        {
            var json = new JSON(jsonString);

            ItemType         = json.ToString("itemType");
            OrderId          = json.ToString("orderId");
            PackageName      = json.ToString("packageName");
            Sku              = json.ToString("sku");
            PurchaseTime     = json.ToLong("purchaseTime");
            PurchaseState    = json.ToInt("purchaseState");
            DeveloperPayload = json.ToString("developerPayload");
            Token            = json.ToString("token");
            OriginalJson     = json.ToString("originalJson");
            Signature        = json.ToString("signature");
            AppstoreName     = json.ToString("appstoreName");
            Receipt          = json.ToString("receipt");

#if UNITY_IOS
            // Catch will be hit if the Sku is already a product id
            try
            {
                Sku = OpenIAB_iOS.StoreSku2Sku(Sku);
            }
            catch (System.Collections.Generic.KeyNotFoundException) { }

            JSON receiptJson = AppleArrayToJSON(Receipt);

            // Parse the iOS receipt token, converting it from Apple's own stupid format to normal JSON data along the way
            if (receiptJson != null)
            {
                string purchaseInfo = receiptJson.ToString("purchase-info");

                if (!string.IsNullOrEmpty(purchaseInfo))
                {
                    JSON purchaseInfoJson = AppleArrayToJSON(purchaseInfo);

                    if (purchaseInfoJson != null)
                    {
                        string transactionId = purchaseInfoJson.ToString("original-transaction-id");

                        if (!string.IsNullOrEmpty(transactionId))
                        {
                            Token = transactionId;
                        }
                        else
                        {
                            Debug.LogError("Failed to get transaction id");
                        }
                    }
                    else
                    {
                        Debug.LogError("Failed to get purchaseInfo JSON!");
                    }
                }
                else
                {
                    Debug.LogError("Failed to get purchase info");
                }
            }
            else
            {
                Debug.LogError("Failed to get receipt JSON!");
            }
#endif
        }