public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg) { if (bSandbox) { pEndPointURL = pEndPointURL_SB; host = host_SB; } string returnURL = $"{baseUri}Checkout/CheckoutReview.aspx"; string cancelURL = $"{baseUri}Checkout/CheckoutCancel.aspx"; NVPCodec encoder = new NVPCodec { ["METHOD"] = "SetExpressCheckout", ["RETURNURL"] = returnURL, ["CANCELURL"] = cancelURL, ["BRANDNAME"] = "Wingtip Toys Sample Application", ["PAYMENTREQUEST_0_AMT"] = String.Format("{0:c}", amt.Replace(',', '.')), //HOTFIX ["PAYMENTREQUEST_0_ITEMAMT"] = String.Format("{0:c}", amt.Replace(',', '.')), //HOTFIX ["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale", ["PAYMENTREQUEST_0_CURRENCYCODE"] = "PLN" }; // Get the Shopping Cart Products using (WingtipToys.Logic.ShoppingCartActions myCartOrders = new WingtipToys.Logic.ShoppingCartActions()) { List <CartItem> myOrderList = myCartOrders.GetCartItems(); for (int i = 0; i < myOrderList.Count; i++) { encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString(); encoder["L_PAYMENTREQUEST_0_AMT" + i] = String.Format("{0:c}", myOrderList[i].Product.UnitPrice.ToString().Replace(',', '.')); //HOTFIX encoder["L_PAYMENTREQUEST_0_QTY" + i] = myOrderList[i].Quantity.ToString(); } } string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token; retMsg = ECURL; return(true); } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); } }
protected void Page_Load(object sender, EventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { decimal cartTotal = 0; cartTotal = usersShoppingCart.GetTotal(); if (cartTotal > 0) { // Display total lblTotal.Text = String.Format("{0:c}", cartTotal); } else { LabelTotalText.Text = ""; lblTotal.Text = ""; ShoppingCartTitle.InnerText = "Shopping Cart is Empty"; UpdateBtn.Visible = false; } } }
protected void Page_PreRender(object sender, EventArgs e) { using (Logic.ShoppingCartActions usersShoppingCart = new Logic.ShoppingCartActions()) { cartCount.InnerText = string.Format("Cart ({0})", usersShoppingCart.GetCount()); } }
public List<CartItem> UpdateCartItems( ) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { String cartId = usersShoppingCart.GetCartId(); ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count]; for (int i =0; i < CartList.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(CartList.Rows[i] ); cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"] ); CheckBox cbRemove = new CheckBox(); cbRemove = (CheckBox) CartList.Rows[i].FindControl( "Remove" ); cartUpdates[i].RemoveItem = cbRemove.Checked; TextBox quantityTextBox = new TextBox(); quantityTextBox =(TextBox) CartList.Rows[i].FindControl("PurchaseQuantity"); cartUpdates[i].PurchaseQuantity =Convert.ToInt16(quantityTextBox.Text.ToString()); } usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates); CartList.DataBind(); lblTotal.Text =String.Format("{0:c}", usersShoppingCart.GetTotal()); return usersShoppingCart.GetCartItems(); } }
public List <Models.CartItem> UpdateCartItems() { using (Logic.ShoppingCartActions usersShoppingCart = new Logic.ShoppingCartActions()) { string cartId = usersShoppingCart.GetCartId(); Logic.ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new Logic.ShoppingCartActions.ShoppingCartUpdates[CartGrid.Rows.Count]; for (int i = 0; i < CartGrid.Rows.Count; i++) { //IOrderedDictionary rowValues = new OrderedDictionary(); IOrderedDictionary rowValues = GetValues(CartGrid.Rows[i]); cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]); //CheckBox cbRemove = new CheckBox(); CheckBox cbRemove = (CheckBox)CartGrid.Rows[i].FindControl("Remove"); cartUpdates[i].RemoveItem = cbRemove.Checked; //TextBox quantityTextBox = new TextBox(); TextBox quantityTextBox = (TextBox)CartGrid.Rows[i].FindControl("PurchaseQuantity"); cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString()); } usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates); CartGrid.DataBind(); lblTotal.Text = string.Format("{0:c}", usersShoppingCart.GetTotal()); return(usersShoppingCart.GetCartItems()); } }
public ShoppingCartActions GetCart(HttpContext context) { using (var cart = new ShoppingCartActions()) { cart.ShoppingCartId = cart.GetCartId(); return cart; } }
protected void Page_PreRender(object sender, EventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { string cartStr = string.Format("Cart ({0})", usersShoppingCart.GetCount()); cartCount.InnerText = cartStr; } }
protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { Session["payment amt"] = usersShoppingCart.GetTotal(); } Response.Redirect( "Checkout/CheckoutStart.aspx" ); }
public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg) { if (bSandbox) { pEndPointURL = pEndPointURL_SB; host = host_SB; } string returnURL = "http://localhost:53417/Checkout/CheckoutReview.aspx"; string cancelURL = "http://localhost:53417/Checkout/CheckoutCancel.aspx"; NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["BRANDNAME"] = "Wingtip Toys Sample Application"; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD"; // Get the Shopping Cart Products WingtipToys.Logic.ShoppingCartActions myCartOrders = new WingtipToys.Logic.ShoppingCartActions(); List<CartItem> myOrderList = myCartOrders.GetCartItems(); for (int i = 0; i < myOrderList.Count; i++) { encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString(); encoder["L_PAYMENTREQUEST_0_AMT" + i] = myOrderList[i].Product.UnitPrice.ToString(); encoder["L_PAYMENTREQUEST_0_QTY" + i] = myOrderList[i].Quantity.ToString(); } string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token; retMsg = ECURL; return true; } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return false; } }
protected void Page_Load(object sender, EventArgs e) { string rawId = Request.QueryString["ProductID"]; int productId; if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId)) { ShoppingCartActions usersShoppingCart = new ShoppingCartActions(); usersShoppingCart.AddToCart(Convert.ToInt16(rawId)); } else { Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId."); throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId."); } Response.Redirect("ShoppingCart.aspx"); }
public ActionResult AddToCard(int? id) { int productId; if (!String.IsNullOrEmpty(id.ToString()) && int.TryParse(id.ToString(), out productId)) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.AddToCart(Convert.ToInt16(id.ToString())); } } else { throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId."); } return RedirectToAction("Index"); }
protected void Page_Load(object sender, EventArgs e) { string rawId = Request.QueryString["ProductID"]; int productId; if (!string.IsNullOrWhiteSpace(rawId) && int.TryParse(rawId, out productId)) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.AddToCart(Convert.ToInt16(rawId)); } } else { Debug.Fail("ERROR : We should never get here..."); throw new Exception("ERROR: illegal operation"); } Response.Redirect("ShoppingCart.aspx"); }
protected void Page_Load(object sender, EventArgs e) { using (Logic.ShoppingCartActions usersShoopingCart = new Logic.ShoppingCartActions()) { decimal cartTotal = usersShoopingCart.GetTotal(); if (cartTotal > 0) { lblTotal.Text = string.Format("{0:c}", cartTotal); } else { LabelTotalText.Text = ""; lblTotal.Text = ""; ShoppingCartTitle.InnerText = "Shopping Cart is Empty"; UpdateBtn.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { string rawId = Request.QueryString["ProductID"]; if (!string.IsNullOrEmpty(rawId) && int.TryParse(rawId, out int productId)) { using (Logic.ShoppingCartActions usersShoppingCart = new Logic.ShoppingCartActions()) { //usersShoppingCart.AddToCart(Convert.ToInt16(rawId)); usersShoppingCart.AddToCart(productId); } } else { Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId."); throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId."); } Response.Redirect("ShoppingCart.aspx"); }
public List<CartItem> UpdateCartItems() { using (ShoppingCartActions sca = new ShoppingCartActions()) { String cartID = sca.GetCartID(); ShoppingCartActions.ShoppingCartUpdates[] cartUpdts = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count]; for (int i = 0; i < CartList.Rows.Count; i++) { IOrderedDictionary rowVals = new OrderedDictionary(); rowVals = GetValues(CartList.Rows[i]); cartUpdts[i].ProductID = Convert.ToInt32(rowVals["ProductID"]); CheckBox cbRemv = (CheckBox)CartList.Rows[i].FindControl("Remove"); cartUpdts[i].RemoveItem = cbRemv.Checked; TextBox txtQty = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity"); cartUpdts[i].PurchaseQty = Convert.ToInt32(txtQty.Text); } sca.UpdateShoppingCartDatabase(cartID, cartUpdts); CartList.DataBind(); lblTotal.Text = String.Format("{0:c}", sca.GetTotal()); return sca.GetCartItems(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NVPAPICaller payPalCaller = new NVPAPICaller(); string retMsg = ""; string token = ""; string PayerID = ""; NVPCodec decoder = new NVPCodec(); token = Session["token"].ToString(); bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg); if (ret) { Session["payerId"] = PayerID; var myOrder = new Order(); myOrder.OrderDate = Convert.ToDateTime(decoder["TIMESTAMP"].ToString()); myOrder.Username = User.Identity.Name; myOrder.FirstName = decoder["FIRSTNAME"].ToString(); myOrder.LastName = decoder["LASTNAME"].ToString(); myOrder.Address = decoder["SHIPTOSTREET"].ToString(); myOrder.City = decoder["SHIPTOCITY"].ToString(); myOrder.State = decoder.Get("SHIPTOSTATE") ?? ""; myOrder.PostalCode = decoder["SHIPTOZIP"].ToString() ?? ""; myOrder.Country = decoder["SHIPTOCOUNTRYCODE"].ToString() ?? ""; myOrder.Email = decoder["EMAIL"].ToString(); myOrder.Total = decimal.Parse(decoder.Get("AMT"), NumberStyles.Currency, PLNNumberFormat.GetPLNNumberFormat); // Verify total payment amount as set on CheckoutStart.aspx. try { decimal paymentAmountOnCheckout = decimal.Parse(Session["payment_amt"].ToString(), NumberStyles.Currency, PLNNumberFormat.GetPLNNumberFormat); decimal paymentAmoutFromPayPal = decimal.Parse(decoder.Get("AMT"), NumberStyles.Currency, PLNNumberFormat.GetPLNNumberFormat); if (paymentAmountOnCheckout != paymentAmoutFromPayPal) { Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch."); } } catch (Exception) { Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch."); } // Get DB context. ProductContext _db = new ProductContext(); // Add order to DB. _db.Orders.Add(myOrder); _db.SaveChanges(); // Get the shopping cart items and process them. using (WingtipToys.Logic.ShoppingCartActions usersShoppingCart = new WingtipToys.Logic.ShoppingCartActions()) { List <CartItem> myOrderList = usersShoppingCart.GetCartItems(); // Add OrderDetail information to the DB for each product purchased. for (int i = 0; i < myOrderList.Count; i++) { // Create a new OrderDetail object. var myOrderDetail = new OrderDetail(); myOrderDetail.OrderId = myOrder.OrderId; myOrderDetail.Username = User.Identity.Name; myOrderDetail.ProductId = myOrderList[i].ProductId; myOrderDetail.Quantity = myOrderList[i].Quantity; myOrderDetail.UnitPrice = myOrderList[i].Product.UnitPrice; // Add OrderDetail to DB. _db.OrderDetails.Add(myOrderDetail); _db.SaveChanges(); } // Set OrderId. Session["currentOrderId"] = myOrder.OrderId; // Display Order information. List <Order> orderList = new List <Order>(); orderList.Add(myOrder); ShipInfo.DataSource = orderList; ShipInfo.DataBind(); // Display OrderDetails. OrderItemList.DataSource = myOrderList; OrderItemList.DataBind(); } } else { Response.Redirect("CheckoutError.aspx?" + retMsg); } } }
public List<CartItem> GetShoppingcartItems( ) { ShoppingCartActions actions = new ShoppingCartActions(); return actions.GetCartItems(); }
protected void Page_PreRender(object sndr, EventArgs e) { using (ShoppingCartActions sca = new ShoppingCartActions()) { string cnt = string.Format("Cart({0})", sca.GetCount()); cartCount.InnerText = cnt; } }
protected void CheckoutBtn_Click(object sender, EventArgs e) { Good[] itemIDAndCount = null; using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { Session["payment_amt"] = usersShoppingCart.GetTotal(); List<CartItem> items = usersShoppingCart.GetCartItems(); int count = items.Count; itemIDAndCount = new Good[count]; for (int i = 0; i < count; ++i) { itemIDAndCount[i].ItemID = items[i].ProductId; itemIDAndCount[i].Count = items[i].Quantity; } } int indexDate = DropDownListDate.SelectedIndex; int indexTime = DropDownListTime.SelectedIndex; DateTime now = DateTime.Now; DateTime time = new DateTime(now.Year, now.Month, now.Day + indexDate, 4 * indexTime, 0, 0); bool allRight = false; try { createRequest(itemIDAndCount, time); allRight = true; //Response.Redirect("http://localhost:24019/Checkout/CheckoutReview.aspx"); } catch (ExceptionSupplierSystemOff) { LabelError.Text = "Поставщики не отвечают."; LabelError.Visible = true; } catch (ExceptionSupplierSystemNotGood) { LabelError.Text = "Запрос не может быть удовлетворён."; LabelError.Visible = true; } catch (ExceptionSupplierSystemConfirmFail) { LabelError.Text = "Проблема связи с поставщиками."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceOff) { LabelError.Text = "Службы доставки не отвечают."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceWrongTime) { LabelError.Text = "Запрос на доставку не может быть удовлетворён."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceConfirmFail) { LabelError.Text = "Проблема связи со службой доставки."; LabelError.Visible = true; } catch (Exception exception) { Console.WriteLine("Exception: {0}", exception); Response.Redirect("http://localhost:24019/Checkout/CheckoutCancel.aspx"); } // //Response.Redirect("Checkout/CheckoutStart.aspx"); if (allRight) { Response.Redirect("Checkout/CheckoutInformation.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { decimal cartTotal = 0; cartTotal = usersShoppingCart.GetTotal(); if (cartTotal > 0) { // Display Total. lblTotal.Text = String.Format("{0:c}", cartTotal); } else { LabelTotalText.Text = ""; lblTotal.Text = ""; ShoppingCartTitle.InnerText = "Корзина пуста"; UpdateBtn.Visible = false; CheckoutBtn.Visible = false; ResultAndADate.Visible = false; } } { int day = DateTime.Now.Day; int month = DateTime.Now.Month; int indexDate = DropDownListDate.SelectedIndex; DropDownListDate.Items.Clear(); for (int i = 0; i < 7; ++i) { DropDownListDate.Items.Add((day + i) + " / " + month); } DropDownListDate.SelectedIndex = indexDate; int indexTime = DropDownListTime.SelectedIndex; DropDownListTime.Items.Clear(); for (int i = 0; i < 6; ++i) { DropDownListTime.Items.Add("c " + (4 * i) + " по " + (4 * i + 4)); } DropDownListTime.SelectedIndex = indexTime; } }
public ShoppingCartActions GetCart(HttpContext context) { var cart = new ShoppingCartActions(); cart.ShoppingCartId = cart.GetCartID(); return cart; }
public List<CartItem> GetShoppingCartItems() { ShoppingCartActions sca = new ShoppingCartActions(); return sca.GetCartItems(); }
protected void Button1_Click(object sender, EventArgs e) { ProductContext _db = new ProductContext(); var myOrder = new Order(); myOrder.OrderDate = DateTime.Today; myOrder.Username = User.Identity.Name; myOrder.FirstName = TextBox1.Text; myOrder.LastName = TextBox2.Text; myOrder.Address = TextBox3.Text; myOrder.Email = User.Identity.Name; myOrder.Total = lbltotal.Text; _db.Orders.Add(myOrder); _db.SaveChanges(); using (WingtipToys.Logic.ShoppingCartActions usersShoppingCart = new WingtipToys.Logic.ShoppingCartActions()) { List <CartItem> myOrderList = usersShoppingCart.GetCartItems(); // Add OrderDetail information to the DB for each product purchased. for (int i = 0; i < myOrderList.Count; i++) { // Create a new OrderDetail object. var myOrderDetail = new OrderDetail(); myOrderDetail.OrderId = myOrder.OrderId; myOrderDetail.Username = User.Identity.Name; myOrderDetail.ProductId = myOrderList[i].ProductId; myOrderDetail.Quantity = myOrderList[i].Quantity; myOrderDetail.UnitPrice = myOrderList[i].Product.UnitPrice; // Add OrderDetail to DB. _db.OrderDetails.Add(myOrderDetail); _db.SaveChanges(); } } try { conn.Open(); SqlCommand cmd = new SqlCommand("Insert into Payments(Date,Username,CardType,CardNo,Amount) values(@Date,@Username,@CardType,@CardNo,@Amount)", conn); cmd.Parameters.AddWithValue("@Date", DateTime.Today); cmd.Parameters.AddWithValue("@Username", User.Identity.Name); cmd.Parameters.AddWithValue("@CardType", ddlcardtype.SelectedValue); cmd.Parameters.AddWithValue("@CardNo", txtCardNumber.Text); cmd.Parameters.AddWithValue("@Amount", lbltotal.Text); cmd.ExecuteNonQuery(); cmd.Dispose(); lblStatus.Text = "Thank for your feedback......!"; } catch (SqlException ex) { lblStatus.Text = ex.Message; } finally { conn.Close(); } }
public List<CartItem> GetShoppingCartItems() { ShoppingCartActions actions = new ShoppingCartActions(); var items = actions.GetCartItems(); return items; }