GameObject DrawLabel(XsollaFormElement element) { if (element.GetTitle() == "") { return(null); } GameObject newItem = Instantiate(labelPrefab) as GameObject; newItem.GetComponentInChildren <Text> ().text = element.GetTitle(); return(newItem); }
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 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); }
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); }