public override GameObject GetView(int position)
        {
            XsollaFormElement element = elements[position];

            //create a new item, name it, and set the parent
            switch (element.GetElementType())
            {
            case XsollaFormElement.TYPE_LABEL:
                return(DrawLabel(element));

            case XsollaFormElement.TYPE_TEXT:
                return(DrawInput(element));

            case XsollaFormElement.TYPE_CHECK:
                return(DrawCheckBox(element));

            case XsollaFormElement.TYPE_SELECT:
                return(DrawSelect(element));

            case XsollaFormElement.TYPE_TABLE:
                return(DrawTable(element));

            default:
                return(DrawLabel(element));
            }
        }
        GameObject DrawSelect(XsollaFormElement element)
        {
            GameObject         newSelect  = Instantiate(selectPrtefab) as GameObject;
            DropDownController controller = newSelect.GetComponent <DropDownController> ();

            newSelect.GetComponentInChildren <Text>().text = element.GetTitle();
            List <Xsolla.XsollaFormElement.Option> options = element.GetOptions();
            List <string> titles = new List <string> (options.Count);

            foreach (Xsolla.XsollaFormElement.Option o in options)
            {
                titles.Add(o.GetLabel());
            }
            controller.SetParentForScroll(gameObject.transform.parent.parent);
            controller.OnItemSelected += (position, title) => {
                OnEndEdit(element.GetName(), options[position].GetValue());
            };
            controller.SetData(titles);
//			GameObject panel = newSelect.GetComponentInChildren<VerticalLayoutGroup> ().gameObject;
//			List<Xsolla.XsollaFormElement.Option> options = element.GetOptions ();
//			foreach (var option in options)
//			{
//				GameObject go = Instantiate(selectElementPrefab) as GameObject;
//				go.GetComponentInChildren<Text>().text = option.GetLabel();
//				go.transform.SetParent(panel.transform);
//			}
            return(newSelect);
        }
        GameObject DrawInput(XsollaFormElement element)
        {
            // if this promo coupone code then draw another prefab
            if (element.GetName() == "couponCode")
            {
                GameObject          newItem    = Instantiate(Resources.Load("Prefabs/SimpleView/_PaymentFormElements/ContainerPromoCode")) as GameObject;
                PromoCodeController controller = newItem.GetComponent <PromoCodeController>();
                controller.InitScreen(_translation, element);
                controller._inputField.onEndEdit.AddListener(delegate
                {
                    OnEndEdit(element, controller._inputField);
                });

                controller._promoCodeApply.onClick.AddListener(delegate
                {
                    bool isLinkRequired = false;
                    if ((form.GetCurrentCommand() == XsollaForm.CurrentCommand.CHECKOUT) && form.GetSkipChekout())
                    {
                        string checkoutToken = form.GetCheckoutToken();
                        isLinkRequired       = checkoutToken != null &&
                                               !"".Equals(checkoutToken) &&
                                               !"null".Equals(checkoutToken) &&
                                               !"false".Equals(checkoutToken);
                    }
                    if (isLinkRequired)
                    {
                        string link = "https://secure.xsolla.com/pages/checkout/?token=" + form.GetCheckoutToken();
                        if (Application.platform == RuntimePlatform.WebGLPlayer
                            //|| Application.platform == RuntimePlatform.OSXWebPlayer
                            //|| Application.platform == RuntimePlatform.WindowsWebPlayer
                            )
                        {
                            Application.ExternalEval("window.open('" + link + "','Window title')");
                        }
                        else
                        {
                            Application.OpenURL(link);
                        }
                    }
                    gameObject.GetComponentInParent <XsollaPaystationController> ().ApplyPromoCoupone(form.GetXpsMap());
                });

                return(newItem);
            }
            else
            {
                GameObject newItem = Instantiate(inputPrefab) as GameObject;
                newItem.GetComponentInChildren <Text>().text = element.GetTitle();
                InputField inputField = newItem.GetComponentInChildren <InputField>();
                inputField.GetComponentInChildren <Text>().text = element.GetExample();
                SetupValidation(element.GetName(), inputField);
                //inputField.onValidateInput += ValidateInput;
                inputField.onEndEdit.AddListener(delegate
                {
                    OnEndEdit(element, inputField);
                });
                return(newItem);
            }
        }
        GameObject DrawTable(XsollaFormElement element)
        {
            GameObject             newItem    = Instantiate(tablePrefab) as GameObject;
            ElementTableController controller = newItem.GetComponent <ElementTableController>();

            controller.InitScreen(element);
            return(newItem);
        }
        public void InitScreen(XsollaFormElement pElem)
        {
            _title.text = pElem.GetTableOptions()._head[0];

            foreach (string item in pElem.GetTableOptions()._body)
            {
                GameObject itemtable = Instantiate(Resources.Load("Prefabs/SimpleView/_PaymentFormElements/ContainerTableItem")) as GameObject;
                itemtable.GetComponentInChildren <Text>().text = item;
                itemtable.transform.SetParent(_container.transform);
            }
        }
        public void InitScreen(XsollaFormElement pElem)
        {
            _title.text = pElem.GetTableOptions()._head[0];

            foreach (string item in pElem.GetTableOptions()._body)
            {
                GameObject itemtable = Instantiate(Resources.Load("Prefabs/SimpleView/_PaymentFormElements/ContainerTableItem")) as GameObject;
                itemtable.GetComponentInChildren<Text>().text = item;
                itemtable.transform.SetParent(_container.transform);
            }
        }
