Ejemplo n.º 1
0
        /**
         * Shows an error message.
         */
        public static void ShowError(string errmsg)
        {
#if UNITY_IOS
            BillingiOS.ShowError(errmsg);
#elif UNITY_ANDROID
            BillingAndroid.ShowError(errmsg);
#else
            UnsupportedPlatform();
#endif
        }
Ejemplo n.º 2
0
        public static bool DefaultHasProduct(string productId)
        {
            if (Application.isEditor)
            {
                return(productId != null);
            }
#if UNITY_IOS
            string billingId = GetBillingIdOfProductWithProductId(productId);
            return(BillingiOS.Billing_HasProduct(billingId));
#elif UNITY_ANDROID
            string billingId = GetBillingIdOfProductWithProductId(productId);
            return(BillingAndroid.HasProduct(billingId));
#else
            UnsupportedPlatform();
            return(false);
#endif
        }
Ejemplo n.º 3
0
        public static string GetPriceTag(string productId)
        {
            string billingId = GetBillingIdOfProductWithProductId(productId);

            if (Application.isEditor)
            {
                return(GetProductWithBillingId(billingId).priceTagInEditor);
            }
#if UNITY_IOS
            var ret = BillingiOS.Billing_GetPriceTag(billingId);
            ret = ret.Replace("GBP", "£").Replace("USD", "$");
            return(ret);
#elif UNITY_ANDROID
            return(BillingAndroid.GetPriceTag(billingId));
#else
            UnsupportedPlatform();
            return("");
#endif
        }
Ejemplo n.º 4
0
        public static void BuyProduct(ProductInfo product, System.Action <bool, string, Shop.BuyResponse> callback, ShopConfirm shopConfirmInterface, ShopNotEnoughCoins notEnoughCoinsInterface)
        {
            string billingid = product.BillingId;

            if (MobyShop.Shop.Verbose)
            {
                Debug.Log("MobyShop: Buy Product : " + product.ToString());
            }
            if (product.billing == BillingType.IngameCurrency)
            {
                BillingUnityEditor_BuyProductInGameCurrency(product, callback, shopConfirmInterface, notEnoughCoinsInterface);
                return;
            }

            // isEditor...
            if (Application.isEditor || ShopConfig.instance.SimulateBillingOnDevice)
            {
                if (MobyShop.Shop.Verbose)
                {
                    Debug.Log("MobyShop: Buying product with billing simulation turned on.");
                }
                BillingUnityEditor_BuyProductWithSimulatedBilling(product, callback);
                return;
            }

            // Has Recieved the Product catalogue.
            if (!HasRecvProductCatalogue)
            {
                Debug.LogError("MobyShop: has not recieved product catalogue yet, and products cannot be bought.");
                if (callback != null)
                {
                    callback(false, "no product catalogue recieved and you cannot make purchase", Shop.BuyResponse.Failed);
                }
                Billing.ShowError("Product Catalogue not recieved yet");
                return;
            }


            if (buyingProduct)
            {
                Debug.LogError("MobyShop: Store: Already buying another project");
            }

            buyingProduct = true;
            Debug.Log("MobyShop: Store: Purchase product : " + billingid + " (init)");

#if UNITY_IOS
            if (iOS_BuyDeleg != null)
            {
                Debug.LogError("MobyShop: Ignoring double puchase, wait until previous is done");
                if (callback != null)
                {
                    callback(false, "Purchase already in progress", Shop.BuyResponse.Wait);
                }
                return;
            }

            iOS_BuyDeleg = callback;
            BillingiOS.Billing_BuyProduct(billingid, NativeCallback.Create((Hashtable args) => {
                bool ok    = args.ContainsKey("ok") ? System.Convert.ToBoolean(args["ok"]) : false;
                string msg = args.ContainsKey("msg") ? System.Convert.ToString(args["msg"]) : "";

                if (ok)
                {
                    Debug.Log("MobyShop: Billing(iOS): ok=true; product bought : " + billingid + "; msg=" + msg);
                }
                else
                {
                    Debug.LogError("MobyShop: Billing(iOS): ok=false; Failed to buy product; msg=" + msg);
                    if (iOS_BuyDeleg != null)
                    {
                        var tmp      = iOS_BuyDeleg;
                        iOS_BuyDeleg = null;                         // remember to reset this one.
                        tmp(false, msg, Shop.BuyResponse.Failed);
                    }
                }

                /*if( callback!=null ) {
                 *      callback(ok,msg);
                 * }*/
            }));
#elif UNITY_ANDROID
            BillingAndroid.BuyProduct(billingid, NativeCallback.Create((Hashtable args) => {
                bool ok    = args.ContainsKey("ok") ? System.Convert.ToBoolean(args["ok"]) : false;
                string msg = args.ContainsKey("msg") ? System.Convert.ToString(args["msg"]) : "";
                Debug.Log("MobyShop: OnBuyProduct Retuned : " + ok + " msg = " + msg);
                var prod = Billing.GetProductInfoByBillingId(billingid);
                if (prod == null)
                {
                    prod = product;
                    Debug.LogError("MobyShop: Error cannot get product wiht billingId: " + billingid);
                }
                if (ok)
                {
                    if (prod == null)
                    {
                        Debug.LogError("MobyShop:Error unable to get the product by the given billing id : " + billingid);
                    }
                    CallUnlockProduct(BoughtOrRestored.Bought, prod);
                }
                else
                {
                }
                if (callback != null)
                {
                    callback(ok, "", Shop.BuyResponse.Ok);
                }
            }));
#else
            UnsupportedPlatform();
#endif
        }
