// GET: /Payment/Cancel public ActionResult Cancel() { PosBdo pos = null; try { Logger.Info("Got response from payment system to cancel transaction (by user)"); //string paySystemUid = Session["__PaySystemUid"] as string; Logger.InfoFormat(" Payment Order nr in session is `{0}`", SessionStore.PaymentOrderNr); //var responseFromPaysera = Factory.PayseraBll.ParseData(Request["data"]); //var t = Factory.TransactionsBll.CancelTransactionByUser(paySystemUid); var t = Factory.TransactionsBll.CancelTransactionByUserUsingOrderNr(SessionStore.PaymentOrderNr); // Try to get POS information if (SessionStore.PosId > 0) { pos = Factory.PosBll.GetById(SessionStore.PosId); } } catch (Exception ex) { Logger.Error("Error canceling transaction", ex); } return View("Cancel", GetLayoutForPos(), pos); }
public void ValidateCurrencyCode(string currencyCode, PosBdo pos) { if (String.IsNullOrEmpty(currencyCode)) { throw new IncorrectPaymentParamersException("Payment request must specify currency code"); } }
public string FormatNoteForPayment(PosBdo pos, ProductBdo product, int maxLength) { if (product == null) { throw new ArgumentNullException("product"); } if (String.IsNullOrEmpty(product.ProductName)) { throw new ArgumentNullException("ProductName"); } StringBuilder sb = new StringBuilder(); sb.Append(pos.Name).Append(" - "); string noteEnd = ". Jusu uzsakymas http://www.dovanukuponai.com/gift/get/[order_nr]. Dekuoju, [owner_name]"; int availableLen = maxLength - sb.Length - noteEnd.Length; if (availableLen < 1) { return(noteEnd); } sb.Append(product.ProductName.Length > availableLen ? product.ProductName.Substring(0, availableLen) : product.ProductName); sb.Append(noteEnd); //string shortProductName = posResponse.ProductName.Length > 90 ? posResponse.ProductName.Substring(0, 90) : posResponse.ProductName; //rq.PayText = String.Concat("RitosMasazai.lt - ", shortProductName, ". Jusu uzsakymas http://www.dovanukuponai.com/gift/get/[order_nr]. Dekoju, [owner_name]"); return(sb.ToString()); }
public PosDal() { PosBdo p = new PosBdo(); p.Id = 1005; p.Name = "Ritos Masažai"; p.Description = "Rankos, suteikiančios pagalbą, švelnesnės negu besimeldžiančios lūpos"; p.PayseraPayerId = "76457"; p.PayseraPassword = "******"; p.PosUrl = new Uri("http://www.ritosmasazai.lt/"); //p.ValidateUrl = new Uri("http://localhost:56620/Test/Validate"); p.ValidateUrl = new Uri("http://www.ritosmasazai.lt/test.php/lt/price/info/posUid/"); p.IsTest = false; p.UseTestPayment = false; _poses.Add(p); p = new PosBdo(); p.Id = 6666; p.Name = "Test LocalShop"; p.Description = "Just testing shop"; p.PosUrl = new Uri("http://localhost:56620/"); p.ValidateUrl = new Uri("http://localhost:56620/Test/Validate"); //p.ValidateUrl = new Uri("http://www.ritosmasazai.lt/lt/price/info/posUid/"); p.IsTest = true; p.UseTestPayment = true; _poses.Add(p); p = new PosBdo(); p.Id = 1006; p.Name = "Knygynai.lt"; p.Description = "Knygų ir knygynų paieška"; p.PayseraPayerId = "80213"; p.PayseraPassword = "******"; p.PosUrl = new Uri("http://knygynai.lt/"); //p.ValidateUrl = new Uri("http://localhost:8079/gspclient/gsinfo.php?posUid="); p.ValidateUrl = new Uri("http://knygynai.lt/gsinfo.php?posUid="); p.IsTest = false; p.UseTestPayment = false; _poses.Add(p); p = new PosBdo(); p.Id = 1007; p.Name = "Melisanda.lt"; p.Description = "Sveikatos ir Grožio Išsaugojimo Centras \"Melisanda\""; p.PayseraPayerId = "82190"; p.PayseraPassword = "******"; //p.PayseraPayerId = "80213"; //p.PayseraPassword = "******"; p.PosUrl = new Uri("http://www.melisanda.lt/"); //p.ValidateUrl = new Uri("http://localhost:8079/gspclient/gsinfo.php?posUid="); p.ValidateUrl = new Uri("http://www.melisanda.lt/lt/price/info/posUid/"); p.IsTest = false; p.UseTestPayment = false; _poses.Add(p); }
public void Test_Form_PaymentNote_Is_Not_Empty() { PosBdo pos = new PosBdo(); ProductBdo product = new ProductBdo { ProductName = "Product" }; string note = _posBll.FormatNoteForPayment(pos, product, 250); Assert.IsFalse(String.IsNullOrEmpty(note)); }
public void Test_PaymentNote_Must_Contain_OrderNr() { PosBdo pos = new PosBdo(); ProductBdo product = new ProductBdo { ProductName = "Product" }; string note = _posBll.FormatNoteForPayment(pos, product, 250); Assert.IsTrue(note.IndexOf("[order_nr]") >= 0); }
public PaymentRequestValidationResponse ValidatePosPaymentRequest(PosBdo pos, string posUserUid) { if (pos.ValidateUrl == null) { throw new ArgumentNullException("POS does not have ValidateUrl to validate request from it"); } PaymentRequestValidationResponse response = null; try { //var validationUri = new Uri(pos.ValidateUrl.ToString() + posUserUid); string url = pos.ValidateUrl.ToString(); url = url.EndsWith("/") || url.EndsWith("=") ? String.Concat(url, posUserUid) : String.Concat(url, "/", posUserUid); var validationUri = new Uri(url); Logger.InfoFormat("Validating request payment from POS: `{0}`", validationUri.ToString()); response = _communicationBll.GetJsonResponse <PaymentRequestValidationResponse>(validationUri); if (response == null) { throw new BadResponseException("Got NULL response from POS on request validation"); } if (response.RequestedAmountMinor < 1) { throw new IncorrectPaymentParamersException("Payment request amount (minor) should be greater than 0"); } if (String.IsNullOrEmpty(response.ProductName)) { throw new IncorrectPaymentParamersException("Payment request must specify product name"); } ValidateCurrencyCode(response.CurrencyCode, pos); // model.Locations = posResponse.Locations ?? new List<ProductServiceLocation>(); foreach (var l in response.Locations) { if (String.IsNullOrEmpty(l.LatLng) == false) { l.LatLngCoordinates = BllFactory.Current.HelperBll.ParseLatLng(l.LatLng, MapTypes.GoogleMap); } } return(response); } catch (InvalidCastException icex) { throw; } catch (Exception ex) { throw; } }
public ProductBdo SaveProductInformationFromPos(string posUserUid, PaymentRequestValidationResponse posResponse, ProductCheckoutModel checkout) { if (posResponse == null) { throw new ArgumentNullException("Response from POS is NULL"); } ProductBdo product = new ProductBdo(); PosBdo pos = new PosBdo(); // TODO: use automapper Mapper.CreateMap <PaymentRequestValidationResponse, ProductBdo>() .ForMember(dest => dest.ProductPrice, orig => orig.MapFrom(x => x.RequestedAmountMinor / 100m)) .ForMember(dest => dest.ValidTill, orig => orig.MapFrom(x => BllFactory.Current.HelperBll.ConvertFromUnixTimestamp(x.ProductValidTillTm))); product = Mapper.Map <ProductBdo>(posResponse); if (checkout.LocationId > 0) { var location = posResponse.Locations.FirstOrDefault(x => x.Id == checkout.LocationId); if (location == null) { throw new ArgumentOutOfRangeException("LocationId", "Incorrect POS service location!"); } product.PosName = location.Name; product.PosCity = location.City; product.PosAddress = location.Address; product.PhoneForReservation = location.PhoneReservation; product.EmailForReservation = location.EmailReservation; } product.CustomerName = checkout.CustomerName; product.CustomerEmail = checkout.CustomerEmail; product.CustomerPhone = checkout.CustomerPhone; product.Remarks = checkout.Remarks; product.PaymentSystem = checkout.PaymentSystem; product.ProductUid = Guid.NewGuid().ToString("N"); product.PosUserUid = posUserUid; product.PaySystemUid = Guid.NewGuid().ToString("N"); Logger.Debug("Saving product information from POS and customer form"); Logger.DebugFormat(" Pass product duration to save: `{0}`", product.ProductDuration); Logger.Debug(DumpBll.Dump(product)); return(_productsDal.SaveProductInformationFromPos(product, pos)); }
public void Test_PaymentNote_Contains_Pos_Name() { PosBdo pos = new PosBdo { Name = "MyShop" }; ProductBdo product = new ProductBdo { ProductName = "Product" }; string note = _posBll.FormatNoteForPayment(pos, product, 250); Assert.IsTrue(note.IndexOf(pos.Name) >= 0); }
public void Test_Extremely_Long_Name_For_PaymentNote() { PosBdo pos = new PosBdo { Id = 1005, Name = "My super-puper online e-Shop" }; ProductBdo product = new ProductBdo { ProductName = "product very long-long-long-long-long name" }; int maxLength = pos.Name.Length + product.ProductName.Length; // Check no exception string note = _posBll.FormatNoteForPayment(pos, product, maxLength); }
public void Test_PaymentNote_Must_Contains_OwnerName() { PosBdo pos = new PosBdo { Id = 1005, Name = "MyShop" }; ProductBdo product = new ProductBdo { ProductName = "Product" }; string note = _posBll.FormatNoteForPayment(pos, product, 250); Assert.IsTrue(note.IndexOf("[owner_name]") > 0); }
public void Test_PaymentNote_Does_Not_Exceed_MaxLength() { int maxLength = 120; PosBdo pos = new PosBdo { Id = 1005, Name = "My super-puper online e-Shop" }; ProductBdo product = new ProductBdo { ProductName = "product very long-long-long name" }; string note = _posBll.FormatNoteForPayment(pos, product, maxLength); Assert.IsTrue(note.Length <= maxLength); }
public void Init() { _pos = new PosBdo(); _pos.Id = 1005; _pos.Name = "Ritos Masazai"; _pos.PosUrl = new Uri("http://www.ritosmasazai.lt/"); _pos.ValidateUrl = new Uri("http://localhost:56620/Test/Validate"); _communicationBllMock.Setup(x => x.GetJsonResponse <BaseResponse>(It.IsAny <Uri>())).Returns(new BaseResponse { Status = true, Message = "Faked OK message" }); _configBllMock = new Mock <IConfigurationBll>(); _configBllMock.Setup(x => x.Get()) .Returns(() => new MySettings { LengthOfPosUid = 32 }); _securityBll = new SecurityBll(_configBllMock.Object, _communicationBllMock.Object); }
public TestController() { var pos = new PosBdo(); pos.Id = 6666; pos.Name = "Test shop"; string uid; if (_products == null) { _products = new List <ProductBdo>(); uid = Factory.HelperBll.GenerateProductUid(pos.Id); _products.Add(new ProductBdo { ProductUid = uid, Id = 666001, ProductName = "Test product #1", ProductPrice = 666.01m, PosId = pos.Id, PosName = pos.Name }); uid = Factory.HelperBll.GenerateProductUid(pos.Id); _products.Add(new ProductBdo { ProductUid = uid, Id = 666001, ProductName = "Test product #2", ProductPrice = 666.22m, PosId = pos.Id, PosName = pos.Name }); } }
public ProductBdo SaveProductInformationFromPos(ProductBdo product, PosBdo pos) { var p = new product(); try { //AutoMapperConfigDal.SetMappingTypeFromBdoToDao(); //p = Mapper.Map<product>(product); p.pos_user_uid = product.PosUserUid; p.pay_system_uid = product.PaySystemUid; p.product_uid = product.ProductUid; p.product_name = product.ProductName; p.product_description = product.ProductDescription; p.product_duration = product.ProductDuration; Logger.DebugFormat(" setting product_duration to: `{0}`", p.product_duration); p.product_price = product.ProductPrice; p.currency_code = product.CurrencyCode; p.customer_name = product.CustomerName; p.customer_phone = product.CustomerPhone; p.customer_email = product.CustomerEmail; p.remarks = product.Remarks; p.email_reservation = product.EmailForReservation; p.phone_reservation = product.PhoneForReservation; p.pos_id = product.PosId; p.pos_name = product.PosName; p.pos_address = product.PosAddress; p.pos_city = product.PosCity; p.valid_from = product.ValidFrom; p.valid_till = product.ValidTill; Logger.Info("Saving product:"); Logger.DebugFormat(" pos_user_uid: `{0}`", p.pos_user_uid); Logger.DebugFormat(" pay_system_uid: `{0}`", p.pay_system_uid); Logger.DebugFormat(" product_uid: `{0}`", p.product_uid); Logger.DebugFormat(" product_name: `{0}`", p.product_name); Logger.DebugFormat(" product_description: `{0}`", p.product_description); Logger.DebugFormat(" product_duration: `{0}`", p.product_duration); Logger.DebugFormat(" product_price: `{0}`", p.product_price); Logger.DebugFormat(" currency_code: `{0}`", p.currency_code); Logger.DebugFormat(" customer_name: `{0}`", p.customer_name); Logger.DebugFormat(" customer_phone: `{0}`", p.customer_phone); Logger.DebugFormat(" customer_email: `{0}`", p.customer_email); Logger.DebugFormat(" remarks: `{0}`", p.remarks); Logger.DebugFormat(" email_reservation: `{0}`", p.email_reservation); Logger.DebugFormat(" phone_reservation: `{0}`", p.phone_reservation); Logger.DebugFormat(" pos_id: `{0}`", p.pos_id); Logger.DebugFormat(" pos_name: `{0}`", p.pos_name); Logger.DebugFormat(" pos_city: `{0}`", p.pos_city); Logger.DebugFormat(" pos_address: `{0}`", p.pos_address); Logger.DebugFormat(" valid_from: `{0}`", p.valid_from); Logger.DebugFormat(" valid_till: `{0}`", p.valid_till); //Logger.DebugFormat(" PaymentSystem: `{0}`", p.Pay); using (var db = new GiftServiceEntities()) { db.products.Add(p); db.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbvex) { Logger.Error("Validation error saving product", dbvex); foreach (var e in dbvex.EntityValidationErrors) { foreach (var sub in e.ValidationErrors) { Logger.ErrorFormat(" {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage); } } throw; } return(product); }
public ProductBdo SaveProductInformationFromPos(ProductBdo product, PosBdo pos) { throw new NotImplementedException(); }
// GET: /Payment/Make/UniquePaymentId public ActionResult Make(string id) { try { StringBuilder sb = new StringBuilder(); sb.AppendLine("Got request to make payment"); sb.AppendFormat(" POS URL: {0}", Request.UserHostAddress).AppendLine(); sb.AppendFormat(" UID from POS: `{0}`", id); Logger.Info(sb.ToString()); int posId = Factory.PosBll.GetPosIdFromUid(id); PosBdo pos = Factory.PosBll.GetById(posId); var posResponse = Factory.SecurityBll.ValidatePosPaymentRequest(pos, id); posResponse.PosId = pos.Id; SessionStore.PosId = pos.Id; if (posResponse.Status != true) { Logger.ErrorFormat("POS returns false on request. " + posResponse.Message); throw new BadResponseException(posResponse.Message); } this.Session["__Product"] = posResponse; ProductCheckoutModel model = new ProductCheckoutModel(); Mapper.CreateMap<PaymentRequestValidationResponse, ProductCheckoutModel>(); model = Mapper.Map<ProductCheckoutModel>(posResponse); model.PosUserUid = id; //model.ProductName = posResponse.ProductName; model.ProductDuration = posResponse.ProductDuration; model.ProductValidTill = Factory.HelperBll.ConvertFromUnixTimestamp(posResponse.ProductValidTillTm); model.RequestedAmount = posResponse.RequestedAmountMinor / 100m; //model.CurrencyCode = posResponse.CurrencyCode; //model.Locations = posResponse.Locations ?? new List<ProductServiceLocation>(); foreach (var l in model.Locations) { l.LatLngCoordinates.LatLngString = Factory.HelperBll.GetLatLngString(l.LatLngCoordinates, MapTypes.YandexMap); } return View("Checkout", GetLayoutForPos(posId), model); } catch (IncorrectPaymentParamersException ippex) { Logger.Error("Incorrect price of product (less than 0)", ippex); return Incorrect(Resources.Language.Payment_Make_Error_IncorrectPriceFromRequest); } catch (System.Net.WebException wex) { Logger.Error("Probably, there is no connection with POS", wex); //throw; return Incorrect(); } catch (Newtonsoft.Json.JsonReaderException jre) { Logger.Error("Incorrect JSON response from POS", jre); return Incorrect(); } catch (Exception ex) { Logger.Error("Error validating payment request from POS", ex); //return new RedirectResult(Url.Action("Error")); return Incorrect(); } }