public Shipment CalculateShipping(Order order) { Shipment result = new Shipment(order); result.ShippingOptions = new List<ShippingMethod>(); result.ShippingOptions.Add(new ShippingMethod(1,"Test Carrier", "Overnight", 10, 1,5)); result.ShippingOptions.Add(new ShippingMethod(2,"Test Carrier", "Next Day", 5, 2,10)); result.ShippingOptions.Add(new ShippingMethod(3,"Test Carrier", "Ground", 2, 5,20)); return result; }
public Transaction AuthorizeCreditCard(Order order) { //this is a fake processor for testing... //if there are transaction errors, //pop them into the TransactionErrors on the Transaction object //for display to the end user string authCode = System.Guid.NewGuid().ToString().Substring(0, 10); Transaction t = new Transaction(order.ID, order.Total, authCode, "FakePaymentGateway"); return t; }
public bool ValidateOrder(Order order) { bool result = true; //make sure there are more than one item result = order.Items.Count > 0; //we have a credit card if (result) result = order.CreditCard != null; //valid number? if (result) result = order.CreditCard.IsValid(); //everything adds up if (result) result = order.SubTotal + order.ShippingAmount + order.TaxAmount == order.Total; return result; }
public Shipment(Order order) { Destination = order.ShippingAddress; }
public Queued(Order order) : base(order) { }
public Processed(Order order) : base(order) { }
public string CreateOrderNumber(Order order) { return "MVC-"+Guid.NewGuid().ToString().Substring(0, 8); }
public Verified(Order order) : base(order) { ID = 3; }
public Returned(Order order) : base(order) { this.ID = 7; order.OnReturned(EventArgs.Empty); }
/// <summary> /// Default .ctor /// </summary> public OrderState(Order order) { this.Order = order; }
public Failed(Order order) : base(order) { }
public Order GetOrder(Guid orderID) { SimpleProductRepository productRepository = new SimpleProductRepository(); SimpleCustomerRepository customerRepository = new SimpleCustomerRepository(); Order result = null; var batch = new BatchSql(); batch.Append(OrdersTable.Select().Where("OrderID", orderID)); //items //products for the items var sql = new SqlStatement(connectionStringName); sql.Add("SELECT "); sql.Add(ProductsTable.COLUMN_LIST); sql.Add(OrderItemsTable.COLUMN_LIST); sql.Add("FROM Products INNER JOIN OrderItems ON Products.SKU = OrderItems.SKU"); sql.Add("WHERE SKU IN (SELECT SKU FROM OrderItems WHERE OrderID=@OrderID)"); //transactions batch.Append(TransactionsTable.Select().Where("orderid", orderID)); int shippingAddressID = 0; int billingAddressID = 0; int shippingMethodID=0; //pull it var cmd = sql.BuildCommand(); using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { if (rdr.Read()) { result = new Order(OrdersTable.ReadOrderStatusID(rdr)) { DateCreated =OrdersTable.ReadCreatedOn(rdr), DateShipped = OrdersTable.ReadDateShipped(rdr), UserName = OrdersTable.ReadUserName(rdr), DiscountAmount = OrdersTable.ReadDiscountAmount(rdr), DiscountReason =OrdersTable.ReadDiscountReason(rdr), EstimatedDelivery = OrdersTable.ReadEstimatedDelivery(rdr), ID = orderID, OrderNumber = OrdersTable.ReadOrderNumber(rdr), ShippingAmount = OrdersTable.ReadShippingAmount(rdr), ShippingService=OrdersTable.ReadShippingService(rdr), TaxAmount = OrdersTable.ReadTaxAmount(rdr), }; billingAddressID = OrdersTable.ReadBillingAddressID(rdr); shippingAddressID = OrdersTable.ReadShippingAddressID(rdr); } //load the items result.Items = new List<OrderLine>(); if (rdr.NextResult()) { while (rdr.Read()) { var product = productRepository.LoadProduct(rdr); var item = new OrderLine(OrderItemsTable.ReadDateAdded(rdr),OrderItemsTable.ReadQuantity(rdr),product); result.Items.Add(item); } } //transactions result.Transactions = new List<Transaction>(); if (rdr.NextResult()) { while (rdr.Read()) { Transaction t = new Transaction( TransactionsTable.ReadTransactionID(rdr), orderID, TransactionsTable.ReadAmount(rdr), TransactionsTable.ReadTransactionDate(rdr), TransactionsTable.ReadAuthorizationCode(rdr), TransactionsTable.ReadNotes(rdr), TransactionsTable.ReadProcessor(rdr)); result.Transactions.Add(t); } } } sql = new SqlStatement(connectionStringName); //addresses batch.Append(AddressesTable.Select().Where("addressid", shippingAddressID)); batch.Append(AddressesTable.Select().Where("addressid", billingAddressID)); //shipping method batch.Append(ShippingMethodsTable.Select().Where("shippingmethodid", shippingMethodID)); cmd = batch.BuildCommand(connectionStringName); using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { //shipping address if (rdr.Read()) { //shipping result.ShippingAddress = customerRepository.LoadAddress(rdr); } //billing address if (rdr.NextResult()) { if (rdr.Read()) { result.BillingAddress = customerRepository.LoadAddress(rdr); } } //shipping method if (rdr.NextResult()) { if (rdr.Read()) { LoadShipping(rdr); } } } return result; }
public void Save(Order order, Transaction transaction) { throw new NotImplementedException(); }
public Submitted(Order order) : base(order) { this.ID = 2; }
public ActionResult Payment(CreditCard card) { //set the card this.CurrentCart.CreditCard = card; //create an order Order order = new Order(this.CurrentCustomer, DateTime.Now.Ticks.ToString()); this.TempData["CurrentOrder"] = order; //TODO: - check boolean this.ValidateOrder(order); //execute the payment.. Transaction trans = this.AuthorizeCreditCard(order); //on success send to Receipt if (trans.TransactionErrors.Count == 0) { //save it down //_orderRepository.Save(order, trans); SetCustomer(true); return RedirectToAction("Receipt", new { id = order.ID.ToString() }); } else { ViewData["ErrorMessage"] = trans.TransactionErrors[0]; //let the View know return View("Finalize"); } }
public Shipped(Order order) : base(order) { ID = 6; }
public Charged(Order order) : base(order) { ID = 4; }
public Closed(Order order) : base(order) { this.ID = 10; }
public Refunded(Order order) : base(order) { this.ID = 9; }
public Succeeded(Order order) : base(order) { }
public TransactionState(Order order) { _order = order; }
public Cancelled(Order order) : base(order) { this.ID = 8; }
public NewOrder(Order order) : base(order) { this.ID = 1; }