public static string Dump(ProductBdo p) { // TODO: reflection StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0,-16}: `{1}`", "ID", p.Id).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PaySystemUid", p.PaySystemUid).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosUserUid", p.PosUserUid).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ProductUid", p.ProductUid).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ProductName", p.ProductName).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ProductPrice", p.ProductPrice).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "CurrencyCode", p.CurrencyCode).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ProductDescription", p.ProductDescription).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "Remarks", p.Remarks).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "CustomerName", p.CustomerName).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "CustomerEmail", p.CustomerEmail).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "CustomerPhone", p.CustomerPhone).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosId", p.PosId).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosName", p.PosName).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosAddress", p.PosAddress).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosCity", p.PosCity).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PosUrl", p.PosUrl).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ValidFrom", p.ValidFrom).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "ValidTill", p.ValidTill).AppendLine(); sb.AppendFormat("{0,-16}: `{1}`", "PaymentSystem", p.PaymentSystem).AppendLine(); return(sb.ToString()); }
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 void EnsureProductIsValid(ProductBdo p) { if (p.ValidTill < DateTime.UtcNow) { throw new InvalidProductException("Product is expired", InvalidProductException.Reasons.ProductExpired); } }
public string FormatClientEmail(ProductBdo product) { StringBuilder sb = new StringBuilder(@"Mielas kliente! Jūs įsigijote kuponą www.ritosmasazai.lt %CustomerName% %ProductName% %ProductDuration% %ProductPrice% %CurrencyCode% Privalote užsiregistruoti telefonu: 8652 98422 Salonas: %PosName% %PosAddress%, %PosCity% * Kuponas galioja iki %ValidTill% <a href=""http://www.dovanukuponai.com/gift/get/%PaySystemUid%"">Daugiau informacijos</a> Ačiū, kad pirkote!"); sb.Replace("%CustomerName%", product.CustomerName); sb.Replace("%ProductName%", product.ProductName); //sb.Replace("%ProductDuration%", product.Du); sb.Replace("%ProductPrice%", product.ProductPrice.ToString("### ##0.00")); sb.Replace("%CurrencyCode%", product.CurrencyCode); sb.Replace("%PosName%", product.PosName); sb.Replace("%PosAddress%", product.PosAddress); sb.Replace("%PosCity%", product.PosCity); //sb.Replace("%ProductUid%", product.ProductUid); sb.Replace("%PaySystemUid%", product.PaySystemUid); sb.Replace("%ValidTill%", product.ValidTill.ToShortDateString()); sb.Replace(Environment.NewLine, "<br />"); return(sb.ToString()); }
public TransactionBdo StartTransaction(string posUserUid, ProductBdo product) { var t = new TransactionBdo(); t.IsTestPayment = _configurationBll.Get().UseTestPayment; t.PosUserUid = posUserUid; t.PaySystemUid = product.PaySystemUid; t.PaymentStatus = PaymentStatusIds.NotProcessed; t.IsPaymentProcessed = false; t.PosId = product.PosId; t.CreatedAt = DateTime.UtcNow; t.ProductUid = product.ProductUid; t.RequestedAmount = product.ProductPrice; t.RequestedCurrencyCode = product.CurrencyCode; // TODO: add project ID t.ProjectId = 0; t.OrderNr = BllFactory.Current.GiftsBll.GetUniqueOrderId(t.PosId); Logger.DebugFormat(" generate unique order nr for new transaction: `{0}`", t.OrderNr); _transactionDal.StartTransaction(t); return(t); }
public void SendEmailToClientOnSuccess(ProductBdo product) { try { Logger.Info("Sending email to client on success payment"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("*****@*****.**", "Ritos Masazai"); mailMessage.To.Add(new MailAddress(product.CustomerEmail, product.CustomerName)); //mailMessage.To.Add(new MailAddress("*****@*****.**")); mailMessage.Bcc.Add(new MailAddress("*****@*****.**")); mailMessage.Subject = "RitosMasazai.lt - Kuponas " + product.ProductName; mailMessage.Body = FormatClientEmail(product); mailMessage.IsBodyHtml = true; SmtpClient client = new SmtpClient("mail.dovanukuponai.com"); client.EnableSsl = false; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential("*****@*****.**", "7sSVYyT_8Wpz"); client.Send(mailMessage); } catch (Exception ex) { Logger.Error("Error sending e-mail to client on success payment", ex); throw; } }
public ProductBdo GetProductByUid(string productUid) { Logger.InfoFormat("Searching product information by UID: `{0}`", productUid); ProductBdo product = null; product p = null; try { using (var db = new GiftServiceEntities()) { p = db.products.First(x => x.product_uid.Equals(productUid, StringComparison.OrdinalIgnoreCase)); } if (p != null) { product = new ProductBdo { Id = p.id, ProductUid = p.product_uid, PosUserUid = p.pos_user_uid, PaySystemUid = p.pay_system_uid, ProductName = p.product_name, ProductDescription = p.product_description, ProductPrice = p.product_price, CurrencyCode = p.currency_code, CustomerName = p.customer_name, CustomerEmail = p.customer_email, CustomerPhone = p.customer_phone, Remarks = p.remarks, ValidFrom = p.valid_from.HasValue ? p.valid_from.Value : DateTime.MinValue, ValidTill = p.valid_till.HasValue ? p.valid_till.Value : DateTime.MinValue, PosId = p.pos_id, PosName = p.pos_name, PosCity = p.pos_city, PosAddress = p.pos_address, PosUrl = p.pos_url, EmailForReservation = p.email_reservation, PhoneForReservation = p.phone_reservation, EmailForGift = p.gift_email, TextForGift = p.gift_text }; } return(product); } catch (Exception ex) { Logger.Error("Error searching product by UID: " + productUid, ex); throw; } }
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 Bitmap GetProductStatusQr(ProductBdo product, int pixelsPerModule, string webCultureName) { BllFactory.Current.SecurityBll.ValidateUid(product.ProductUid); string url = String.Concat(GetFullUrl(webCultureName), "check/", product.ProductUid); var qrData = new QRCodeGenerator().CreateQrCode(url, QRCodeGenerator.ECCLevel.H); var qrCode = new QRCode(qrData); return(qrCode.GetGraphic(pixelsPerModule)); }
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 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() { _configurationBllMock = new Mock <IConfigurationBll>(); _configurationBllMock.Setup(x => x.Get()) .Returns(() => new MySettings { UseTestPayment = true }); _transactionDal = new Mock <ITransactionDal>(); _bll = new TransactionsBll(_configurationBllMock.Object, BllFactory.Current.SecurityBll, _transactionDal.Object); _product = new ProductBdo(); _product.PosId = 1005; }
public ProductBdo GetProductByPaySystemUid(string paySystemUid) { ProductBdo product = null; product productDao = null; Logger.InfoFormat("Searching for product information by payment system UID: `{0}`", paySystemUid); using (var db = new GiftServiceEntities()) { productDao = db.products.First(x => paySystemUid.Equals(x.pay_system_uid, StringComparison.OrdinalIgnoreCase)); } if (productDao != null) { product = new ProductBdo { Id = productDao.id, ProductUid = productDao.product_uid, PosUserUid = productDao.pos_user_uid, PaySystemUid = productDao.pay_system_uid, ProductName = productDao.product_name, ProductDescription = productDao.product_description, ProductDuration = productDao.product_duration, ProductPrice = productDao.product_price, CurrencyCode = productDao.currency_code, CustomerName = productDao.customer_name, CustomerEmail = productDao.customer_email, CustomerPhone = productDao.customer_phone, Remarks = productDao.remarks, ValidFrom = productDao.valid_from.HasValue ? productDao.valid_from.Value : DateTime.MinValue, ValidTill = productDao.valid_till.HasValue ? productDao.valid_till.Value : DateTime.MinValue, PosId = productDao.pos_id, PosName = productDao.pos_name, PosCity = productDao.pos_city, PosAddress = productDao.pos_address, PosUrl = productDao.pos_url, EmailForReservation = productDao.email_reservation, PhoneForReservation = productDao.phone_reservation }; } Logger.DebugFormat(" set product duration (from DB) to: `{0}`", product.ProductDuration); return(product); }
public void MakeProductGift(ProductBdo product, string friendEmail, string text) { using (var db = new GiftServiceEntities()) { var p = db.products.First(x => x.product_uid == product.ProductUid); if (String.IsNullOrEmpty(p.gift_email) == false) { // Throw exception if product was sent to other e-mail if (p.gift_email.Equals(friendEmail, StringComparison.OrdinalIgnoreCase) == false) { throw new Models.Exceptions.InvalidProductException(String.Concat("Product was sent to other e-mail: ", p.gift_email), Models.Exceptions.InvalidProductException.Reasons.ProductIsGiftAlready); } } p.gift_email = friendEmail; p.gift_text = text; db.SaveChanges(); } }
public void MakeProductGift(ProductBdo product, string friendEmail, string text) { throw new NotImplementedException(); }
public ProductBdo SaveProductInformationFromPos(ProductBdo product, PosBdo pos) { throw new NotImplementedException(); }
private void FillContent(Document doc, ProductBdo product, TransactionBdo transaction, bool asGift) { if (asGift) { var pMessage = doc.LastSection.AddParagraph(); pMessage.Format.SpaceBefore = "8cm"; pMessage.Format.SpaceAfter = "1cm"; pMessage.Format.Font.Size = 14; pMessage.Format.Font.Bold = false; pMessage.Format.Font.Italic = true; pMessage.Format.Alignment = ParagraphAlignment.Center; pMessage.AddText(product.TextForGift); //pMessage.AddText("Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. Kazkos ilgas tekstas su sveikinimu ir t.t.t.t.t.t. "); } var p = doc.LastSection.AddParagraph(); if (asGift) { p.Format.SpaceBefore = "1cm"; p.Format.SpaceAfter = "0cm"; } else { p.Format.SpaceBefore = "8cm"; p.Format.SpaceAfter = "1cm"; } //p.Format.SpaceBefore = asGift ? "1cm" : "8cm"; //p.Format.SpaceAfter = "1cm"; p.Format.Font.Size = 14; p.Format.Font.Bold = true; p.Format.Alignment = ParagraphAlignment.Center; p.AddText(product.ProductName); var t = doc.LastSection.AddTable(); t.BottomPadding = "0.5cm"; t.Format.Alignment = ParagraphAlignment.Center; t.Borders.DistanceFromLeft = "2cm"; // Before you can add a row, you must define the columns Column column = t.AddColumn("10cm"); column.Format.Alignment = ParagraphAlignment.Left; column = t.AddColumn("7cm"); column.Format.Alignment = ParagraphAlignment.Left; Row r = t.AddRow(); if (asGift == false) { //r.Cells[0].AddParagraph(product.CustomerName); //r.Cells[0].AddParagraph("Jus gavote dovana"); r.Cells[0].AddParagraph("Pirkėjas:") .Format.Font.Bold = true; // TODO: Extract info from payment or make custome name mandatory field if (String.IsNullOrEmpty(product.CustomerName)) { r.Cells[0].AddParagraph("-"); } else { r.Cells[0].AddParagraph(product.CustomerName); } r.Cells[1].AddParagraph("Kaina:") .Format.Font.Bold = true; r.Cells[1].AddParagraph(String.Concat(product.ProductPrice.ToString("### ##0.00"), " ", product.CurrencyCode)); } //r = t.AddRow(); //r.Cells[0].AddParagraph("Privalote užsiregistruoti:") // .Format.Font.Bold = true; //r.Cells[0].AddParagraph(product.PhoneForReservation); //if (String.IsNullOrEmpty(product.ProductDuration) == false) //{ // r.Cells[1].AddParagraph("Trukme:") // .Format.Font.Bold = true; // r.Cells[1].AddParagraph(product.ProductDuration); //} r = t.AddRow(); r.Cells[0].AddParagraph("Aptarnavimo vieta:") .Format.Font.Bold = true; r.Cells[0].AddParagraph(product.PosName); r.Cells[0].AddParagraph(product.PosAddress); r.Cells[0].AddParagraph(product.PosCity); r.Cells[1].AddParagraph("Privalote užsiregistruoti:") .Format.Font.Bold = true; r.Cells[1].AddParagraph(product.PhoneForReservation); if (String.IsNullOrEmpty(product.ProductDuration) == false) { r.Cells[1].AddParagraph("Trukme:") .Format = new ParagraphFormat { SpaceBefore = "0.5cm", Font = new Font { Bold = true } }; r.Cells[1].AddParagraph(product.ProductDuration); } //r.Cells[1].AddParagraph("Kuponas galioja:") // .Format.Font.Bold = true; //r.Cells[1].AddParagraph(product.ValidTill.ToShortDateString()) // .Format.Font.Color = Colors.Red; var orderTable = doc.LastSection.AddTable(); orderTable.Borders.DistanceFromLeft = "2cm"; column = orderTable.AddColumn("10cm"); column.Format.Alignment = ParagraphAlignment.Left; //column = orderTable.AddColumn("3cm"); //column.Format.Alignment = ParagraphAlignment.Left; column = orderTable.AddColumn("7cm"); column.Format.Alignment = ParagraphAlignment.Left; r = orderTable.AddRow(); r.Cells[0].AddParagraph("Kupono numeris:") .Format.Font.Bold = true; r.Cells[0].AddParagraph(transaction.OrderNr.ToUpper()) .Format.Font = new Font { Size = 13, Color = Colors.Red }; r.Cells[1].AddParagraph("Kuponas galioja:") .Format.Font.Bold = true; r.Cells[1].AddParagraph(product.ValidTill.ToShortDateString()) .Format.Font = new Font { Size = 13, Color = Colors.Red }; //r.Cells[1].AddImage("c:\\temp\\qr1.png"); var desription = doc.LastSection.AddParagraph(); desription.Format.SpaceBefore = "1cm"; desription.Format.Alignment = ParagraphAlignment.Justify; desription.Format.Font.Size = 10; desription.AddText(product.ProductDescription); }
public void Test_Error_On_Null_ProductName() { ProductBdo p = new ProductBdo(); _posBll.FormatNoteForPayment(null, p, 250); }
public void Test_Error_On_No_Product_Formatting_PaymentNote() { ProductBdo p = null; _posBll.FormatNoteForPayment(null, p, 250); }
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 void Exception_On_Incorrect_Product_Uid() { var p = new ProductBdo(); _bll.GetProductStatusQr(p, 10, "lt"); }