Exemplo n.º 1
0
 private void OnPricepointsRecieved(XsollaPricepointsManager pricepoints)
 {
     if (PricepointsRecieved != null)
     {
         PricepointsRecieved(pricepoints);
     }
 }
        public void OpenPricepoints(string title, XsollaPricepointsManager pricepoints, string virtualCurrencyName, string buyBtnText, bool pCustomHref = false, XsollaUtils pUtils = null)
        {
            Resizer.ResizeToParrent(gameObject);
            menu.transform.parent.parent.gameObject.SetActive(false);
            SetTitle(title);
            // if we have custom amount we need show link object
            if (pCustomHref)
            {
                CustomAmountLink.SetActive(true);
                string customAmountShowTitle = pUtils.GetTranslations().Get(XsollaTranslations.PRICEPOINT_PAGE_CUSTOM_AMOUNT_SHOW_TITLE);
                string customAmountHideTitle = pUtils.GetTranslations().Get(XsollaTranslations.PRICEPOINT_PAGE_CUSTOM_AMOUNT_HIDE_TITLE);

                Text titleCustomAmount = CustomAmountLink.GetComponent <Text>();
                titleCustomAmount.text = customAmountShowTitle;

                Toggle toggle = CustomAmountLink.GetComponent <Toggle>();
                toggle.onValueChanged.AddListener((value) =>
                {
                    if (value)
                    {
                        titleCustomAmount.text = customAmountHideTitle;
                    }
                    else
                    {
                        titleCustomAmount.text = customAmountShowTitle;
                    }

                    CustomAmountScreen.SetActive(value);
                    ShopPanel.SetActive(!value);

                    Logger.Log("Change value toggle " + value.ToString());
                });

                CustomVirtCurrAmountController controller = CustomAmountScreen.GetComponent <CustomVirtCurrAmountController>() as CustomVirtCurrAmountController;
                controller.initScreen(pUtils, pricepoints.GetItemByPosition(1).currency, CalcCustomAmount, TryPayCustomAmount);
            }
            else
            {
                CustomAmountLink.SetActive(false);
            }

            pAdapter.SetManager(pricepoints, virtualCurrencyName, buyBtnText);
            if (pAdapter.OnBuyPricepoints == null)
            {
                pAdapter.OnBuyPricepoints += (outAmount) => {
                    Dictionary <string, object> map = new Dictionary <string, object> (1);
                    map.Add("out", outAmount);
                    OpenPaymentMethods(map, false);
                };
            }
            DrawContent(pAdapter, 3);
        }
        public void OpenPricepoints(XsollaUtils utils, XsollaPricepointsManager pricepoints)
        {
            DrawShopScreen();
            string title   = utils.GetTranslations().Get(XsollaTranslations.PRICEPOINT_PAGE_TITLE);
            string vcName  = utils.GetProject().virtualCurrencyName;
            string buyText = utils.GetTranslations().Get(XsollaTranslations.VIRTUAL_ITEM_OPTION_BUTTON);

            if (utils.GetSettings().components.virtualCurreny.customAmount)
            {
                _shopViewController.OpenPricepoints(title, pricepoints, vcName, buyText, true, utils);
            }
            else
            {
                _shopViewController.OpenPricepoints(title, pricepoints, vcName, buyText);
            }
        }
Exemplo n.º 4
0
        private void PricePointsRecived(JSONNode pNode)
        {
            Logger.Log("PricePoints recived");
            XsollaPricepointsManager lGoods = new XsollaPricepointsManager().Parse(pNode) as XsollaPricepointsManager;

            // Если группа пустая
            mEmptyLabel.gameObject.SetActive(lGoods.GetCount() == 0);
            if (lGoods.GetCount() == 0)
            {
                mItemsContentGrid.SetActive(false);
            }

            // расчитываем кол-во столбцов
            if ((lGoods.GetCount() % 4) == 0)
            {
                mItemsContentGrid.GetComponent <GridLayoutGroup>().constraintCount = 4;
            }
            if ((lGoods.GetCount() % 5) == 0)
            {
                mItemsContentGrid.GetComponent <GridLayoutGroup>().cellSize        = new Vector2(120, mItemsContentGrid.GetComponent <GridLayoutGroup>().cellSize.y);
                mItemsContentGrid.GetComponent <GridLayoutGroup>().constraintCount = 5;
            }

            // Добавляем кнопки
            lGoods.GetItemsList().ForEach((item) =>
            {
                AddPricePointItem(item);
            });

            // Инициализируем панель кастомного пополнения
            if (mCustomAmountLink.activeSelf)
            {
                int lCountItems = lGoods.GetItemsList().Count;
                int lAvgIdx     = lCountItems / 2 + ((lCountItems % 2) > 0 ? 1 : 0);
                mCustomController.init(mUtils, lGoods.GetItemsList()[lAvgIdx - 1]);
            }

            mStopProgressBar();
        }
 protected override void ShowPricepoints(XsollaUtils utils, XsollaPricepointsManager pricepoints)
 {
     Logger.Log("Pricepoints recived");
     OpenPricepoints(utils, pricepoints);
     SetLoading(false);
 }
