public IActionResult OnePayResult(string vpc_TxnResponseCode) { //"http://onepay.vn" VPCRequest conn = new VPCRequest(); conn.SetSecureSecret(VPCRequest.SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa var hashvalidateResult = conn.Process3PartyResponse(HttpContext.Request.Query); Orders order = _context.Orders.FirstOrDefault(o => o.OrderId == IdLasted); if (hashvalidateResult == "CANCEL") { order.OrderStatus = (int?)0; _context.SaveChanges(); return(RedirectToAction("PaymentFailed", "Checkout")); } if (hashvalidateResult == "CORRECTED" && vpc_TxnResponseCode.Trim() == "0") { order.OrderStatus = (int?)1; _context.SaveChanges(); return(RedirectToAction("Invoice", "Checkout", order)); } else if (hashvalidateResult == "INVALIDATED" && vpc_TxnResponseCode.Trim() == "0") { } order.OrderStatus = (int?)0; _context.SaveChanges(); return(RedirectToAction("PaymentFailed", "Checkout")); }
public ActionResult SubmitInvoidOnePay(string idOrder, double deposit) { PaymentConfigOnePay pay = new PaymentConfigOnePay(); using (var db = new MyDbDataContext()) { pay = db.PaymentConfigOnePays.FirstOrDefault(); } if (pay != null) { System.Web.HttpContext context = System.Web.HttpContext.Current; string ip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; VPCRequest conn = new VPCRequest("https://onepay.vn/vpcpay/vpcpay.op"); conn.SetSecureSecret(pay.Hashcode); conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "en"); conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", pay.MerchantId); conn.AddDigitalOrderField("vpc_AccessCode", pay.AccessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", idOrder); conn.AddDigitalOrderField("vpc_OrderInfo", idOrder); conn.AddDigitalOrderField("vpc_Amount", deposit.ToString()); conn.AddDigitalOrderField("vpc_ReturnURL", pay.WebSite + "/BookTour/MessageOnePay"); conn.AddDigitalOrderField("vpc_TicketNo", ip); String url = conn.Create3PartyQueryString(); return(Redirect(url)); } else { return(View()); } }
public void makePay(string genId, string totalAtm) { string ipaddress; ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipaddress == "" || ipaddress == null) { ipaddress = Request.ServerVariables["REMOTE_ADDR"]; } string SECURE_SECRET = "0C1D637C06AC75FDE9D7B4B550A3A641"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://onepay.vn/onecomm-pay/vpc.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "Mibo.vn - Cong thanh toan OnePay"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "NGUYENPHONG"); conn.AddDigitalOrderField("vpc_AccessCode", "GWJBCBJX"); conn.AddDigitalOrderField("vpc_MerchTxnRef", genId); conn.AddDigitalOrderField("vpc_OrderInfo", "Tin Hoc Nguyen Phong - Mibo.vn"); conn.AddDigitalOrderField("vpc_Amount", totalAtm); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", "http://mibo.vn/pay-process.aspx"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ipaddress); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); Page.Response.Redirect(url); }
public IActionResult OnePayPayment(Orders order) { var current_invoice = CreateInvoice(order); //Send request to OnePay string returnURL = Url.Action("OnePayResult", "OnePay", null, Request.Scheme); VPCRequest conn = new VPCRequest(); conn.SetSecureSecret(VPCRequest.SECURE_SECRET); conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", VPCRequest.MERCHANT_ID); conn.AddDigitalOrderField("vpc_AccessCode", VPCRequest.ACCESS_CODE); conn.AddDigitalOrderField("vpc_MerchTxnRef", "HoaDon #:" + current_invoice.OrderId); conn.AddDigitalOrderField("vpc_OrderInfo", "HoaDon #:" + current_invoice.OrderId); conn.AddDigitalOrderField("vpc_Amount", current_invoice.Total + "00"); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", returnURL); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_Customer_Phone", order.Phone); conn.AddDigitalOrderField("vpc_Customer_Email", order.Email); // Chuyen huong trinh duyet sang cong thanh toan string url = conn.Create3PartyQueryString(); return(Redirect(url)); }
}//String function end public VPCRequest AmexConfig() { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Collect Information for AMEX Gateway"); VPCRequest conn = new VPCRequest(_TNS.Properties.Settings.Default.PaymentServerURL); // Configure the proxy details (if needed) conn.SetProxyHost(_TNS.Properties.Settings.Default.ProxyHost); conn.SetProxyUser(_TNS.Properties.Settings.Default.ProxyUser); conn.SetProxyPassword(_TNS.Properties.Settings.Default.ProxyPassword); conn.SetProxyDomain(_TNS.Properties.Settings.Default.ProxyDomain); conn.SetSecureSecret(_TNS.Properties.Settings.Default.vpc_SecureSecret); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("vpc_Version", _TNS.Properties.Settings.Default.vpc_Version); conn.AddDigitalOrderField("vpc_AccessCode", _TNS.Properties.Settings.Default.vpc_AccessCode); conn.AddDigitalOrderField("vpc_Merchant", _TNS.Properties.Settings.Default.vpc_Merchant); conn.AddDigitalOrderField("vpc_User", _TNS.Properties.Settings.Default.vpc_User); conn.AddDigitalOrderField("vpc_Password", _TNS.Properties.Settings.Default.vpc_Password); return(conn); //Configure the Hard coded details (if needed) //VPCRequest conn = new VPCRequest("https://vpos.amxvpos.com/vpcdps"); //conn.SetProxyHost(""); //conn.SetProxyUser(""); //conn.SetProxyPassword(""); //conn.SetProxyDomain(""); //conn.SetSecureSecret("44DD98D32ECD3C1AA7F12A1D0F8B41EA"); }
public void makePay(Accept acc) { string ipaddress; ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipaddress == "" || ipaddress == null) { ipaddress = Request.ServerVariables["REMOTE_ADDR"]; } string SECURE_SECRET = "0C1D637C06AC75FDE9D7B4B550A3A641"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://onepay.vn/onecomm-pay/vpc.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "Mibo.vn - Cong thanh toan OnePay"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "NGUYENPHONG"); conn.AddDigitalOrderField("vpc_AccessCode", "GWJBCBJX"); conn.AddDigitalOrderField("vpc_MerchTxnRef", genId); conn.AddDigitalOrderField("vpc_OrderInfo", "Tin Hoc Nguyen Phong - Mibo.vn"); conn.AddDigitalOrderField("vpc_Amount", acc.TotalAmt.ToString()+"00"); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", "http://mibo.vn/pay-process.aspx"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ipaddress); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); Page.Response.Redirect(url); }
public string RedirectToOnpayMienNam(string codeInvoice, string amount, string ip) { //khởi tạo lớp thư viện VPCRequest conn = new VPCRequest(OnePayProperties.URL_ONEPAY_TEST); conn.SetSecureSecret(OnePayProperties.HASH_CODE); //truyền các thông số để chuyển sang cổng onepay conn.AddDigitalOrderField("AgainLink", OnePayProperties.AGAIN_LINK); conn.AddDigitalOrderField("Title", "Online Payment With OnePay"); conn.AddDigitalOrderField("vpc_Locale", OnePayProperties.PAYGATE_LANGUAGE); conn.AddDigitalOrderField("vpc_Version", OnePayProperties.VERSION); conn.AddDigitalOrderField("vpc_Command", OnePayProperties.COMMAND); conn.AddDigitalOrderField("vpc_Merchant", OnePayProperties.MERCHANT_ID); conn.AddDigitalOrderField("vpc_AccessCode", OnePayProperties.ACCESS_CODE); conn.AddDigitalOrderField("vpc_MerchTxnRef", RandomString()); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_OrderInfo", codeInvoice); conn.AddDigitalOrderField("vpc_Amount", amount); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("OnepayResponseMienNam", "OnePay", null, Request.Scheme, null)); //thông tin khách hàng conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); conn.AddDigitalOrderField("vpc_TicketNo", ip); string url = conn.Create3rdPartyQueryString(); return(url); }
public string RedirectOnepay(string codeInvoice, string amount, string ip) { // Khoi tao lop thu vien VPCRequest conn = new VPCRequest(OnePayProperty.Url_ONEPAY_TEST); conn.SetSecureSecret(OnePayProperty.HASH_CODE); // Gan cac thong so de truyen sang cong thanh toan onepay conn.AddDigitalOrderField("AgainLink", OnePayProperty.AGAIN_LINK); conn.AddDigitalOrderField("Title", "Tich hop onepay vao web asp.net mvc3,4"); conn.AddDigitalOrderField("vpc_Locale", OnePayProperty.PAYGATE_LANGUAGE); conn.AddDigitalOrderField("vpc_Version", OnePayProperty.VERSION); conn.AddDigitalOrderField("vpc_Command", OnePayProperty.COMMAND); conn.AddDigitalOrderField("vpc_Merchant", OnePayProperty.MERCHANT_ID); conn.AddDigitalOrderField("vpc_AccessCode", OnePayProperty.ACCESS_CODE); conn.AddDigitalOrderField("vpc_MerchTxnRef", "Thanh Toán"); conn.AddDigitalOrderField("vpc_OrderInfo", codeInvoice); conn.AddDigitalOrderField("vpc_Amount", amount); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("OnepayResponse", "GioHang", null, Request.Url.Scheme, null)); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); conn.AddDigitalOrderField("vpc_TicketNo", ip); string url = conn.Create3PartyQueryString(); return(url); }
public ActionResult OnePayNoiDia() { string amount = (ShoppingCart.Instance.GetTotal() * 100).ToString(); // Khoi tao lop thu vien VPCRequest conn = new VPCRequest(OnepayProperty.URL_ONEPAY_TEST); conn.SetSecureSecret(OnepayProperty.HASH_CODE); conn.AddDigitalOrderField("Title", "Thanh toán trực tuyến"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", OnepayProperty.VERSION); conn.AddDigitalOrderField("vpc_Command", OnepayProperty.COMMAND); conn.AddDigitalOrderField("vpc_Merchant", OnepayProperty.MERCHANT_ID); conn.AddDigitalOrderField("vpc_AccessCode", OnepayProperty.ACCESS_CODE); conn.AddDigitalOrderField("vpc_MerchTxnRef", RandomString()); conn.AddDigitalOrderField("vpc_OrderInfo", "Test đơn hàng"); conn.AddDigitalOrderField("vpc_Amount", amount); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("OnePayNoiDiaRes", "CheckOut", null, Request.Url.Scheme, null)); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); conn.AddDigitalOrderField("vpc_TicketNo", Request.UserHostAddress); string url = conn.Create3PartyQueryString(); return(Redirect(url)); }
public string GetRedirectUrl(PaymentMethod config, Guid paymentTransactionId, string orderCode, long amount , string ipAddress, Guid languageId, string siteDomainUrl) { var secureSecret = Config.SecureSecret; var apiUrl = Config.ApiPayUrl; var accessCode = Config.AccessCode; var merchant = Config.Merchant; var returnUrl = Config.ReturnUrl; var siteUrl = (string.IsNullOrEmpty(siteDomainUrl) ? "http://onepay.vn" : siteDomainUrl).Trim(new[] { ' ', '/' }); if (returnUrl.IndexOf("http://", StringComparison.OrdinalIgnoreCase) < 0 || returnUrl.IndexOf("https://", StringComparison.OrdinalIgnoreCase) < 0) { returnUrl = siteUrl + "/" + Config.ReturnUrl.Trim(new[] { ' ', '/', ':' }); } var langUi = "en"; VPCRequest conn = new VPCRequest(apiUrl); conn.SetSecureSecret(secureSecret); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("AgainLink", siteUrl); conn.AddDigitalOrderField("Title", merchant); conn.AddDigitalOrderField("vpc_Locale", langUi);//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", Config.PayVersion); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", merchant); conn.AddDigitalOrderField("vpc_AccessCode", accessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", paymentTransactionId.ToString()); conn.AddDigitalOrderField("vpc_OrderInfo", orderCode); conn.AddDigitalOrderField("vpc_Amount", (amount * 100).ToString()); conn.AddDigitalOrderField("vpc_ReturnURL", returnUrl); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ipAddress); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(url); }
public ActionResult OnepayResponse() { string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest(OnepayProperty.URL_ONEPAY_TEST); conn.SetSecureSecret(OnepayProperty.HASH_CODE); // Xu ly tham so tra ve va du lieu ma hoa string a = "https://" + Request.Host.ToString() + "/Onepay/Onepay" + Request.QueryString.ToString(); hashvalidateResult = conn.Process3PartyResponse(new Uri(a).ParseQueryString()); // Lay tham so tra ve tu cong thanh toan string vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode"); string amount = conn.GetResultField("vpc_Amount"); string localed = conn.GetResultField("vpc_Locale"); string command = conn.GetResultField("vpc_Command"); string version = conn.GetResultField("vpc_Version"); string cardType = conn.GetResultField("vpc_Card"); string orderInfo = conn.GetResultField("vpc_OrderInfo"); string merchantID = conn.GetResultField("vpc_Merchant"); string authorizeID = conn.GetResultField("vpc_AuthorizeId"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef"); string transactionNo = conn.GetResultField("vpc_TransactionNo"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message"); // Kiem tra 2 tham so tra ve quan trong nhat if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { Khachhang kh = db.Khachhang.Where(x => x.Email == HttpContext.Session.Get <string>("user")).SingleOrDefault(); Hoadon hd = new Hoadon { Ngaydat = DateTime.Now, Ngaygiao = DateTime.Now.AddDays(7), Cachthanhtoan = "Onepay" }; hd.Makh = kh.Makh; hd.Matrangthai = 1; return(RedirectToAction("DoCheckOut", "CheckOut", hd)); //return View("PaySuccess"); } else { return(RedirectToAction("DoCheckOut", "CheckOut", null)); //return Content("PayUnSuccess"); } }
// GET: KetQuaThanhToan //public ActionResult IndexVpc_dr() //{ // string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; // string hashvalidateResult = ""; // // Khoi tao lop thu vien // VPCRequest conn = new VPCRequest("http://onepay.vn"); // conn.SetSecureSecret(SECURE_SECRET); // // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa // hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // // Lay gia tri tham so tra ve tu cong thanh toan // String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); // string amount = conn.GetResultField("vpc_Amount", "Unknown"); // string localed = conn.GetResultField("vpc_Locale", "Unknown"); // string command = conn.GetResultField("vpc_Command", "Unknown"); // string version = conn.GetResultField("vpc_Version", "Unknown"); // string cardBin = conn.GetResultField("vpc_Card", "Unknown"); // string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); // string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); // string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); // string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); // string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); // string txnResponseCode = vpc_TxnResponseCode; // string message = conn.GetResultField("vpc_Message", "Unknown"); // //int loop1; // int result = -1; // long maDDHString = 0; // // Sua lai ham check chuoi ma hoa du lieu // if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") // { // maDDHString = long.Parse(merchTxnRef); // result = 0; // } // else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") // { // result = 1; // } // else // { // result = 2; // } // TempData["MaDonHang"] = maDDHString; // TempData["result"] = result; // return RedirectToAction("Index", "KetQuaThanhToan"); //} public ActionResult IndexVpc_drr() { string SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardType = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); //int loop1; int result = -1; long maDDHString = 0; // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { maDDHString = long.Parse(merchTxnRef); result = 0; } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { result = 1; } else { result = 2; } TempData["MaDonHang"] = maDDHString; TempData["result"] = result; return(RedirectToAction("Index", "KetQuaThanhToan")); }
public ActionResult MessageOnePay(string vpc_OrderInfo, string vpc_TxnResponseCode, string vpc_SecureHash) { PaymentConfigOnePay paymentConfig = new PaymentConfigOnePay(); using (var db = new MyDbDataContext()) { paymentConfig = db.PaymentConfigOnePays.FirstOrDefault(); SendEmail sendEmail = db.SendEmails.FirstOrDefault( a => a.Type == TypeSendEmail.BookTour && a.LanguageID == Request.Cookies["LanguageID"].Value); int state = 0; string message = ""; var conn = new VPCRequest("https://onepay.vn/vpcpay/vpcpost.op"); conn.SetSecureSecret(paymentConfig.Hashcode); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa string hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan var merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); if (hashvalidateResult == "CORRECTED" && vpc_TxnResponseCode.Trim() == "0") { message = "Transaction was paid successful"; state = 1; ViewBag.Messages = sendEmail.Success; } else if (hashvalidateResult == "INVALIDATED" && vpc_TxnResponseCode.Trim() == "0") { message = "Transaction is pending"; state = 2; ViewBag.Messages = sendEmail.Error; } else { message = "Transaction was not paid successful"; state = 3; ViewBag.Messages = sendEmail.Error; } ViewBag.Message = message; ViewBag.State = state; if (state == 1) { // do something return(View()); } return(View()); } }
public IActionResult OnePayResponseMienNam() { string hashValidateResult = ""; //khởi tạo lớp thư viện VPCRequest conn = new VPCRequest(OnePayProperties.URL_ONEPAY_TEST); conn.SetSecureSecret(OnePayProperties.HASH_CODE); //lấy kết quả từ url được trả về từ cổng thanh toán hashValidateResult = conn.Process3rdPartyResponse(HttpUtility.ParseQueryString(Request.QueryString.ToString())); //lấy tham số trả về từ cổng thanh toán string vpc_TxnResponseCode = conn.GetResponseData("vpc_TxnResponseCode"); string amount = conn.GetResponseData("vpc_Amount"); string localed = conn.GetResponseData("vpc_Locale"); string command = conn.GetResponseData("vpc_Command"); string version = conn.GetResponseData("vpc_Version"); string cardType = conn.GetResponseData("vpc_Card"); string orderInfo = conn.GetResponseData("vpc_OrderInfo"); string merchantID = conn.GetResponseData("vpc_Merchant"); string authorizeID = conn.GetResponseData("vpc_AuthorizeId"); string merchTxnRef = conn.GetResponseData("vpc_MerchTxnRef"); string transactionNo = conn.GetResponseData("vpc_TransactionNo"); string acqResponseCode = conn.GetResponseData("vpc_AcqResponseCode"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResponseData("vpc_Message"); if (hashValidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { var hd = _hoaDonService.GetHoaDon(); hd.Tinhtrang = 1; _db.Hoadons.Update(hd); _db.SaveChanges(); return(RedirectToAction("ThanhToanTourMienNamThanhCong", "OnePay")); } else if (hashValidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { return(View("/Views/OnePay/ThanhToanDangGiaiQuyet.cshtml")); } else { return(View("/Views/OnePay/ThanhToanKhongThanhCong.cshtml")); } }
public ActionResult OnepayResponse() { string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest(OnePayProperty.Url_ONEPAY_TEST); conn.SetSecureSecret(OnePayProperty.HASH_CODE); // Xu ly tham so tra ve va du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay tham so tra ve tu cong thanh toan string vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode"); string amount = conn.GetResultField("vpc_Amount"); string localed = conn.GetResultField("vpc_Locale"); string command = conn.GetResultField("vpc_Command"); string version = conn.GetResultField("vpc_Version"); string cardType = conn.GetResultField("vpc_Card"); string orderInfo = conn.GetResultField("vpc_OrderInfo"); string merchantID = conn.GetResultField("vpc_Merchant"); string authorizeID = conn.GetResultField("vpc_AuthorizeId"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef"); string transactionNo = conn.GetResultField("vpc_TransactionNo"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message"); // Kiem tra 2 tham so tra ve quan trong nhat if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { return(RedirectToAction("XacNhanGioHang", "GioHang", new { id = 1 })); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { return(View("PayPending")); } else { return(RedirectToAction("DatHang", "GioHang")); } }
public IActionResult OnePayResult(string vpc_TxnResponseCode) { VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(VPCRequest.SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa var hashvalidateResult = conn.Process3PartyResponse(HttpContext.Request.Query); string result = ""; if (hashvalidateResult == "CORRECTED" && vpc_TxnResponseCode.Trim() == "0") { result = "Giao dịch thành công"; } else if (hashvalidateResult == "INVALIDATED" && vpc_TxnResponseCode.Trim() == "0") { result = "Giao dịch đang chờ xử lý"; } else { result = "Giao dịch không thành công"; } ViewBag.Result = result; return(View()); }
public ActionResult XacNhanDonHang(FormCollection f) { if (f["CMND"].Length != 9 && f["CMND"].Length != 12) { ViewData["L1"] = "Vui lòng nhập đúng CMND"; return(View()); } List <GIOHANG> gh = LayGioHang(); DONDATHANG donhang = new DONDATHANG(); donhang.CMND = f["CMND"]; donhang.Ngaydat = DateTime.Now; donhang.Ngaygiao = DateTime.Parse(f["NgayGiao"]); donhang.DiaChiLienHe = f["DCGiaoHang"]; donhang.EmailLienHe = f["Email"]; donhang.SDTLienHe = f["SDT"]; donhang.Tinhtranggiaohang = false; donhang.TongTien = TongTien(); donhang.Dathanhtoan = false; donhang.TrangThai = true; db.DONDATHANGs.InsertOnSubmit(donhang); db.SubmitChanges(); string mathanhtoantructuyen = DateTime.Now.Ticks.ToString(); if (string.Compare(f["rbHinhThucThanhToan"], "Onepay") == 0) { string SECURE_SECRET = OnepayCode.SECURE_SECRET;// HAO : CAN THANH MA THAT TRONG APP CODE //// KHOI TAO LOP THU VIEN VA GAN GIA TRI CAC THAM SO VPCRequest conn = new VPCRequest(OnepayCode.VPCRequest); conn.SetSecureSecret(SECURE_SECRET); //add digital order field conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn"); conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", OnepayCode.Merchant); conn.AddDigitalOrderField("vpc_AccessCode", OnepayCode.AccessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", mathanhtoantructuyen); conn.AddDigitalOrderField("vpc_OrderInfo", mathanhtoantructuyen); conn.AddDigitalOrderField("vpc_Amount", (TongTien() * 100).ToString()); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", OnepayCode.ReturnURL); conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); conn.AddDigitalOrderField("vpc_TicketNo", Request.UserHostAddress); string ketQua = ""; string url = conn.Create3PartyQueryString(); ketQua = url; foreach (var item in gh) { CHITIETDONTHANG ctdh = new CHITIETDONTHANG(); DONGHO dh = db.DONGHOs.SingleOrDefault(m => m.MaSP == item.iMaSP); ctdh.MaDonHang = donhang.MaDonHang; ctdh.MaSP = item.iMaSP; ctdh.Soluong = item.iSoLuong; ctdh.ThanhTien = item.fThanhTien; ctdh.Dongia = item.fDonGia; db.CHITIETDONTHANGs.InsertOnSubmit(ctdh); dh.Soluongton = dh.Soluongton - item.iSoLuong; UpdateModel(dh); } Session["GIOHANG"] = null; db.SubmitChanges(); ViewBag.Ma = donhang.MaDonHang; return(Redirect(ketQua)); } else { foreach (var item in gh) { CHITIETDONTHANG ctdh = new CHITIETDONTHANG(); DONGHO dh = db.DONGHOs.SingleOrDefault(m => m.MaSP == item.iMaSP); ctdh.MaDonHang = donhang.MaDonHang; ctdh.MaSP = item.iMaSP; ctdh.Soluong = item.iSoLuong; ctdh.ThanhTien = item.fThanhTien; ctdh.Dongia = item.fDonGia; db.CHITIETDONTHANGs.InsertOnSubmit(ctdh); dh.Soluongton = dh.Soluongton - item.iSoLuong; UpdateModel(dh); } Session["GIOHANG"] = null; db.SubmitChanges(); return(View()); } }
public ActionResult CreateOrder(string orderViewModel) { var order = new JavaScriptSerializer().Deserialize <OrderViewModel>(orderViewModel); var orderNew = new Order(); order.CreatedDate = DateTime.Now; order.CreatedBy = order.CustomerName; orderNew.UpdateOrder(order); List <OrderDetail> orderDetails = new List <OrderDetail>(); var sessionCart = (List <ShoppingCartViewModel>)Session[CommonConstants.SessionCart]; var cart = new List <CartInsertViewModel>(); foreach (var session in sessionCart) { if (cart.Any(x => x.ProductId == session.ProductId)) { foreach (var item in cart) { if (item.ProductId == session.ProductId) { item.Quantity += session.Quantity; item.Note = item.Note + " " + session.Quantity + " " + "màu: " + " " + session.Color + ",size: " + session.Size + ";"; } } } else { CartInsertViewModel newItem = new CartInsertViewModel(); newItem.ProductId = session.ProductId; newItem.Product = session.Product; newItem.Quantity = session.Quantity; newItem.Color = session.Color; newItem.Size = session.Size; newItem.Note = session.Quantity + " " + "màu" + " " + session.Color + ",size: " + session.Size + ";"; cart.Add(newItem); } } decimal total = 0; foreach (var item in cart) { var detail = new OrderDetail(); detail.ProductID = item.ProductId; detail.Quantity = item.Quantity; if (item.Product.PromotionPrice.HasValue) { detail.Price = item.Product.PromotionPrice.Value; total += (item.Product.PromotionPrice.GetValueOrDefault(0) * item.Quantity); } else { detail.Price = item.Product.Price; total += (item.Product.Price * item.Quantity); } detail.Note = item.Note; orderDetails.Add(detail); } decimal totals = total * 100; string text = ""; foreach (var item in cart) { text = text + item.Quantity + "x" + item.Product.Name + "-" + item.Note + " "; } if (order.PaymentMethod == "Thanh toán khi giao hàng") { _orderService.Create(ref orderNew, orderDetails); _productService.Save(); string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/template/neworder.html")); content = content.Replace("{{CustomerName}}", order.CustomerName); content = content.Replace("{{Phone}}", order.CustomerMobile); content = content.Replace("{{Email}}", order.CustomerEmail); content = content.Replace("{{Address}}", order.CustomerAddress); content = content.Replace("{{Total}}", total.ToString("N0")); var adminEmail = ConfigHelper.GetByKey("AdminEmail"); MailHelper.SendMail(order.CustomerEmail, "Đơn hàng mới từ TheShoes", content); MailHelper.SendMail(adminEmail, "Đơn hàng mới từ TheShoes", content); Session[CommonConstants.SessionCart] = null; Session[CommonConstants.SessionConfirmCart] = null; Session[CommonConstants.SessionOrder] = null; return(Json(new { status = true })); } else { Session.Add(CommonConstants.SessionConfirmCart, cart); Session.Add(CommonConstants.SessionOrder, orderNew); string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://mtf.onepay.vn/onecomm-pay/vpc.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "ONEPAY"); conn.AddDigitalOrderField("vpc_AccessCode", "D67342C2"); conn.AddDigitalOrderField("vpc_MerchTxnRef", MaHoaMD5(ngaunhien().ToString())); conn.AddDigitalOrderField("vpc_OrderInfo", text); conn.AddDigitalOrderField("vpc_Amount", totals.ToString()); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("ConfirmOrder", "ShoppingCart", null, Request.Url.Scheme)); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", "Vietnam"); conn.AddDigitalOrderField("vpc_Customer_Phone", order.CustomerMobile); conn.AddDigitalOrderField("vpc_Customer_Email", order.CustomerEmail); conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ""); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(Json(new { status = true, urlCheckout = url, })); } }
public ActionResult ConfirmOrder() { string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa try { hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); } catch { return(Redirect("/gio-hang.html")); } // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { var order = (Order)Session[CommonConstants.SessionOrder]; var orderNew = new Order(); order.PaymentStatus = true; orderNew = order; List <OrderDetail> orderDetails = new List <OrderDetail>(); var sessionCart = (List <CartInsertViewModel>)Session[CommonConstants.SessionConfirmCart]; foreach (var item in sessionCart) { var detail = new OrderDetail(); detail.ProductID = item.ProductId; detail.Quantity = item.Quantity; if (item.Product.PromotionPrice.HasValue) { detail.Price = item.Product.PromotionPrice.Value; } else { detail.Price = item.Product.Price; } detail.Note = item.Note; orderDetails.Add(detail); } _orderService.Create(ref orderNew, orderDetails); _productService.Save(); ViewBag.Amount = decimal.Parse(amount) / 100; ViewData["OrderID"] = orderNew.ID; ViewData["PaymentMethod"] = orderNew.PaymentMethod; string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/template/neworder.html")); content = content.Replace("{{CustomerName}}", order.CustomerName); content = content.Replace("{{Phone}}", order.CustomerMobile); content = content.Replace("{{Email}}", order.CustomerEmail); content = content.Replace("{{Address}}", order.CustomerAddress); content = content.Replace("{{Total}}", (decimal.Parse(amount) / 100).ToString("N0")); var adminEmail = ConfigHelper.GetByKey("AdminEmail"); MailHelper.SendMail(order.CustomerEmail, "Đơn hàng mới từ TheShoes", content); MailHelper.SendMail(adminEmail, "Đơn hàng mới từ TheShoes", content); Session[CommonConstants.OrderInfo] = Session[CommonConstants.SessionCart]; Session[CommonConstants.SessionCart] = null; Session[CommonConstants.SessionConfirmCart] = null; Session[CommonConstants.SessionOrder] = null; return(View((List <ShoppingCartViewModel>)Session[CommonConstants.OrderInfo])); } else { return(Redirect("/loi-thanh-toan.html")); } }
protected void Page_Load(object sender, EventArgs e) { //if (!IsPostBack) //{ // if (Session["OrderNumber"] != null) // { // var oOrder = new Orders(); // oOrder.OrdersQuickUpdate_PayStatusID(Session["OrderNumber"].ToString(), "2"); // Session["Cart"] = null; // Session["CheckOut"] = null; // } // else // Response.Redirect("~/gio-hang.aspx"); //} if (Session["UserName"] != null) { string SECURE_SECRET = ""; //if (Session["PaymentMethod"].ToString() == "onepaynd") // SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; //else if (Session["PaymentMethod"].ToString() == "onepayqt") // SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB"; if (Session["PaymentMethod"].ToString() == "onepaynd") SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26"; else if (Session["PaymentMethod"].ToString() == "onepayqt") SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardType = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); var oOrders = new Orders(); //var oOrderDetail = new OrderDetail(); var dtCart = Session["Cart"] as DataTable; double Amount = 0, sAmount = 0; string LastName, FirstName, Address, Email, ProvinceCode, DistrictName, CountryName, Phone, AddressBookID; string OrderNumber = Session["OrderNumber"].ToString(); var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; var OrderStatusID = "1"; var ShippingStatusID = "1"; var PaymentMethodID = Session["PaymentMethod"].ToString(); var Notes = Session["Message"].ToString(); var Comission = ""; var PaymentMethodName = Session["PaymentMethod"] == "money" ? "Tiền Mặt" : (Session["PaymentMethod"] == "onepaynd" ? "Thẻ ATM nội địa qua OnePay" : (Session["PaymentMethod"] == "onepayqt" ? "Thẻ VISA, MASTER qua OnePAY" : "Chuyển khoản trực tiếp")); var oAddressBook = new AddressBook(); var dtAddressBook = oAddressBook.AddressBookSelectOne(Session["ShippingID"].ToString()); AddressBookID = dtAddressBook.Rows[0]["AddressBookID"].ToString(); LastName = dtAddressBook.Rows[0]["LastName"].ToString(); FirstName = dtAddressBook.Rows[0]["FirstName"].ToString(); Address = dtAddressBook.Rows[0]["Address1"].ToString(); Email = dtAddressBook.Rows[0]["Email"].ToString(); ProvinceCode = dtAddressBook.Rows[0]["ProvinceName"].ToString(); CountryName = dtAddressBook.Rows[0]["CountryName"].ToString(); DistrictName = dtAddressBook.Rows[0]["DistrictName"].ToString(); Phone = dtAddressBook.Rows[0]["HomePhone"].ToString(); var BillingAddressID = AddressBookID; var ShippingAddressID = AddressBookID; var ShippingPrice = Session["ShippingPrice"]; var YourName = FirstName + " " + LastName; var YourEmail = Email; var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName; var To = "*****@*****.**"; //var To = "*****@*****.**"; var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderNumber; //var Host = "118.69.199.203"; //int Port = 25; var Host = "smtp.gmail.com"; int Port = 587; //var strMailFromAlias = "*****@*****.**"; //var Password = "******"; var strDisplayNameMailFrom = ""; var From = "*****@*****.**"; var sPassword = "******"; //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng"; //var From = "*****@*****.**"; //var sPassword = "******"; bool bEnableSSL = true; // Sua lai ham check chuoi ma hoa du lieu //if (recive_SecureHash !=doSecureHash) if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //Common.ShowAlert(SECURE_SECRET); //string Host = "118.69.199.203"; //int Port = 25; //string From = "*****@*****.**"; //string Password = "******"; string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>"; Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>"; Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>"; Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>"; //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>"; Body += "</div>"; //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>"; Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>"; //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>"; Body += "<div style='font-size: 11px; font-family: Verdana'>"; //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>"; //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>"; Body += "<p><b>* Phương thức thanh toán</b>: " + PaymentMethodName + "</p>"; //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>"; Body += "</div>"; Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>"; //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; foreach (DataRow dr in dtCart.Rows) { string ProductCode = dr["Tag"].ToString(); string ProductID = dr["ProductID"].ToString(); string ProductName = dr["ProductName"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity); var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); Body += "<tr>"; Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>"; //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>"; Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>"; Body += "</tr>"; } Body += "</table>"; Body += "<div style='clear: both;'></div>"; var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //sAmount = Amount; var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>"; Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>"; Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>"; Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>"; Body += "</table>"; Body += "<div style='clear: both;'></div>"; //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>"; //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>"; //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>"; //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>"; //Body += "</ul>"; Body += "</div>"; Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>"; Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>"; Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>"; Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>"; Body += "<p>Add: 403, Hai Bà Trưng, Phường 8, Quận 3, Tp HCM.</p>"; Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>"; //Body += "<p>M: +84 908 xxx xxx>"; Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>"; Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>"; Body += "</div>"; Body += "</div>"; Body += "</div>"; //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false); var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true); if (bSendEmail) { //oOrders.OrdersInsert1( // OrderNumber, // UserName, // OrderStatusID, // ShippingStatusID, // PaymentMethodID, // BillingAddressID, // ShippingAddressID, // Notes, // Comission, // "", // "", // YourAddress, // "", // Email // ); //foreach (DataRow dr in dtCart.Rows) //{ // string ProductID = dr["ProductID"].ToString(); // string Quantity = dr["Quantity"].ToString(); // string Price = dr["Price"].ToString(); // string CreateBy = UserName; // string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); // string ProductLengthName = dr["ProductLengthName"].ToString(); // string ProductName = dr["ProductName"].ToString(); // oOrderDetail.OrderDetailInsert1( // OrderNumber, // ProductID, // Quantity, // Price, // CreateBy, // ProductOptionCategoryName, // ProductLengthName, // Email // ); //} //OrderNumber = oOrders.OrderID; oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "1" ); } //Common.ShowAlert("Bạn đã đặt hàng thành công. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!"); vpc_Result.Text = "Giao dịch đã thành công"; Panel2.Visible = true; Session["Cart"] = null; Session["CheckOut"] = null; } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "2" ); vpc_Result.Text = "Giao dịch đang chờ xử lý"; Session["Cart"] = null; Session["CheckOut"] = null; //Response.Redirect("~/gio-hang.aspx"); } else { oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "3" ); vpc_Result.Text = "Giao dịch không thành công. Vui lòng tiến hành thanh toán lại"; Session["Cart"] = null; Session["CheckOut"] = null; //Response.Redirect("~/gio-hang.aspx"); } } else if (Session["Email"] != null) { string SECURE_SECRET = ""; //if (Session["PaymentMethod"].ToString() == "onepaynd") // SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; //else if (Session["PaymentMethod"].ToString() == "onepayqt") // SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB"; if (Session["PaymentMethod"].ToString() == "onepaynd") SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26"; else if (Session["PaymentMethod"].ToString() == "onepayqt") SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardType = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); var oOrders = new Orders(); //var oOrderDetail = new OrderDetail(); var dtCart = Session["Cart"] as DataTable; double Amount = 0, sAmount = 0; string LastName, FirstName, Address, Email, ProvinceCode, DistrictName, CountryName, Phone, AddressBookID; string OrderNumber = Session["OrderNumber"].ToString(); var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; var OrderStatusID = "1"; var ShippingStatusID = "1"; var PaymentMethodID = Session["PaymentMethod"].ToString(); var Notes = Session["Message"].ToString(); var Comission = ""; var PaymentMethodName = Session["PaymentMethod"] == "money" ? "Tiền Mặt" : (Session["PaymentMethod"] == "onepaynd" ? "Thẻ ATM nội địa qua OnePay" : (Session["PaymentMethod"] == "onepayqt" ? "Thẻ VISA, MASTER qua OnePAY" : "Chuyển khoản trực tiếp")); var oAddressBook1 = new AddressBook1(); var dtAddressBook = oAddressBook1.AddressBook1SelectOne(Session["AddressBookID"].ToString()); AddressBookID = dtAddressBook.Rows[0]["AddressBookID"].ToString(); LastName = dtAddressBook.Rows[0]["LastName"].ToString(); FirstName = dtAddressBook.Rows[0]["FirstName"].ToString(); Address = dtAddressBook.Rows[0]["Address1"].ToString(); Email = dtAddressBook.Rows[0]["Email"].ToString(); ProvinceCode = dtAddressBook.Rows[0]["ProvinceName"].ToString(); CountryName = dtAddressBook.Rows[0]["CountryName"].ToString(); DistrictName = dtAddressBook.Rows[0]["DistrictName"].ToString(); Phone = dtAddressBook.Rows[0]["HomePhone"].ToString(); var BillingAddressID = AddressBookID; var ShippingAddressID = AddressBookID; var ShippingPrice = Session["ShippingPrice"]; var YourName = FirstName + " " + LastName; var YourEmail = Email; var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName; //var To = "*****@*****.**"; var To = "*****@*****.**"; var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderNumber; //var Host = "118.69.199.203"; //int Port = 25; var Host = "smtp.gmail.com"; int Port = 587; //var strMailFromAlias = "*****@*****.**"; //var Password = "******"; var strDisplayNameMailFrom = ""; var From = "*****@*****.**"; var sPassword = "******"; //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng"; //var From = "*****@*****.**"; //var sPassword = "******"; bool bEnableSSL = true; // Sua lai ham check chuoi ma hoa du lieu //if (recive_SecureHash !=doSecureHash) if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //Common.ShowAlert(SECURE_SECRET); //string Host = "118.69.199.203"; //int Port = 25; //string From = "*****@*****.**"; //string Password = "******"; string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>"; Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>"; Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>"; Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>"; //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>"; Body += "</div>"; //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>"; Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>"; //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>"; Body += "<div style='font-size: 11px; font-family: Verdana'>"; //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>"; //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>"; Body += "<p><b>* Phương thức thanh toán</b>: " + PaymentMethodName + "</p>"; //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>"; Body += "</div>"; Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>"; //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; foreach (DataRow dr in dtCart.Rows) { string ProductCode = dr["Tag"].ToString(); //string ProductID = dr["ProductID"].ToString(); string ProductName = dr["ProductName"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity); var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); Body += "<tr>"; Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>"; //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>"; Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>"; Body += "</tr>"; } Body += "</table>"; Body += "<div style='clear: both;'></div>"; var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //sAmount = Amount; var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>"; Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>"; Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>"; Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>"; Body += "</table>"; Body += "<div style='clear: both;'></div>"; //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>"; //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>"; //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>"; //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>"; //Body += "</ul>"; Body += "</div>"; Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>"; Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>"; Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>"; Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>"; Body += "<p>Add: 403, Hai Bà Trưng, Phường 8, Quận 3, Tp HCM.</p>"; Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>"; //Body += "<p>M: +84 908 xxx xxx>"; Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>"; Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>"; Body += "</div>"; Body += "</div>"; Body += "</div>"; //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false); var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true); if (bSendEmail) { //oOrders.OrdersInsert1( // OrderNumber, // UserName, // OrderStatusID, // ShippingStatusID, // PaymentMethodID, // BillingAddressID, // ShippingAddressID, // Notes, // Comission, // "", // "", // YourAddress, // "", // Email // ); //foreach (DataRow dr in dtCart.Rows) //{ // string ProductID = dr["ProductID"].ToString(); // string Quantity = dr["Quantity"].ToString(); // string Price = dr["Price"].ToString(); // string CreateBy = UserName; // string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); // string ProductLengthName = dr["ProductLengthName"].ToString(); // //string ProductName = dr["ProductName"].ToString(); // oOrderDetail.OrderDetailInsert1( // OrderNumber, // ProductID, // Quantity, // Price, // CreateBy, // ProductOptionCategoryName, // ProductLengthName, // Email // ); //} //OrderNumber = oOrders.OrderID; oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "1" ); } //Common.ShowAlert("Bạn đã đặt hàng thành công. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!"); vpc_Result.Text = "Giao dịch đã thành công"; Panel2.Visible = true; Session["Cart"] = null; Session["CheckOut"] = null; } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "2" ); vpc_Result.Text = "Giao dịch đang chờ xử lý"; Session["Cart"] = null; Session["CheckOut"] = null; //Response.Redirect("~/gio-hang.aspx"); } else { oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "3" ); vpc_Result.Text = "Giao dịch không thành công. Vui lòng tiến hành thanh toán lại"; Session["Cart"] = null; Session["CheckOut"] = null; //Response.Redirect("~/gio-hang.aspx"); } } else Response.Redirect("~/login.aspx?returnurl=" + Request.Url.PathAndQuery); }
protected void Page_Load(object sender, EventArgs e) { string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); //int loop1; // Bo cac ham ma hoa du lieu cu //NameValueCollection coll = Request.QueryString; //// Get names of all keys into a string array. //String[] arr1 = coll.AllKeys; //for (int j = 0; j < arr1.Length;j++ ) //{ // arr1[j] = Server.HtmlEncode(arr1[j]); //} //Array.Sort(arr1, arr1); //string sdataHash = ""; //for (loop1 = 0; loop1 < arr1.Length; loop1++) //{ // String[] arr2 = coll.GetValues(arr1[loop1]); // if ((arr2[0] != null) && (arr2[0].Length > 0) && (arr1[loop1]!="vpc_SecureHash")) // { // sdataHash += Server.HtmlEncode(arr2[0]); // } //} // sdataHash = SECURE_SECRET + sdataHash; // string doSecureHash = DoMD5(sdataHash).Trim(); // Sua lai ham check chuoi ma hoa du lieu string mathanhtoantructuyen = merchTxnRef; if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { // var products = (from p in db.DONDATHANGs // orderby p.MaDonHang descending // select p).Skip(0).Take(1); //int a = 0; //foreach (var item in products) //{ // a = item.MaDonHang; //} //DONDATHANG dh = db.DONDATHANGs.SingleOrDefault(m => m.MaDonHang == a); //// nếu tôn tại đơn hàng //if (dh != null) //{ // dh.Dathanhtoan = true; // UpdateModel(dh); // db.SubmitChanges(); //} //vpc_Result.Text = "Transaction was paid successful"; Response.Write("<div class='result'>Đã Thanh Toán Thành Công</div><br/><div style='text-align:center'><a href='http://tsqwatch.somee.com/Home/Update' class='btn btn-primary' style='text-decoration:none;'>Vui lòng bấm <b style='color:red'>Xác Nhận</b> để kết thúc giao dịch</a></div>"); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { //var products = (from p in db.DONDATHANGs // orderby p.MaDonHang descending // select p).Skip(0).Take(1); //int a = 0; //foreach (var item in products) //{ // a = item.MaDonHang; //} //DONDATHANG dh = db.DONDATHANGs.SingleOrDefault(m => m.MaDonHang == a); //// nếu tôn tại đơn hàng //if (dh != null) //{ // dh.Dathanhtoan = false; // UpdateModel(dh); // db.SubmitChanges(); //} Response.Write("Error description: " + message + "<br/>"); Response.Write("<br/><div class='result'>Thanh Toán Đang Chờ</div><br/><div style='text-align:center'><a href='http://tsqwatch.somee.com/Home/Update1' class='btn btn-primary' style='text-decoration:none;'>Vui lòng bấm <b style='color:red'>Xác Nhận</b> để kết thúc giao dịch</a></div>"); //vpc_Result.Text = "Transaction is pending"; } else { //vpc_Result.Text = "Transaction was not paid successful"; Response.Write("Error description: " + message + "<br/>"); Response.Write("<div style='text-align:center'><a href='/'class='btn btn-primary' style='text-decoration:none;color:red'>Về Trang Chủ</a></div><br/><div class='result'>Thanh Toán Không Thành Công</div>"); } }
public static OnepayDomResult ProcessDr(string vpc_MerchTxnRef, string vpc_OrderInfo, string vpc_Amount) { vpc_MerchTxnRef = (vpc_MerchTxnRef ?? string.Empty).Trim(); vpc_Amount = (vpc_Amount ?? string.Empty).Trim(); var paymentTranasctionId = Guid.Empty; PaymentTransaction pt = null; ShoppingCart cart = null; if (Guid.TryParse(vpc_MerchTxnRef, out paymentTranasctionId)) { using (var db = new CoreEcommerceDbContext()) { pt = db.PaymentTransactions.SingleOrDefault(i => i.Id == paymentTranasctionId); cart = db.ShoppingCarts.SingleOrDefault( i => i.OrderCode.Equals(vpc_OrderInfo, StringComparison.OrdinalIgnoreCase)); } } if (string.IsNullOrEmpty(vpc_MerchTxnRef) || string.IsNullOrEmpty(vpc_Amount) || paymentTranasctionId == Guid.Empty || pt == null || cart == null) { return(new OnepayDomResult() { Message = "Not found payment transaction: " + vpc_MerchTxnRef + " for order code: " + vpc_OrderInfo, Success = false, Status = Enums.ShoppingCartPayStatus.PaymentFail }); } //if (pt.Amount != long.Parse(vpc_Amount)) //{ // return new PaymentMethodInternational.OnepayIntResult() // { // Message = "Invalid amount for payment transaction: " + vpc_MerchTxnRef + " for order code: " + vpc_OrderInfo, // Success = false, // Status = Enums.ShoppingCartPayStatus.Fail // }; //} string secureSecret = Config.SecureSecret; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest(Config.ApiPayUrl); conn.SetSecureSecret(secureSecret); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(HttpContext.Current.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", ""); string amount = conn.GetResultField("vpc_Amount", ""); string localed = conn.GetResultField("vpc_Locale", ""); string command = conn.GetResultField("vpc_Command", ""); string version = conn.GetResultField("vpc_Version", ""); string cardBin = conn.GetResultField("vpc_Card", ""); string orderInfo = conn.GetResultField("vpc_OrderInfo", ""); string merchantID = conn.GetResultField("vpc_Merchant", ""); string authorizeID = conn.GetResultField("vpc_AuthorizeId", ""); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", ""); string transactionNo = conn.GetResultField("vpc_TransactionNo", ""); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", ""); var model = new OnepayDomResult(); if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { model.Message = "Transaction was paid successful"; model.Status = Enums.ShoppingCartPayStatus.PaymentSuccess; model.Success = true; MemoryMessageBuss.PushCommand(new SuccessPaymentTransaction(paymentTranasctionId)); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { model.Message = "Transaction is pending"; model.Status = Enums.ShoppingCartPayStatus.PaymentProcess; model.Success = false; MemoryMessageBuss.PushCommand(new ProcessPaymentTransaction(paymentTranasctionId)); } else { model.Message = "Transaction was not paid successful"; model.Status = Enums.ShoppingCartPayStatus.PaymentFail; model.Success = false; MemoryMessageBuss.PushCommand(new FailPaymentTransaction(paymentTranasctionId)); } model.Message += "<br>" + message + $"<br>({vpc_TxnResponseCode} {transactionNo})" + $"<br>{vpc_MerchTxnRef} {vpc_OrderInfo}"; model.Amount = long.Parse(vpc_Amount) / 100; model.OrderCode = vpc_OrderInfo; return(model); }
protected void Page_Load(object sender, EventArgs e) { string SECURE_SECRET = OnepayQuocTeCode.SECURE_SECRET;//Hòa: cần thay bằng mã thật từ app_code string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardType = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); mathanhtoantructuyen = merchTxnRef; // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction was paid successful"; #region Cập nhật vào db theo mã đơn hàng DataTable dt = Order.Info_Order_by_OrderPay(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "1";//1: có nghĩa là thành toán thành công string detail = "Done"; Order.Order_Update(dt.Rows[0]["OrderID"].ToString(), dt.Rows[0]["DateCreated"].ToString(), dt.Rows[0]["OrderMoney"].ToString(), tinhTrangDonHang, dt.Rows[0]["CustomerID"].ToString(), dt.Rows[0]["CustomerNA"].ToString(), dt.Rows[0]["CallNumCUS"].ToString(), dt.Rows[0]["EmailCUS"].ToString(), detail); } #endregion //Response.Write("<div class='result'>Đã thanh toán thành công</div>"); Response.Write("<div class='result'>Payment successfully</div>"); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { #region Cập nhật vào db theo mã đơn hàng DataTable dt = Order.Info_Order_by_OrderPay(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "0";//1: có nghĩa là thành toán chưa thành công string detail = "Working"; Order.Order_Update(dt.Rows[0]["OrderID"].ToString(), dt.Rows[0]["DateCreated"].ToString(), dt.Rows[0]["OrderMoney"].ToString(), tinhTrangDonHang, dt.Rows[0]["CustomerID"].ToString(), dt.Rows[0]["CustomerNA"].ToString(), dt.Rows[0]["CallNumCUS"].ToString(), dt.Rows[0]["EmailCUS"].ToString(), detail); } #endregion //vpc_Result.Text = "Transaction is pending"; Response.Write("Error description : " + message + "<br/>"); //Response.Write("<div class='result'>Thanh toán đang chờ</div>"); Response.Write("<div class='result'>Payment successfully</div>"); } else { #region Cập nhật vào db theo mã đơn hàng DataTable dt = Order.Info_Order_by_OrderPay(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "0";//1: có nghĩa là thành toán chưa thành công string detail = "Working"; Order.Order_Update(dt.Rows[0]["OrderID"].ToString(), dt.Rows[0]["DateCreated"].ToString(), dt.Rows[0]["OrderMoney"].ToString(), tinhTrangDonHang, dt.Rows[0]["CustomerID"].ToString(), dt.Rows[0]["CustomerNA"].ToString(), dt.Rows[0]["CallNumCUS"].ToString(), dt.Rows[0]["EmailCUS"].ToString(), detail); } #endregion //vpc_Result.Text = "Transaction was not paid successful"; Response.Write("Error description : " + message + "<br/>"); //Response.Write("<div class='result'>Thanh toán không thành công</div>"); Response.Write("<div class='result'>Payment successfully</div>"); } //ScriptManager.RegisterStartupScript(this, this.GetType(), "", "Redirect('" + TatThanhJsc.Website.URL.WebisteUrl + "', 6);", true); }
//Xây dựng chức năng đặt hàng public ActionResult DatHang(KhachHang kh) { // Kiểm tra giỏ hàng tồn tại hay chưa if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } KhachHang khang = new KhachHang(); if (Session["TaiKhoan"] == null) { //Thêm kh vào bảng KhachHang ...khi chưa đăng nhập khang = kh; db.KhachHangs.Add(khang); db.SaveChanges(); } else { // Thêm kh bằng session Taikhoan ThanhVien tv = Session["TaiKhoan"] as ThanhVien; khang.TenKH = tv.HoTen; khang.DiaChi = tv.DiaChi; khang.Email = tv.Email; khang.SoDienThoai = tv.SoDienThoai; khang.MaThanhVien = tv.MaThanhVien; db.KhachHangs.Add(khang); db.SaveChanges(); } //Thêm đơn hàng DonDatHang ddh = new DonDatHang(); ddh.MaKH = khang.MaKH; ddh.NgayDat = DateTime.Now; ddh.TinhTrangGiaoHang = false; ddh.DaThanhToan = false; ddh.UuDai = 0; ddh.DaHuy = false; ddh.DaXoa = false; ddh.MaDDHString = DateTime.Now.Ticks; db.DonDatHangs.Add(ddh); db.SaveChanges(); // Thêm chi tiết đơn hàng List <itemGioHang> lstGioHang = LayGioHang(); // double Amoun = 0; foreach (var item in lstGioHang) { ChiTietDonDatHang ctdh = new ChiTietDonDatHang(); ctdh.MaDDH = ddh.MaDDH; ctdh.TenSP = item.TenSP; ctdh.MaSP = item.MaSP; ctdh.SoLuong = item.SoLuong; ctdh.DonGia = item.DonGia; // Amoun = Amoun + (double) ctdh.DonGia * ctdh.SoLuong; db.ChiTietDonDatHangs.Add(ctdh); } db.SaveChanges(); //#region "Thanh toán online thẻ nội địa" //string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; //// Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan //VPCRequest conn = new VPCRequest("https://mtf.onepay.vn/onecomm-pay/vpc.op"); //conn.SetSecureSecret(SECURE_SECRET); //// Add the Digital Order Fields for the functionality you wish to use //// Core Transaction Fields //conn.AddDigitalOrderField("Title", "onepay paygate"); //conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) //conn.AddDigitalOrderField("vpc_Version", "2"); //conn.AddDigitalOrderField("vpc_Command", "pay"); //conn.AddDigitalOrderField("vpc_Merchant", "ONEPAY"); //conn.AddDigitalOrderField("vpc_AccessCode", "D67342C2"); //conn.AddDigitalOrderField("vpc_MerchTxnRef", ddh.MaDDHString.ToString()); //conn.AddDigitalOrderField("vpc_OrderInfo", "9704250000000001 NGUYEN VAN A"); //conn.AddDigitalOrderField("vpc_Amount", (TinhTongTien()*100).ToString()); //conn.AddDigitalOrderField("vpc_Currency", "VND"); //conn.AddDigitalOrderField("vpc_ReturnURL", "http://*****:*****@onepay.vn"); //conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); //// Dia chi IP cua khach hang //conn.AddDigitalOrderField("vpc_TicketNo", DateTime.Now.Ticks.ToString()); //// Chuyen huong trinh duyet sang cong thanh toan //String url = conn.Create3PartyQueryString(); //return Redirect(url); //#endregion #region "Thanh toán online quốc tế" string SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://mtf.onepay.vn/vpcpay/vpcpay.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn.AddDigitalOrderField("Title", "onepay.vn"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "TESTONEPAY"); conn.AddDigitalOrderField("vpc_AccessCode", "6BEB2546"); conn.AddDigitalOrderField("vpc_MerchTxnRef", ddh.MaDDHString.ToString()); conn.AddDigitalOrderField("vpc_OrderInfo", "4000000000000002 | 05/21 | 123 | Tran Quang Khai"); conn.AddDigitalOrderField("vpc_Amount", (TinhTongTien() * 100).ToString()); conn.AddDigitalOrderField("vpc_ReturnURL", "http://*****:*****@onepay.vn"); conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", DateTime.Now.Ticks.ToString()); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(Redirect(url)); #endregion }
protected void Page_Load(object sender, EventArgs e) { string SECURE_SECRET = OnepayCode.SECURE_SECRET;//Hòa: cần thay bằng mã thật từ app_code string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); System.Decimal TongThanhTien = 0; String hoten, sdt, diachi, tinh, quan, maDH, datetime, email; DataTable dt = new DataTable(); DataTable info = new DataTable(); // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction was paid successful"; dt = (DataTable)Session["GioHang"]; info = (DataTable)Session["info"]; hoten = info.Rows[0]["hoten"].ToString(); sdt = info.Rows[0]["sdt"].ToString(); maDH = info.Rows[0]["maDH"].ToString(); TongThanhTien = int.Parse(info.Rows[0]["TongThanhTien"].ToString()); datetime = info.Rows[0]["datetime"].ToString(); email = info.Rows[0]["email"].ToString(); diachi = info.Rows[0]["diachi"].ToString(); XuLyDonHang.getDonDatHang(2, sdt, hoten, maDH, TongThanhTien, datetime, dt, email, diachi, 0); #region xử lý mail string smtpUserName = "******"; string smtpPassword = "******"; string smtpHost = "smtp.gmail.com"; int smtpPort = 25; string emailTo = email; string subject = "Vương quốc son môi - thanh toán quốc tế"; string body = string.Format("Xin chào, " + email + Environment.NewLine + "\n Số tiền bạn đã thanh toán: " + String.Format("{0:0,00}₫", TongThanhTien) + ":" + Environment.NewLine + "\n Bạn đã thanh toán đơn hàng bằng hình thức thanh toán quốc tế thành công! Đơn hàng đang chờ được duyệt" + Environment.NewLine + "\n Cảm ơn bạn đã sử dụng dịch vụ của Vương quốc son môi!" + Environment.NewLine + "\n Chúc bạn có thêm nhiều niềm vui với bưu phẩm của mình <3"); MailUtils service = new MailUtils(); bool kq = service.Send(smtpUserName, smtpPassword, smtpHost, smtpPort, emailTo, subject, body); #endregion Session["Giohang"] = null; Session["info"] = null; Response.Write("<div class='result'>Đã thanh toán thành công</div>"); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction is pending"; //Response.Write("Error description : " + message + "<br/>"); Response.Write("<div class='result'>Thanh toán đang chờ</div>"); } else { //vpc_Result.Text = "Transaction was not paid successful"; //Response.Write("Error description : " + message + "<br/>"); Response.Write("<div class='result'>Thanh toán không thành công</div>"); } }
public ActionResult ThanhToanTT() { var sessionCart = (List <CartItem>)Session[CommonConstants.CartSession]; var orderNew = new ORDER(); decimal total = 0; foreach (var item in sessionCart) { var detail = new ORDERDETAIL(); detail.OrderID = orderNew.ID; detail.ProductID = item.Product.ID; detail.Quantity = item.Quantity; if (item.Product.PromotionPrice.HasValue) { detail.Price = item.Product.PromotionPrice.Value; total += (item.Product.PromotionPrice.GetValueOrDefault(0) * item.Quantity); } else { detail.Price = item.Product.Price; total += (item.Product.Price.Value * item.Quantity); } } decimal totals = total * 100; var id = sessionCart.ToList().LastOrDefault(); string text = ""; foreach (var cart in sessionCart) { text = text + cart.Product.Name + " " + cart.Product.Quantity; if (cart.Product.ID != id.Product.ID) { text = text + " + "; } } Session[CommonConstants.CartSession] = null; string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://mtf.onepay.vn/onecomm-pay/vpc.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "ONEPAY"); conn.AddDigitalOrderField("vpc_AccessCode", "D67342C2"); conn.AddDigitalOrderField("vpc_MerchTxnRef", MaHoaMD5(ngaunhien().ToString())); conn.AddDigitalOrderField("vpc_OrderInfo", text); conn.AddDigitalOrderField("vpc_Amount", totals.ToString()); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("Index", "TrangChu", null, Request.Url.Scheme)); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", "Vietnam"); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ""); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(Redirect(url)); }
protected void Page_Load(object sender, EventArgs e) { string SECURE_SECRET = OnepayCode.SECURE_SECRET;//Hòa: cần thay bằng mã thật từ app_code string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); string mathanhtoantructuyen = merchTxnRef; // Sua lai ham check chuoi ma hoa du lieu if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction was paid successful"; #region Cập nhật vào db theo mã đơn hàng DataTable dt = DonDatHang.Thongtin_Dondathang_by_maThanhToan(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "1";//1: có nghĩa là thành toán thành công DonDatHang.Dondathang_Update(dt.Rows[0]["MaDonDatHang"].ToString(), dt.Rows[0]["NgayTao"].ToString(), dt.Rows[0]["ThanhTienDH"].ToString(), tinhTrangDonHang, dt.Rows[0]["MaKH"].ToString(), dt.Rows[0]["TenKH"].ToString(), dt.Rows[0]["sdtKH"].ToString(), dt.Rows[0]["EmailKH"].ToString()); } #endregion Response.Write("<div class='result'>Đã thanh toán thành công</div>"); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { #region Cập nhật vào db theo mã đơn hàng DataTable dt = DonDatHang.Thongtin_Dondathang_by_maThanhToan(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "0";//1: có nghĩa là thành toán chưa thành công DonDatHang.Dondathang_Update(dt.Rows[0]["MaDonDatHang"].ToString(), dt.Rows[0]["NgayTao"].ToString(), dt.Rows[0]["ThanhTienDH"].ToString(), tinhTrangDonHang, dt.Rows[0]["MaKH"].ToString(), dt.Rows[0]["TenKH"].ToString(), dt.Rows[0]["sdtKH"].ToString(), dt.Rows[0]["EmailKH"].ToString()); } #endregion //vpc_Result.Text = "Transaction is pending"; Response.Write("Error description : " + message + "<br/>"); Response.Write("<div class='result'>Thanh toán đang chờ</div>"); } else { #region Cập nhật vào db theo mã đơn hàng DataTable dt = DonDatHang.Thongtin_Dondathang_by_maThanhToan(mathanhtoantructuyen); //Nếu tồn tại đơn hàng này --> cập nhật lại trạng thái if (dt.Rows.Count > 0) { string tinhTrangDonHang = "0";//1: có nghĩa là thành toán chưa thành công DonDatHang.Dondathang_Update(dt.Rows[0]["MaDonDatHang"].ToString(), dt.Rows[0]["NgayTao"].ToString(), dt.Rows[0]["ThanhTienDH"].ToString(), tinhTrangDonHang, dt.Rows[0]["MaKH"].ToString(), dt.Rows[0]["TenKH"].ToString(), dt.Rows[0]["sdtKH"].ToString(), dt.Rows[0]["EmailKH"].ToString()); } #endregion //vpc_Result.Text = "Transaction was not paid successful"; Response.Write("Error description : " + message + "<br/>"); Response.Write("<div class='result'>Thanh toán không thành công</div>"); } }
protected void btnOrderLogin_Click(object sender, EventArgs e) { var dtCart = Session["Cart"] as DataTable; if (dtCart != null) { string OrderNumber = DateTime.Now.ToString("ddMMyy") + Guid.NewGuid().GetHashCode().ToString("X").Substring(0, 4); Session["OrderNumber"] = OrderNumber; double Amount = 0, sAmount = 0; string LastName, FirstName, Address, Email, ProvinceCode, DistrictName, CountryName, AddressBookID, HomePhone, strMessage; //CellPhone, //CountryCode, //City, //Nationality, //ZipCode; var dtAddressBook = (DataView)OdsAddressBook.Select(); AddressBookID = dtAddressBook[0]["AddressBookID"].ToString(); LastName = dtAddressBook[0]["LastName"].ToString(); FirstName = dtAddressBook[0]["FirstName"].ToString(); Address = dtAddressBook[0]["Address1"].ToString(); Email = dtAddressBook[0]["Email"].ToString(); ProvinceCode = dtAddressBook[0]["ProvinceName"].ToString(); CountryName = dtAddressBook[0]["CountryName"].ToString(); DistrictName = dtAddressBook[0]["DistrictName"].ToString(); HomePhone = (FormView1.FindControl("txtPhone") as TextBox).Text; strMessage = (FormView1.FindControl("txtMessage") as TextBox).Text; //ZipCode = dtAddressBook[0]["ZipCode"].ToString(); //City = dtAddressBook[0]["City"].ToString(); //CountryCode = dtAddressBook[0]["CountryShortName"].ToString(); //Nationality = dtAddressBook[0]["Nationality"].ToString(); //HomePhone = dtAddressBook[0]["HomePhone"].ToString(); //CellPhone = dtAddressBook[0]["CellPhone"].ToString(); //var BuyerName = LastName1 + " " + FirstName1; //var BuyerAddress = Address1 + ", " + DistrictName1 + ", " + ProvinceCode1 + ", " + CountryName1; //var lblSubTotal = ((Label)lstShoppingCart.FindControl("lblSubTotal")).Text.Trim(); var ShippingPrice = Session["ShippingPrice"]; //var To = "*****@*****.**"; //var Subject = "Đặt hàng/Order"; var YourName = FirstName + " " + LastName; //var YourEmail = Email; var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName; //var To = "*****@*****.**"; var To = "*****@*****.**"; var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderNumber; //var Host = "118.69.199.203"; //int Port = 25; var Host = "smtp.gmail.com"; int Port = 587; var strDisplayNameMailFrom = ""; var From = "*****@*****.**"; var sPassword = "******"; //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng"; //var From = "*****@*****.**"; //var sPassword = "******"; bool bEnableSSL = true; //string Host = "118.69.199.203"; //int Port = 25; //string From = "*****@*****.**"; //string Password = "******"; var oOrders = new Orders(); var oOrderDetail = new OrderDetail(); var OrderID = OrderNumber; var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; var OrderStatusID = "1"; var ShippingStatusID = "1"; var BillingAddressID = AddressBookID; var ShippingAddressID = AddressBookID; var Notes = strMessage; var Comission = ""; if (rbtMoney.Checked) { //var To = "*****@*****.**"; string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>"; Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>"; Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>"; Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>"; //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>"; Body += "</div>"; //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>"; Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>"; //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>"; Body += "<div style='font-size: 11px; font-family: Verdana'>"; //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>"; //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>"; Body += "<p><b>* Phương thức thanh toán</b>: Tiền mặt</p>"; //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>"; Body += "</div>"; Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>"; //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; foreach (DataRow dr in dtCart.Rows) { string ProductCode = dr["Tag"].ToString(); //string ProductID = dr["ProductID"].ToString(); string ProductName = dr["ProductName"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity); var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); Body += "<tr>"; Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>"; //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>"; Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>"; Body += "</tr>"; } Body += "</table>"; Body += "<div style='clear: both;'></div>"; var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //sAmount = Amount; var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>"; Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>"; Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>"; Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>"; Body += "</table>"; Body += "<div style='clear: both;'></div>"; //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>"; //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>"; //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>"; //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>"; //Body += "</ul>"; Body += "</div>"; Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>"; Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>"; Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>"; Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>"; Body += "<p>Add: 403, Hai Bà Trưng , P.8, Quận 3, HCM </p>"; Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>"; //Body += "<p>M: +84 908 xxx xxx>"; Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>"; Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>"; Body += "</div>"; Body += "</div>"; Body += "</div>"; var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true); //var a = Common.SendMail(Host, Port, "*****@*****.**", "web123master", "*****@*****.**", "", "LIÊN HỆ CÔNG TY TNHH THƯƠNG MẠI - XUẤT KHẨU SONG KIM LONG HẢI", Body, true); if (bSendEmail) { //var OrderID = OrderNumber; //var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; //var OrderStatusID = "1"; //var ShippingStatusID = "1"; var PaymentMethodID = "money"; //var BillingAddressID = AddressBookID; //var ShippingAddressID = AddressBookID; //var Notes = strMessage; //var Comission = ""; oOrders.OrdersInsert1( OrderID, UserName, OrderStatusID, ShippingStatusID, PaymentMethodID, BillingAddressID, ShippingAddressID, Notes, Comission, "", "", YourAddress, "", Email ); foreach (DataRow dr in dtCart.Rows) { string ProductID = dr["ProductID"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string CreateBy = UserName; string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); //string ProductName = dr["ProductName"].ToString(); //string Type = dr["Tag"].ToString(); //string Description = dr["Description"].ToString(); oOrderDetail.OrderDetailInsert1( OrderID, ProductID, Quantity, Price, CreateBy, ProductOptionCategoryName, ProductLengthName, Email ); } Session["PaymentMethod"] = "money"; Session["Message"] = strMessage; Response.Redirect("~/xac-nhan-don-hang.aspx"); } } else if (rbtOnePayNoiDia.Checked) { foreach (DataRow dr in dtCart.Rows) { string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); } var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //var OrderID = OrderNumber; //var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; //var OrderStatusID = "1"; //var ShippingStatusID = "1"; var PaymentMethodID = "onepaynd"; //var BillingAddressID = AddressBookID; //var ShippingAddressID = AddressBookID; //var Notes = strMessage; //var Comission = ""; oOrders.OrdersInsert1( OrderID, UserName, OrderStatusID, ShippingStatusID, PaymentMethodID, BillingAddressID, ShippingAddressID, Notes, Comission, "", "", YourAddress, "", Email ); foreach (DataRow dr in dtCart.Rows) { string ProductID = dr["ProductID"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string CreateBy = UserName; string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); oOrderDetail.OrderDetailInsert1( OrderID, ProductID, Quantity, Price, CreateBy, ProductOptionCategoryName, ProductLengthName, Email ); } oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "2" ); var uri = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) + Request.ApplicationPath; // Core Transaction Fields var vpc_Locale = "vn"; var vpc_Version = "2"; var vpc_Command = "pay"; var vpc_Merchant = "ONEPAY";//Merchant test var vpc_AccessCode = "D67342C2";//Access Code test //var vpc_Merchant = "PANDEMOS"; //var vpc_AccessCode = "JRCFWZTK"; var vpc_MerchTxnRef = OrderNumber; var vpc_OrderInfo = OrderNumber; var vpc_Amount = sAmount * 100; var vpc_Currency = "VND"; var vpc_ReturnURL = uri + "/thanh-toan-thanh-cong.aspx?ord=" + OrderNumber; //Thong tin khach hang var vpc_SHIP_Street01 = Common.ChangeSymBol(Address); var vpc_SHIP_Provice = Common.ChangeSymBol(DistrictName); var vpc_SHIP_City = Common.ChangeSymBol(ProvinceCode); var vpc_SHIP_Country = "Vietnam"; var vpc_Customer_Phone = Common.ChangeSymBol(HomePhone); var vpc_Customer_Email = Email; var vpc_Customer_Id = ""; var vpc_Customer_Name = Common.ChangeSymBol(FirstName); var vpc_TicketNo = ""; var vpc_SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";//Secure Hash test //var vpc_SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26"; var vpc_URL_Payment = "https://mtf.onepay.vn/onecomm-pay/vpc.op";//dia chi thanh toan test //var vpc_URL_Payment = "https://onepay.vn/onecomm-pay/vpc.op";//dia chi thanh toan that VPCRequest conn = new VPCRequest(vpc_URL_Payment); conn.SetSecureSecret(vpc_SECURE_SECRET); // Core Transaction Fields conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", vpc_Locale);//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", vpc_Version); conn.AddDigitalOrderField("vpc_Command", vpc_Command); conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant); conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", vpc_MerchTxnRef); conn.AddDigitalOrderField("vpc_OrderInfo", vpc_OrderInfo); conn.AddDigitalOrderField("vpc_Amount", vpc_Amount.ToString()); conn.AddDigitalOrderField("vpc_Currency", vpc_Currency); conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL); //Thong tin khach hang conn.AddDigitalOrderField("vpc_SHIP_Street01", vpc_SHIP_Street01); conn.AddDigitalOrderField("vpc_SHIP_Provice", vpc_SHIP_Provice); conn.AddDigitalOrderField("vpc_SHIP_City", vpc_SHIP_City); conn.AddDigitalOrderField("vpc_SHIP_Country", vpc_SHIP_Country); conn.AddDigitalOrderField("vpc_Customer_Phone", vpc_Customer_Phone); conn.AddDigitalOrderField("vpc_Customer_Email", vpc_Customer_Email); conn.AddDigitalOrderField("vpc_Customer_Id", vpc_Customer_Id); conn.AddDigitalOrderField("vpc_Customer_Name", vpc_Customer_Name); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", vpc_TicketNo); // Chuyen huong trinh duyet sang cong thanh toan Session["PaymentMethod"] = "onepaynd"; Session["Message"] = strMessage; String url = conn.Create3PartyQueryString(); Page.Response.Redirect(url); } else if (rbtOnePayQuocTe.Checked) { foreach (DataRow dr in dtCart.Rows) { string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); } var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //var OrderID = OrderNumber; //var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; //var OrderStatusID = "1"; //var ShippingStatusID = "1"; var PaymentMethodID = "onepayqt"; //var BillingAddressID = AddressBookID; //var ShippingAddressID = AddressBookID; //var Notes = strMessage; //var Comission = ""; oOrders.OrdersInsert1( OrderID, UserName, OrderStatusID, ShippingStatusID, PaymentMethodID, BillingAddressID, ShippingAddressID, Notes, Comission, "", "", YourAddress, "", Email ); foreach (DataRow dr in dtCart.Rows) { string ProductID = dr["ProductID"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string CreateBy = UserName; string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); oOrderDetail.OrderDetailInsert1( OrderID, ProductID, Quantity, Price, CreateBy, ProductOptionCategoryName, ProductLengthName, Email ); } oOrders.OrdersQuickUpdate_PayStatusID( OrderNumber, "2" ); var uri = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) + Request.ApplicationPath; // Core Transaction Fields var vpc_Locale = "en"; var vpc_Version = "2"; var vpc_Command = "pay"; var vpc_Merchant = "TESTONEPAY";//Merchant Test var vpc_AccessCode = "6BEB2546";//Access Code Test //var vpc_Merchant = "PANDEMOS"; //var vpc_AccessCode = "B94D84AE"; var vpc_MerchTxnRef = OrderNumber; var vpc_OrderInfo = OrderNumber; var vpc_Amount = sAmount * 100; var vpc_Currency = "VND"; var vpc_ReturnURL = uri + "/thanh-toan-thanh-cong.aspx?ord=" + OrderNumber; //Thong tin khach hang var vpc_SHIP_Street01 = "194 Tran Quang Khai"; var vpc_SHIP_Provice = "Hanoi"; var vpc_SHIP_City = "Hanoi"; var vpc_SHIP_Country = "Vietnam"; var vpc_Customer_Phone = "043966668"; var vpc_Customer_Email = "*****@*****.**"; var vpc_Customer_Id = "onepay_paygate"; var vpc_Customer_Name = ""; var vpc_TicketNo = ""; var vpc_SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";//Secure Hash test //var vpc_SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A"; var vpc_URL_Payment = "https://mtf.onepay.vn/vpcpay/vpcpay.op";//dia chi thanh toan test //var vpc_URL_Payment = "https://onepay.vn/vpcpay/vpcpay.op";//dia chi thanh toan that VPCRequest conn = new VPCRequest(vpc_URL_Payment); conn.SetSecureSecret(vpc_SECURE_SECRET); // Core Transaction Fields conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", vpc_Version); conn.AddDigitalOrderField("vpc_Command", vpc_Command); conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant); conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", vpc_MerchTxnRef); conn.AddDigitalOrderField("vpc_OrderInfo", vpc_OrderInfo); conn.AddDigitalOrderField("vpc_Amount", vpc_Amount.ToString()); conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", vpc_SHIP_Street01); conn.AddDigitalOrderField("vpc_SHIP_Provice", vpc_SHIP_Provice); conn.AddDigitalOrderField("vpc_SHIP_City", vpc_SHIP_City); conn.AddDigitalOrderField("vpc_SHIP_Country", vpc_SHIP_Country); conn.AddDigitalOrderField("vpc_Customer_Phone", vpc_Customer_Phone); conn.AddDigitalOrderField("vpc_Customer_Email", vpc_Customer_Email); conn.AddDigitalOrderField("vpc_Customer_Id", vpc_Customer_Id); conn.AddDigitalOrderField("vpc_Customer_Name", vpc_Customer_Name); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", vpc_TicketNo); // Chuyen huong trinh duyet sang cong thanh toan Session["PaymentMethod"] = "onepayqt"; Session["Message"] = strMessage; //Common.ShowAlert(vpc_SHIP_Provice); String url = conn.Create3PartyQueryString(); Page.Response.Redirect(url); } else if (rbtEmail.Checked) { string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>"; Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>"; Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>"; Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>"; //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>"; Body += "</div>"; //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>"; Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>"; //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>"; Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>"; Body += "<div style='font-size: 11px; font-family: Verdana'>"; //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>"; //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>"; Body += "<p><b>* Phương thức thanh toán</b>: Thanh toán bằng chuyển khoản trực tiếp</p>"; //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>"; Body += "</div>"; Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>"; //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>"; foreach (DataRow dr in dtCart.Rows) { string ProductCode = dr["Tag"].ToString(); string ProductID = dr["ProductID"].ToString(); string ProductName = dr["ProductName"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity); var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND"; Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity); Body += "<tr>"; Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>"; //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>"; Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>"; Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>"; Body += "</tr>"; } Body += "</table>"; Body += "<div style='clear: both;'></div>"; var iShippingPrice = Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice); sAmount = Amount + iShippingPrice; //sAmount = Amount; var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ"; Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>"; Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>"; Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>"; Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>"; Body += "</table>"; Body += "<div style='clear: both;'></div>"; //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>"; //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>"; //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>"; //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>"; //Body += "</ul>"; Body += "</div>"; Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>"; Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>"; Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>"; Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>"; Body += "<p>Add: 403, Hai Bà Trưng , P.8, Quận 3, HCM </p>"; Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>"; //Body += "<p>M: +84 908 xxx xxx>"; Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>"; Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>"; Body += "</div>"; Body += "</div>"; Body += "</div>"; //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false); var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true); if (bSendEmail) { //var OrderID = OrderNumber; //var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name; //var OrderStatusID = "1"; //var ShippingStatusID = "1"; var PaymentMethodID = "transfer"; //var BillingAddressID = AddressBookID; //var ShippingAddressID = AddressBookID; //var Notes = strMessage; //var Comission = ""; oOrders.OrdersInsert1( OrderID, UserName, OrderStatusID, ShippingStatusID, PaymentMethodID, BillingAddressID, ShippingAddressID, Notes, Comission, "", "", YourAddress, "", Email ); foreach (DataRow dr in dtCart.Rows) { string ProductID = dr["ProductID"].ToString(); string Quantity = dr["Quantity"].ToString(); string Price = dr["Price"].ToString(); string CreateBy = UserName; string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString(); string ProductLengthName = dr["ProductLengthName"].ToString(); //string ProductName = dr["ProductName"].ToString(); //string Type = dr["Tag"].ToString(); //string Description = dr["Description"].ToString(); oOrderDetail.OrderDetailInsert1( OrderID, ProductID, Quantity, Price, CreateBy, ProductOptionCategoryName, ProductLengthName, Email ); } Session["PaymentMethod"] = "transfer"; Session["Message"] = strMessage; Response.Redirect("~/xac-nhan-don-hang.aspx"); } } } }
public ActionResult MakePayment() { FindItemReponse <UserModel> response = _userService.FindUserByID(Session["User-UserID"].ToString()); if (response.Item != null) { FindAllItemReponse <MailingAddressModel> mailingResponse = _mailingService.FindMailingAddressByUser(Session["User-UserID"].ToString()); if (mailingResponse.Items != null) { var mailing = mailingResponse.Items.SingleOrDefault(); if (mailing != null) { //Caculate payment //Get fee int fee = -1; DateTime earlyBird = new DateTime(2017, 6, 30); DateTime regular = new DateTime(2017, 11, 26); int age = DataHelper.GetInstance().CalculateAge(response.Item.DateOfBirth.Value); switch (mailing.ParticipantType) { case "International delegates": case "International youth": if (age < 25) { fee = 150; } else { if (DateTime.UtcNow <= earlyBird) { fee = 550; } else { fee = 600; } } break; case "Vietnamese delegate": case "Vietnamese youth": if (age < 25) { fee = 100; } else { if (DateTime.UtcNow <= earlyBird) { fee = 200; } else { fee = 250; } } break; default: fee = -1; break; } if (fee == -1) { return(RedirectToAction("RegistrationIncompleted")); } //Parse currency decimal amount = 0; decimal usdrate = 0; try { usdrate = DataHelper.GetInstance().GetCurrencyRate(FROM_CURRENCY, 22265); } catch (Exception) { //Try convert using google try { string _amount = DataHelper.GetInstance().CurrencyConvert(fee, FROM_CURRENCY, TO_CURRENCY); _amount = _amount.Substring(0, _amount.IndexOf(" ")); amount = decimal.Parse(_amount); } catch (Exception) { return(RedirectToAction("Index", "RequestError")); } } //Calculate amount if (usdrate != 0) { amount = fee * usdrate; } if (amount == 0) { return(RedirectToAction("Index", "RequestError")); } //amount X 100 before parse to OnePay amount = amount * 100; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest(VIRTUAL_PAYMENT_CLIENT); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn.AddDigitalOrderField("Title", "onepay paygate"); //Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Locale", vpc_Locale); conn.AddDigitalOrderField("vpc_Version", vpc_Version); conn.AddDigitalOrderField("vpc_Command", vpc_Command); //Test account string subId = string.Format("{0}", DateTime.Now.Ticks); conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant); conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode); conn.AddDigitalOrderField("vpc_MerchTxnRef", subId); //Package order conn.AddDigitalOrderField("vpc_Amount", amount.ToString()); var transactionReference = DateTime.Now.Ticks; StringBuilder builder = new StringBuilder(); builder.Append(string.Format("Transaction vpc_MerchTxnRef {0}, ", subId)); builder.Append(string.Format("Transaction vpc_Merchant {0}, ", vpc_Merchant)); builder.Append(string.Format("Transaction vpc_Amount {0}, ", amount)); builder.Append(string.Format("Transaction fullname {0}, ", response.Item.FullName)); builder.Append(string.Format("Transaction email {0}", response.Item.Email)); builder.Append(string.Format("Transaction reference {0}", transactionReference)); TransactionHistoryModel trans = new TransactionHistoryModel { Action = "Create payment", CreatedDate = DateTime.Now, Log = builder.ToString(), Status = (int)TransactionStatus.Created, UserId = response.Item.UserID, Email = response.Item.Email, TransactionReference = transactionReference }; var insertResponse = _transaction.Create(trans); //Order info conn.AddDigitalOrderField("vpc_OrderInfo", transactionReference.ToString()); //Return url conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", Request.UserHostAddress); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(Redirect(url)); } } } return(RedirectToAction("RegistrationIncompleted")); }
public IActionResult OnePayPayment([Bind("vpc_Customer_Phone,vpc_Customer_Email,vpc_Customer_Id,vpc_Customer_Name")] VPC vpc) { string value = SessionHelper.GetObjectFromJson <string>(HttpContext.Session, "User"); var user = eMarketContext.TaiKhoan.Include(p => p.ThongTinTaiKhoan).Where(p => p.UserName == value).FirstOrDefault(); List <GioHang> danhsachhang = SessionHelper.GetObjectFromJson <List <GioHang> >(HttpContext.Session, "cart"); double total = 0; foreach (var x in danhsachhang) { total += x.HangHoa.Gia * x.SoLuong; } total = VPCRequest.USD_VND * total; var current_invoice = CreateInvoice(danhsachhang, vpc.vpc_Customer_Name, vpc.vpc_Customer_Email, vpc.vpc_Customer_Address, vpc.vpc_Customer_Phone); HttpContext.Session.SetString("cart", ""); foreach (var item in danhsachhang) { var topselling = eMarketContext.TopSelling.Where(p => p.HangHoaId == item.HangHoa.HangHoaId).FirstOrDefault(); if (topselling == null) { var newcolumn = new TopSelling(); newcolumn.HangHoaId = item.HangHoa.HangHoaId; newcolumn.SoLan = 1; eMarketContext.Add(newcolumn); eMarketContext.SaveChanges(); } else { topselling.SoLan += 1; eMarketContext.Update(topselling); eMarketContext.SaveChanges(); } } //Send request to OnePay string returnURL = Url.Action("OnePayResult", "GioHang", null, Request.Scheme);; VPCRequest conn = new VPCRequest(); conn.SetSecureSecret(VPCRequest.SECURE_SECRET); conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", VPCRequest.MERCHANT_ID); conn.AddDigitalOrderField("vpc_AccessCode", VPCRequest.ACCESS_CODE); conn.AddDigitalOrderField("vpc_MerchTxnRef", "HoaDon_" + current_invoice.HoaDonId); conn.AddDigitalOrderField("vpc_OrderInfo", "HoaDon_" + current_invoice.HoaDonId); conn.AddDigitalOrderField("vpc_Amount", total + "00"); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", returnURL); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_Customer_Phone", vpc.vpc_Customer_Phone); conn.AddDigitalOrderField("vpc_Customer_Email", vpc.vpc_Customer_Email); conn.AddDigitalOrderField("vpc_Customer_Id", "" + user.TaiKhoanId); // Dia chi IP cua khach hang string ipAddress = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(); conn.AddDigitalOrderField("vpc_TicketNo", ipAddress); // Chuyen huong trinh duyet sang cong thanh toan string url = conn.Create3PartyQueryString(); return(Redirect(url)); }
public ActionResult PaymentReturn() { string hashvalidateResult = ""; string vpc_TxnResponseCode = "Unknown"; string amount = "Unknown"; string localed = "Unknown"; string command = "Unknown"; string version = "Unknown"; string cardType = "Unknown"; string orderInfo = "Unknown"; string merchantID = "Unknown"; string authorizeID = "Unknown"; string merchTxnRef = "Unknown"; string transactionNo = "Unknown"; string acqResponseCode = "Unknown"; string txnResponseCode = "Unknown"; string message = "Unknown"; string msg = string.Empty; try { // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); amount = conn.GetResultField("vpc_Amount", "Unknown"); localed = conn.GetResultField("vpc_Locale", "Unknown"); command = conn.GetResultField("vpc_Command", "Unknown"); version = conn.GetResultField("vpc_Version", "Unknown"); cardType = conn.GetResultField("vpc_Card", "Unknown"); orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown"); txnResponseCode = vpc_TxnResponseCode; message = conn.GetResultField("vpc_Message", "Unknown"); } catch (Exception ex) { msg = "The payment is in-progress, please ask administrator for looking at this!"; Log(merchTxnRef, merchantID, amount, orderInfo, hashvalidateResult, ex.StackTrace); return(View(new InsertResponse { Message = "An error occurs at payment service, please contact administrator!", ErrorCode = (int)ErrorCode.Error })); } //Find user var participantType = ""; long reference = 0; long.TryParse(orderInfo, out reference); var transactionResponse = _transaction.FindByTransactionReference(reference); string userID = ""; string email = ""; if (transactionResponse.Items != null && transactionResponse.Items.Count > 0) { FindItemReponse <UserModel> userResponse = _userService.FindUserByID(transactionResponse.Items.First().UserId); if (userResponse.Item != null) { userID = userResponse.Item.UserID; email = userResponse.Item.Email; FindAllItemReponse <MailingAddressModel> mailingResponse = _mailingService.FindMailingAddressByUser(userResponse.Item.UserID); if (mailingResponse.Items != null) { var mailing = mailingResponse.Items.SingleOrDefault(); if (mailing != null) { participantType = mailing.ParticipantType; } } } } //Save payment PaymentModel payment = new PaymentModel(); payment.PaymentID = Guid.NewGuid().ToString(); payment.UserID = userID; payment.Amount = double.Parse(amount) / 100; payment.CreatedBy = userID; payment.CreatedDate = DateTime.Now; payment.MerchRef = merchTxnRef; payment.PaymentType = participantType; if (string.IsNullOrEmpty(payment.PaymentType)) { payment.PaymentType = "Unknown"; } try { //Validate transaction if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction was paid successful"; payment.Status = (int)PaymentStatus.Completed; msg = "Your payment was paid successful!"; //Sending email //USD decimal usd = 0; decimal usdrate = 0; try { usdrate = DataHelper.GetInstance().GetCurrencyRate(FROM_CURRENCY, 22265); usd = decimal.Parse(amount) / usdrate; } catch (Exception) { } string messageBody = DataHelper.GetInstance().BuildInvoicePdfTemplate(payment.PaymentType, merchTxnRef, transactionNo, usd.ToString(), amount, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture)); string title = string.Format(PAYMENT_TITLE, transactionNo); Task.Run(() => DataHelper.GetInstance().SendEmail(email, title, messageBody)); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { //vpc_Result.Text = "Transaction is pending"; payment.Status = (int)PaymentStatus.Pending; msg = "Your payment was in pending status, please contact our administrator!"; } else { //vpc_Result.Text = "Transaction was not paid successful"; payment.Status = (int)PaymentStatus.Error; msg = "The payment was not paid successful, please try again!"; } } catch (Exception ex) { msg = "The payment is in-progress, please ask administrator for looking at this!"; Log(merchTxnRef, merchantID, amount, orderInfo, hashvalidateResult, ex.StackTrace); } InsertResponse _response = _paymentService.Create(payment); _response.Message = msg; // Log info StringBuilder strBuilder = new StringBuilder(); strBuilder.Append(string.Format("Transaction vpc_MerchTxnRef {0}, ", merchTxnRef)); strBuilder.Append(string.Format("Transaction vpc_Merchant {0}, ", merchantID)); strBuilder.Append(string.Format("Transaction vpc_Amount {0}, ", amount)); strBuilder.Append(string.Format("Transaction vpc_OrderInfo {0}, ", orderInfo)); strBuilder.Append(string.Format("Transaction hashvalidateResult {0}, ", hashvalidateResult)); strBuilder.Append(string.Format("Transaction userId {0}, ", userID)); strBuilder.Append(string.Format("Transaction email {0}, ", email)); TransactionHistoryModel transaction = new TransactionHistoryModel { Action = "Payment completed", CreatedDate = DateTime.Now, Log = strBuilder.ToString(), Status = (int)TransactionStatus.Completed, UserId = merchTxnRef, Email = email, TransactionReference = reference }; _transaction.Create(transaction); return(View(_response)); }
}//String function end public VPCRequest AmexConfig() { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Collect Information for AMEX Gateway"); VPCRequest conn = new VPCRequest(_TNS.Properties.Settings.Default.PaymentServerURL); // Configure the proxy details (if needed) conn.SetProxyHost(_TNS.Properties.Settings.Default.ProxyHost); conn.SetProxyUser(_TNS.Properties.Settings.Default.ProxyUser); conn.SetProxyPassword(_TNS.Properties.Settings.Default.ProxyPassword); conn.SetProxyDomain(_TNS.Properties.Settings.Default.ProxyDomain); conn.SetSecureSecret(_TNS.Properties.Settings.Default.vpc_SecureSecret); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("vpc_Version", _TNS.Properties.Settings.Default.vpc_Version); conn.AddDigitalOrderField("vpc_AccessCode", _TNS.Properties.Settings.Default.vpc_AccessCode); conn.AddDigitalOrderField("vpc_Merchant", _TNS.Properties.Settings.Default.vpc_Merchant); conn.AddDigitalOrderField("vpc_User", _TNS.Properties.Settings.Default.vpc_User); conn.AddDigitalOrderField("vpc_Password", _TNS.Properties.Settings.Default.vpc_Password); return conn; //Configure the Hard coded details (if needed) //VPCRequest conn = new VPCRequest("https://vpos.amxvpos.com/vpcdps"); //conn.SetProxyHost(""); //conn.SetProxyUser(""); //conn.SetProxyPassword(""); //conn.SetProxyDomain(""); //conn.SetSecureSecret("44DD98D32ECD3C1AA7F12A1D0F8B41EA"); }
private void GuiDonHang() { string ketQua = ""; string detail = "Working"; //Lấy các thông tin người dùng gửi lên string hoTen = Request.Params["hoTen"]; string diaChi = Request.Params["diaChi"]; string soDienThoai = Request.Params["soDienThoai"]; string email = Request.Params["email"]; string phuongThucThanhToan = Request.Params["phuongThucThanhToan"]; //Nếu tồn tại giỏ hàng thì mới xử lý đặt hàng if (Session["GioHang"] != null) { //Khai báo datatable để chứa giỏ hàng DataTable dtGioHang = new DataTable(); dtGioHang = (DataTable)Session["GioHang"]; #region Lặp trong giỏ hàng để lấy ra tổng tiền double tongTien = 0; for (int i = 0; i < dtGioHang.Rows.Count; i++) { tongTien += int.Parse(dtGioHang.Rows[i]["SoLuong"].ToString()) * double.Parse(dtGioHang.Rows[i]["GiaSP"].ToString()); } #endregion #region Kiểm tra và thêm thông tin vào bảng Khách hàng string maKH = XuLyThongTinKhachHang(hoTen, diaChi, soDienThoai, email); #endregion //Lấy ngày giờ hiện tại trả về dạng số để làm mã thanh toán trực tuyến string mathanhtoantructuyen = DateTime.Now.Ticks.ToString(); #region Thêm thông tin vào bảng Đơn đặt hàng //Tạo đơn đặt hàng string ngayTao = DateTime.Now.ToString(); Order.Order_Inser(ngayTao, tongTien.ToString(), mathanhtoantructuyen, maKH, hoTen, soDienThoai, email, detail.ToString(), ""); //Lấy ra thông tin Đơn đặt hàng vừa tạo DataTable dtDonDatHang = Order.Info_Order_Desc(); string maDonDatHang = dtDonDatHang.Rows[0]["OrderID"].ToString(); #endregion #region Đọc giỏ hàng và thêm từng sản phẩm vào bảng Chi tiết đơn đặt hàng for (int i = 0; i < dtGioHang.Rows.Count; i++) { OrderDetail.OrderDetail_Inser(dtGioHang.Rows[i]["MaSP"].ToString(), maDonDatHang, dtGioHang.Rows[i]["SoLuong"].ToString(), dtGioHang.Rows[i]["GiaSP"].ToString(), ""); } #endregion #region Xóa session giỏ hàng Session["GioHang"] = null; #endregion #region Xử lý tương ứng cho các hình thức thanh toán switch (phuongThucThanhToan) { case "ChuyenKhoan": break; case "Onepay": #region Chuyển sang trang Onepay string SECURE_SECRET = OnepayCode.SECURE_SECRET; //Hòa: cần thanh bằng mã thật cấu hình trong app_code // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest(OnepayCode.VPCRequest); //Hòa: Cần thay bằng cổng thật cấu hình trong app_code conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn"); //Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", OnepayCode.Merchant); //Hòa: cần thanh bằng mã thật cấu hình trong app_code conn.AddDigitalOrderField("vpc_AccessCode", OnepayCode.AccessCode); //Hòa: cần thanh bằng mã thật cấu hình trong app_code conn.AddDigitalOrderField("vpc_MerchTxnRef", mathanhtoantructuyen); //Hòa: mã thanh toán conn.AddDigitalOrderField("vpc_OrderInfo", mathanhtoantructuyen); //Hòa: thông tin đơn hàng conn.AddDigitalOrderField("vpc_Amount", (tongTien * 100).ToString()); //Hòa: chi phí cần nhân 100 theo yêu cầu của onepay conn.AddDigitalOrderField("vpc_Currency", "$"); conn.AddDigitalOrderField("vpc_ReturnURL", OnepayCode.ReturnURL); //Hòa: địa chỉ nhận kết quả trả về // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", ""); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", ""); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", Request.UserHostAddress); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); #endregion ketQua = url; break; case "OnepayQuocTe": string SECURE_SECRET1 = OnepayQuocTeCode.SECURE_SECRET; //Hòa: cần thanh bằng mã thật cấu hình trong app_code; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn1 = new VPCRequest(OnepayQuocTeCode.VPCRequest); //Hòa: Cần thay bằng cổng thật conn1.SetSecureSecret(SECURE_SECRET1); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn1.AddDigitalOrderField("AgainLink", "http://onepay.vn"); conn1.AddDigitalOrderField("Title", "onepay paygate"); conn1.AddDigitalOrderField("vpc_Locale", "en"); //Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn1.AddDigitalOrderField("vpc_Version", "2"); conn1.AddDigitalOrderField("vpc_Command", "pay"); conn1.AddDigitalOrderField("vpc_Merchant", OnepayQuocTeCode.Merchant); //Hòa: cần thanh bằng mã thật cấu hình trong app_code conn1.AddDigitalOrderField("vpc_AccessCode", OnepayQuocTeCode.AccessCode); //Hòa: cần thanh bằng mã thật cấu hình trong app_code conn1.AddDigitalOrderField("vpc_MerchTxnRef", mathanhtoantructuyen); //Hòa: mã thanh toán conn1.AddDigitalOrderField("vpc_OrderInfo", mathanhtoantructuyen); //Hòa: mã thanh toán conn1.AddDigitalOrderField("vpc_Amount", (tongTien * 100).ToString()); //Hòa: chi phí cần nhân 100 theo yêu cầu của onepay conn1.AddDigitalOrderField("vpc_ReturnURL", OnepayQuocTeCode.ReturnURL); //Hòa: địa chỉ nhận kết quả trả về // Thong tin them ve khach hang. De trong neu khong co thong tin conn1.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn1.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn1.AddDigitalOrderField("vpc_SHIP_City", ""); conn1.AddDigitalOrderField("vpc_SHIP_Country", ""); conn1.AddDigitalOrderField("vpc_Customer_Phone", ""); conn1.AddDigitalOrderField("vpc_Customer_Email", ""); conn1.AddDigitalOrderField("vpc_Customer_Id", ""); // Dia chi IP cua khach hang conn1.AddDigitalOrderField("vpc_TicketNo", Request.UserHostAddress); // Chuyen huong trinh duyet sang cong thanh toan String url1 = conn1.Create3PartyQueryString(); ketQua = url1; break; } #endregion } else { ketQua = "Giỏ hàng đã hết hạn, vui lòng thực hiện chọn lại sản phẩm và đặt hàng lại"; } Response.Write(ketQua); }
protected void Page_Load(object sender, EventArgs e) { if (Session["isPrePay"] == null) { if (Session["isFirstPay"] == null) { Response.Redirect(Pages.CLIENT_INDEX); } } if (Session["AcceptSlipNo"] == null) { Response.Redirect(Pages.CLIENT_INDEX); } if (IsPostBack) { return; } string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; string hashvalidateResult = ""; // Khoi tao lop thu vien VPCRequest conn = new VPCRequest("http://onepay.vn"); conn.SetSecureSecret(SECURE_SECRET); // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString); // Lay gia tri tham so tra ve tu cong thanh toan String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown"); string amount = conn.GetResultField("vpc_Amount", "Unknown"); string localed = conn.GetResultField("vpc_Locale", "Unknown"); string command = conn.GetResultField("vpc_Command", "Unknown"); string version = conn.GetResultField("vpc_Version", "Unknown"); string cardBin = conn.GetResultField("vpc_Card", "Unknown"); string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown"); string merchantID = conn.GetResultField("vpc_Merchant", "Unknown"); string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown"); string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown"); string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown"); string txnResponseCode = vpc_TxnResponseCode; string message = conn.GetResultField("vpc_Message", "Unknown"); if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0") { paySuccess(); } else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0") { Response.Redirect(Pages.CLIENT_INDEX); } else if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "99") { Response.Redirect(Pages.CLIENT_INDEX); } else { vpc_Result.Text = "<center><h1>Đặt hàng không thành công</h1> ! <br/>Có lỗi trong quá trình thanh toán. vui lòng thử lại <a href='checkout.aspx'>tại đây</a></center>"; } Session["isPrePay"] = null; Session["isFirstPay"] = null; Session["AcceptSlipNo"] = null; }