Example #7
0
 /* * * * * * * * * * * * * * * * * * * * * * * * * * *
 * PUBLIC METHODS
 * * * * * * * * * * * * * * * * * * * * * * * * * * */
 public void AddElement(XsollaFormElement xsollaFormElement)
 {
     elements.Add(xsollaFormElement);
     if (xsollaFormElement.IsVisible() /*&& !"couponCode".Equals(xsollaFormElement.GetName())*/)
         elementsVisible.Add(xsollaFormElement);
     map.Add(xsollaFormElement.GetName(), xsollaFormElement);
     if (xsollaFormElement.GetName () != null)
     {
         xpsMap.Add (xpsPrefix + xsollaFormElement.GetName (), xsollaFormElement.GetValue ());
     }
     size++;
 }
        GameObject DrawLabel(XsollaFormElement element)
        {
            if (element.GetTitle() == "")
            {
                return(null);
            }

            GameObject newItem = Instantiate(labelPrefab) as GameObject;

            newItem.GetComponentInChildren <Text> ().text = element.GetTitle();
            return(newItem);
        }
        GameObject DrawCheckBox(XsollaFormElement element)
        {
            GameObject newItem = Instantiate(checkBoxPrefab) as GameObject;
            Toggle     toggle  = newItem.GetComponentInChildren <Toggle> ();

            OnEndEdit(element.GetName(), toggle.isOn?"1":"0");
            toggle.onValueChanged.AddListener((b) => {
                OnEndEdit(element.GetName(), b?"1":"0");
            });
            newItem.GetComponentInChildren <Text> ().text = element.GetTitle();
            return(newItem);
        }
