public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); var validator = new PaymentInfoValidator(T); var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { warnings.Add(error.ErrorMessage); } } return(warnings); }
/// <summary> /// Take the payment using the given card details. /// </summary> /// <param name="paymentInfo">The card information needed to authorise the payment.</param> /// <param name="amount">The amount to take.</param> /// <returns>An asynchronous task of MethodResult indicating whether the operation was successful or not.</returns> public async Task <MethodResult> TakePaymentAsync(PaymentInfo paymentInfo, decimal amount) { if (amount <= 0) { MethodResult paymentFailed = MethodResult.Failed("Amount must be greater than zero"); return(paymentFailed); } // Validate the payment info provided. var paymentInfoValidator = new PaymentInfoValidator(); ValidationResult paymentValidResult = await paymentInfoValidator.ValidateAsync(paymentInfo); if (paymentValidResult.IsValid == false) { // Convert each ValidationFailure to an error message string and assign to an array. string[] errors = ((List <ValidationFailure>)paymentValidResult.Errors).ConvertAll(x => x.ErrorMessage).ToArray(); MethodResult paymentFailed = MethodResult.Failed(errors); return(paymentFailed); } // Payment info and ammount are valid. // Simulate taking a payment. return(MethodResult.Success); }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList <string> ValidatePaymentForm(IFormCollection form) { if (form == null) { throw new ArgumentNullException(nameof(form)); } //validate payment info (custom validation) var validationResult = new PaymentInfoValidator(_localizationService).Validate(new PaymentInfoModel { CardholderName = form[nameof(PaymentInfoModel.CardholderName)], CardNumber = form[nameof(PaymentInfoModel.CardNumber)], ExpireMonth = form[nameof(PaymentInfoModel.ExpireMonth)], ExpireYear = form[nameof(PaymentInfoModel.ExpireYear)], CardCode = form[nameof(PaymentInfoModel.CardCode)], Installment = form[nameof(PaymentInfoModel.Installment)] }); if (!validationResult.IsValid) { return(validationResult.Errors.Select(error => error.ErrorMessage).ToList()); } return(new List <string>()); }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList <string> ValidatePaymentForm(IFormCollection form) { if (form == null) { throw new ArgumentNullException(nameof(form)); } if (_qualpaySettings.UseEmbeddedFields) { //try to get errors from Qualpay card tokenization if (form.TryGetValue(nameof(PaymentInfoModel.Errors), out var errorsString) && !StringValues.IsNullOrEmpty(errorsString)) { return(errorsString.ToString().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList()); } } else { //validate payment info (custom validation) var validationResult = new PaymentInfoValidator(_localizationService).Validate(new PaymentInfoModel { CardholderName = form[nameof(PaymentInfoModel.CardholderName)], CardNumber = form[nameof(PaymentInfoModel.CardNumber)], ExpireMonth = form[nameof(PaymentInfoModel.ExpireMonth)], ExpireYear = form[nameof(PaymentInfoModel.ExpireYear)], CardCode = form[nameof(PaymentInfoModel.CardCode)], BillingCardId = form[nameof(PaymentInfoModel.BillingCardId)], SaveCardDetails = form.TryGetValue(nameof(PaymentInfoModel.SaveCardDetails), out var saveCardDetails) && bool.TryParse(saveCardDetails.FirstOrDefault(), out var saveCard) && saveCard });
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList <string> ValidatePaymentForm(IFormCollection form) { if (form == null) { throw new ArgumentNullException(nameof(form)); } var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_braintreePaymentSettings, _localizationService); var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"], CardNonce = form["CardNonce"] }; var validationResult = validator.Validate(model); if (validationResult.IsValid) { return(warnings); } warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); return(warnings); }
public async Task <IList <string> > ValidatePaymentForm(IFormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_brainTreePaymentSettings, _localizationService); var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"], CardNonce = form["CardNonce"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { warnings.Add(error.ErrorMessage); } } return(await Task.FromResult(warnings)); }
public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { Country = form["Country"], PhoneNumber = form["PhoneNumber"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { warnings.Add(error.ErrorMessage); } } else { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var manualPaymentSettings = _settingService.LoadSetting <SendSpendPaymentSettings>(storeScope); System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (var client = new HttpClient()) { var oAuth = new Models.ApiAuthRequest { apiId = manualPaymentSettings.AppId, countryCode = model.Country, customer_fmm_UserNameOrMobileNo = model.PhoneNumber }; var content = new StringContent(JsonConvert.SerializeObject(oAuth)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (var res = client.PostAsync(String.Format("{0}api/v1/SecurePayment/Authentication", manualPaymentSettings.AppUrl), content)) { res.Wait(); if (res.Result.IsSuccessStatusCode) { var data = res.Result.Content.ReadAsStringAsync(); var ret = JsonConvert.DeserializeObject <Models.ApiResponse>(data.Result.ToString()); switch (ret.responseCode.ToUpper()) { case "APPROVED": warnings.Clear(); break; default: warnings.Add(ret.responseText); break; } } else { warnings.Add("Unable to authenticate your request, Please try again later."); } } } } return(warnings); }
public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); string aeroplanNumber = form["AeroplanNumber"]; if (!string.IsNullOrEmpty(aeroplanNumber)) { aeroplanNumber = string.Join("", aeroplanNumber.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); } string voucherNum = form["Voucher"]; if (!string.IsNullOrEmpty(voucherNum)) { voucherNum = string.Join("", voucherNum.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); } var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"], Email = form["Email"], PhoneNumber = form["PhoneNumber"], City = form["City"], ZipPostalCode = form["ZipPostalCode"], Booking = form["Booking"], NamePassport = form["NamePassport"], PassportNumber = form["PassportNumber"], Country = form["Countries"], Address1 = form["Address1"], Voucher = voucherNum }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); } return(warnings); }
public IList <string> ValidatePaymentForm(IFormCollection form) { var warnings = new List <string>(); try { //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); var validationCheck = validationResult.IsValid; if (form.Keys.Contains("ProfileID") && !String.IsNullOrEmpty(form["ProfileID"].ToString())) { validationCheck = true; } if (!validationCheck) { warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); } } catch (Exception ex) { var innerMsg = ""; if (ex.InnerException != null) { innerMsg = ex.InnerException.Message; } _logger.Error("error in ValidatePaymentForm() --- " + ex.Message + " inner exception " + innerMsg, ex, null); throw ex; } return(warnings); }
public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { EMail = form["EMail"], Phonenumber = form["Phonenumber"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); } return(warnings); }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList<string> ValidatePaymentForm(IFormCollection form) { var warnings = new List<string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); return warnings; }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList <string> ValidatePaymentForm(IFormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { Reference = 0.ToString(), Order = 0, IssuingEmail = "*****@*****.**" }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); } return(warnings); }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public IList <string> ValidatePaymentForm(IFormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel { BancoEmisorId = 0.ToString(), BancoReceptorId = 0.ToString(), Referencia = 0.ToString() }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); } return(warnings); }
public override IList<string> ValidatePaymentForm(FormCollection form) { var warnings = new List<string>(); var validator = new PaymentInfoValidator(Services.Localization); var model = new PayPalDirectPaymentInfoModel { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) { validationResult.Errors.Each(x => warnings.Add(x.ErrorMessage)); } return warnings; }
public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], }; var validationResult = validator.Validate(model); if (validationResult.IsValid) { return(warnings); } warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); return(warnings); }
public override IList<string> ValidatePaymentForm(FormCollection form) { var warnings = new List<string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"] }; var validationResult = validator.Validate(model); if (!validationResult.IsValid) foreach (var error in validationResult.Errors) warnings.Add(error.ErrorMessage); return warnings; }
public async Task <IViewComponentResult> InvokeAsync() { var model = new PaymentInfoModel(); if (_brainTreePaymentSettings.Use3DS) { var cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.ShoppingCart); if (!cart.Any()) { throw new Exception("Your cart is empty"); } //get settings var useSandBox = _brainTreePaymentSettings.UseSandBox; var merchantId = _brainTreePaymentSettings.MerchantId; var publicKey = _brainTreePaymentSettings.PublicKey; var privateKey = _brainTreePaymentSettings.PrivateKey; var gateway = new BraintreeGateway { Environment = useSandBox ? Braintree.Environment.SANDBOX : Braintree.Environment.PRODUCTION, MerchantId = merchantId, PublicKey = publicKey, PrivateKey = privateKey }; ViewBag.ClientToken = gateway.ClientToken.Generate(); ViewBag.OrderTotal = (await _orderTotalCalculationService.GetShoppingCartTotal(cart)).shoppingCartTotal; return(View("~/Plugins/Payments.BrainTree/Views/PaymentInfo_3DS.cshtml", model)); } //years for (var i = 0; i < 15; i++) { var year = Convert.ToString(DateTime.Now.Year + i); model.ExpireYears.Add(new SelectListItem { Text = year, Value = year, }); } //months for (var i = 1; i <= 12; i++) { var text = (i < 10) ? "0" + i : i.ToString(); model.ExpireMonths.Add(new SelectListItem { Text = text, Value = i.ToString(), }); } //set postback values (we cannot access "Form" with "GET" requests) if (Request.Method == WebRequestMethods.Http.Get) { return(View("~/Plugins/Payments.BrainTree/Views/PaymentInfo.cshtml", model)); } var form = await HttpContext.Request.ReadFormAsync(); model.CardholderName = form["CardholderName"]; model.CardNumber = form["CardNumber"]; model.CardCode = form["CardCode"]; var selectedMonth = model.ExpireMonths .FirstOrDefault(x => x.Value.Equals(form["ExpireMonth"], StringComparison.InvariantCultureIgnoreCase)); if (selectedMonth != null) { selectedMonth.Selected = true; } var selectedYear = model.ExpireYears .FirstOrDefault(x => x.Value.Equals(form["ExpireYear"], StringComparison.InvariantCultureIgnoreCase)); if (selectedYear != null) { selectedYear.Selected = true; } var validator = new PaymentInfoValidator(_brainTreePaymentSettings, _localizationService); var results = validator.Validate(model); if (!results.IsValid) { var query = from error in results.Errors select error.ErrorMessage; model.Errors = string.Join(", ", query); } return(View("~/Plugins/Payments.BrainTree/Views/PaymentInfo.cshtml", model)); }
/// <summary> /// Validate payment form /// </summary> /// <param name="form">The parsed form values</param> /// <returns>List of validating errors</returns> public async Task <IList <string> > ValidatePaymentFormAsync(IFormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); var model = new PaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], }; var validationResult = validator.Validate(model); warnings.AddRange(validationResult.Errors.Select(error => error.ErrorMessage)); if (warnings.Count > 0) { return(await Task.FromResult <IList <string> >(warnings)); } string url = _paramPaymentSettings.UseSandbox ? _paramPaymentSettings.TestUrl : _paramPaymentSettings.ProductUrl; string data = "" + "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + "<TP_KK_Verify xmlns=\"https://turkpos.com.tr/\">" + "<G>" + "<CLIENT_CODE>" + _paramPaymentSettings.ClientCode + "</CLIENT_CODE>" + "<CLIENT_USERNAME>" + _paramPaymentSettings.ClientUsername + "</CLIENT_USERNAME>" + "<CLIENT_PASSWORD>" + _paramPaymentSettings.ClientPassword + "</CLIENT_PASSWORD>" + "</G>" + "<KK_No>" + form["CardNumber"] + "</KK_No>" + "<KK_SK_Ay>" + form["ExpireMonth"] + "</KK_SK_Ay>" + "<KK_SK_Yil>" + form["ExpireYear"] + "</KK_SK_Yil>" + "<KK_CVC>" + form["CardCode"] + "</KK_CVC>" + "<Return_URL></Return_URL>" + "<Data1></Data1>" + "<Data2></Data2>" + "<Data3></Data3>" + "<Data4></Data4>" + "<Data5></Data5>" + "</TP_KK_Verify>" + "</soap:Body>" + "</soap:Envelope>"; byte[] buffer = Encoding.ASCII.GetBytes(data); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; request.ContentType = "text/xml; charset=\"utf-8\""; request.ContentLength = buffer.Length; request.Headers.Add("SOAPAction", "https://turkpos.com.tr/TP_KK_Verify"); Stream post = request.GetRequestStream(); post.Write(buffer, 0, buffer.Length); post.Close(); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseData = response.GetResponseStream(); StreamReader responseReader = new StreamReader(responseData); string responseResult = responseReader.ReadToEnd(); responseResult = responseResult.Replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", ""); responseResult = responseResult.Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); responseResult = responseResult.Replace(" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"", ""); responseResult = responseResult.Replace("soap:", "").Replace(":soap", ""); responseResult = responseResult.Replace(" xmlns=\"https://turkpos.com.tr/\"", ""); responseResult = responseResult.Replace("<Body>", "").Replace("</Body>", ""); responseResult = responseResult.Replace("<Envelope>", "<root>").Replace("</Envelope>", "</root>"); XDocument xdoc = XDocument.Parse(responseResult); string islem_ID = xdoc.Descendants("Islem_ID").FirstOrDefault().Value; string uCD_URL = xdoc.Descendants("UCD_URL").FirstOrDefault().Value; string sonuc_Str = xdoc.Descendants("Sonuc_Str").FirstOrDefault().Value; string banka_Sonuc_Kod = xdoc.Descendants("Banka_Sonuc_Kod").FirstOrDefault().Value; if (islem_ID == "0" && sonuc_Str != "") { warnings.Add(sonuc_Str); } return(await Task.FromResult <IList <string> >(warnings)); }
public override IList <string> ValidatePaymentForm(FormCollection form) { var warnings = new List <string>(); //validate var validator = new PaymentInfoValidator(_localizationService); string aeroplanNumber = form["AeroplanNumber"]; if (!string.IsNullOrEmpty(aeroplanNumber)) { aeroplanNumber = string.Join("", aeroplanNumber.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); } string voucherNum = form["Voucher"]; if (!string.IsNullOrEmpty(voucherNum)) { voucherNum = string.Join("", voucherNum.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); } var model = new PaymentInfoModel() { CardholderName = form["CardholderName"], CardNumber = form["CardNumber"], CardCode = form["CardCode"], ExpireMonth = form["ExpireMonth"], ExpireYear = form["ExpireYear"], Email = form["Email"], PhoneNumber = form["PhoneNumber"], City = form["City"], ZipPostalCode = form["ZipPostalCode"], Booking = form["Booking"], NamePassport = form["NamePassport"], PassportNumber = form["PassportNumber"], AeroplanNumber = aeroplanNumber, Voucher = voucherNum }; var validationResult = validator.Validate(model); FluentValidation.Results.ValidationFailure Invalid = null; if (!String.IsNullOrEmpty(voucherNum)) { Voucher voucher = _discountService.GetVoucherByNum(voucherNum); if (voucher == null) { Invalid = new FluentValidation.Results.ValidationFailure("Voucher", _localizationService.GetResource("Payment.Voucher.Invalid")); } else { if (voucher.IsUse) { Invalid = new FluentValidation.Results.ValidationFailure("Voucher", _localizationService.GetResource("Payment.Voucher.Used")); } } } if (Invalid != null) { validationResult.Errors.Add(Invalid); } //validationResult.Errors.Add(test) if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { warnings.Add(error.ErrorMessage); } } return(warnings); }