public Order UpdateDiscount(Order order,Contact contact) { if (order.NumberOfItems >= _qty) { decimal discountTotal = 0; //loops through each item, to match functionality in current //Publications database foreach (OrderLine item in order.CurrentOrderLines) { decimal discountOnRow = Decimal.Round( Decimal.Multiply((Decimal.Divide(_perCent, Convert.ToDecimal(100))), (Convert.ToDecimal(item.PaymentLineTotal))), 2); order.CurrentOrderLines.First(x => x.OrderLineId == item.OrderLineId).LineDiscount = discountOnRow; discountTotal = Decimal.Round(Decimal.Add(discountTotal, discountOnRow), 2); } order.DiscountTotal = discountTotal; order.DiscountInfo = "Since twenty or more items are ordered, a 10% discount is applied."; } else { order.DiscountTotal = 0; order.DiscountInfo = "No discount has been applied on this order. If you order twenty or more items, a 10% discount is applied."; } return order; }
public Order PerformAdditionalProcessing(Order order, Domain.Contacts.Contact contact) { var affiliateUrl = new StringBuilder(); affiliateUrl.AppendFormat("https://scripts.affiliatefuture.com/AFSaleNoCookie.asp?orderID={0}&orderValue={1}&merchant=6202&programmeID=17173&bannerID=0&affiliateSiteID={2}&ref=&payoutCodes=&offlineCode=&r=&img=0", order.OrderId, order.ProductSubTotal,contact.ReferrerId); WebRequest webRequest = WebRequest.Create(affiliateUrl.ToString()); WebResponse webResp = webRequest.GetResponse(); return order; }
public void AddPercentageVoucher() { Order order=new Order{ VoucherPercentage = 10, VoucherId=1 }; List<OrderLine> orderLines = new List<OrderLine>(); orderLines.Add(new OrderLine{ Quantity=1, PaymentAmount=10 }); order.OrderLines = orderLines; Assert.IsTrue(order.GetVoucherTotal()==1); Debug.WriteLine(order.GetVoucherDetail().Detail); }
public void AddProductToOrder() { Order order = new Order(); Product product = new Product {Title = "Test Product",ProductId=1,Price=50}; var orderOperationStatus=order.Add(product, 2, "F", 50); Assert.IsTrue(orderOperationStatus.Status); Assert.IsTrue(order.NumberOfItems == 2); Assert.IsTrue(order.ContainsProduct(product)); Assert.IsTrue(order.PaymentTotal==100); }
public void AddPerItemVoucherWithProductCategoryFilter() { Order order = new Order { VoucherPerItemAmount = 1, VoucherProductCategoryFilter = "TEST1", VoucherId = 1 }; List<OrderLine> orderLines = new List<OrderLine>(); orderLines.Add(new OrderLine { ProductCategory = "TEST1CATEGORY", Quantity = 1, PaymentAmount = 10, ProductTitle = "Test Product 1 for Voucher" }); orderLines.Add(new OrderLine { ProductCategory = "TEST2CATEGORY", Quantity = 1, PaymentAmount = 10, ProductTitle = "Test Product 2 for Voucher" }); order.OrderLines = orderLines; Assert.IsTrue(order.GetVoucherTotal() == 1); Debug.WriteLine(order.GetVoucherDetail().Detail); }
public void AddPerItemVoucherWithMiniumPayment() { Order order = new Order { VoucherPerItemAmount = 1, VoucherMinimumPayment=25, VoucherId = 1 }; List<OrderLine> orderLines = new List<OrderLine>(); orderLines.Add(new OrderLine { Quantity = 1, PaymentAmount = 10, ProductTitle = "Test Product 1 for Voucher" }); orderLines.Add(new OrderLine { Quantity = 1, PaymentAmount = 10, ProductTitle = "Test Product 2 for Voucher" }); order.OrderLines = orderLines; Assert.IsTrue(order.GetVoucherTotal() == 0); Debug.WriteLine(order.GetVoucherDetail().Detail); }
public OrderOperationStatus QueueOrder(Order order, Contact contact) { var operationStatus = new OrderOperationStatus(); try { SendEmails(order, contact); _additionalQueueProcessingHandlerFactory.GetHandler(order.AdditionalQueueProcessingHandler).PerformAdditionalProcessing(order,contact); order.Status = "QUE"; order.UpdateOrderLines("QUE"); _orderRepository.SaveOrder(order); operationStatus.Order = order; operationStatus.Status = true; } catch (Exception e) { operationStatus = OperationStatusExceptionHelper<OrderOperationStatus> .CreateFromException("An error has occurred processing the order", e); } return operationStatus; }
private Order GetOrderConfiguration(Order order) { IOrderTypeSetting orderTypeSetting = _config.GetConfiguration().OrderTypeSettings[order.OrderIndex.ToString()]; order.Description = (orderTypeSetting != null) ? orderTypeSetting.Description : ""; order.CheckoutPage = (orderTypeSetting != null) ? orderTypeSetting.CheckoutPage : _config.GetConfiguration().CheckoutPage; order.OrderPage = (orderTypeSetting != null) ? orderTypeSetting.OrderPage : _config.GetConfiguration().OrderPage; order.ContactDetailsPage = (orderTypeSetting != null) ? orderTypeSetting.ContactDetailsPage : _config.GetConfiguration().ContactDetailsPage; order.SpecialRequirementsText = (orderTypeSetting != null) ? orderTypeSetting.SpecialRequirementsText : _config.GetConfiguration().SpecialRequirementsText; order.PaymentGatewayForm = (orderTypeSetting != null) ? orderTypeSetting.PaymentGatewayForm : _config.GetConfiguration().PaymentGatewayForm; order.PaymentGatewayAccount = (orderTypeSetting != null) ? orderTypeSetting.PaymentGatewayAccount : _config.GetConfiguration().PaymentGatewayAccount; order.PaymentGatewayCallbackUrl = (orderTypeSetting != null) ? orderTypeSetting.PaymentGatewayCallbackUrl : ""; order.PaymentGatewayCompletionPage = (orderTypeSetting != null) ? orderTypeSetting.PaymentGatewayCompletionPage : ""; order.PaymentGatewayCheckCode = (orderTypeSetting != null) ? orderTypeSetting.PaymentGatewayCheckCode : ""; order.AdditionalQueueProcessingHandler = (orderTypeSetting != null) ? orderTypeSetting.AdditionalQueueProcessingHandler : ""; return order; }
public Order PerformAdditionalProcessing(Order order, Domain.Contacts.Contact contact) { return order; }
public OrderOperationStatus SaveOrder(Order order, bool updateOrderLines) { var orderOperationStatus = new OrderOperationStatus(); try { if (!_database.IsNew(order)) { _database.Update(order); if (updateOrderLines) { for (int i = 0; i < order.OrderLines.Count; i++) { if (_database.IsNew(order.OrderLines[i])) { order.OrderLines[i].OrderLineId = (int)_database.Insert(order.OrderLines[i]); } else { _database.Update(order.OrderLines[i]); } } } orderOperationStatus.Status = true; orderOperationStatus.Message = "The order has been saved successfully."; } else { orderOperationStatus.Status = false; orderOperationStatus.Message = "The order could not be found."; } orderOperationStatus.Order = order; } catch (Exception e) { orderOperationStatus = OperationStatusExceptionHelper<OrderOperationStatus> .CreateFromException("An error has occurred saving the order"+e.Message+e.StackTrace, e); } return orderOperationStatus; }
public OrderOperationStatus ProcessOrder(Order order, Contact contact) { throw new NotImplementedException(); }
public void ShouldNotUpdateWhereNotExistingProductInOrder() { Order order = new Order(); Product product = new Product { Title = "Test Product", ProductId = 1, OptionId = 1, OptionTitle = "Option1",Price=50 }; var operationStatus = order.Update(product, product, 6, "F", 50); Assert.IsTrue(operationStatus.Status == false); Assert.IsTrue(operationStatus.MessageCode == "CPX.ItemNotInOrder"); }
public void ShouldNotUpdateItemToExistingProduct() { Order order = new Order(); Product product = new Product {Title = "Test Product", ProductId = 1, OptionId = 1, OptionTitle = "Option1",Price=50}; order.Add(product, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 2); Assert.IsTrue(order.ContainsProduct(product)); Assert.IsTrue(order.PaymentTotal == 100); Product product2 = new Product { Title = "Test Product", ProductId = 1, OptionId = 2, OptionTitle = "Option2", Price=50 }; order.Add(product2, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 4); Assert.IsTrue(order.ContainsProduct(product2)); Assert.IsTrue(order.PaymentTotal == 200); Product updateProduct = new Product { Title = "Test Product", ProductId = 1, OptionId = 2, OptionTitle = "Option2", Price=50 }; var operationStatus = order.Update(product, updateProduct, 6, "F", 50); Assert.IsTrue(operationStatus.Status == false); Assert.IsTrue(operationStatus.MessageCode == "CPX.ItemAlreadyInOrder"); }
public Order UpdateShipping(Order order, Contact contact) { if (order.NumberOfItems == 0) { order.ShippingTotal = 0; return order; } //default country to UK if not specified string country = (String.IsNullOrEmpty(contact.Country)) ? "United Kingdom" : contact.Country; decimal total = (decimal) order.PaymentSubTotalIncludingDiscountAndVoucher; order.ShippingInfo = "Shipping based on delivery to " + country; if (country == "United Kingdom - Mainland" || country == "United Kingdom" || country == "UK") { if (total > 0 && total <= (decimal) 6.50) { order.ShippingTotal = 1; return order; } if (total <= 15 && total > 6) { order.ShippingTotal = 2; return order; } if (total <= 30 && total > 15) { order.ShippingTotal = 3; return order; } if (total <= 100 && total > 30) { order.ShippingTotal = 5; return order; } if (total <= 150 && total > 100) { order.ShippingTotal = 8; return order; } order.ShippingTotal = 0; return order; } /* Offshore post Upto £6.50 - £1 £6.51to £15 - £2 £15.01-30 - £3 £30.01-£100 - £5 £100.01-£150 - £12 £150.05 and over - £15 */ if (country == "United Kingdom - Islands" || country == "UKI") { if (total > 0 && total <= (decimal) 6.50) { order.ShippingTotal = 1; return order; } if (total <= 15 && total > 6) { order.ShippingTotal = 2; return order; } if (total <= 30 && total > 15) { order.ShippingTotal = 3; return order; } if (total <= 100 && total > 30) { order.ShippingTotal = 5; return order; } if (total <= 150 && total > 100) { order.ShippingTotal = 12; return order; } order.ShippingTotal = 15; return order; } if (total > 0 && total <= 15) { order.ShippingTotal = 4; return order; } if (total <= 30 && total > 15) { order.ShippingTotal = 7; return order; } if (total <= 75 && total > 30) { order.ShippingTotal = 15; return order; } if (total <= 150 && total > 75) { order.ShippingTotal = 20; return order; } order.ShippingTotal = 25; return order; }
public Order UpdateDiscount(Order order, Contact contact) { return order; }
private void SendEmails(Order order, Contact contact) { //TODO: email content needs to be editable var mailBodyNotification = new StringBuilder(); var mailBodyCustomer = new StringBuilder(); var mailBodyCourses = new StringBuilder(); var mailBodyMemberships = new StringBuilder(); var mailBodyDonations = new StringBuilder(); bool sendMail = false; mailBodyNotification.Append("<p>Contact Details</p>"); mailBodyNotification.AppendFormat("<p>Name: {0} {1} {2}</p>", contact.Title, contact.FirstName, contact.LastName); mailBodyNotification.AppendFormat("<p>Address: {0}<br />{1}<br />{2}<br />{3}<br />{4}<br />{5}</p>", contact.Address1, contact.Address2, contact.Town, contact.County, contact.Postcode, contact.CountryDesc); mailBodyNotification.AppendFormat("<p>Telephone : {0}\nMobile: {1}</p>", contact.Telephone, contact.Mobile); mailBodyNotification.AppendFormat("<p>Email: {0}</p>", contact.Email); if (order.ContainsCourses()) { sendMail = true; mailBodyNotification.Append("<p>This person has booked the following courses:</p>"); mailBodyCustomer.Append( "Thank you for requesting the course(s) below. The centre(s) running them will confirm availability and contact you shortly."); //create the main email first //loop through each item in the cart and add it to the email body foreach (OrderLine orderLine in order.GetCourseOrderLines()) { mailBodyCourses.AppendFormat("<p><b>Course: {0} {1}</b></p>", orderLine.ProductTitle, orderLine.ProductDescription); mailBodyCourses.AppendFormat("<p>Booking Option: {0} £{1}</p>", orderLine.ProductOptionTitle, orderLine.ProductPrice); mailBodyCourses.AppendFormat("<p>Number of attendees: {0}", orderLine.Quantity); mailBodyCourses.AppendFormat("<p>Payment Made Per attendee: £{0}</p>", orderLine.PaymentAmount); mailBodyCourses.AppendFormat("<p>Total Payment: £{0}</p>", orderLine.PaymentLineTotal); } mailBodyCourses.AppendFormat("<p>Special Requirements: {0}</p>", order.SpecialRequirements); //create the centre emails next //loop through each centre and check whether they have any bookings var locationEmails = order.GetLocationEmails(); foreach (string email in locationEmails) { var mailBodyLocation = new StringBuilder(); string locationEmail = email; bool foundCourses = false; foreach (OrderLine orderLine in order.CurrentOrderLines.Where(x => x.LocationEmail == locationEmail)) { //if there is a booking for this centre, add it to the centre email foundCourses = true; mailBodyLocation.AppendFormat("<p><b>Course: {0} {1}</b></p>", orderLine.ProductTitle, orderLine.ProductDescription); mailBodyLocation.AppendFormat("<p>Booking Type: {0}</p>", orderLine.PaymentTypeDescription); mailBodyLocation.AppendFormat("<p>Booking Option: {0} £{1}</p>", orderLine.ProductOptionTitle, orderLine.ProductPrice); mailBodyLocation.AppendFormat("<p>Number of attendees: {0}", orderLine.Quantity); mailBodyLocation.AppendFormat("<p>Total Payment: £{0}</p>", orderLine.PaymentLineTotal); } //send the centre email if (foundCourses) { mailBodyLocation.AppendFormat("<p>Special Requirements: {0}</p>", order.SpecialRequirements); if (order.HasValidVoucher()) { mailBodyLocation.AppendFormat("<p><b>The following voucher has been applied to this order: {0} {1}.</b></p>", order.VoucherInfo, order.GetVoucherDetail()); } SendEmail("*****@*****.**", locationEmail, "WEBSITE Individuals and Families Booking", mailBodyNotification.ToString() + mailBodyLocation.ToString()); } } mailBodyNotification.Append(mailBodyCourses); mailBodyCustomer.Append(mailBodyCourses); } if (order.ContainsProductType("M")) { sendMail = true; mailBodyNotification.Append("<p>This person has requested the following membership:</p>"); mailBodyCustomer.Append( "<p>Thank you for joining FSC. Your membership will support our work to inspire young people to understand and experience the natural world including the wider benefits that a greater appreciation of nature can bring.</p>"); mailBodyCustomer.Append( "<p>A welcome pack will be sent to you by post within 2-3 weeks. You will receive a membership card that is renewed annually. We produce a members’ magazine FSC Magazine twice a year and you will also receive access to an exclusive members’ preview of the annual leisure learning and professional development programme.</p>"); foreach (OrderLine orderLine in order.GetMembershipOrderLines()) { mailBodyMemberships.AppendFormat("<p><b>{0} {1}</b></p>", orderLine.ProductTitle, orderLine.ProductDescription); mailBodyMemberships.AppendFormat("<p>Total Payment: £{0}</p>", orderLine.PaymentLineTotal); } mailBodyNotification.Append(mailBodyMemberships); mailBodyCustomer.Append(mailBodyMemberships); } if (order.ContainsProductType("D")) { sendMail = true; mailBodyNotification.Append("<p>This person has made the following donation(s):</p>"); mailBodyCustomer.Append( "<p>Thank you for your donation which will support our work to inspire young people to understand and experience the natural world including the wider benefits that a greater appreciation of nature can bring.</p>"); foreach (OrderLine orderLine in order.GetDonationOrderLines()) { mailBodyDonations.AppendFormat("<p><b>{0} {1}</b></p>", orderLine.ProductTitle, orderLine.ProductDescription); mailBodyDonations.AppendFormat("<p>Total Payment: £{0}</p>", orderLine.PaymentLineTotal); } mailBodyNotification.Append(mailBodyDonations); mailBodyCustomer.Append(mailBodyDonations); } if (order.GiftAidAgreement) { mailBodyNotification.Append("<p><b>This person has made a Gift Aid Agreement.</b></p>"); mailBodyCustomer.Append( "Thank you for making a Gift Aid declaration."); } if (order.HasValidVoucher()) { mailBodyNotification.AppendFormat("<p><b>The following voucher has been applied to this order: {0} {1}.</b></p>", order.VoucherInfo, order.GetVoucherDetail()); mailBodyCustomer.AppendFormat("<p><b>The following voucher has been applied to your order: {0} {1}.</b></p>", order.VoucherInfo, order.GetVoucherDetail()); } if (sendMail) { //send the notification email SendEmail("*****@*****.**", "*****@*****.**", "WEBSITE Individuals and Families Booking", mailBodyNotification.ToString()); //send the customer email SendEmail("*****@*****.**", contact.Email, "FSC Individuals and Families Booking", mailBodyCustomer.ToString()); } }
public void ShouldHavePositiveVoucherTotalWithMoreThanMiniumItems() { Order order = new Order { VoucherPerItemAmount = 1, VoucherMinimumItems = 1, VoucherId = 1 }; List<OrderLine> orderLines = new List<OrderLine>(); orderLines.Add(new OrderLine { Quantity = 2, PaymentAmount = 10 }); orderLines.Add(new OrderLine { Quantity = 2, PaymentAmount = 10 }); order.OrderLines = orderLines; Assert.IsTrue(order.GetVoucherTotal() == 4); Debug.WriteLine(order.GetVoucherDetail().Detail); }
public Order UpdateShipping(Order order, Contact contact) { return order; }
public void ShouldReturnLocationEmailsCorrectly() { Order order = new Order(); Product product = new Product { Title = "Test Product", ProductId = 1, OptionId = 1, OptionTitle = "Option1", LocationEmail = "*****@*****.**", Price=50 }; order.Add(product, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 2); Assert.IsTrue(order.ContainsProduct(product)); var expectedEmailList = new List<string> {"*****@*****.**"}; var actualEmailList = order.GetLocationEmails(); Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count); Assert.AreEqual(expectedEmailList[0],actualEmailList[0]); Product product2 = new Product { Title = "Test Product 2", ProductId = 2, LocationEmail = "*****@*****.**", Price=50 }; order.Add(product2, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 4); Assert.IsTrue(order.ContainsProduct(product2)); expectedEmailList = new List<string> {"*****@*****.**", "*****@*****.**"}; actualEmailList = order.GetLocationEmails(); Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count); Assert.AreEqual(expectedEmailList[0],actualEmailList[0]); Assert.AreEqual(expectedEmailList[1],actualEmailList[1]); //check that it only returns distinct email addresses Product product3 = new Product { Title = "Test Product 3", ProductId = 3, LocationEmail = "*****@*****.**", Price=50 }; order.Add(product3,2, "F", 50); Assert.IsTrue(order.NumberOfItems == 6); Assert.IsTrue(order.ContainsProduct(product3)); actualEmailList = order.GetLocationEmails(); Assert.AreEqual(expectedEmailList.Count,actualEmailList.Count); Assert.AreEqual(expectedEmailList[0],actualEmailList[0]); Assert.AreEqual(expectedEmailList[1],actualEmailList[1]); }
public OrderOperationStatus SaveOrder(Order order) { return SaveOrder(order, true); }
public OrderOperationStatus SaveOrder(Order order,bool updateOrderLines) { return _orderRepository.SaveOrder(order,updateOrderLines); }
private Order CreateOrder(Contact contact, int orderIndex) { var order = new Order {UserId = contact.UserId, UserName = contact.UserName, ContactId=contact.ContactId,OrderIndex = orderIndex,GiftAidAgreement = contact.GiftAidAgreement}; order.OrderId = (int) _database.Insert("cpxOrder", "OrderId", true, order); return order; }
public void UpdateProductInOrderToDifferentOption() { Order order = new Order(); Product product = new Product { Title = "Test Product", ProductId = 1,OptionId = 1,OptionTitle = "Option1", Price=50}; order.Add(product, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 2); Assert.IsTrue(order.ContainsProduct(product)); Assert.IsTrue(order.PaymentTotal == 100); Product updateProduct = new Product { Title = "Test Product", ProductId = 1, OptionId = 2, OptionTitle = "Option2",Price=50 }; order.Update(product, updateProduct, 6, "F", 50); Assert.IsTrue(order.NumberOfItems == 6); Assert.IsTrue(order.ContainsProduct(updateProduct)); Assert.IsFalse(order.ContainsProduct(product)); Assert.IsTrue(order.PaymentTotal == 300); }
public void ShouldUpdateQuantityAndEventDatesWhenAddingExistingEvent() { Order order = new Order(); Product event1 = new Product { Title = "Test Event 1", ProductId = 1, StartDate = new DateTime(2014,08,1),FinishDate = new DateTime(2014,08,5), Price = 50 }; order.Add(event1, 2, "F", 50); Assert.IsTrue(order.NumberOfItems == 2); Assert.IsTrue(order.ContainsProduct(event1)); Assert.IsTrue(order.PaymentTotal == 100); Product event2 = new Product { Title = "Test Event 2", ProductId = 1, StartDate = new DateTime(2014,08,1),FinishDate = new DateTime(2014,08,4), Price = 50 }; order.Add(event2, 3, "F", 50); Assert.IsTrue(order.NumberOfItems == 3); Assert.IsTrue(order.PaymentTotal == 150); Assert.IsTrue(order.ContainsProduct(event1)); var eventInOrder = order.GetOrderLine(event1); Assert.IsTrue(eventInOrder.StartDate == new DateTime(2014, 08, 1)); Assert.IsTrue(eventInOrder.FinishDate == new DateTime(2014, 08, 4)); }
public Order UpdateOrderWithShippingAndDiscounts(Order order, Contact contact) { IOrderTypeSetting orderTypeSetting = _config.GetConfiguration().OrderTypeSettings[order.OrderIndex.ToString()]; string shippingConfig = (orderTypeSetting != null) ? orderTypeSetting.ShippingHandler : _config.GetConfiguration().ShippingHandler; order = _shippingHandlerFactory.getShippingHandler(shippingConfig).UpdateShipping(order, contact); string discountConfig = (orderTypeSetting != null) ? orderTypeSetting.DiscountHandler : _config.GetConfiguration().DiscountHandler; order = _discountHandlerFactory.getDiscountHandler(discountConfig).UpdateDiscount(order, contact); return order; }