Beispiel #1
0
        public static PurchasableVirtualItem GetPurchasableItemWithProductId(string productId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetPurchasableItemWithProductId(productId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string nonConsJson = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            JSONObject obj = new JSONObject(nonConsJson);
            return((PurchasableVirtualItem)VirtualItem.factoryItemFromJSONObject(obj));
#else
            return(null);
#endif
        }
Beispiel #2
0
        public static UpgradeVG GetLastUpgradeForVirtualGood(string goodItemId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            UpgradeVG vgu = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getGoodLastUpgrade", goodItemId)) {
                vgu = new UpgradeVG(jniUpgradeVG);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vgu);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetLastUpgradeForVirtualGood(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string json = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            JSONObject obj = new JSONObject(json);
            return(new UpgradeVG(obj));
#else
            return(null);
#endif
        }
Beispiel #3
0
        public static string GetGoodCurrentUpgrade(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodCurrentUpgrade with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                string currentItemId = "";
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    currentItemId = AndroidJNIHandler.CallStatic <string>(jniStoreInventory, "getGoodCurrentUpgrade", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(currentItemId);
#elif UNITY_IOS && !UNITY_EDITOR
                IntPtr p   = IntPtr.Zero;
                int    err = storeInventory_GetGoodCurrentUpgrade(goodItemId, out p);

                IOS_ErrorCodes.CheckAndThrowException(err);

                string result = Marshal.PtrToStringAnsi(p);
                Marshal.FreeHGlobal(p);

                return(result);
#endif
            }
            return(null);
        }
Beispiel #4
0
        public static VirtualItem GetItemByItemId(string itemId)
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch an item with itemId: " + itemId);
#if UNITY_ANDROID && !UNITY_EDITOR
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getVirtualItem", itemId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vi);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetItemByItemId(itemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string json = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            StoreUtils.LogDebug(TAG, "Got json: " + json);

            JSONObject obj = new JSONObject(json);
            return(VirtualItem.factoryItemFromJSONObject(obj));
#else
            return(null);
#endif
        }
        /// <summary>
        /// Retrieves the upgrade level of the virtual good with the given <c>goodItemId</c>.
        /// For Example:
        /// Let's say there's a strength attribute to one of the characters in your game and you provide
        /// your users with the ability to upgrade that strength on a scale of 1-3.
        /// This is what you've created:
        /// 1. <c>SingleUseVG</c> for "strength".
        /// 2. <c>UpgradeVG</c> for strength 'level 1'.
        /// 3. <c>UpgradeVG</c> for strength 'level 2'.
        /// 4. <c>UpgradeVG</c> for strength 'level 3'.
        /// In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
        /// </summary>
        /// <param name="goodItemId">Good item identifier.</param>
        /// <returns>The good upgrade level.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected int _getGoodUpgradeLevel(string goodItemId)
        {
            int level = 0;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                level = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getGoodUpgradeLevel", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(level);
        }
