public ActionResult ShoppingBag(int sb_id = 0, int p_id = 0) { db = new AvonessaDBEntities(); if (p_id != 0 & sb_id != 0) //удаление товара из сумки: { outputProductExistsInBag = new ObjectParameter("pExistsInBag", typeof(bool)); var i = db.sp_DeleteProductFromSB(sb_id, p_id, outputProductExistsInBag); db.SaveChanges(); bool exists = true; exists = bool.Parse(outputProductExistsInBag.Value.ToString()); if (!exists) //сумка пуста , exists = false { //удаляем куки:======================================= HttpCookie ShoppingBagCookie; ShoppingBagCookie = new HttpCookie("AvonessaShoppingBag"); ShoppingBagCookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(ShoppingBagCookie); //==================================================== return(RedirectToAction("Index", "Home")); } } var sb = from SB in db.sp_GetShoppingBagById(sb_id) select SB; //SendMail("*****@*****.**", "*****@*****.**", "Оплачен товар на Avonessa.com", "ToBuyer", "164", "RU"); //SendMail("*****@*****.**", "*****@*****.**", "Payment to Avonessa.com is completed", "ToBuyer", "165", "EN"); ViewBag.sbUrl = ""; return(View(sb.ToList())); }
public ActionResult Photoshoots() { db = new AvonessaDBEntities(); var ps = from s in db.sp_GetPhotoshoots() select s; return(View(ps.ToList())); }
public string GetShoppingBagQuantity() { int iSB_Id = int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_id"].ToString()); db = new AvonessaDBEntities(); string sbq = ""; var SBQ = (from sb in db.sp_GetSBQuantity(iSB_Id) select sb).SingleOrDefault(); sbq = SBQ.Value.ToString(); return(sbq); }
private void MakeShoppingBagInDB(string p_id, string quantity) { db = new AvonessaDBEntities(); short iQuntity = short.Parse(quantity); outputSB_ID = new ObjectParameter("SB_Id_out", typeof(int)); var i = db.sp_MakeShoppingBag(int.Parse(p_id), iSB_Id, iQuntity, outputSB_ID); db.SaveChanges(); iSB_Id = int.Parse(outputSB_ID.Value.ToString()); if (iSB_Id == -1) { bpExists = true; //уже есть в сумке } }
public ActionResult Products(int id = 0) { db = new AvonessaDBEntities(); var ps = from p in db.sp_GetProducts_1(id, -1) select p; var cn = (from c in db.Categories where c.C_Id == id select new { n = c.CategoryName }).SingleOrDefault(); var cnEn = (from c in db.Categories where c.C_Id == id select new { n = c.CategoryNameEnglish }).SingleOrDefault(); ViewBag.CategoryName = cn.n; ViewBag.CategoryNameEnglish = cnEn.n; return(View(ps.ToList())); }
private void GetProductData(int p_id) { db = new AvonessaDBEntities(); var pt = (from p in db.sp_GetProducts_1(0, p_id) select p).SingleOrDefault(); ViewBag.ProductName = pt.ProductName; ViewBag.ProductNameEnglish = pt.ProductNameEnglish; ViewBag.ProductCost = pt.ProductCost; ViewBag.P_Id = pt.P_Id; ViewBag.ImageFilePath = pt.ImageFilePath; ViewBag.ImageFilePath2 = pt.ImageFilePath2; ViewBag.Notes = pt.Notes; ViewBag.NotesEnglish = pt.NotesEnglish; ViewBag.CategoryName = pt.CategoryName; ViewBag.CategoryNameEnglish = pt.CategoryNameEnglish; }
//Для PayPal public ActionResult Success(string sb_id) { string payerID = Request.QueryString["PayerID"].ToString(); string paymentId = Request.QueryString["paymentId"].ToString(); //var sdkConfig = new Dictionary<string, string> { { "mode", "sandbox" } };// when you're live, change "sandbox" to "live" //string accessToken = new OAuthTokenCredential("ATrx7laOExss5QgsAMYpryJJZfo_Vw3gz0_HzOXMNFJjl4bb5rMrmUpj6nRyzm7uJgi-mebtQ7LhUF8y", // "ECDJMgNsx4rwhkHsATlsnp1DUoy6xZXOdLfLpOPqE6ErAHKkRuDQOctcDgEBgSBz68jmzn5OGtwuMTYN", sdkConfig) // .GetAccessToken(); var sdkConfig = new Dictionary <string, string> { { "mode", "live" } }; // when you're live, change "sandbox" to "live" string accessToken = new OAuthTokenCredential("AbZ5lBaf9HfwR9ixms8A4qunW_4m06hliKjqB8NgLOup_4kP1AemIlzu04FOZoKjg2cu0OJYUt4P-YUt", "EOniNB_yLiy4XCNsTzZoadF9dG7MK5aUYwJo4cJk6v0WY54ZIKkZIiBtJWqA1Jam_1rDuR57sYqKCXts", sdkConfig) .GetAccessToken(); var pymntExecution = new PaymentExecution { payer_id = payerID }; var payment = new Payment { id = paymentId } .Execute(new APIContext(accessToken) { Config = sdkConfig }, pymntExecution); //добавляем в таблицу БД Orders sPayerId======== int iSB_Id = int.Parse(sb_id);// int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_Id"].ToString()); db = new AvonessaDBEntities(); var i = db.sp_InsertOrderDeleteSB(payerID, iSB_Id, paymentId); //удаляем куки:======================================= HttpCookie ShoppingBagCookie; ShoppingBagCookie = new HttpCookie("AvonessaShoppingBag"); ShoppingBagCookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(ShoppingBagCookie); ViewBag.OrderId = payerID; return(View()); }
public ActionResult Index(int id = 0) { if (Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"].ToString().Substring(0, 2) != "ru") { bIsRussian = false; } db = new AvonessaDBEntities(); int c_id = 0; if (id == 0) { c_id = 1; } else { c_id = 13; } if (bIsRussian) { var vCatNameRu = (from cn in db.Categories where cn.C_Id == c_id select new { n = cn.CategoryName }).SingleOrDefault(); ViewBag.CategoryNameRu = vCatNameRu.n; } else { var vCatNameEn = (from cn in db.Categories where cn.C_Id == c_id select new { n = cn.CategoryNameEnglish }).SingleOrDefault(); ViewBag.CategoryNameEn = vCatNameEn.n; } var ci = from CI in db.sp_GetCategories(c_id) select CI; return(View(ci.ToList())); }
//Для PayPal IPN не забыть изменить адрес без sandbox!!! public void MakePayPalOrderVerification() { string Receiver_email = ""; string Payment_status = ""; string Payer_id = ""; string Payment_amount; string str = ""; str = Request.Form + "&cmd=_notify-validate"; ServerXMLHTTP srv = new ServerXMLHTTP(); try { //srv.open("POST", @"https://www.sandbox.paypal.com/cgi-bin/webscr", false, null, null); srv.open("POST", @"https://www.paypal.com/cgi-bin/webscr", false, null, null); srv.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); srv.send(str); Receiver_email = Request.Form["receiver_email"].ToString(); Payer_id = Request.Form["payer_id"].ToString(); Payment_status = Request.Form["payment_status"].ToString(); Payment_date = Request.Form["payment_date"].ToString(); Payer_email = Request.Form["payer_email"].ToString(); Payment_amount = Request.Form["mc_gross"].ToString(); First_name = Request.Form["first_name"].ToString(); Last_name = Request.Form["last_name"].ToString(); Address_country = Request.Form["address_country"].ToString(); Address_country_code = Request.Form["address_country_code"].ToString(); Address_zip = Request.Form["address_zip"].ToString(); Address_state = Request.Form["address_state"].ToString(); Address_city = Request.Form["address_city"].ToString(); Address_street = Request.Form["address_street"].ToString(); Txn_id = Request.Form["txn_id"].ToString(); if (srv.status != 200) //HTTP error handling //отправка email мне { SendMail("*****@*****.**", "*****@*****.**", "Ошибка 200 - платёж не прошёл", "Error_200"); } else if (srv.responseText == "VERIFIED") { if (Payment_status == "Completed") //check that Payment_status=Completed { //insert into DB значений db = new AvonessaDBEntities(); var i = (db.sp_InsertDataFromPayPal_0(First_name + " " + Last_name, Payer_email, Address_country, Address_zip, Address_country_code, Address_state, Address_city, Address_street, Payer_id, Payment_date, Txn_id)).SingleOrDefault(); //отправляем оповещения SendMail("*****@*****.**", "*****@*****.**", "Оплачено покупателем avonessa.com", "ToUs", i.Value.ToString()); SendMail("*****@*****.**", Payer_email, "", "ToBuyer", i.Value.ToString(), Address_country_code); } if (Receiver_email != "*****@*****.**") //check that Receiver_email is your Primary PayPal [email protected] { SendMail("*****@*****.**", "*****@*****.**", "IPN is hacked", "IPN_IsHacked"); } } else if (srv.responseText == "INVALID") { SendMail("*****@*****.**", "*****@*****.**", "IPN is hacked, maybe", "responseText_INVALID"); } else { SendMail("*****@*****.**", "*****@*****.**", "Unknown error", "Unknown_error"); } } finally { IDisposable disposable = srv as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
//Для PayPal отправляется Form "SBCFormEn". Не забыть изменить sandbox на live public void MakePayPalTransactionEn() { string sTotal = ""; decimal dTotal = 0; short sQuantity = 0; short i = 0; //выборка сумки из базы db = new AvonessaDBEntities(); int iSB_Id = int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_Id"].ToString()); var query = from sb in db.sp_GetShoppingBagById(iSB_Id) select sb; List <Item> itms = new List <Item>(); Item item = null; foreach (var sb_data in query.ToList()) { sQuantity = short.Parse(Request.Form["qty_item_en_" + i.ToString()].ToString()); var iq = db.sp_InsertQuantityToSB(int.Parse(sb_data.P_Id.ToString()), iSB_Id, sQuantity); dTotal += sQuantity * decimal.Parse(sb_data.ProductCost.ToString()); item = new Item(); item.name = sb_data.ProductNameEnglish; //название на английском item.currency = "USD"; item.price = sb_data.ProductCost.ToString().Replace(",", "."); item.quantity = Request.Form["qty_item_en_" + i.ToString()].ToString(); item.sku = sb_data.P_Id.ToString(); itms.Add(item); i++; } ItemList itemList = new ItemList(); itemList.items = itms; ////Country Code======================= //LookupService ls = new LookupService(@"E:/web/avoness1/App_Data/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); //Country c = ls.getCountry(Request.ServerVariables["REMOTE_ADDR"]); //string cc = c.getCode(); ////=================================== //ShippingAddress sa = new ShippingAddress(); //sa.country_code = cc; //itemList.shipping_address = sa; //===================================== //var sdkConfig = new Dictionary<string, string> { { "mode", "sandbox" } };// when you're live, change "sandbox" to "live" //string accessToken = new OAuthTokenCredential("ATrx7laOExss5QgsAMYpryJJZfo_Vw3gz0_HzOXMNFJjl4bb5rMrmUpj6nRyzm7uJgi-mebtQ7LhUF8y", // "ECDJMgNsx4rwhkHsATlsnp1DUoy6xZXOdLfLpOPqE6ErAHKkRuDQOctcDgEBgSBz68jmzn5OGtwuMTYN", sdkConfig) // .GetAccessToken(); var sdkConfig = new Dictionary <string, string> { { "mode", "live" } }; // when you're live, change "sandbox" to "live" string accessToken = new OAuthTokenCredential("AbZ5lBaf9HfwR9ixms8A4qunW_4m06hliKjqB8NgLOup_4kP1AemIlzu04FOZoKjg2cu0OJYUt4P-YUt", "EOniNB_yLiy4XCNsTzZoadF9dG7MK5aUYwJo4cJk6v0WY54ZIKkZIiBtJWqA1Jam_1rDuR57sYqKCXts", sdkConfig) .GetAccessToken(); var redirectUrls = new RedirectUrls { cancel_url = "http://www.avonessa.com/ShopBagOrder/ShoppingBag/?sb_id=" + iSB_Id + "&cancel=true", return_url = "http://www.avonessa.com/ShopBagOrder/Success/?sb_id=" + iSB_Id + "&success=true" }; // Specify details of your payment amount. Details _details = new Details(); decimal _dShip = 8.75m; // цена поставки sTotal = dTotal.ToString().Replace(",", "."); _details.shipping = _dShip.ToString().Replace(",", "."); _details.subtotal = sTotal; _details.tax = "0"; dTotal = dTotal + _dShip; sTotal = dTotal.ToString().Replace(",", "."); var amnt = new Amount { currency = "USD", total = sTotal, details = _details }; var createdPayment = new Payment { intent = "sale", payer = new Payer { payment_method = "paypal" }, transactions = new List <Transaction> { new Transaction { description = "Payment for the product", amount = amnt, item_list = itemList } }, redirect_urls = redirectUrls }.Create(new APIContext(accessToken) { Config = sdkConfig }); var approvalUrl = createdPayment.links.Single(l => l.rel == "approval_url").href; //Переход на страницу PayPal для продолжения оплаты: Response.Redirect(approvalUrl); }
//[HttpPost] //public ActionResult InsertContacts() //{ // string sPostCode = Request.Form["postalCodeRu"].ToString(); // string sContactName = Request.Form["yourNameRu"].ToString(); // string sEmail = Request.Form["emailRu"].ToString(); // //db = new AvonessaDBEntities(); // //var i = db.sp_InsertContactData(contact.PostalCode, contact.ContactName, contact.Email); // Dictionary<string, object> postData = new Dictionary<string, object>(); // //перевод из PHP в C# для Payeer.com:+++++++++++++++++++++++++++ // /* // string sm_shop = "61102332"; // string sm_orderid = "12345"; // //============================= // var m_amount = 1.05; // string sm_amount = m_amount.ToString("f2"); // //============================= // string sm_curr = "USD"; // string senc_description = Base64Encode("Test Description"); // string sm_key = "545747sql"; // String[] arHash = new String[] { // sm_shop, sm_orderid, sm_amount, sm_curr, senc_description, sm_key // }; // string sm_sign = sha256(String.Join(":", arHash)); // postData.Add("m_shop", sm_shop); // postData.Add("m_orderid", sm_orderid); // postData.Add("m_amount", sm_amount); // postData.Add("m_curr", sm_curr); // postData.Add("m_desc", senc_description); // postData.Add("m_sign", sm_sign.ToUpper()); // postData.Add("m_process", "send"); // return this.RedirectAndPost("https://payeer.com/merchant/", postData); // */ // //++++++++++++++++++++++++++++++++++++++++++++++++++ // //return new RedirectAndPostActionResult("ShoppingBag", postData); // //или // //return this.RedirectAndPost("http://TheUrlToPostDataTo", postData); // return this.RedirectAndPost("http://TheUrlToPostDataTo", postData); //} //Для PayPal отправляется Form "SBCFormRu". Не забыть изменить sandbox на live public void MakePayPalTransactionRu() { string sTotal = ""; decimal dTotal = 0; short sQuantity = 0; short i = 0; //выборка сумки из базы ===== db = new AvonessaDBEntities(); int iSB_Id = int.Parse(Request.Cookies["AvonessaShoppingBag"]["sb_Id"].ToString()); var query = from sb in db.sp_GetShoppingBagById(iSB_Id) select sb; List <Item> itms = new List <Item>(); Item item = null; foreach (var sb_data in query.ToList()) { sQuantity = short.Parse(Request.Form["qty_item_ru_" + i.ToString()].ToString()); var iq = db.sp_InsertQuantityToSB(int.Parse(sb_data.P_Id.ToString()), iSB_Id, sQuantity); dTotal += sQuantity * decimal.Parse(sb_data.ProductCost.ToString()); item = new Item(); item.name = sb_data.ProductName; //Русское название item.currency = "USD"; item.price = sb_data.ProductCost.ToString().Replace(",", "."); item.quantity = Request.Form["qty_item_ru_" + i.ToString()].ToString(); item.sku = sb_data.P_Id.ToString(); itms.Add(item); i++; } ItemList itemList = new ItemList(); itemList.items = itms; //заносим адрес поставки в базу:===== var ic = db.sp_InsertContactData(Request.Form["yourNameRu"].ToString(), Request.Form["emailRu"].ToString().Trim(), Request.Form["countryRu"].ToString(), Request.Form["postalCodeRu"].ToString(), Request.Form["cityRu"].ToString(), Request.Form["streetHomeFlatRu"].ToString()); //Country Code======================= LookupService ls = new LookupService(@"E:/web/avoness1/App_Data/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); Country c = ls.getCountry(Request.ServerVariables["REMOTE_ADDR"]); string cc = c.getCode(); //=================================== ShippingAddress sa = new ShippingAddress(); sa.country_code = cc; sa.city = Request.Form["cityRu"].ToString(); sa.line1 = Request.Form["streetHomeFlatRu"].ToString(); sa.recipient_name = Request.Form["yourNameRu"].ToString(); sa.postal_code = Request.Form["postalCodeRu"].ToString(); itemList.shipping_address = sa; //var sdkConfig = new Dictionary<string, string> { { "mode", "sandbox" } };// when you're live, change "sandbox" to "live" //string accessToken = new OAuthTokenCredential("ATrx7laOExss5QgsAMYpryJJZfo_Vw3gz0_HzOXMNFJjl4bb5rMrmUpj6nRyzm7uJgi-mebtQ7LhUF8y", // "ECDJMgNsx4rwhkHsATlsnp1DUoy6xZXOdLfLpOPqE6ErAHKkRuDQOctcDgEBgSBz68jmzn5OGtwuMTYN", sdkConfig) // .GetAccessToken(); //мои данные [email protected] /* * var sdkConfig = new Dictionary<string, string> { { "mode", "live" } };// when you're live, change "sandbox" to "live" * string accessToken = new OAuthTokenCredential("AYdL5I1bbxg91dez6GLuMSkQHVqtzocJ7LlgNULyEks_ElPjniV5OTP2Ka4IQotS6NyRjAQA87E6hztU", * "EKUkXPL0ZxM2tdmI-r9iMRiQYCVfQxIP7qh6kS21WI5qJ3gPuMOIt3kYGAH0VMi9Eaid07p1KsHecvtD", sdkConfig) * .GetAccessToken(); */ var sdkConfig = new Dictionary <string, string> { { "mode", "live" } }; // when you're live, change "sandbox" to "live" string accessToken = new OAuthTokenCredential("AbZ5lBaf9HfwR9ixms8A4qunW_4m06hliKjqB8NgLOup_4kP1AemIlzu04FOZoKjg2cu0OJYUt4P-YUt", "EOniNB_yLiy4XCNsTzZoadF9dG7MK5aUYwJo4cJk6v0WY54ZIKkZIiBtJWqA1Jam_1rDuR57sYqKCXts", sdkConfig) .GetAccessToken(); var redirectUrls = new RedirectUrls { cancel_url = "http://www.avonessa.com/ShopBagOrder/ShoppingBag/?sb_id=" + iSB_Id + "&cancel=true", return_url = "http://www.avonessa.com/ShopBagOrder/Success/?sb_id=" + iSB_Id + "&success=true" }; // Specify details of your payment amount. Details _details = new Details(); decimal _dShip = 8.75m; // цена поставки sTotal = dTotal.ToString().Replace(",", "."); _details.shipping = _dShip.ToString().Replace(",", "."); _details.subtotal = sTotal; _details.tax = "0"; dTotal = dTotal + _dShip; sTotal = dTotal.ToString().Replace(",", "."); var amnt = new Amount { currency = "USD", total = sTotal, details = _details }; var createdPayment = new Payment { intent = "sale", payer = new Payer { payment_method = "paypal" }, transactions = new List <Transaction> { new Transaction { description = "Оплата за товар", amount = amnt, item_list = itemList } }, redirect_urls = redirectUrls }.Create(new APIContext(accessToken) { Config = sdkConfig }); var approvalUrl = createdPayment.links.Single(l => l.rel == "approval_url").href; //Переход на страницу PayPal для продолжения оплаты: Response.Redirect(approvalUrl); }