protected PurchasableVirtualItem(AndroidJavaObject jniVirtualItem) :
            base(jniVirtualItem)
        {
            StoreUtils.LogDebug(TAG, "Trying to create PurchasableVirtualItem with itemId: " + jniVirtualItem.Call <string>("getItemId"));
            using (AndroidJavaObject jniPurchaseType = jniVirtualItem.Call <AndroidJavaObject>("getPurchaseType")) {
                System.IntPtr cls = AndroidJNI.FindClass("com/soomla/store/purchaseTypes/PurchaseWithMarket");
                if (AndroidJNI.IsInstanceOf(jniPurchaseType.GetRawObject(), cls))
                {
                    using (AndroidJavaObject jniMarketItem = jniPurchaseType.Call <AndroidJavaObject>("getGoogleMarketItem")) {
                        PurchaseType = new PurchaseWithMarket(jniMarketItem.Call <string>("getProductId"), jniMarketItem.Call <double>("getPrice"));
                    }
                }
                else
                {
                    cls = AndroidJNI.FindClass("com/soomla/store/purchaseTypes/PurchaseWithVirtualItem");
                    if (AndroidJNI.IsInstanceOf(jniPurchaseType.GetRawObject(), cls))
                    {
                        string itemId = jniPurchaseType.Call <string>("getTargetItemId");
                        int    amount = jniPurchaseType.Call <int>("getAmount");

                        PurchaseType = new PurchaseWithVirtualItem(itemId, amount);
                    }
                    else
                    {
                        StoreUtils.LogError(TAG, "Couldn't determine what type of class is the given purchaseType.");
                    }
                }
            }
        }
        /// <summary>
        /// see parent
        /// </returns>
        public override JSONObject toJSONObject()
        {
            JSONObject jsonObject = base.toJSONObject();

            try {
                JSONObject purchasableObj = new JSONObject(JSONObject.Type.OBJECT);

                if (PurchaseType is PurchaseWithMarket)
                {
                    purchasableObj.AddField(JSONConsts.PURCHASE_TYPE, JSONConsts.PURCHASE_TYPE_MARKET);

                    MarketItem mi = ((PurchaseWithMarket)PurchaseType).MarketItem;
                    purchasableObj.AddField(JSONConsts.PURCHASE_MARKET_ITEM, mi.toJSONObject());
                }
                else if (PurchaseType is PurchaseWithVirtualItem)
                {
                    purchasableObj.AddField(JSONConsts.PURCHASE_TYPE, JSONConsts.PURCHASE_TYPE_VI);

                    purchasableObj.AddField(JSONConsts.PURCHASE_VI_ITEMID, ((PurchaseWithVirtualItem)PurchaseType).ItemId);
                    purchasableObj.AddField(JSONConsts.PURCHASE_VI_AMOUNT, ((PurchaseWithVirtualItem)PurchaseType).Amount);
                }

                jsonObject.AddField(JSONConsts.PURCHASABLE_ITEM, purchasableObj);
            } catch (System.Exception e) {
                StoreUtils.LogError(TAG, "An error occurred while generating JSON object. " + e.Message);
            }

            return(jsonObject);
        }
示例#3
0
//		private static AndroidJavaObject jniUnityEventHandler = null;
#endif

        public static void Initialize(IStoreAssets storeAssets)
        {
            if (string.IsNullOrEmpty(Soomla.GetInstance().customSecret) || string.IsNullOrEmpty(Soomla.GetInstance().soomSec))
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY MISSING customSecret or soomSec !!! Stopping here !!");
                throw new ExitGUIException();
            }

            if (Soomla.GetInstance().customSecret == Soomla.ONLY_ONCE_DEFAULT || Soomla.GetInstance().soomSec == Soomla.ONLY_ONCE_DEFAULT)
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY You have to change customSecret and soomSec !!! Stopping here !!");
                throw new ExitGUIException();
            }
            //init SOOM_SEC
