Beispiel #1
0
        public IParseble Parse(JSONNode summaryNode)
        {
            purchases = new List <IXsollaSummaryItem>();
            JSONNode nodeItems         = summaryNode ["purchase"] ["virtual_items"];
            JSONNode nodeCurrency      = summaryNode ["purchase"] ["virtual_currency"];
            JSONNode nodeSubscriptions = summaryNode ["purchase"] ["subscriptions"];

            if (nodeItems != null)
            {
                IEnumerator <JSONNode> iEnumerator = nodeItems.Childs.GetEnumerator();
                while (iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }

            if (nodeCurrency != null)
            {
                IEnumerator <JSONNode> iEnumerator = nodeCurrency.Childs.GetEnumerator();
                while (iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }

            if (nodeSubscriptions != null)
            {
                IEnumerator <JSONNode> iEnumerator = nodeSubscriptions.Childs.GetEnumerator();
                while (iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummarySubscription().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }
//			IEnumerator<JSONNode> enumerator = summaryNode ["purchase"].Childs.GetEnumerator ();
//			IEnumerator<JSONNode> innerEnumerator;
//			while(enumerator.MoveNext()){
//				innerEnumerator = enumerator.Current.Childs.GetEnumerator();
//				if(!enumerator.Current.AsObject.ContainsKey("subscriptions")){
//					while (innerEnumerator.MoveNext())
//					{
//						JSONNode purchaseNode = innerEnumerator.Current;
//						purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
//					}
//				} else {
//					while (innerEnumerator.MoveNext())
//					{
//						JSONNode purchaseNode = innerEnumerator.Current;
//						purchases.Add(new XsollaSummarySubscription().Parse(purchaseNode) as IXsollaSummaryItem);
//					}
//				}
//			}
            finance = new XsollaFinance().Parse(summaryNode["finance"]) as XsollaFinance;
            return(this);
        }
        public void InitView(XsollaTranslations translations, XsollaSummary summary)
        {
            _translations = translations;
            _summary      = summary;

            if (this.gameObject.GetComponent <VerticalLayoutGroup>() == null)
            {
                this.gameObject.AddComponent <VerticalLayoutGroup>();
                VerticalLayoutGroup obj = this.GetComponent <VerticalLayoutGroup>();
                obj.childForceExpandHeight = false;
            }
            GameObject header = Instantiate(orderSummaryPrefab);

            header.GetComponentsInChildren <Text> () [0].text = translations.Get(XsollaTranslations.PAYMENT_SUMMARY_HEADER);
            linearLayout.AddObject(header);
            foreach (IXsollaSummaryItem purchase in _summary.GetPurchases())
            {
                linearLayout.AddObject(GetSummaryItem(purchase));
            }
            XsollaFinance finance = _summary.GetFinance();

            linearLayout.AddObject(GetItem(subTotalPrefab, translations.Get(XsollaTranslations.PAYMENT_SUMMARY_SUBTOTAL), PriceFormatter.Format(finance.subTotal.amount, finance.subTotal.currency)));
            if (finance.discount != null && finance.discount.amount > 0)
            {
                linearLayout.AddObject(GetItem(financeItemPrefab, translations.Get(XsollaTranslations.PAYMENT_SUMMARY_DISCOUNT), "- " + PriceFormatter.Format(finance.discount.amount, finance.discount.currency)));
            }
            if (finance.fee != null)
            {
                linearLayout.AddObject(GetItem(financeItemPrefab, translations.Get(XsollaTranslations.PAYMENT_SUMMARY_FEE), PriceFormatter.Format(finance.fee.amount, finance.fee.currency)));
            }
            if (finance.xsollaCredits != null && finance.xsollaCredits.amount > 0)
            {
                linearLayout.AddObject(GetItem(financeItemPrefab, translations.Get(XsollaTranslations.PAYMENT_SUMMARY_XSOLLA_CREDITS), PriceFormatter.Format(finance.xsollaCredits.amount, finance.xsollaCredits.currency)));
            }
            linearLayout.AddObject(GetItem(totalPrefab, translations.Get(XsollaTranslations.PAYMENT_SUMMARY_TOTAL), PriceFormatter.Format(finance.total.amount, finance.total.currency)));
            if (finance.vat != null && finance.vat.amount > 0)
            {
                linearLayout.AddObject(GetItem(financeItemPrefab, "VAT", PriceFormatter.Format(finance.vat.amount, finance.vat.currency)));
            }
            linearLayout.Invalidate();
        }
        public IParseble Parse(JSONNode summaryNode)
        {
            purchases = new List<IXsollaSummaryItem>();
            JSONNode nodeItems = summaryNode ["purchase"] ["virtual_items"];
            JSONNode nodeCurrency = summaryNode ["purchase"] ["virtual_currency"];
            JSONNode nodeSubscriptions = summaryNode ["purchase"] ["subscriptions"];
            if (nodeItems != null) {
                IEnumerator<JSONNode> iEnumerator = nodeItems.Childs.GetEnumerator ();
                while(iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }

            if (nodeCurrency != null) {
                IEnumerator<JSONNode> iEnumerator = nodeCurrency.Childs.GetEnumerator ();
                while(iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }

            if (nodeSubscriptions != null) {
                IEnumerator<JSONNode> iEnumerator = nodeSubscriptions.Childs.GetEnumerator ();
                while(iEnumerator.MoveNext())
                {
                    JSONNode purchaseNode = iEnumerator.Current;
                    purchases.Add(new XsollaSummarySubscription().Parse(purchaseNode) as IXsollaSummaryItem);
                }
            }
            //			IEnumerator<JSONNode> enumerator = summaryNode ["purchase"].Childs.GetEnumerator ();
            //			IEnumerator<JSONNode> innerEnumerator;
            //			while(enumerator.MoveNext()){
            //				innerEnumerator = enumerator.Current.Childs.GetEnumerator();
            //				if(!enumerator.Current.AsObject.ContainsKey("subscriptions")){
            //					while (innerEnumerator.MoveNext())
            //					{
            //						JSONNode purchaseNode = innerEnumerator.Current;
            //						purchases.Add(new XsollaSummaryItem().Parse(purchaseNode) as IXsollaSummaryItem);
            //					}
            //				} else {
            //					while (innerEnumerator.MoveNext())
            //					{
            //						JSONNode purchaseNode = innerEnumerator.Current;
            //						purchases.Add(new XsollaSummarySubscription().Parse(purchaseNode) as IXsollaSummaryItem);
            //					}
            //				}
            //			}
            finance = new XsollaFinance().Parse(summaryNode["finance"]) as XsollaFinance;
            return this;
        }