Example #10
0
 /* * * * * * * * * * * * * * * * * * * * * * * * * * *
 * PUBLIC METHODS
 * * * * * * * * * * * * * * * * * * * * * * * * * * */
 public void AddElement(XsollaFormElement xsollaFormElement)
 {
     elements.Add(xsollaFormElement);
     if (xsollaFormElement.IsVisible() /*&& !"couponCode".Equals(xsollaFormElement.GetName())*/)
     {
         elementsVisible.Add(xsollaFormElement);
     }
     map.Add(xsollaFormElement.GetName(), xsollaFormElement);
     if (xsollaFormElement.GetName() != null)
     {
         xpsMap.Add(xpsPrefix + xsollaFormElement.GetName(), xsollaFormElement.GetValue());
     }
     size++;
 }
        public void InitScreen(XsollaTranslations pTranslation, XsollaFormElement pForm)
        {
            _promoBtn.GetComponent<Text>().text = pTranslation.Get("coupon_control_header");
            _promoDesc.text = pTranslation.Get("coupon_control_hint");
            _promoCodeApply.gameObject.GetComponentInChildren<Text>().text = pTranslation.Get("coupon_control_apply");
            _acceptLable.text = pTranslation.Get("coupon_control_accepted");

            _inputField.onValueChanged.AddListener(delegate
                {
                    if (_panelError.activeSelf)
                        _panelError.SetActive(false);
                });

            if (pForm.IsReadOnly() && !pForm.GetValue().Equals(""))
            {
                _inputField.text = pForm.GetValue();
                ApplySuccessful();
            }
        }
        public void InitScreen(XsollaTranslations pTranslation, XsollaFormElement pForm)
        {
            _promoBtn.GetComponent <Text>().text = pTranslation.Get("coupon_control_header");
            _promoDesc.text = pTranslation.Get("coupon_control_hint");
            _promoCodeApply.gameObject.GetComponentInChildren <Text>().text = pTranslation.Get("coupon_control_apply");
            _acceptLable.text = pTranslation.Get("coupon_control_accepted");

            _inputField.onValueChanged.AddListener(delegate
            {
                if (_panelError.activeSelf)
                {
                    _panelError.SetActive(false);
                }
            });

            if (pForm.IsReadOnly() && !pForm.GetValue().Equals(""))
            {
                _inputField.text = pForm.GetValue();
                ApplySuccessful();
            }
        }
Example #13
0
        public List <XsollaFormElement> GetVisible()
        {
            List <XsollaFormElement> resList    = new List <XsollaFormElement>();
            XsollaFormElement        couponCode = null;

            elementsVisible.ForEach((item) =>
            {
                if (item.GetName().Equals("couponCode"))
                {
                    couponCode = item;
                }
                else
                {
                    resList.Add(item);
                }
            });
            if (couponCode != null)
            {
                resList.Add(couponCode);
            }

            return(resList);
        }