Beispiel #6
0
 /// <summary>
 /// Starts a purchase process in the market.
 /// </summary>
 /// <param name="productId">id of the item to buy.</param>
 protected override void _buyMarketItem(string productId, string payload)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaObject jniPurchasableItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
         AndroidJNIHandler.CallVoid(jniStoreController, "buyWithMarket",
                                    jniPurchasableItem.Call <AndroidJavaObject>("getPurchaseType").Call <AndroidJavaObject>("getMarketItem"),
                                    payload);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
        /// <summary>
        /// Retrieves the current upgrade of the good with the given id.
        /// </summary>
        /// <param name="goodItemId">Id of the good whose upgrade we want to fetch. </param>
        /// <returns>The good's current upgrade.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected string _getGoodCurrentUpgrade(string goodItemId)
        {
            string currentItemId = "";

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                currentItemId = AndroidJNIHandler.CallStatic <string>(jniStoreInventory, "getGoodCurrentUpgrade", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(currentItemId);
        }
        /** NON-CONSUMABLES **/

        /// <summary>
        /// Checks if the non-consumable with the given <c>nonConsItemId</c> exists.
        /// </summary>
        /// <param name="nonConsItemId">Id of the item to check if exists.</param>
        /// <returns>True if non-consumable item with nonConsItemId exists, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _nonConsumableItemExists(string nonConsItemId)
        {
            bool result = false;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "nonConsumableItemExists", nonConsItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(result);
        }
        /// <summary>
        /// Checks if the virtual good with the given <c>goodItemId</c> is currently equipped.
        /// </summary>
        /// <param name="goodItemId">Id of the virtual good who we want to know if is equipped.</param>
        /// <returns>True if the virtual good is equipped, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _isVertualGoodEquipped(string goodItemId)
        {
            bool result = false;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "isVirtualGoodEquipped", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(result);
        }
        /** VIRTUAL ITEMS **/

        /// <summary>
        /// Retrieves the balance of the virtual item with the given <c>itemId</c>.
        /// </summary>
        /// <param name="itemId">Id of the virtual item to be fetched.</param>
        /// <returns>Balance of the virtual item with the given item id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected int _getItemBalance(string itemId)
        {
            AndroidJNI.PushLocalFrame(100);
            int balance = 0;

            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                balance = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getVirtualItemBalance", itemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(balance);
        }
Beispiel #11
0
        /// <summary>
        /// Gets the category that the virtual good with the given <c>goodItemId</c> belongs to.
        /// </summary>
        /// <param name="goodItemId">Item id.</param>
        /// <returns>Category that the item with given id belongs to.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if category is not found.</exception>
        override protected VirtualCategory _getCategoryForVirtualGood(string goodItemId)
        {
            VirtualCategory vc = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualVategory = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getCategory", goodItemId)) {
                vc = new VirtualCategory(jniVirtualVategory);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vc);
        }
Beispiel #12
0
        /// <summary>
        /// Gets the purchasable item with the given <c>productId</c>.
        /// </summary>
        /// <param name="productId">Product id.</param>
        /// <returns>Purchasable virtual item with the given id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception>
        override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId)
        {
            VirtualItem vi = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
        }
Beispiel #13
0
        /// <summary>
        /// Gets the last upgrade for the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">item id</param>
        /// <returns>last upgrade for virtual good with the given id</returns>
        override protected UpgradeVG _getLastUpgradeForVirtualGood(string goodItemId)
        {
            UpgradeVG vgu = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getGoodLastUpgrade", goodItemId)) {
                vgu = new UpgradeVG(jniUpgradeVG);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vgu);
        }
Beispiel #14
0
        public static void BuyMarketItem(string productId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniPurchasableItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                AndroidJNIHandler.CallVoid(jniStoreController, "buyWithGooglePlay",
                                           jniPurchasableItem.Call <AndroidJavaObject>("getPurchaseType").Call <AndroidJavaObject>("getGoogleMarketItem"),
                                           "");
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
            storeController_BuyMarketItem(productId);
#endif
        }
Beispiel #15
0
        public static bool IsVirtualGoodEquipped(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling IsVirtualGoodEquipped with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                bool result = false;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "isVirtualGoodEquipped", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(result);
#elif UNITY_IOS && !UNITY_EDITOR
                bool result = false;
                int  err    = storeInventory_IsVirtualGoodEquipped(goodItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }
Beispiel #16
0
        /** NonConsumables **/


        public static bool NonConsumableItemExists(string nonConsItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling NonConsumableItemExists with: " + nonConsItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                bool result = false;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "nonConsumableItemExists", nonConsItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(result);
#elif UNITY_IOS && !UNITY_EDITOR
                bool result = false;
                int  err    = storeInventory_NonConsumableItemExists(nonConsItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }
Beispiel #17
0
        /** Virtual Items **/


        public static int GetItemBalance(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetItemBalance with: " + itemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                int balance = 0;
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    balance = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getVirtualItemBalance", itemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(balance);
#elif UNITY_IOS && !UNITY_EDITOR
                int balance = 0;
                int err     = storeInventory_GetItemBalance(itemId, out balance);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(balance);
#endif
            }
            return(0);
        }
Beispiel #18
0
        public static int GetGoodUpgradeLevel(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodUpgradeLevel with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                int level = 0;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    level = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getGoodUpgradeLevel", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(level);
#elif UNITY_IOS && !UNITY_EDITOR
                int level = 0;
                int err   = storeInventory_GetGoodUpgradeLevel(goodItemId, out level);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(level);
#endif
            }
            return(0);
        }