public ActionResult Index() { string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMOREA420200703"; string accessKey = "QlGE6S9AlZNwni3M"; string serectkey = "JHt0d6lBW8pg1TNGFDLxTxG3MDTUMvbj"; string orderInfo = "Thanh toán MoMo"; string returnUrl = "https://momo.vn/return"; string notifyurl = "https://momo.vn/notify"; string amount = tongTien().ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString()); return(RedirectToAction("Index", "Cart")); }
public string SignatureMomoSendResponse(string requestId, string orderId, string errorCode, string message, string responseTime, string extraData) { string rawHash = string.Format( "partnerCode={0}" + "&accessKey={1}" + "&requestId={2}" + "&orderId={3}" + "&errorCode={4}" + "&message={5}" + "&responseTime={6}" + "&extraData={7}", DefinePaymentMomo.PartnerCode, //0 partnerCode DefinePaymentMomo.AccessKey, //1 accessKey requestId, //2 requestId orderId, //4 orderId errorCode, message, //8 extraData responseTime, extraData ); MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey); return(signature); }
public string SignatureMomo(string requestId, string amount, string orderId, string orderInfo, string extraData = "") { string rawHash = string.Format( "partnerCode={0}" + "&accessKey={1}" + "&requestId={2}" + "&amount={3}" + "&orderId={4}" + "&orderInfo={5}" + "&returnUrl={6}" + "¬ifyUrl={7}" + "&extraData={8}", DefinePaymentMomo.PartnerCode, //0 partnerCode DefinePaymentMomo.AccessKey, //1 accessKey requestId, //2 requestId amount, //3 amount orderId, //4 orderId orderInfo, //5 orderInfo DefinePaymentMomo.ReturnUrl, //6 returnUrl DefinePaymentMomo.NotifyUrl, //7 notifyUrl extraData //8 extraData ); MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey); return(signature); }
public IActionResult MoMoCallback(string partnerCode, string accessKey, string orderId, string localMessage, string message, string transId, string orderInfo, string amount, string errorCode, string responseTime, string requestId, string extraData, string payType, string orderType, string signature) { string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo + "&orderType=" + orderType + "&transId=" + transId + "&message=" + message + "&localMessage=" + localMessage + "&responseTime=" + responseTime + "&errorCode=" + errorCode + "&payType=" + payType + "&extraData=" + extraData; string serectkey = "XcCyHTwk2JXwXZQkDY3but2On0HKjqyQ"; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string partnerSignature = crypto.signSHA256(rawHash, serectkey); if (signature.Equals(partnerSignature)) { // Lưu dữ liệu lại nè: Recharge recharge = new Recharge(); recharge.User = this.GetCurrentUser(); recharge.Amount = Int32.Parse(amount); recharge.Type = "MoMo"; recharge.Money = recharge.Amount / 1000; recharge.User.Gold += recharge.Money; _context.Add(recharge); _context.SaveChanges(); // Di chuyển sang lịch sử giao dịch nha return(RedirectToAction(nameof(History))); } else { return(RedirectToAction(nameof(Index))); } }
public ActionResult PayMomo(ViewPayMomo momo) { string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMO828G20201211"; string accessKey = "I0M0E6bt9OC7nBfz"; string serectKey = "Bz4LGbbJ9AHHFRRSb92zL18B1Vq5XbfA"; string orderInfo = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss"); string returnUrl = "/Payments/Index"; string notifyUrl = "/Payments/Index"; string amount = momo.Amount; string orderId = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; // before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyUrl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, serectKey); JObject message = new JObject() { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderId }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyUrl }, { "requestType", "captureMoMoWallet" }, { "extraData", extraData }, { "signature", signature } }; string url = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&signature=" + signature + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyUrl + "&extraData=" + extraData + "&requestType=" + "captureMoMoWallet"; string responesFromMoMo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responesFromMoMo); string payUrl = jmessage.ToString(); return(Redirect("https://test-payment.momo.vn/gw_payment/payment/qr?" + url)); }
public ActionResult ReturnUrl() { string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1); param = Server.UrlDecode(param); string serctkey = ConfigurationManager.AppSettings["serctkey"].ToString(); MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(param, serctkey); if (signature != Request["signature"].ToString()) { ViewBag.message = " Thông tin Request không hợp lệ"; return(View()); } if (!Request.QueryString["errorCode"].Equals("0")) { ViewBag.message = "Thanh toán thất bại"; } else { ViewBag.message = "Thanh toán thành công"; Session["Cart"] = new List <GioHang>(); } return(View()); }
public ActionResult PayMoMo(int?id) { var coo = new FunctionsController(); var idus = coo.CookieID(); Pakage pakage = db.Pakages.Find(id); var money = pakage.pakage_coin * 1000; //request params need to request to MoMo system string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMO5RGX20191128"; string accessKey = "M8brj9K6E22vXoDB"; string serectkey = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4"; string orderInfo = "Nạp " + pakage.pakage_coin + " vào tài khoản " + idus.user_email; string returnUrl = "https://localhost:44327/Pays/ReturnUrl"; string notifyurl = "https://localhost:44327/Pays/ReturnUrl"; string amount = money.ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, serectkey); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); Session["idpake"] = id; return(Redirect(jmessage.GetValue("payUrl").ToString())); }
public ActionResult ReturnUrl() { string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1); param = Server.UrlDecode(param); MoMoSecurity crypto = new MoMoSecurity(); string secretKey = MomoConfig.SecretKey; string signature = crypto.signSHA256(param, secretKey); if (signature != Request["Signature"].ToString()) { ViewBag.message = "Invalid Information"; return(View()); } if (!Request.QueryString["errorCode"].Equals("0")) { ViewBag.message = "Payment failed"; } else { ViewBag.message = "Payment Success"; } //Add Invoice // return(View()); }
protected string ThanhToanMoMo(string maDonHang, string tongCong) { string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMOHDRK20200430"; string accessKey = "68tVdaHzCcvtfzwH"; string serectkey = "8AWejATXBF96XL3CqeICtqiiKwheEUAv"; string orderInfo = "OrderBook"; string returnUrl = "https://webbansach17dtha3.cf//Cart/Success"; string notifyurl = "https://webbansach17dtha3.cf/"; string amount = tongCong; string orderid = maDonHang; string requestId = maDonHang; string extraData = ""; string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); log.Debug("Return from MoMo: " + jmessage.ToString()); return(jmessage.GetValue("payUrl").ToString()); }
public ActionResult PayByMomo(string totalMoney) { string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMOBKUN20180529"; string accessKey = "klm05TvNBzhg7h7j"; string serectkey = "at67qH6mk8w5Y1nAyMoYKMWACiEi2bsa"; string orderInfo = "Thanh toán đơn hàng"; string returnUrl = "http://localhost:3000/order_success_page"; string notifyurl = "https://momo.vn/notify"; string amount = totalMoney; string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = "merchantName=Payment"; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jMessage = JObject.Parse(responseFromMomo); return(Ok(jMessage["payUrl"].ToString())); }
private static string TransactionOnline(Dictionary <string, string> obj, string secretKey, bool test, string requestType = "") { string endpoint = test ? "https://test-payment.momo.vn/gw_payment/transactionProcessor" : "https://payment.momo.vn/gw_payment/transactionProcessor"; StringBuilder builder = new StringBuilder(); string condition = string.Empty; foreach (var item in obj) { builder.AppendFormat("{0}{1}={2}", condition, item.Key, item.Value); condition = "&"; } var rawHash = builder.ToString(); var crypto = new MoMoSecurity(); //sign signature SHA256 var signature = crypto.signSHA256(rawHash, secretKey); //build body json request var message = new JObject(); foreach (var item in obj) { message.Add(item.Key, item.Value); } if (!string.IsNullOrEmpty(requestType)) { message.Add("requestType", requestType); } message.Add("signature", signature); Logger.Debug("Json request to MoMo: " + message); var responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); return(responseFromMomo); }
//------------------------------------------------------------------------------------------------------------------------------------------- public ActionResult PaymentWithMoMo(User user) { var cart = (List <CartItem>)Session[CartSession]; string endpoint = ConfigurationManager.AppSettings["endpoint"].ToString(); string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString(); string accessKey = ConfigurationManager.AppSettings["accessKey"].ToString(); string serectkey = ConfigurationManager.AppSettings["serectkey"].ToString(); string orderInfo = ConfigurationManager.AppSettings["orderInfo"].ToString(); string returnUrl = ConfigurationManager.AppSettings["returnUrl"].ToString(); string notifyurl = ConfigurationManager.AppSettings["notifyurl"].ToString(); string amount = cart.Sum(n => n.Product.Price).ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(Redirect(jmessage.GetValue("payUrl").ToString())); }
public ActionResult ThanhToan() { List <GioHang> gioHang = Session["Cart"] as List <GioHang>; string endpoint = ConfigurationManager.AppSettings["endpoint"].ToString(); string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString(); string accessKey = ConfigurationManager.AppSettings["accessKey"].ToString(); string serectkey = ConfigurationManager.AppSettings["serectkey"].ToString(); string orderInfo = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss"); string returnUrl = ConfigurationManager.AppSettings["returnUrl"].ToString(); string notifyurl = ConfigurationManager.AppSettings["notifyurl"].ToString(); string amount = gioHang.Sum(n => n._ThanhTien).ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //before sign HMAC SHA256 signature abc string rawHash = "partnerCode" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo" + orderInfo + "&returnUrl" + returnUrl + "¬ifyUrl" + notifyurl + "&extraData" + extraData; MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, serectkey); JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", partnerCode }, { "returnUrl", partnerCode }, { "notifyUrl", notifyurl }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(Redirect(jmessage.GetValue("payUrl").ToString())); }
public string payment() { string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = PARTNER_CODE; string accessKey = ACCESS_KEY; string serectKey = SERECT_KEY; string orderInfo = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss"); string returnUrl = RETURN_URL; string notifyUrl = NOTIFY_URL; string amount = "10000"; string orderId = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyUrl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, serectKey); JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderId }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyUrl }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(jmessage.GetValue("payUrl").ToString()); }
public JsonResult NotifyUrl() { string param = ""; // Request.Form.ToString().Substring(0, Request.Form.ToString().IndexOf("signature") -1); param = "partner_Code=" + Request["partner_code"] + "&access_key=" + Request["access_key"] + "&amount=" + Request["access_key"] + "&order_id=" + Request["order_id"] + "&order_info=" + Request["order_info"] + "&order_type=" + Request["order_type"] + "&transaction_id=" + Request["transaction_id"] + "&message=" + Request["message"] + "&response_time=" + Request["response_time"] + "&status_code=" + Request["status_code"]; param = Server.UrlDecode(param); MoMoSecurity crypto = new MoMoSecurity(); string serectkey = ConfigurationManager.AppSettings["serectkey"].ToString(); string signature = crypto.signSHA256(param, serectkey); //Không được phép cập nhật trạng thái đơn khi trạng đơn trong databasse khác trạng đang chờ thanh toán //Trạng thái đơn kích nút thanh toán - Đang chờ thanh toán(-1) //Trạng thái giao dịch thành công(1) //Trạng thái giao dịch thất bại(0) if (signature != Request["signature"].ToString()) { //Kiểm tra đơn hàng của các bạn trong database có khác trạng thái đang chờ thanh toán hay không //Nếu mà bạn đã cập nhật trạng thái đơn hàng về (1) hoặc 0 rồi thì không cần phải cập nhật nữa //Nếu trạng thái đơn hàng của các bạn đang là chờ thanh toán thì các ạn cập nhật trạng thái = 0 là thất bại ở đây //Khi nào thì mới cập nhật trạng thái đơn hàng? } string status_code = Request["status_code"].ToString(); if ((status_code != "0")) { //Thất bại - Cập nhật trạng thái đơn hàng } else { //Thành công - Cập nhật trạng thái đơn hàng } return(Json("", JsonRequestBehavior.AllowGet)); }
public void ReturnUrl() { string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1); param = WebUtility.UrlDecode(param); MoMoSecurity crypto = new MoMoSecurity(); string serectKey = SERECT_KEY; string signature = crypto.signSHA256(param, serectKey); if (signature != Request.Query["signature"].ToString()) { Console.WriteLine("Thông tin Request không hợp lệ"); } if (!Request.Query["errorCode"].Equals("0")) { Console.WriteLine("Thanh toán thất bại"); } else { Console.WriteLine("Thanh toán thành công"); } }
public string SignatureMomoRequest(string requestId, string amount, string orderId, string orderInfo, string orderType, string transId, string message, string localMessage, string responseTime, string errorCode, string payType, string extraData) { string rawHash = string.Format( "partnerCode={0}" + "&accessKey={1}" + "&requestId={2}" + "&amount={3}" + "&orderId={4}" + "&orderInfo={5}" + "&orderType={6}" + "&transId={7}" + "&message={8}" + "&localMessage={9}" + "&responseTime={10}" + "&errorCode={11}" + "&payType={12}" + "&extraData={13}", DefinePaymentMomo.PartnerCode, //0 partnerCode DefinePaymentMomo.AccessKey, //1 accessKey requestId, //2 requestId amount, //3 amount orderId, //4 orderId orderInfo, //5 orderInfo orderType, //6 returnUrl transId, //7 notifyUrl message, //8 extraData localMessage, responseTime, errorCode, payType, extraData ); MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey); return(signature); }
public JsonResult NotifyUrl() { string param = "partner_code=" + Request["partner_code"] + "&access_keys=" + Request["access_keys"] + "&amount=" + Request["amount"] + "&order_id=" + Request["order_id"] + "&order_info=" + Request["order_info"] + "&order_type=" + Request["order_type"] + "&transaction_id=" + Request["transaction_id"] + "&message=" + Request["message"] + "&response_time=" + Request["response_time"] + "&status_code=" + Request["status_code"]; param = Server.UrlDecode(param); MoMoSecurity scryto = new MoMoSecurity(); string secretKey = MomoConfig.SecretKey; string signature = scryto.signSHA256(param, secretKey); string statusCode = Request["status_code"].ToString(); /* * if (signature != Request["Signature"].ToString()) * { * ViewBag.message = "Invalid Information"; * return ; * } */ if (statusCode != "0") { //Failed } else { //Success } return(Json("", JsonRequestBehavior.AllowGet)); }
public string SignatureCheckResponseMomo(string requestId, string orderId, string message, string localMessage, string payUrl, string errorCode, string requestType) { string rawHash = string.Format( "requestId={0}" + "&orderId={1}" + "&message={2}" + "&localMessage={3}" + "&payUrl={4}" + "&errorCode={5}" + "&requestType={6}", requestId, //2 requestId orderId, //3 amount message, //4 orderId localMessage, //5 orderlocalMessageInfo payUrl, //6 payUrl errorCode, //7 errorCode requestType //8 requestType ); MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey); return(signature); }
public ActionResult DatHang() { //Kiểm tra đăng nhập if ((Session["TaiKhoan"] == null) || (Session["TaiKhoan"].ToString() == "")) { return(RedirectToAction("DangNhap", "NguoiDung")); } //Kiểm tra giỏ hàng if (Session["GioHang"] == null) { RedirectToAction("Index", "Home"); } //thêm đơn hàng DonHang dh = new DonHang(); KhachHang kh = (KhachHang)Session["TaiKhoan"]; List <GioHang> gh = LayGioHang(); dh.MaKH = kh.MaKH; dh.DaThanhToan = Convert.ToInt32(TongTien()); dh.TinhTrangGiaoHang = 0; dh.NgayDat = DateTime.Now; dh.NgayGiao = DateTime.Now; db.DonHangs.Add(dh); db.SaveChanges(); //Thêm chi tiết đơn hàng foreach (var item in gh) { ChiTietDonHang ctdh = new ChiTietDonHang(); ctdh.MaDonHang = dh.MaDonHang; ctdh.MaGiay = item._MaGiay; ctdh.SoLuong = item._SoLuong; ctdh.DonGia = item._DonGia.ToString(); Giay giay = db.Giays.SingleOrDefault(n => n.MaGiay == item._MaGiay); giay.SoLuongTon -= item._SoLuong; db.ChiTietDonHangs.Add(ctdh); db.SaveChanges(); Session["GioHang"] = null; } //momopay string endpoint = ConfigurationManager.AppSettings["endpoint"].ToString(); string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString(); string accessKey = ConfigurationManager.AppSettings["accessKey"].ToString(); string serectkey = ConfigurationManager.AppSettings["serectkey"].ToString(); string orderInfo = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss"); string returnUrl = ConfigurationManager.AppSettings["returnUrl"].ToString(); string notifyurl = ConfigurationManager.AppSettings["notifyurl"].ToString(); string amount = gh.Sum(n => n._ThanhTien).ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); string signature = crypto.signSHA256(rawHash, serectkey); JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(Redirect(jmessage.GetValue("payUrl").ToString())); //mômopay }
public ActionResult Payment(string shipName, string address, string mobile, string email) { var session = (UserLogin)Session[Common.CommonConstants.USER_SESSION]; var order = new Order(); if (session != null) { order.CustomerID = session.UserID; order.CreateDate = DateTime.Now; order.ShipAddress = address; order.ShipEmail = email; order.ShipMobile = mobile; order.ShipName = shipName; order.Status = false; } else { order.CreateDate = DateTime.Now; order.ShipAddress = address; order.ShipEmail = email; order.ShipMobile = mobile; order.ShipName = shipName; order.Status = false; } try { var id = new OrderDao().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDao = new OrderDetailDao(); var orderdao = new OrderDao(); decimal total = 0; foreach (var item in cart) { var orderr = new Order(); var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.Price = item.Product.Price; orderDetail.OrderID = id; orderDetail.Quantity = item.Quantity; total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); orderDetail.Total = total; detailDao.Insert(orderDetail); } string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/template/neworder.html")); content = content.Replace("{{CustomerName}}", shipName); content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["FromEmailAddress"].ToString(); /* new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content); * new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);*/ string endpoint = ConfigurationManager.AppSettings["endpoint"].ToString(); string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString(); string accessKey = ConfigurationManager.AppSettings["accessKey"].ToString(); string serectKey = ConfigurationManager.AppSettings["serectKey"].ToString(); string orderInfo = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss"); string returnUrl = ConfigurationManager.AppSettings["returnUrl"].ToString(); string notifyUrl = ConfigurationManager.AppSettings["notifyUrl"].ToString(); string amount = total.ToString(); string orderId = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = order.ShipName + "SP" + order.ShipMobile; string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyUrl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectKey); JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderId }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyUrl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(Redirect(jmessage.GetValue("payUrl").ToString())); } catch (Exception ex) { throw (ex); } }
public async Task <IActionResult> WebPaymentRequest(string orderInfo, string amount) { //request params need to request to MoMo system string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = configMomo.partnerCode; string accessKey = configMomo.accessKey; string serectkey = configMomo.serectkey; string returnUrl = "https://momo.vn"; string notifyurl = "https://momo.vn"; string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); log.Debug("Return from MoMo: " + jmessage.ToString()); //DialogResult result = MessageBox.Show(responseFromMomo, "Open in browser", MessageBoxButtons.OKCancel); //if (result == DialogResult.OK) //{ // //yes... //return Ok(System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString())); //} //else if (result == DialogResult.Cancel) //{ // //no... //} return(Ok(jmessage.GetValue("payUrl").ToString())); }
public ActionResult Index(Morder order) { Random rand = new Random((int)DateTime.Now.Ticks); int numIterations = 0; numIterations = rand.Next(1, 100000); DateTime time = DateTime.Now; string orderCode = numIterations + "" + time; string sumOrder = Request["sumOrder"]; string payment_method = Request["option_payment"]; // Neu Ship COde if (payment_method.Equals("COD")) { // cap nhat thong tin sau khi dat hang thanh cong saveOrder(order, "COD", 2, orderCode); var cart = Session[SessionCart]; var list = new List <Cart_item>(); ViewBag.cart = (List <Cart_item>)cart; Session["SessionCart"] = null; var listProductOrder = db.Orderdetails.Where(m => m.orderid == order.ID); return(View("payment")); } //Neu Thanh toan MOMO else if (payment_method.Equals("MOMO")) { //request params need to request to MoMo system string endpoint = momoInfo.endpoint; string partnerCode = momoInfo.partnerCode; string accessKey = momoInfo.accessKey; string serectkey = momoInfo.serectkey; string orderInfo = momoInfo.orderInfo; string returnUrl = momoInfo.returnUrl; string notifyurl = momoInfo.notifyurl; string amount = sumOrder; string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); saveOrder(order, "Cổng thanh toán MOMO", 2, orderid); return(Redirect(jmessage.GetValue("payUrl").ToString())); } //Neu Thanh toan Ngan Luong else if (payment_method.Equals("NL")) { string str_bankcode = Request["bankcode"]; RequestInfo info = new RequestInfo(); info.Merchant_id = nganluongInfo.Merchant_id; info.Merchant_password = nganluongInfo.Merchant_password; info.Receiver_email = nganluongInfo.Receiver_email; info.cur_code = "vnd"; info.bank_code = str_bankcode; info.Order_code = orderCode; info.Total_amount = sumOrder; info.fee_shipping = "0"; info.Discount_amount = "0"; info.order_description = "Thanh toán ngân lượng cho đơn hàng"; info.return_url = nganluongInfo.return_url; info.cancel_url = nganluongInfo.cancel_url; info.Buyer_fullname = order.deliveryname; info.Buyer_email = order.deliveryemail; info.Buyer_mobile = order.deliveryphone; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseInfo result = objNLChecout.GetUrlCheckout(info, payment_method); // neu khong gap loi gi if (result.Error_code == "00") { saveOrder(order, "Cổng thanh toán Ngân Lượng", 2, orderCode); // chuyen sang trang ngan luong return(Redirect(result.Checkout_url)); } else { ViewBag.errorPaymentOnline = result.Description; return(View("payment")); } } //Neu Thanh Toán ATM online else if (payment_method.Equals("ATM_ONLINE")) { string str_bankcode = Request["bankcode"]; RequestInfo info = new RequestInfo(); info.Merchant_id = nganluongInfo.Merchant_id; info.Merchant_password = nganluongInfo.Merchant_password; info.Receiver_email = nganluongInfo.Receiver_email; info.cur_code = "vnd"; info.bank_code = str_bankcode; info.Order_code = orderCode; info.Total_amount = sumOrder; info.fee_shipping = "0"; info.Discount_amount = "0"; info.order_description = "Thanh toán ngân lượng cho đơn hàng"; info.return_url = nganluongInfo.return_url; info.cancel_url = nganluongInfo.cancel_url; info.Buyer_fullname = order.deliveryname; info.Buyer_email = order.deliveryemail; info.Buyer_mobile = order.deliveryphone; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseInfo result = objNLChecout.GetUrlCheckout(info, payment_method); // neu khong gap loi gi if (result.Error_code == "00") { saveOrder(order, "ATM Online qua ngân lượng", 2, orderCode); return(Redirect(result.Checkout_url)); } else { ViewBag.errorPaymentOnline = result.Description; return(View("payment")); } } return(View("payment")); }
private void doMomoPayment() { //request params need to request to MoMo system string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string accessKey = "M8brj9K6E22vXoDB"; string partnerCode = "MOMO5RGX20191128"; string serectkey = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4"; string orderInfo = "Payment by Momo for customer"; string returnUrl = "https://momo.vn/return"; string notifyurl = "https://momo.vn/notify"; string amount = total.ToString(); string orderId = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderId }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); PaymentRequest pq = new PaymentRequest(); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); log.Debug("Return from MoMo: " + jmessage.ToString()); if (MessageBox.Show("Bạn có muốn thanh toán cho đơn hàng này", "Checkout", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString()); this.Alert("Đơn hàng của bạn đang được chuẩn bị", Notice.enmType.Waiting); updateOrderLine(); } }
private void Load() { string endpoint = @"https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMO5HQZ20200623"; string accessKey = "Z4Qa3sv4hNWPxtFG"; string serectkey = "J2c9EHI4m169OBpJGmUjJR2rfgi2y6kB"; string orderInfo = "Order food"; string returnUrl = @"https://facebook.com"; string notifyurl = @"https://google.com"; string amount = Cart.Instance.caculatePrice().ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); log.Debug("Signature = " + signature); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; log.Debug("Json request to MoMo: " + message.ToString()); string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); log.Debug("Return from MoMo: " + jmessage.ToString()); try { payurl = jmessage.GetValue("payUrl").ToString(); wbMono.Navigate(jmessage.GetValue("payUrl").ToString()); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public IActionResult MoMo(string Amount) { int amountInt = Int32.Parse(Amount); if (amountInt < 1000 || amountInt > 20000000) { return(RedirectToAction(nameof(Index))); } //request params need to request to MoMo system string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMO3R5720190725"; string accessKey = "ZarJz6vwlJUijSih"; string serectkey = "XcCyHTwk2JXwXZQkDY3but2On0HKjqyQ"; string orderInfo = "Nạp tiền nè các bạn"; string returnUrl = "https://localhost:44372/Payment/MomoCallback"; string notifyurl = "https://momo.vn/notify"; string amount = Amount; string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = ""; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); return(Redirect(jmessage.GetValue("payUrl").ToString())); // return View(); }
public ActionResult momo() { var taikHoan = GetUserRole(); if (taikHoan == null) { return(RedirectToAction("Index", "Home")); } var cart = Session[CartSession]; var list = new List <CartItem>(); if (cart != null) { list = (List <CartItem>)cart; } decimal prices = 0; if (list.Count() > 0) { foreach (var item in list) { if (item.Product.GiaKhuyenMai != null) { prices += item.Product.GiaKhuyenMai.Value; } else { prices += item.Product.Gia.Value; } } } String maDH = Guid.NewGuid().ToString(); String Endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string endpoint = Endpoint.ToString().Equals("") ? "https://test-payment.momo.vn/gw_payment/transactionProcessor" : Endpoint.ToString(); string partnerCode = "MOMO8FMY20210401"; string accessKey = "TPw4ACUsbQwz4TjK"; string serectkey = "JQL5Lw7u5Nf5GNVBGq0nmppYKMTO4hVc"; string orderInfo = maDH; //"thong tin don hang tin";// chỗ này thông tin đơn hàng; string returnUrl = "https://*****:*****@gmail.com"; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyurl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature } }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); // Response.Write(ViewBag.vb_tongtien.ToString()); // return Redirect(""); return(Redirect(jmessage.GetValue("payUrl").ToString())); }
public ActionResult ReturnUrl() { string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1); param = Server.UrlDecode(param); MoMoSecurity crypto = new MoMoSecurity(); string serectkey = ConfigurationManager.AppSettings["serectkey"].ToString(); string signature = crypto.signSHA256(param, serectkey); if (signature != Request["signature"].ToString()) { ViewBag.message = "Thong tin request khong hop le"; return(View()); } if (!Request.QueryString["errorCode"].Equals("0")) { ViewBag.message = "Thanh toán thất bại"; } else { //Khoi tao hoa don var order = new KetnoiCSDL.EF.Order(); //Kiểm tra xem khách hàng có đăng nhập hay không var user_temp = (BunyStore.Common.UserLogin)Session[BunyStore.Common.CommonConstants.USER_SESSION]; if (user_temp != null) { //Nếu có đăng nhập thì gán vào UserID order.CustomerID = user_temp.UserID; } // tiến hành tạo bill order.CreatedDate = DateTime.Now; order.ShipAddress = Common.CommonConstants.CustomerTemp.Address; order.ShipMobile = Common.CommonConstants.CustomerTemp.Phone; order.ShipName = Common.CommonConstants.CustomerTemp.shipName; order.ShipEmail = Common.CommonConstants.CustomerTemp.Email; order.ShipPrecinct = Common.CommonConstants.CustomerTemp.PrecinctID; order.ShipProvince = Common.CommonConstants.CustomerTemp.ProvinceID; order.ShipDistrict = Common.CommonConstants.CustomerTemp.DistrictID; order.Status = "Chờ xử lý"; order.PaymentForms = "Momo"; try { var id = new OrderDao().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDao = new KetnoiCSDL.DAO.OrderDetailDao(); decimal total = 0; foreach (var item in cart) { // Tạo mới hóa đơn vào database var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; detailDao.Insert(orderDetail); //cập nhật số lượng bán Product Update_product = db.Products.Where(p => p.ID == item.Product.ID).FirstOrDefault(); // chắc chắn rằng không rỗng if (Update_product != null) { //vì trong database set mặc định là null nên không thể cộng được mà phải thêm 1 phần if để kiểm tra null hay có giá trị if (Update_product.BoughtCount == null) { Update_product.BoughtCount = int.Parse(item.Quantity.ToString()); } else { Update_product.BoughtCount += item.Quantity; } db.Products.AddOrUpdate(Update_product); db.SaveChanges(); var a = Update_product.BoughtCount; } //db.SaveChanges(); Session[CartSession] = null; } Common.CommonConstants.CustomerTemp = null; } catch (Exception ex) { //ghi log return(Redirect("/loi-thanh-toan")); } return(RedirectToAction("Success", "Cart")); } return(View()); }
public ActionResult Payment(int icOfGuest, string nameOfGuest, string addressOfGuest, bool genderOfGuest, int CatOfGuest, float totalCost, string invoiceIDInput) { //request params need to request to MoMo system string endpoint = @"https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = MomoConfig.ParnerCode; string accessKey = MomoConfig.AccessKey; string serectkey = MomoConfig.SecretKey; string orderInfo = "orderInfo"; //string returnUrl = MomoConfig.ReturnUrl + "?icOfGuest=" + icOfGuest + "&nameOfGuest=" + nameOfGuest + "&addressOfGuest=" + addressOfGuest + "&genderOfGuest=" + genderOfGuest + "&CatOfGuest=" + CatOfGuest + "&totalCost=" + totalCost; string returnUrl = MomoConfig.ReturnUrl; string notifyUrl = MomoConfig.NotifyUrl; string myInvoiceID = Guid.NewGuid().ToString(); string amount = totalCost.ToString(); string orderid = myInvoiceID; string requestId = Guid.NewGuid().ToString(); string extraData = icOfGuest + nameOfGuest + addressOfGuest + genderOfGuest + CatOfGuest + totalCost;; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyUrl + "&extraData=" + extraData; MoMoSecurity crypto = new MoMoSecurity(); //sign signature SHA256 string signature = crypto.signSHA256(rawHash, serectkey); //build body json request JObject message = new JObject { { "partnerCode", partnerCode }, { "accessKey", accessKey }, { "requestId", requestId }, { "amount", amount }, { "orderId", orderid }, { "orderInfo", orderInfo }, { "returnUrl", returnUrl }, { "notifyUrl", notifyUrl }, { "extraData", extraData }, { "requestType", "captureMoMoWallet" }, { "signature", signature }, }; string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString()); JObject jmessage = JObject.Parse(responseFromMomo); //System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString()); var controller = new ManagerController(); controller.Test(icOfGuest, nameOfGuest, addressOfGuest, genderOfGuest, CatOfGuest, totalCost, myInvoiceID); return(Redirect(jmessage.GetValue("payUrl").ToString())); }