/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { transactionId = Utility.GetIntParameter("tid"); orderId = Utility.GetIntParameter("oid"); if (transactionId > 0) { Transaction transaction = new Transaction(transactionId); Order order = new OrderController().FetchOrder(transaction.OrderId, WebUtility.GetUserName()); if (order.OrderId > 0) { lblReceipt.Text = order.ToHtml(); } } if (orderId > 0) { Order order = new OrderController().FetchOrder(orderId, WebUtility.GetUserName()); if (order.OrderId > 0) { lblReceipt.Text = order.ToHtml(); } } this.Title = string.Format(WebUtility.MainTitleTemplate, Master.SiteSettings.SiteName, LocalizationUtility.GetText("lblReceipt")); } catch (Exception ex) { Logger.Error(typeof(receipt).Name + ".Page_Load", ex); throw; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { SetRegisterControlProperties(); int orderItemCount = new OrderController().GetItemCountInOrder(WebUtility.GetUserName()); if (orderItemCount > 0) { lblBeforeRegisterUserName.Text = WebUtility.GetUserName(); } }
/// <summary> /// Calculates the tax. /// </summary> /// <param name="userName">Name of the user.</param> public static void CalculateTax(string userName) { Order order = new OrderController().FetchOrder(userName); TaxService taxService = new TaxService(); taxService.GetTaxRate(order); foreach(OrderItem orderItem in order.OrderItemCollection) { orderItem.Save(userName); } order.Save(userName); }
protected void Page_Load(object sender, EventArgs e) { //Log this so we can investigate if something goofy happens Logger.Information(string.Format("{0}::{1}", "REQUEST", Request.Form.ToString())); //Per PayPal Order Management / Integration Guide Pg.25 //we have to validate the price, transactionId, etc. string transactionId = Request.Form["txn_id"].ToString(); string orderId = Request.Form["custom"].ToString(); string amount = Request.Form["mc_gross"].ToString(); decimal parsedAmount = 0.00M; bool isParsed = decimal.TryParse(amount, out parsedAmount); string paymentStatus = Request.Form["payment_status"].ToString(); string receiverEmail = Request.Form["receiver_email"].ToString(); if (transactionId.IndexOf(",") > -1) { transactionId = transactionId.Substring(0, transactionId.IndexOf(",", 0)); transactionId = HttpUtility.UrlDecode(transactionId); } if (orderId.IndexOf(",") > -1) { orderId = orderId.Substring(0, orderId.IndexOf(",", 0)); orderId = HttpUtility.UrlDecode(orderId); } byte[] buffer = Request.BinaryRead(HttpContext.Current.Request.ContentLength); string formValues = System.Text.Encoding.ASCII.GetString(buffer); //string formValues = Request.Form.ToString(); string response = Verify(formValues); if (response.StartsWith("VERIFIED")) { OrderController orderController = new OrderController(); Guid orderGuid = new Guid(orderId); Order order = orderController.FetchOrder(orderGuid); if (order.OrderId > 0) { //check the payment_status is Completed //check that txn_id has not been previously processed //check that receiver_email is your Primary PayPal email //check that payment_amount/payment_currency are correct //TODO: CMC: Need to update the PayPalProConfiguration with preferred business email if ((paymentStatus.ToUpper().Equals("COMPLETED") && (order.OrderStatusDescriptorId == (int)OrderStatus.NotProcessed) && (order.Total == parsedAmount))) { Transaction transaction = OrderController.CommitStandardTransaction(order, transactionId, decimal.Parse(amount)); Logger.Information(string.Format("{0}::{1}", "IPN", order.OrderNumber)); //Send response 200 Response.StatusCode = (int)System.Net.HttpStatusCode.OK; Response.Flush(); Response.End(); } } } else { Logger.Information(string.Format("{0}::{1}", "RESPONSE", HttpUtility.HtmlEncode(response))); } }
protected void Page_Load(object sender, EventArgs e) { try { //Log the querystring in case we have to investigate Logger.Information(Request.QueryString.ToString()); string transactionId = Request.QueryString["tx"]; string orderId = Request.QueryString["cm"]; if (transactionId.IndexOf(",") > -1) { transactionId = transactionId.Substring(0, transactionId.IndexOf(",", 0)); transactionId = HttpUtility.UrlDecode(transactionId); } else { transactionId = HttpUtility.UrlDecode(transactionId); } if (orderId.IndexOf(",") > -1) { orderId = orderId.Substring(0, orderId.IndexOf(",", 0)); orderId = HttpUtility.UrlDecode(orderId); } else { orderId = HttpUtility.UrlDecode(orderId); } string response = Synchronize(transactionId); if (response.StartsWith("SUCCESS")) { string grossAmt = GetPDTValue(response, "mc_gross"); decimal grossAmount = 0; decimal.TryParse(grossAmt, out grossAmount); OrderController orderController = new OrderController(); Guid orderGuid = new Guid(orderId); Order order = orderController.FetchOrder(orderGuid); if (order.OrderId > 0) { Transaction transaction = null; if (order.OrderStatusDescriptorId == (int)OrderStatus.NotProcessed) {//then it hasn't been pinged by the ipn service transaction = OrderController.CommitStandardTransaction(order, transactionId, grossAmount); Logger.Information(string.Format("{0}::{1}", "PDT", order.OrderNumber)); } else {//it has been pinged by the ipn service, so just grab the transaction transaction = new Transaction(Transaction.Columns.OrderId, order.OrderId); } Response.Redirect(string.Format("~/receipt.aspx?tid={0}", transaction.TransactionId), true); } } } catch (System.Threading.ThreadAbortException) { throw; } catch (Exception ex) { Logger.Error(typeof(pdthandler).Name, ex); } }
/// <summary> /// Handles the Click event of the btnSearch control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnSearch_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtOrderNumber.Text)) { string likeClause = string.Format("{0}%", txtOrderNumber.Text.Trim()); Query query = new Query(Order.Schema).AddWhere(Order.Columns.OrderNumber, Comparison.Like, likeClause); OrderCollection orderCollection = new OrderController().FetchByQuery(query); BindOrderCollection(orderCollection); } } catch (Exception ex) { Logger.Error(typeof(orders).Name + ".btnSearch_Click", ex); Master.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { orderId = Utility.GetIntParameter("orderId"); view = Utility.GetParameter("view"); if(orderId > 0 && view == "r") { SetReceiptProperties(); OrderCollection orderCollection = new OrderController().FetchAssociatedOrders(orderId); rptrReceipts.DataSource = orderCollection; rptrReceipts.ItemDataBound += new RepeaterItemEventHandler(rptrReceipts_ItemDataBound); rptrReceipts.DataBind(); } } catch(Exception ex) { Logger.Error(typeof(receipt).Name + ".Page_Load", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Loads the orders. /// </summary> private void LoadOrders() { OrderCollection orderCollection = new OrderController().FetchOrdersForUser(ddlCustomer.SelectedValue); orderCollection.Sort(Order.Columns.CreatedOn, false); dgOrders.DataSource = orderCollection; dgOrders.ItemDataBound += new DataGridItemEventHandler(dgOrders_ItemDataBound); dgOrders.Columns[0].HeaderText = LocalizationUtility.GetText("hdrDetails"); dgOrders.Columns[1].HeaderText = LocalizationUtility.GetText("hdrOrderNumber"); dgOrders.Columns[2].HeaderText = LocalizationUtility.GetText("hdrTotal"); dgOrders.Columns[3].HeaderText = LocalizationUtility.GetText("hdrStatus"); dgOrders.Columns[4].HeaderText = LocalizationUtility.GetText("hdrOrderDate"); dgOrders.DataBind(); }
/// <summary> /// Handles the Click event of the lbDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param> protected void lbDelete_Click(object sender, CommandEventArgs e) { int orderItemId = 0; int.TryParse(e.CommandArgument.ToString(), out orderItemId); if (orderItemId > 0) { Order modifiedOrder = new OrderController().FetchOrder(WebUtility.GetUserName()); new OrderController().RemoveItem(modifiedOrder.OrderId, orderItemId, WebUtility.GetUserName()); if (modifiedOrder.OrderItemCollection.Count == 0) { Order.Delete(modifiedOrder.OrderId); } } Response.Redirect("~/cart.aspx", true); }
/// <summary> /// Migrates the cart. /// </summary> /// <param name="anonymousCartId">The anonymous cart id.</param> /// <param name="registeredCartId">The registered cart id.</param> public static void MigrateCart(string anonymousCartId, string registeredCartId) { Order anonymousOrder = new OrderController().FetchOrder(anonymousCartId); Order registeredOrder = new OrderController().FetchOrder(registeredCartId); //first see if there is an order for the now-recognized user if (string.IsNullOrEmpty(registeredOrder.OrderNumber) && !string.IsNullOrEmpty(anonymousOrder.OrderNumber)) { //if not, just update the old order with the new user's username anonymousOrder.UserName = registeredCartId; anonymousOrder.Save(registeredCartId); } else { //the logged-in user has an existing basket. //if there is no basket from their anon session, //we don't need to do anything if (!string.IsNullOrEmpty(anonymousOrder.OrderNumber)) { //in this case, there is an order (cart) from their anon session //and an order that they had open from their last session //need to marry the items. //this part is up to your business needs - some merchants //will want to replace the cart contents //others will want to synch them. We're going to assume that //this scenario will synch the existing items. //############### Synch the Cart Items if (registeredOrder.OrderItemCollection.Count > 0 && anonymousOrder.OrderItemCollection.Count > 0) { //there are items in both carts, move the old to the new //when synching, find matching items in both carts //update the quantities of the matching items in the logged-in cart //removing them from the anon cart //a switch to tell us if we need to update the from orders //1.) Find items that are the same between the two carts and add the anon quantity to the registered user quantity //2.) Mark found items as items to be removed from the anon cart. ArrayList toBeRemoved = new ArrayList(anonymousOrder.OrderItemCollection.Count); for (int i = 0; i < anonymousOrder.OrderItemCollection.Count; i++) { OrderItem foundItem = registeredOrder.OrderItemCollection.Find(delegate(OrderItem orderItemToFind) { return((orderItemToFind.Sku == anonymousOrder.OrderItemCollection[i].Sku) && (orderItemToFind.Attributes == anonymousOrder.OrderItemCollection[i].Attributes)); }); if (foundItem != null) { foundItem.Quantity += anonymousOrder.OrderItemCollection[i].Quantity; toBeRemoved.Add(i); } } //3.) Now remove any foundItems from the anon cart, but trim it up first toBeRemoved.TrimToSize(); for (int i = 0; i < toBeRemoved.Count; i++) { anonymousOrder.OrderItemCollection.RemoveAt((int)toBeRemoved[i]); } //4.) Move over to the registered user cart any remaining items in the anon cart. foreach (OrderItem anonItem in anonymousOrder.OrderItemCollection) { //reset the orderID anonItem.OrderId = registeredOrder.OrderId; registeredOrder.OrderItemCollection.Add(anonItem); } //5.) Finally, save it down to the DB // (Since we know toOrder.Items.Count > 0 && fromOrder.Items.Count > 0, we know a Save needs to occur) registeredOrder.OrderItemCollection.SaveAll(registeredCartId); registeredOrder.Save(registeredCartId); } else if (registeredOrder.OrderItemCollection.Count == 0) { //items exist only in the anon cart //move the anon items to the new cart //then save the order and the order items. registeredOrder.IsNew = true; registeredOrder.OrderStatusDescriptorId = anonymousOrder.OrderStatusDescriptorId; registeredOrder.OrderGuid = anonymousOrder.OrderGuid; registeredOrder.UserName = registeredCartId; registeredOrder.OrderNumber = anonymousOrder.OrderNumber; registeredOrder.Save(registeredCartId); foreach (OrderItem item in anonymousOrder.OrderItemCollection) { //reset the orderID on each item item.OrderId = registeredOrder.OrderId; registeredOrder.OrderItemCollection.Add(item); } registeredOrder.OrderItemCollection.SaveAll(registeredCartId); registeredOrder.Save(registeredCartId); } else if (anonymousOrder.OrderItemCollection.Count == 0) { //no items in the old cart, do nothing } //finally, drop the anon order from the DB, we don't want to //keep it OrderItem.Delete(OrderItem.Columns.OrderId, anonymousOrder.OrderId); Order.Delete(anonymousOrder.OrderId); } } }
/// <summary> /// Loads the orders. /// </summary> private void LoadOrders() { Query query = new Query(Order.Schema).AddWhere(Order.Columns.OrderStatusDescriptorId, Comparison.NotEquals, (int)OrderStatus.NotProcessed); OrderCollection orderCollection = new OrderController().FetchByQuery(query); orderCollection.Sort(Order.Columns.ModifiedOn, false); BindOrderCollection(orderCollection); }
/// <summary> /// Sets the shipping. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="shippingAmount">The shipping amount.</param> /// <param name="shippingMethod">The shipping method.</param> public static void SetShipping(string userName, decimal shippingAmount, string shippingMethod) { Order order = new OrderController().FetchOrder(userName); order.ShippingAmount = shippingAmount; order.ShippingMethod = shippingMethod; order.Save(userName); }
/// <summary> /// Migrates the cart. /// </summary> /// <param name="anonymousCartId">The anonymous cart id.</param> /// <param name="registeredCartId">The registered cart id.</param> public static void MigrateCart(string anonymousCartId, string registeredCartId) { Order anonymousOrder = new OrderController().FetchOrder(anonymousCartId); Order registeredOrder = new OrderController().FetchOrder(registeredCartId); //first see if there is an order for the now-recognized user if (string.IsNullOrEmpty(registeredOrder.OrderNumber) && !string.IsNullOrEmpty(anonymousOrder.OrderNumber)) { //if not, just update the old order with the new user's username anonymousOrder.UserName = registeredCartId; anonymousOrder.Save(registeredCartId); } else { //the logged-in user has an existing basket. //if there is no basket from their anon session, //we don't need to do anything if (!string.IsNullOrEmpty(anonymousOrder.OrderNumber)) { //in this case, there is an order (cart) from their anon session //and an order that they had open from their last session //need to marry the items. //this part is up to your business needs - some merchants //will want to replace the cart contents //others will want to synch them. We're going to assume that //this scenario will synch the existing items. //############### Synch the Cart Items if (registeredOrder.OrderItemCollection.Count > 0 && anonymousOrder.OrderItemCollection.Count > 0) { //there are items in both carts, move the old to the new //when synching, find matching items in both carts //update the quantities of the matching items in the logged-in cart //removing them from the anon cart //a switch to tell us if we need to update the from orders //1.) Find items that are the same between the two carts and add the anon quantity to the registered user quantity //2.) Mark found items as items to be removed from the anon cart. ArrayList toBeRemoved = new ArrayList(anonymousOrder.OrderItemCollection.Count); for (int i = 0; i < anonymousOrder.OrderItemCollection.Count; i++) { OrderItem foundItem = registeredOrder.OrderItemCollection.Find(delegate(OrderItem orderItemToFind) { return (orderItemToFind.Sku == anonymousOrder.OrderItemCollection[i].Sku) && (orderItemToFind.Attributes == anonymousOrder.OrderItemCollection[i].Attributes); }); if (foundItem != null) { foundItem.Quantity += anonymousOrder.OrderItemCollection[i].Quantity; toBeRemoved.Add(i); } } //3.) Now remove any foundItems from the anon cart, but trim it up first toBeRemoved.TrimToSize(); for (int i = 0; i < toBeRemoved.Count; i++) { anonymousOrder.OrderItemCollection.RemoveAt((int)toBeRemoved[i]); } //4.) Move over to the registered user cart any remaining items in the anon cart. foreach (OrderItem anonItem in anonymousOrder.OrderItemCollection) { //reset the orderID anonItem.OrderId = registeredOrder.OrderId; registeredOrder.OrderItemCollection.Add(anonItem); } //5.) Finally, save it down to the DB // (Since we know toOrder.Items.Count > 0 && fromOrder.Items.Count > 0, we know a Save needs to occur) registeredOrder.OrderItemCollection.SaveAll(registeredCartId); registeredOrder.Save(registeredCartId); } else if (registeredOrder.OrderItemCollection.Count == 0) { //items exist only in the anon cart //move the anon items to the new cart //then save the order and the order items. registeredOrder.IsNew = true; registeredOrder.OrderStatusDescriptorId = anonymousOrder.OrderStatusDescriptorId; registeredOrder.OrderGuid = anonymousOrder.OrderGuid; registeredOrder.UserName = registeredCartId; registeredOrder.OrderNumber = anonymousOrder.OrderNumber; registeredOrder.Save(registeredCartId); foreach (OrderItem item in anonymousOrder.OrderItemCollection) { //reset the orderID on each item item.OrderId = registeredOrder.OrderId; registeredOrder.OrderItemCollection.Add(item); } registeredOrder.OrderItemCollection.SaveAll(registeredCartId); registeredOrder.Save(registeredCartId); } else if (anonymousOrder.OrderItemCollection.Count == 0) { //no items in the old cart, do nothing } //finally, drop the anon order from the DB, we don't want to //keep it OrderItem.Delete(OrderItem.Columns.OrderId, anonymousOrder.OrderId); Order.Delete(anonymousOrder.OrderId); } } }
/// <summary> /// Fetches the shipping options. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static ShippingOptionCollection FetchShippingOptions(string userName) { Order order = new OrderController().FetchOrder(userName); ShippingService shippingService = new ShippingService(); ShippingOptionCollection shippingOptionCollection = shippingService.GetShippingOptions(order); return shippingOptionCollection; }
/// <summary> /// Handles the Click event of the btnAddToCart control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnAddToCart_Click(object sender, EventArgs e) { if (Master.SiteSettings.LoginRequirement == LoginRequirement.Add_To_Cart) { if (!User.Identity.IsAuthenticated) { Response.Redirect(string.Format("login.aspx?ReturnUrl={0}", Request.Url), true); } } int quantity; if (ddlQuantity.Visible) { int.TryParse(ddlQuantity.SelectedValue, out quantity); } else { int.TryParse(txtQuantity.Text.Trim(), out quantity); } if (quantity > 0) { string sku = productAttributes.GetSku(); decimal pricePaid = _product.OurPrice; Store.AttributeCollection selectedAttributes = productAttributes.SelectedAttributes; foreach (Store.Attribute attribute in selectedAttributes) { foreach (AttributeItem attributeItem in attribute.AttributeItemCollection) { pricePaid += attributeItem.Adjustment; } } //string selectAttributesString = selectedAttributes.ToString(); OrderController orderController = new OrderController(); orderController.AddItemToOrder(WebUtility.GetUserName(), _product.ProductId, _product.Name, sku, quantity, pricePaid, _product.ItemTax, _product.Weight, selectedAttributes.ToString(), selectedAttributes.ExtentedProperties.ToXml()); Response.Redirect("~/cart.aspx", true); } }
/// <summary> /// Handles the Click event of the lbUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void lbUpdate_Click(object sender, EventArgs e) { TextBox txtQuantity; Label lblOrderItemId; Label lblName; DropDownList ddlQuantity; foreach(RepeaterItem item in orderSummary.Repeater.Items) { txtQuantity = item.FindControl("txtQuantity") as TextBox; ddlQuantity = item.FindControl("ddlQuantity") as DropDownList; lblOrderItemId = item.FindControl("lblOrderItemId") as Label; lblName = item.FindControl("lblName") as Label; int orderItemId = 0; int quantity = 0; if((txtQuantity != null || ddlQuantity != null) && lblOrderItemId != null) { int.TryParse(lblOrderItemId.Text, out orderItemId); if(orderItemId > 0) { if(!string.IsNullOrEmpty(txtQuantity.Text)) { int.TryParse(txtQuantity.Text, out quantity); } if(!string.IsNullOrEmpty(ddlQuantity.SelectedValue)) { int.TryParse(ddlQuantity.SelectedValue, out quantity); } if(quantity > 0) { new OrderController().AdjustQuantity(order.OrderId, orderItemId, quantity, WebUtility.GetUserName()); } else { new OrderController().RemoveItem(order.OrderId, orderItemId, WebUtility.GetUserName()); } } } } Order modifiedOrder = new OrderController().FetchOrder(WebUtility.GetUserName()); if(modifiedOrder.OrderItemCollection.Count == 0) { Order.Delete(modifiedOrder.OrderId); } Response.Redirect("~/cart.aspx"); }
/// <summary> /// Gets the item count. /// </summary> /// <returns></returns> private string GetItemCount() { int orderItemCount = new OrderController().GetItemCountInOrder(WebUtility.GetUserName()); return "(" + orderItemCount.ToString() + ")"; }