#if UNITY_ANDROID && !UNITY_EDITOR
            if (string.IsNullOrEmpty(Soomla.GetInstance().androidPublicKey))
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY MISSING publickKey !!! Stopping here !!");
                throw new ExitGUIException();
            }

            if (Soomla.GetInstance().androidPublicKey == Soomla.AND_PUB_KEY_DEFAULT)
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY You have to change android publicKey !!! Stopping here !!");
                throw new ExitGUIException();
            }

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {
                jniStoreAssets.CallStatic("setSoomSec", Soomla.GetInstance().soomSec);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
            storeController_SetSSV(Soomla.GetInstance().iosServerSideVerification);
            storeController_SetSoomSec(Soomla.GetInstance().soomSec);
#endif

            StoreInfo.Initialize(storeAssets);
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJNI.PushLocalFrame(100);
            //init EventHandler
            using (AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.unity.EventHandler")) {
                jniEventHandler.CallStatic("initialize");
            }
            using (AndroidJavaObject jniStoreAssetsInstance = new AndroidJavaObject("com.soomla.unity.StoreAssets")) {
                using (AndroidJavaClass jniStoreControllerClass = new AndroidJavaClass("com.soomla.store.StoreController")) {
                    jniStoreController = jniStoreControllerClass.CallStatic <AndroidJavaObject>("getInstance");
                    jniStoreController.Call("initialize", jniStoreAssetsInstance, Soomla.GetInstance().androidPublicKey, Soomla.GetInstance().customSecret);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);

            // setting test mode on Android
            SetAndroidTestMode(Soomla.GetInstance().androidTestMode);
#elif UNITY_IOS && !UNITY_EDITOR
            storeController_Init(Soomla.GetInstance().customSecret);
#endif
        }
示例#4
0
        public static VirtualItem factoryItemFromJNI(AndroidJavaObject jniItem)
        {
            StoreUtils.LogDebug(TAG, "Trying to create VirtualItem with itemId: " + jniItem.Call <string>("getItemId"));

            if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualGoods/SingleUseVG"))
            {
                return(new SingleUseVG(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualGoods/LifetimeVG"))
            {
                return(new LifetimeVG(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualGoods/EquippableVG"))
            {
                return(new EquippableVG(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualGoods/SingleUsePackVG"))
            {
                return(new SingleUsePackVG(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualGoods/UpgradeVG"))
            {
                return(new UpgradeVG(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualCurrencies/VirtualCurrency"))
            {
                return(new VirtualCurrency(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/virtualCurrencies/VirtualCurrencyPack"))
            {
                return(new VirtualCurrencyPack(jniItem));
            }
            else if (isInstanceOf(jniItem, "com/soomla/store/domain/NonConsumableItem"))
            {
                return(new NonConsumableItem(jniItem));
            }
            else
            {
                StoreUtils.LogError(TAG, "Couldn't determine what type of class is the given jniItem.");
            }

            return(null);
        }
        /// <summary>
        /// see parent
        /// </returns>
        protected PurchasableVirtualItem(JSONObject jsonItem) :
            base(jsonItem)
        {
            JSONObject purchasableObj = (JSONObject)jsonItem[JSONConsts.PURCHASABLE_ITEM];
            string     purchaseType   = purchasableObj[JSONConsts.PURCHASE_TYPE].str;

            if (purchaseType == JSONConsts.PURCHASE_TYPE_MARKET)
            {
                JSONObject marketItemObj = (JSONObject)purchasableObj[JSONConsts.PURCHASE_MARKET_ITEM];

                PurchaseType = new PurchaseWithMarket(new MarketItem(marketItemObj));
            }
            else if (purchaseType == JSONConsts.PURCHASE_TYPE_VI)
            {
                string itemId = purchasableObj[JSONConsts.PURCHASE_VI_ITEMID].str;
                int    amount = System.Convert.ToInt32(((JSONObject)purchasableObj[JSONConsts.PURCHASE_VI_AMOUNT]).n);

                PurchaseType = new PurchaseWithVirtualItem(itemId, amount);
            }
            else
            {
                StoreUtils.LogError(TAG, "Couldn't determine what type of class is the given purchaseType.");
            }
        }
示例#6
0
//		private static AndroidJavaObject jniUnityEventHandler = null;
#endif

        public static void Initialize(IStoreAssets storeAssets)
        {
            if (string.IsNullOrEmpty(Soomla.GetInstance().customSecret) || string.IsNullOrEmpty(Soomla.GetInstance().soomSec))
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY MISSING customSecret or soomSec !!! Stopping here !!");
                throw new ExitGUIException();
            }

            if (Soomla.GetInstance().customSecret == Soomla.ONLY_ONCE_DEFAULT || Soomla.GetInstance().soomSec == Soomla.ONLY_ONCE_DEFAULT)
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY You have to change customSecret and soomSec !!! Stopping here !!");
                throw new ExitGUIException();
            }
            //init SOOM_SEC
#if UNITY_ANDROID
            if (string.IsNullOrEmpty(Soomla.GetInstance().androidPublicKey))
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY MISSING publickKey !!! Stopping here !!");
                throw new ExitGUIException();
            }

            if (Soomla.GetInstance().androidPublicKey == Soomla.AND_PUB_KEY_DEFAULT)
            {
                StoreUtils.LogError(TAG, "SOOMLA/UNITY You have to change android publicKey !!! Stopping here !!");
                throw new ExitGUIException();
            }

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {
                jniStoreAssets.CallStatic("setSoomSec", Soomla.GetInstance().soomSec);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
            storeController_SetSoomSec(Soomla.GetInstance().soomSec);
#endif

            StoreInfo.Initialize(storeAssets);
#if UNITY_ANDROID
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniStoreAssetsInstance = new AndroidJavaObject("com.soomla.unity.StoreAssets")) {
                using (AndroidJavaClass jniStoreControllerClass = new AndroidJavaClass("com.soomla.store.StoreController")) {
                    jniStoreController = jniStoreControllerClass.CallStatic <AndroidJavaObject>("getInstance");
                    jniStoreController.Call("initialize", jniStoreAssetsInstance, Soomla.GetInstance().androidPublicKey, Soomla.GetInstance().customSecret);
                }
            }
            //init EventHandler
            using (AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.unity.EventHandler")) {
                jniEventHandler.CallStatic("initialize");
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);

            // setting test mode on Android
            SetAndroidTestMode(Soomla.GetInstance().androidTestMode);
#elif UNITY_IOS
            storeController_Init(Soomla.GetInstance().customSecret);
#endif

#if UNITY_EDITOR
            if (UnityEngine.Random.value < 0.1)
            {
                // make billing ddisabled
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Simulate disabled billing");
                Events.OnBillingNotSupported();
            }
            else
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Simulate enabled billing");
                Events.OnBillingSupported();
            }
#endif
        }