public new void OnFormReceived(XsollaForm form) { XsollaForm.CurrentCommand command = form.GetCurrentCommand(); switch (command) { case XsollaForm.CurrentCommand.FORM: XsollaError error = form.GetError(); if (!form.IsValidPaymentSystem()) { OnErrorReceived(XsollaError.GetUnsuportedError()); } else if (error == null) { form.UpdateElement(XsollaApiConst.CARD_NUMBER, _cardNumber); form.UpdateElement(XsollaApiConst.CARD_EXP_YEAR, _cardExpYear); form.UpdateElement(XsollaApiConst.CARD_EXP_MONTH, _cardExpMonth); form.UpdateElement(XsollaApiConst.CARD_CVV, _cardCvv); form.UpdateElement(XsollaApiConst.CARD_ZIP, _cardZip); form.UpdateElement(XsollaApiConst.CARD_HOLDER, _cardHolder); NextStep(form.GetXpsMap()); } else { OnErrorReceived(error); } break; case XsollaForm.CurrentCommand.CHECK: if (form.GetItem(XsollaApiConst.CARD_ZIP) != null) { form.UpdateElement(XsollaApiConst.CARD_ZIP, _cardZip); NextStep(form.GetXpsMap()); } else { OnNextStepRecieved(form); } break; case XsollaForm.CurrentCommand.ACCOUNT: case XsollaForm.CurrentCommand.STATUS: case XsollaForm.CurrentCommand.CREATE: default: break; } }
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); }
public new void OnFormReceived(XsollaForm form) { XsollaForm.CurrentCommand command = form.GetCurrentCommand (); switch (command) { case XsollaForm.CurrentCommand.FORM: XsollaError error = form.GetError(); if (!form.IsValidPaymentSystem ()) { OnErrorReceived (XsollaError.GetUnsuportedError ()); } else if (error == null) { form.UpdateElement (XsollaApiConst.CARD_NUMBER, _cardNumber); form.UpdateElement (XsollaApiConst.CARD_EXP_YEAR, _cardExpYear); form.UpdateElement (XsollaApiConst.CARD_EXP_MONTH, _cardExpMonth); form.UpdateElement (XsollaApiConst.CARD_CVV, _cardCvv); form.UpdateElement (XsollaApiConst.CARD_ZIP, _cardZip); form.UpdateElement (XsollaApiConst.CARD_HOLDER, _cardHolder); NextStep (form.GetXpsMap()); } else { OnErrorReceived (error); } break; case XsollaForm.CurrentCommand.CHECK: if(form.GetItem(XsollaApiConst.CARD_ZIP) != null) { form.UpdateElement (XsollaApiConst.CARD_ZIP, _cardZip); NextStep (form.GetXpsMap()); } else { OnNextStepRecieved(form); } break; case XsollaForm.CurrentCommand.ACCOUNT: case XsollaForm.CurrentCommand.STATUS: case XsollaForm.CurrentCommand.CREATE: default: break; } }