Ejemplo n.º 5
0
        /**
         * Call this to unlock the products that was previously bought by the user.
         */
        public static void RestorePurchases(System.Action <bool, string> cbOnDone, System.Action <string> cbOnRestoreProduct)
        {
            if (Application.isEditor)
            {
                inst.StartCoroutine(Wait(5f, () => {
                    int index = -1;
                    foreach (var pi in BillingIdList)
                    {
                        var product = GetProductInfoByBillingId(pi);
                        index++;
                        if (pi == null)
                        {
                            Debug.LogError("MobyShop: Error: product id at index : " + index + " of product list is null");
                            continue;
                        }
                        if (product.Consumeable)
                        {
                            // ship consumeable...
                        }
                        else
                        {
                            CallUnlockProduct(BoughtOrRestored.Restored, product);
                            if (cbOnRestoreProduct != null)
                            {
                                cbOnRestoreProduct(pi);
                            }
                        }
                    }
                    if (cbOnDone != null)
                    {
                        cbOnDone(true, "");
                    }
                }));
            }
            else
            {
                if (ShopConfig.instance.SimulateBillingOnDevice)
                {
                    if (cbOnDone != null)
                    {
                        cbOnDone(true, "sim");
                    }
                    return;
                }
                onRestoredProduct = cbOnRestoreProduct;
#if UNITY_IOS
                BillingiOS.Billing_RestorePurchases(NativeCallback.Create((Hashtable args) => {
                    bool ok    = args.ContainsKey("ok") ? System.Convert.ToBoolean(args["ok"]) : false;
                    string msg = args.ContainsKey("msg") ? System.Convert.ToString(args["msg"]) : "";
                    //string pidlist = args.ContainsKey("msg") ? System.Convert.ToString(args["pidlist"]) : "";
                    if (cbOnDone != null)
                    {
                        cbOnDone(ok, msg);
                    }
                    onRestoredProduct = null;
                }));
#elif UNITY_ANDROID
                BillingAndroid.RestorePurchases(inst.gameObject.name, "AndroidNativeCallback_TransactionRestored", NativeCallback.Create((Hashtable args) => {
                    bool ok    = args.ContainsKey("ok") ? System.Convert.ToBoolean(args["ok"]) : false;
                    string msg = args.ContainsKey("msg") ? System.Convert.ToString(args["msg"]) : "";
                    Debug.Log("MobyShop: Restore Purchases DONE!! OK = " + ok);
                    if (cbOnDone != null)
                    {
                        cbOnDone(ok, msg);
                    }
                    onRestoredProduct = null;
                }));
#else
                UnsupportedPlatform();
#endif
            }
        }
Ejemplo n.º 6
0
        /**
         * Sets up all infomration used to do native billing.
         */
        void Awake()
        {
            if (Application.isEditor && this.gameObject.GetComponent <BillingSimulator>() == null)
            {
                this.gameObject.AddComponent <BillingSimulator>();
            }
            DontDestroyOnLoad(this.gameObject);
            inst = this;
            if (initializing == true)
            {
                throw new System.Exception("MobyShop: Cannot initialize twice.");
            }
            initializing = true;
#if !UNITY_EDITOR
            Debug.Log("MobyShop: Init");
            Debug.Log("MobyShop: Base64 License Code : " + AndroidPurchaseLicenseBase64);
            Debug.Log("MobyShop: ProductId List ( Unlockables )" + string.Join(",", ProductIdsOfUnlockables));
            Debug.Log("MobyShop: ProductId List ( Consumeables ) " + string.Join(",", ProductIdsOfConsumeables));
            Debug.Log("MobyShop: this.Object " + this.gameObject.name);
#endif
            initialized = false;

            if (Application.isEditor || ShopConfig.instance.SimulateBillingOnDevice)
            {
                BillingSimulator.Init(( bool ok ) => {
                    if (MobyShop.Shop.Verbose)
                    {
                        Debug.Log("MobyShop: Initialized Billing simulator");
                    }
                });
                return;
            }
#if UNITY_IOS
            BillingiOS.Billing_Init(inst.name, string.Join(",", ProductBillingIdListForRealProducts), NativeCallback.Create(( Hashtable res ) => {
                initializing = false;
                bool ok      = res.ContainsKey("ok") ? System.Convert.ToBoolean(res["ok"]) : false;
                string msg   = res.ContainsKey("msg") ? System.Convert.ToString(res["msg"]) : "";
                Debug.Log("MobyShop: Store Init Done; ok=" + ok + " msg = '" + msg + "'");
                if (ok)
                {
                    initialized = true;
                }
                else
                {
                }
            }));
            initializing = false;
            initialized  = true;
#elif UNITY_ANDROID
            initializing = true;
            BillingAndroid.Init(
                AndroidPurchaseLicenseBase64,
                ProductIdsOfUnlockables,
                ProductIdsOfConsumeables,
                this.gameObject.name,
                NativeCallback.Create(( Hashtable res ) => {
                initializing = false;
                bool ok      = res.ContainsKey("ok") ? System.Convert.ToBoolean(res["ok"]) : false;
                string msg   = res.ContainsKey("msg") ? System.Convert.ToString(res["msg"]) : "";
                Debug.Log("MobyShop: Store Init Done; ok=" + ok + " msg = '" + msg + "'");
                if (ok)
                {
                    initialized = true;
                }
                else
                {
                }
            })
                );
#else
            UnsupportedPlatform();
#endif
        }