Example #14
0
        public GameObject GetCardViewWeb(XsollaForm xsollaForm, XsollaTranslations translations)
        {
            GameObject cardViewObj = Instantiate(Resources.Load("Prefabs/SimpleView/_ScreenCheckout/CardViewLayoutWeb")) as GameObject;

            InputField[] inputs = cardViewObj.GetComponentsInChildren <InputField>();
            validators = new List <ValidatorInputField> ();
            for (int i = inputs.Length - 1; i >= 0; i--)
            {
                XsollaFormElement   element     = null;
                string              newErrorMsg = "Invalid";
                InputField          input       = inputs[i];
                ValidatorInputField validator   = input.GetComponentInChildren <ValidatorInputField>();
                // CVV > *HOLDER* > *ZIP* > YEAR > MONTH > NUMBER
                switch (i)               //input.tag)
                {
                case 5:                  //"CardNumber":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_NUMBER);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_CARDNUMBER);
                    CCEditText ccEditText = input.GetComponent <CCEditText>();
                    isMaestro = ccEditText.IsMaestro();
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    validator.AddValidator(new ValidatorCreditCard(newErrorMsg));
                    break;

                case 4:                        //"Month":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_EXP_MONTH);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_CARD_MONTH);
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    validator.AddValidator(new ValidatorMonth(newErrorMsg));
                    break;

                case 3:                        //"Year":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_EXP_YEAR);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_CARD_YEAR);
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    validator.AddValidator(new ValidatorYear(newErrorMsg));
                    break;

                case 2:                        //"Zip":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_ZIP);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_REQUIRED);
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    break;

                case 1:                        //"CardHolder":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_HOLDER);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_REQUIRED);
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    break;

                case 0:                        //"Cvv":
                    element     = xsollaForm.GetItem(XsollaApiConst.CARD_CVV);
                    newErrorMsg = translations.Get(XsollaTranslations.VALIDATION_MESSAGE_CVV);
                    validator.AddValidator(new ValidatorEmpty(newErrorMsg));
                    validator.AddValidator(new ValidatorCvv(newErrorMsg, isMaestro));
                    break;

                default:
                    break;
                }

                if (element != null)
                {
                    //		input.text = element.GetTitle();
                    //						input.GetComponentInChildren<MainValidator>().setErrorMsg(newErrorMsg);
                    if (element.GetName() != XsollaApiConst.CARD_CVV)
                    {
                        input.GetComponentInChildren <Text>().text = element.GetExample();
                    }
                    // FIX update with unity 5.2
                    input.onValueChanged.AddListener(delegate { OnValueChange(input, element.GetName()); });
                }
                else
                {
                    DestroyImmediate(input.transform.parent.gameObject);
                }

                if (validator != null)
                {
                    validators.Add(validator);
                }
            }
            // Toggle allowSubscription
            // get toggle object
            Toggle toggle = cardViewObj.GetComponentInChildren <Toggle> ();

            if (xsollaForm.Contains(XsollaApiConst.ALLOW_SUBSCRIPTION))
            {
                XsollaFormElement ToggleElement = null;
                ToggleElement = xsollaForm.GetItem(XsollaApiConst.ALLOW_SUBSCRIPTION);
                // set label name
                Text lable = toggle.transform.GetComponentInChildren <Text>();
                lable.text = ToggleElement.GetTitle();
                OnValueChange(ToggleElement.GetName(), toggle.isOn?"1":"0");
                toggle.onValueChanged.AddListener((b) => {
                    OnValueChange(ToggleElement.GetName(), b?"1":"0");
                });
            }
            else
            {
                GameObject.Find(toggle.transform.parent.name).SetActive(false);
            }

            if (xsollaForm.Contains("couponCode") && xsollaForm.GetItem("couponCode").IsVisible())
            {
                GameObject          promoController = Instantiate(Resources.Load("Prefabs/SimpleView/_PaymentFormElements/ContainerPromoCode")) as GameObject;
                PromoCodeController controller      = promoController.GetComponent <PromoCodeController>();
                controller.InitScreen(translations, xsollaForm.GetItem("couponCode"));
                controller._inputField.onValueChanged.AddListener((s) => {
                    OnValueChange("couponCode", s.Trim());
                });
                controller._promoCodeApply.onClick.AddListener(() =>
                {
                    bool isLinkRequired = false;
                    if ((_form.GetCurrentCommand() == XsollaForm.CurrentCommand.CHECKOUT) && _form.GetSkipChekout())
                    {
                        string checkoutToken = _form.GetCheckoutToken();
                        isLinkRequired       = checkoutToken != null &&
                                               !"".Equals(checkoutToken) &&
                                               !"null".Equals(checkoutToken) &&
                                               !"false".Equals(checkoutToken);
                    }
                    if (isLinkRequired)
                    {
                        string link = "https://secure.xsolla.com/pages/checkout/?token=" + _form.GetCheckoutToken();
                        if (Application.platform == RuntimePlatform.WebGLPlayer ||
                            Application.platform == RuntimePlatform.OSXWebPlayer ||
                            Application.platform == RuntimePlatform.WindowsWebPlayer)
                        {
                            Application.ExternalEval("window.open('" + link + "','Window title')");
                        }
                        else
                        {
                            Application.OpenURL(link);
                        }
                    }
                    gameObject.GetComponentInParent <XsollaPaystationController> ().ApplyPromoCoupone(_form.GetXpsMap());
                });
                promoController.transform.SetParent(cardViewObj.transform);
            }
            return(cardViewObj);
        }
//		void ValidateCard(InputField _inputField){
//			string text = _inputField.text;
//		}

        public void OnEndEdit(XsollaFormElement element, InputField _input)
        {
            form.UpdateElement(element.GetName(), _input.text);
        }