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 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 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); } }
public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg) { if (bSandbox) { pEndPointURL = pEndPointURL_SB; host = host_SB; } var returnURL = "https://localhost:44324/Checkout/CheckoutReview.aspx"; var cancelURL = "https://localhost:44324/Checkout/CheckoutCancel.aspx"; var encoder = new NVPCodec { ["METHOD"] = "SetExpressCheckout", ["RETURNURL"] = returnURL, ["CANCELURL"] = cancelURL, ["BRANDNAME"] = "Wingtip Toys Sample Application", ["PAYMENTREQUEST_0_AMT"] = amt, ["PAYMENTREQUEST_0_ITEMAMT"] = amt, ["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale", ["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD" }; // Get the Shopping Cart Products using (var myCartOrders = new ShoppingCartActions()) { var myOrderList = myCartOrders.GetCartItems(); for (int i = 0; i < myOrderList.Count; i++) { encoder[$"L_PAYMENTREQUEST_0_NAME{i}"] = myOrderList[i].Product.Name; encoder[$"L_PAYMENTREQUEST_0_AMT{i}"] = myOrderList[i].Product.UnitPrice.ToString(); encoder[$"L_PAYMENTREQUEST_0_QTY{i}"] = myOrderList[i].Quantity.ToString(); } } var pStrrequestforNvp = encoder.Encode(); var pStresponsenvp = HttpCall(pStrrequestforNvp); var decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); var strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; var 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); } }
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; } }
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(); } }
public List<CartItem> GetShoppingcartItems( ) { ShoppingCartActions actions = new ShoppingCartActions(); return actions.GetCartItems(); }
public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg) { if (bSandbox) { pEndPointURL = pEndPointURL_SB; host = host_SB; } string returnURL = "https://localhost:44302/Checkout/CheckoutReview.aspx"; string cancelURL = "https://localhost:44302/Checkout/CheckoutCancel.aspx"; NVPCodec encoder = new NVPCodec { ["METHOD"] = "SetExpressCheckout", ["RETURNURL"] = returnURL, ["CANCELURL"] = cancelURL, ["BRANDNAME"] = "Wingtip Toys Sample Application", ["PAYMENTREQUEST_0_AMT"] = amt, ["PAYMENTREQUEST_0_ITEMAMT"] = amt, ["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale", ["PAYMENTREQUEST_0_CURRENCYCODE"] = PaymentCurrencyCode }; // Get the Shopping Cart Products using (ShoppingCartActions myCartOrders = new 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(); var unitPrice = myOrderList[i].Product.UnitPrice; encoder["L_PAYMENTREQUEST_0_AMT" + i] = unitPrice.HasValue ? ((double)unitPrice).ToString(CultureInfo.InvariantCulture) : string.Empty; 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); } }
public List<CartItem> GetShoppingCartItems() { ShoppingCartActions actions = new ShoppingCartActions(); var items = actions.GetCartItems(); return items; }
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 sca = new ShoppingCartActions(); return sca.GetCartItems(); }
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) { 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); } } }