Exemplo n.º 6
0
        private void ProcessingRequestResult(int pType, RequestClass pRequestResult, Dictionary <string, object> pDataArgs)
        {
            if (!pRequestResult.HasError)
            {
                // Start Processing
                Debug.Log("Type -> " + pType);
                Debug.Log("WWW_request -> " + pRequestResult.TextRequest);

                JSONNode rootNode = JSON.Parse(pRequestResult.TextRequest);
                if (rootNode != null && rootNode.Count > 2 || rootNode["error"] == null)
                {
                    switch (pType)
                    {
                    case TRANSLATIONS:
                    {
                        if (rootNode.Count > 2)
                        {
                            XsollaUtils utils = new XsollaUtils().Parse(rootNode) as XsollaUtils;
                            projectId = utils.GetProject().id.ToString();

                            OnUtilsRecieved(utils);
                            // if base param not containKey access token, then add token from util
                            if (!baseParams.ContainsKey(XsollaApiConst.ACCESS_TOKEN))
                            {
                                _accessToken = utils.GetAcceessToken();
                            }
                            OnTranslationRecieved(utils.GetTranslations());
                        }
                        else
                        {
                            XsollaError error = new XsollaError();
                            error.Parse(rootNode);
                            OnErrorReceived(error);
                        }
                    }
                    break;

                    case DIRECTPAYMENT_FORM:
                    {
                        if (rootNode.Count > 8)
                        {
                            XsollaForm form = new XsollaForm();
                            form.Parse(rootNode);
                            switch (form.GetCurrentCommand())
                            {
                            case XsollaForm.CurrentCommand.STATUS:
                                GetStatus(form.GetXpsMap());
                                break;

                            case XsollaForm.CurrentCommand.CHECKOUT:
                            case XsollaForm.CurrentCommand.CHECK:
                            case XsollaForm.CurrentCommand.FORM:
                            case XsollaForm.CurrentCommand.CREATE:
                            case XsollaForm.CurrentCommand.ACCOUNT:
                                OnFormReceived(form);
                                break;

                            case XsollaForm.CurrentCommand.UNKNOWN:
                                if (rootNode.Count > 10)
                                {
                                    OnFormReceived(form);
                                }
                                else
                                {
                                    XsollaError error = new XsollaError();
                                    error.Parse(rootNode);
                                    OnErrorReceived(error);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            XsollaStatusPing statusPing = new XsollaStatusPing();
                            statusPing.Parse(rootNode);
                            OnStatusChecked(statusPing);
                        }
                    }
                    break;

                    case DIRECTPAYMENT_STATUS:
                    {
                        XsollaForm form = new XsollaForm();
                        form.Parse(rootNode);
                        XsollaStatus status = new XsollaStatus();
                        status.Parse(rootNode);
                        OnStatusReceived(status, form);
                    }
                    break;

                    case PRICEPOINTS:
                    {
                        XsollaPricepointsManager pricepoints = new XsollaPricepointsManager();
                        pricepoints.Parse(rootNode);
                        OnPricepointsRecieved(pricepoints);
                    }
                    break;

                    case GOODS:
                    {
                        XsollaGoodsManager goods = new XsollaGoodsManager();
                        goods.Parse(rootNode);
                        OnGoodsRecieved(goods);
                    }
                    break;

                    case GOODS_GROUPS:
                    {
                        XsollaGroupsManager groups = new XsollaGroupsManager();
                        groups.Parse(rootNode);
                        OnGoodsGroupsRecieved(groups);
                    }
                    break;

                    case GOODS_ITEMS:
                    {
                        XsollaGoodsManager goods = new XsollaGoodsManager();
                        goods.Parse(rootNode);
                        OnGoodsRecieved(goods);
                    }
                    break;

                    case PAYMENT_LIST:
                    {
                        XsollaPaymentMethods paymentMethods = new XsollaPaymentMethods();
                        paymentMethods.Parse(rootNode);
                        OnPaymentMethodsRecieved(paymentMethods);
                    }
                    break;

                    case SAVED_PAYMENT_LIST:
                    {
                        XsollaSavedPaymentMethods savedPaymentsMethods = new XsollaSavedPaymentMethods();
                        savedPaymentsMethods.Parse(rootNode);
                        OnSavedPaymentMethodsRecieved(savedPaymentsMethods);
                    }
                    break;

                    case QUICK_PAYMENT_LIST:
                    {
                        XsollaQuickPayments quickPayments = new XsollaQuickPayments();
                        quickPayments.Parse(rootNode);
                        OnQuickPaymentMethodsRecieved(quickPayments);
                    }
                    break;

                    case COUNTRIES:
                    {
                        XsollaCountries countries = new XsollaCountries();
                        countries.Parse(rootNode);
                        OnCountriesRecieved(countries);
                    }
                    break;

                    case VIRTUAL_PAYMENT_SUMMARY:
                    {
                        XVirtualPaymentSummary summary = new XVirtualPaymentSummary();
                        summary.Parse(rootNode);
                        Logger.Log("VIRTUAL_PAYMENT_SUMMARY " + summary.ToString());
                        if (summary.IsSkipConfirmation)
                        {
                            Logger.Log("IsSkipConfirmation true");
                            pDataArgs.Add("dont_ask_again", 0);
                            ProceedVPayment(pDataArgs);
                        }
                        else
                        {
                            Logger.Log("IsSkipConfirmation false");
                            OnVPSummaryRecieved(summary);
                        }
                    }
                    break;

                    case VIRTUAL_PROCEED:
                    {
                        XProceed proceed = new XProceed();
                        proceed.Parse(rootNode);
                        Logger.Log("VIRTUAL_PROCEED " + proceed.ToString());
                        if (proceed.IsInvoiceCreated)
                        {
                            Logger.Log("VIRTUAL_PROCEED 1");
                            long operationId = proceed.OperationId;
                            pDataArgs.Add("operation_id", operationId);
                            VPaymentStatus(pDataArgs);
                        }
                        else
                        {
                            Logger.Log("VIRTUAL_PROCEED 0 ");
                            OnVPProceedError(proceed.Error);
                        }
                    }
                    break;

                    case VIRTUAL_STATUS:
                    {
                        XVPStatus vpStatus = new XVPStatus();
                        vpStatus.Parse(rootNode);
                        //{"errors":[ {"message":"Insufficient balance to complete operation"} ], "api":{"ver":"1.0.1"}, "invoice_created":"false", "operation_id":"0", "code":"0"}
                        Logger.Log("VIRTUAL_STATUS" + vpStatus.ToString());
                        OnVPStatusRecieved(vpStatus);
                    }
                    break;

                    case APPLY_PROMO_COUPONE:
                    {
                        XsollaForm form = new XsollaForm();
                        form.Parse(rootNode);
                        OnApplyCouponeReceived(form);
                    }
                    break;

                    case COUPON_PROCEED:
                    {
                        XsollaCouponProceedResult couponProceed = new XsollaCouponProceedResult();
                        couponProceed.Parse(rootNode);
                        if (couponProceed._error != null)
                        {
                            Logger.Log("COUPON_PROCEED ERROR: " + couponProceed._error);
                            OnCouponProceedErrorRecived(couponProceed);
                        }
                        else
                        {
                            long operationId = couponProceed._operationId;
                            if (pDataArgs.ContainsKey("coupon_code"))
                            {
                                pDataArgs.Remove("coupon_code");
                            }
                            pDataArgs.Add("operation_id", operationId);
                            VPaymentStatus(pDataArgs);
                        }
                    }
                    break;

                    case HISTORY:
                    {
                        XsollaHistoryList history = new XsollaHistoryList().Parse(rootNode["operations"]) as XsollaHistoryList;
                        OnHistoryRecieved(history);
                    }
                    break;

                    case CALCULATE_CUSTOM_AMOUNT:
                    {
                        //TODO: fill method
                        CustomVirtCurrAmountController.CustomAmountCalcRes res = new CustomVirtCurrAmountController.CustomAmountCalcRes().Parse(rootNode["calculation"]) as CustomVirtCurrAmountController.CustomAmountCalcRes;
                        OnCustomAmountResRecieved(res);
                    }
                    break;

                    default:
                        break;
                    }
                }
                else
                {
                    XsollaError error = new XsollaError();
                    error.Parse(rootNode);
                    OnErrorReceived(error);
                }
            }
            else
            {
                JSONNode errorNode = JSON.Parse(pRequestResult.TextRequest);
                string   errorMsg  = errorNode["errors"].AsArray[0]["message"].Value
                                     + ". Support code " + errorNode["errors"].AsArray[0]["support_code"].Value;
                int errorCode = 0;
                if (pRequestResult.ErrorText.Length > 3)
                {
                    errorCode = int.Parse(pRequestResult.ErrorText.Substring(0, 3));
                }
                else
                {
                    errorCode = int.Parse(pRequestResult.ErrorText);
                }
                OnErrorReceived(new XsollaError(errorCode, errorMsg));
            }
            if (projectId != null && !"".Equals(projectId))
            {
                LogEvent("UNITY " + SDK_VERSION + " REQUEST", projectId, pRequestResult.Url);
            }
            else
            {
                LogEvent("UNITY " + SDK_VERSION + " REQUEST", "undefined", pRequestResult.Url);
            }
        }
Exemplo n.º 7
0
 protected abstract void ShowPricepoints(XsollaUtils utils, XsollaPricepointsManager pricepoints);
Exemplo n.º 8
0
        protected override object[] ParseResult(JSONNode rootNode)
        {
            var data = new XsollaPricepointsManager().Parse(rootNode) as XsollaPricepointsManager;

            return(new object[] { data });
        }
        private IEnumerator WaitForRequest(int pType, WWW www, Dictionary <string, object> post)
        {
            Logger.Log("Start get www");
            yield return(www);

            // check for errors
            if (www.error == null)
            {
                Debug.Log("Type -> " + pType);
                Debug.Log("WWW_request -> " + www.text);
                string data = www.text;

                JSONNode rootNode = JSON.Parse(www.text);
                if (rootNode != null && rootNode.Count > 2 || rootNode["error"] == null)
                {
                    switch (pType)
                    {
                    case TRANSLATIONS:
                    {
                        if (rootNode.Count > 2)
                        {
                            XsollaUtils utils = new XsollaUtils().Parse(rootNode) as XsollaUtils;
                            projectId = utils.GetProject().id.ToString();
                            if (baseParams.ContainsKey(XsollaApiConst.ACCESS_TOKEN))
                            {
                                utils.SetAccessToken(baseParams[XsollaApiConst.ACCESS_TOKEN].ToString());
                            }

                            OnUtilsRecieved(utils);
//								// if base param not containKey access token, then add token from util
//								if (!baseParams.ContainsKey(XsollaApiConst.ACCESS_TOKEN))
//									_accessToken = utils.GetAcceessToken();
                            OnTranslationRecieved(utils.GetTranslations());
                        }
                        else
                        {
                            XsollaError error = new XsollaError();
                            error.Parse(rootNode);
                            OnErrorReceived(error);
                        }
                        break;
                    }

                    case DIRECTPAYMENT_FORM:
                    {
                        if (rootNode.Count > 8)
                        {
                            XsollaForm form = new XsollaForm();
                            form.Parse(rootNode);
                            switch (form.GetCurrentCommand())
                            {
                            case XsollaForm.CurrentCommand.STATUS:
                                // if we replaced or add saved account, we must start loop on get list saved account
                                if (post.ContainsKey("save_payment_account_only") || (post.ContainsKey("replace_payment_account")))
                                {
                                    if (!form.IsCardPayment() && !(post.ContainsKey("replace_payment_account")))
                                    {
                                        OnWaitPaymentChange();
                                        break;
                                    }
                                    else
                                    {
                                        OnPaymentManagerMethod(null, post.ContainsKey("replace_payment_account")?false:true);
                                        break;
                                    }
                                }
                                GetStatus(form.GetXpsMap());
                                break;

                            case XsollaForm.CurrentCommand.CHECKOUT:
                            case XsollaForm.CurrentCommand.CHECK:
                            case XsollaForm.CurrentCommand.FORM:
                            case XsollaForm.CurrentCommand.CREATE:
                            case XsollaForm.CurrentCommand.ACCOUNT:
                                OnFormReceived(form);
                                break;

                            case XsollaForm.CurrentCommand.UNKNOWN:
                                if (rootNode.Count > 10)
                                {
                                    OnFormReceived(form);
                                }
                                else
                                {
                                    XsollaError error = new XsollaError();
                                    error.Parse(rootNode);
                                    OnErrorReceived(error);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            XsollaStatusPing statusPing = new XsollaStatusPing();
                            statusPing.Parse(rootNode);
                            OnStatusChecked(statusPing);
                        }
                        break;
                    }

                    case DIRECTPAYMENT_STATUS:
                    {
                        XsollaForm form = new XsollaForm();
                        form.Parse(rootNode);
                        XsollaStatus status = new XsollaStatus();
                        status.Parse(rootNode);
                        OnStatusReceived(status, form);
                        break;
                    }

                    case PRICEPOINTS:
                    {
                        XsollaPricepointsManager pricepoints = new XsollaPricepointsManager();
                        pricepoints.Parse(rootNode);
                        OnPricepointsRecieved(pricepoints);
                        break;
                    }

                    case GOODS:
                    {
                        XsollaGoodsManager goods = new XsollaGoodsManager();
                        goods.Parse(rootNode);
                        OnGoodsRecieved(goods);
                        break;
                    }

                    case GOODS_GROUPS:
                    {
                        XsollaGroupsManager groups = new XsollaGroupsManager();
                        groups.Parse(rootNode);
                        OnGoodsGroupsRecieved(groups);
                        break;
                    }

                    case GOODS_ITEMS:
                    {
                        XsollaGoodsManager goods = new XsollaGoodsManager();
                        goods.Parse(rootNode);
                        OnGoodsRecieved(goods);
                        break;
                    }

                    case PAYMENT_LIST:
                    {
                        XsollaPaymentMethods paymentMethods = new XsollaPaymentMethods();
                        paymentMethods.Parse(rootNode);
                        OnPaymentMethodsRecieved(paymentMethods);
                        break;
                    }

                    case SAVED_PAYMENT_LIST:
                    {
                        XsollaSavedPaymentMethods savedPaymentsMethods = new XsollaSavedPaymentMethods();
                        savedPaymentsMethods.Parse(rootNode);
                        OnSavedPaymentMethodsRecieved(savedPaymentsMethods);
                        break;
                    }

                    case QUICK_PAYMENT_LIST:
                    {
                        XsollaQuickPayments quickPayments = new XsollaQuickPayments();
                        quickPayments.Parse(rootNode);
                        OnQuickPaymentMethodsRecieved(quickPayments);
                        break;
                    }

                    case COUNTRIES:
                    {
                        XsollaCountries countries = new XsollaCountries();
                        countries.Parse(rootNode);
                        OnCountriesRecieved(countries);
                        break;
                    }

                    case VIRTUAL_PAYMENT_SUMMARY:
                    {
                        XVirtualPaymentSummary summary = new XVirtualPaymentSummary();
                        summary.Parse(rootNode);
                        Logger.Log("VIRTUAL_PAYMENT_SUMMARY " + summary.ToString());
                        if (summary.IsSkipConfirmation)
                        {
                            Logger.Log("IsSkipConfirmation true");
                            post.Add("dont_ask_again", 0);
                            ProceedVPayment(post);
                        }
                        else
                        {
                            Logger.Log("IsSkipConfirmation false");
                            OnVPSummaryRecieved(summary);
                        }
                        break;
                    }

                    case VIRTUAL_PROCEED:
                    {
                        XProceed proceed = new XProceed();
                        proceed.Parse(rootNode);
                        Logger.Log("VIRTUAL_PROCEED " + proceed.ToString());
                        if (proceed.IsInvoiceCreated)
                        {
                            Logger.Log("VIRTUAL_PROCEED 1");
                            long operationId = proceed.OperationId;
                            post.Add("operation_id", operationId);
                            VPaymentStatus(post);
                        }
                        else
                        {
                            Logger.Log("VIRTUAL_PROCEED 0 ");
                            OnVPProceedError(proceed.Error);
                        }
                        break;
                    }

                    case VIRTUAL_STATUS:
                    {
                        XVPStatus vpStatus = new XVPStatus();
                        vpStatus.Parse(rootNode);
                        Logger.Log("VIRTUAL_STATUS" + vpStatus.ToString());
                        OnVPStatusRecieved(vpStatus);
                        break;
                    }

                    case APPLY_PROMO_COUPONE:
                    {
                        XsollaForm form = new XsollaForm();
                        form.Parse(rootNode);
                        OnApplyCouponeReceived(form);
                        break;
                    }

                    case COUPON_PROCEED:
                    {
                        XsollaCouponProceedResult couponProceed = new XsollaCouponProceedResult();
                        couponProceed.Parse(rootNode);
                        if (couponProceed._error != null)
                        {
                            Logger.Log("COUPON_PROCEED ERROR: " + couponProceed._error);
                            OnCouponProceedErrorRecived(couponProceed);
                        }
                        else
                        {
                            long operationId = couponProceed._operationId;
                            if (post.ContainsKey("coupon_code"))
                            {
                                post.Remove("coupon_code");
                            }
                            post.Add("operation_id", operationId);

                            VPaymentStatus(post);
                        }
                        break;
                    }

                    case CALCULATE_CUSTOM_AMOUNT:
                    {
                        CustomVirtCurrAmountController.CustomAmountCalcRes res = new CustomVirtCurrAmountController.CustomAmountCalcRes().Parse(rootNode["calculation"]) as CustomVirtCurrAmountController.CustomAmountCalcRes;
                        OnCustomAmountResRecieved(res);
                        break;
                    }

                    case PAYMENT_MANAGER_LIST:
                    {
                        XsollaSavedPaymentMethods res = new XsollaSavedPaymentMethods().Parse(rootNode) as XsollaSavedPaymentMethods;
                        OnPaymentManagerMethod(res, false);
                        break;
                    }

                    case DELETE_SAVED_METHOD:
                    {
                        OnDeleteSavedPaymentMethod();
                        break;
                    }

                    case SUBSCRIPTIONS_MANAGER_LIST:
                    {
                        XsollaManagerSubscriptions lSubsList = new XsollaManagerSubscriptions().Parse(rootNode["subscriptions"]) as XsollaManagerSubscriptions;
                        OnManageSubsListrecived(lSubsList);
                        break;
                    }

                    default:
                        break;
                    }
                }
                else
                {
                    XsollaError error = new XsollaError();
                    error.Parse(rootNode);
                    OnErrorReceived(error);
                }
            }
            else
            {
                JSONNode errorNode = JSON.Parse(www.text);
                string   errorMsg  = errorNode["errors"].AsArray[0]["message"].Value
                                     + ". Support code " + errorNode["errors"].AsArray[0]["support_code"].Value;
                int errorCode = 0;
                if (www.error.Length > 3)
                {
                    errorCode = int.Parse(www.error.Substring(0, 3));
                }
                else
                {
                    errorCode = int.Parse(www.error);
                }
                OnErrorReceived(new XsollaError(errorCode, errorMsg));
            }
            if (projectId != null && !"".Equals(projectId))
            {
                LogEvent("UNITY " + SDK_VERSION + " REQUEST", projectId, www.url);
            }
            else
            {
                LogEvent("UNITY " + SDK_VERSION + " REQUEST", "undefined", www.url);
            }
        }
Exemplo n.º 10
0
 public void SetManager(XsollaPricepointsManager pricepoints, string virtualCurrencyName, string buyBtnText)
 {
     _virtualCurrencyName = virtualCurrencyName;
     _buyBtnText          = buyBtnText;
     SetManager(pricepoints);
 }
Exemplo n.º 11
0
 public void SetManager(XsollaPricepointsManager pricepoints)
 {
     manager = pricepoints;
 }