예제 #1
0
        public JsonResult NotifyUrl()
        {
            string param = ""; //Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1);

            param = "partner_code=" + Request["partner_code"] +
                    "&access_key=" + Request["access_key"] +
                    "&amount=" + Request["amount"] +
                    "&order_id=" + Request["order_id"] +
                    "&order_info=" + Request["order_info"] +
                    "&order_type=" + Request["order_type"] +
                    "&transaction_id=" + Request["transaction_id"] +
                    "&mesage=" + Request["mesage"] +
                    "&response_time=" + Request["response_time"] +
                    "&status_code=" + Request["status_code"];
            param = Server.UrlDecode(param);
            MoMoSecurity crypto      = new MoMoSecurity();
            string       serectkey   = ConfigurationManager.AppSettings["serectkey"].ToString();
            string       status_code = Request["status_code"].ToString();

            if ((status_code != "0"))
            {
            }
            else
            {
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ActionResult ReturnUrl()
        {
            string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1);

            param = Server.UrlDecode(param);


            MoMoSecurity crypto = new MoMoSecurity();

            string secretKey = MomoConfig.SecretKey;

            string signature = crypto.signSHA256(param, secretKey);

            if (signature != Request["Signature"].ToString())
            {
                ViewBag.message = "Invalid Information";
                return(View());
            }

            if (!Request.QueryString["errorCode"].Equals("0"))
            {
                ViewBag.message = "Payment failed";
            }
            else
            {
                ViewBag.message = "Payment Success";
            }

            //Add Invoice

            //
            return(View());
        }
예제 #3
0
        public ActionResult Index()
        {
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMOREA420200703";
            string accessKey   = "QlGE6S9AlZNwni3M";
            string serectkey   = "JHt0d6lBW8pg1TNGFDLxTxG3MDTUMvbj";
            string orderInfo   = "Thanh toán MoMo";
            string returnUrl   = "https://momo.vn/return";
            string notifyurl   = "https://momo.vn/notify";

            string amount    = tongTien().ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            log.Debug("rawHash = " + rawHash);

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            JObject jmessage = JObject.Parse(responseFromMomo);

            System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString());

            return(RedirectToAction("Index", "Cart"));
        }
예제 #4
0
        public void NotifyUrl()
        {
            string param = "partner_code=" + Request.Query["partner_code"] +
                           "&access_key=" + Request.Query["access_key"] +
                           "&amount=" + Request.Query["amount"] +
                           "&order_id=" + Request.Query["order_id"] +
                           "&order_info=" + Request.Query["order_info"] +
                           "&order_type=" + Request.Query["order_type"] +
                           "&transaction_id=" + Request.Query["transaction_id"] +
                           "&message=" + Request.Query["message"] +
                           "&response_time=" + Request.Query["response_time"] +
                           "&status_code=" + Request.Query["status_code"];

            param = WebUtility.UrlDecode(param);
            MoMoSecurity crypto      = new MoMoSecurity();
            string       serectKey   = SERECT_KEY;
            string       status_code = Request.Query["status_code"].ToString();

            if ((status_code != "0"))
            {
                //Thất bại - Cập nhật trạng thái đơn hàng
            }
            else
            {
                //Thành công - Cập nhật trạng thái đơn hàng
            }
            //return new Newtonsoft.Json.JsonSerializerSettings();
        }
예제 #5
0
        public string SignatureMomo(string requestId, string amount, string orderId, string orderInfo, string extraData = "")
        {
            string rawHash = string.Format(
                "partnerCode={0}" +
                "&accessKey={1}" +
                "&requestId={2}" +
                "&amount={3}" +
                "&orderId={4}" +
                "&orderInfo={5}" +
                "&returnUrl={6}" +
                "&notifyUrl={7}" +
                "&extraData={8}",
                DefinePaymentMomo.PartnerCode,              //0 partnerCode
                DefinePaymentMomo.AccessKey,                //1 accessKey
                requestId,                                  //2 requestId
                amount,                                     //3 amount
                orderId,                                    //4 orderId
                orderInfo,                                  //5 orderInfo
                DefinePaymentMomo.ReturnUrl,                //6 returnUrl
                DefinePaymentMomo.NotifyUrl,                //7 notifyUrl
                extraData                                   //8 extraData
                );
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey);

            return(signature);
        }
예제 #6
0
        public ActionResult PayMomo(ViewPayMomo momo)
        {
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMO828G20201211";
            string accessKey   = "I0M0E6bt9OC7nBfz";
            string serectKey   = "Bz4LGbbJ9AHHFRRSb92zL18B1Vq5XbfA";
            string orderInfo   = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string returnUrl   = "/Payments/Index";
            string notifyUrl   = "/Payments/Index";

            string amount    = momo.Amount;
            string orderId   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            // before sign HMAC SHA256 signature
            string rawHash =
                "partnerCode=" + partnerCode +
                "&accessKey=" + accessKey +
                "&requestId=" + requestId +
                "&amount=" + amount +
                "&orderId=" + orderId +
                "&orderInfo=" + orderInfo +
                "&returnUrl=" + returnUrl +
                "&notifyUrl=" + notifyUrl +
                "&extraData=" + extraData;
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectKey);
            JObject      message   = new JObject()
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderId },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyUrl },
                { "requestType", "captureMoMoWallet" },
                { "extraData", extraData },
                { "signature", signature }
            };
            string url =
                "partnerCode=" + partnerCode +
                "&accessKey=" + accessKey +
                "&requestId=" + requestId +
                "&amount=" + amount +
                "&orderId=" + orderId +
                "&signature=" + signature +
                "&orderInfo=" + orderInfo +
                "&returnUrl=" + returnUrl +
                "&notifyUrl=" + notifyUrl +
                "&extraData=" + extraData +
                "&requestType=" + "captureMoMoWallet";
            string  responesFromMoMo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responesFromMoMo);
            string  payUrl           = jmessage.ToString();

            return(Redirect("https://test-payment.momo.vn/gw_payment/payment/qr?" + url));
        }
예제 #7
0
        public IActionResult MoMoCallback(string partnerCode, string accessKey, string orderId, string localMessage, string message, string transId,
                                          string orderInfo, string amount, string errorCode, string responseTime, string requestId, string extraData, string payType, string orderType,
                                          string signature)
        {
            string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderId + "&orderInfo=" + orderInfo +
                             "&orderType=" + orderType + "&transId=" + transId + "&message=" + message + "&localMessage=" + localMessage + "&responseTime=" + responseTime + "&errorCode=" + errorCode +
                             "&payType=" + payType + "&extraData=" + extraData;

            string       serectkey = "XcCyHTwk2JXwXZQkDY3but2On0HKjqyQ";
            MoMoSecurity crypto    = new MoMoSecurity();
            //sign signature SHA256
            string partnerSignature = crypto.signSHA256(rawHash, serectkey);

            if (signature.Equals(partnerSignature))
            {
                // Lưu dữ liệu lại nè:
                Recharge recharge = new Recharge();
                recharge.User       = this.GetCurrentUser();
                recharge.Amount     = Int32.Parse(amount);
                recharge.Type       = "MoMo";
                recharge.Money      = recharge.Amount / 1000;
                recharge.User.Gold += recharge.Money;
                _context.Add(recharge);
                _context.SaveChanges();

                // Di chuyển sang lịch sử giao dịch nha
                return(RedirectToAction(nameof(History)));
            }
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #8
0
        /// <summary>
        ///     Kiem tra trang thai giao dich offline
        /// </summary>
        /// <param name="partnerCode">Ma doi tac do momo cung cap</param>
        /// <param name="merchantRefId">Ma don hang luu tren he thong momo</param>
        /// <param name="publicKey">Public key do momo cung cap</param>
        /// <param name="requestId">Request id</param>
        /// <param name="description"></param>
        /// <param name="test">Test=true la moi truong test, test=false la moi truong production. Mac dinh la false</param>
        /// <returns></returns>
        public static string QueryTransactionStatusPayOffline(string partnerCode,
                                                              string merchantRefId,
                                                              string publicKey,
                                                              string requestId,
                                                              string description,
                                                              bool test = false)
        {
            string endpoint = test
                                      ? "https://test-payment.momo.vn/pay/query-status"
                                      : "https://payment.momo.vn/pay/query-status";
            string version = CommonConstant.MOMO_VERSION;

            publicKey = RsaKeyConverter.PemToXml(RsaKeyConverter.FormatPem(publicKey,
                                                                           "PUBLIC KEY"));

            //get hash
            MoMoSecurity momoCrypto = new MoMoSecurity();
            string       hash       = momoCrypto.buildQueryHash(partnerCode,
                                                                merchantRefId,
                                                                requestId,
                                                                publicKey);

            //request to MoMo
            string jsonRequest = "{\"partnerCode\":\"" + partnerCode + "\",\"partnerRefId\":\"" + merchantRefId + "\",\"description\":\"" + description + "\",\"version\":" + version + ",\"hash\":\"" + hash + "\"}";

            //response from MoMo
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint,
                                                                        jsonRequest);

            Logger.Debug(responseFromMomo);

            return(responseFromMomo);
        }
예제 #9
0
        public ActionResult ReturnUrl()
        {
            string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1);

            param = Server.UrlDecode(param);
            string       serctkey  = ConfigurationManager.AppSettings["serctkey"].ToString();
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(param, serctkey);

            if (signature != Request["signature"].ToString())
            {
                ViewBag.message = " Thông tin Request không hợp lệ";
                return(View());
            }
            if (!Request.QueryString["errorCode"].Equals("0"))
            {
                ViewBag.message = "Thanh toán thất bại";
            }
            else
            {
                ViewBag.message = "Thanh toán thành công";
                Session["Cart"] = new List <GioHang>();
            }
            return(View());
        }
예제 #10
0
        public ActionResult PayMoMo(int?id)
        {
            var coo  = new FunctionsController();
            var idus = coo.CookieID();

            Pakage pakage = db.Pakages.Find(id);

            var money = pakage.pakage_coin * 1000;

            //request params need to request to MoMo system
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMO5RGX20191128";
            string accessKey   = "M8brj9K6E22vXoDB";
            string serectkey   = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4";
            string orderInfo   = "Nạp " + pakage.pakage_coin + " vào tài khoản " + idus.user_email;
            string returnUrl   = "https://localhost:44327/Pays/ReturnUrl";
            string notifyurl   = "https://localhost:44327/Pays/ReturnUrl";

            string amount    = money.ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectkey);
            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            Session["idpake"] = id;

            return(Redirect(jmessage.GetValue("payUrl").ToString()));
        }
예제 #11
0
        public string SignatureMomoSendResponse(string requestId, string orderId, string errorCode,
                                                string message, string responseTime, string extraData)
        {
            string rawHash = string.Format(
                "partnerCode={0}" +
                "&accessKey={1}" +
                "&requestId={2}" +
                "&orderId={3}" +
                "&errorCode={4}" +
                "&message={5}" +
                "&responseTime={6}" +
                "&extraData={7}",
                DefinePaymentMomo.PartnerCode,              //0 partnerCode
                DefinePaymentMomo.AccessKey,                //1 accessKey
                requestId,                                  //2 requestId
                orderId,                                    //4 orderId
                errorCode,
                message,                                    //8 extraData
                responseTime,
                extraData
                );
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey);

            return(signature);
        }
예제 #12
0
        public object SetOrderByMomo(Guid orderNo, decimal money)
        {
            var orderData = _unitOfWork.Orders.Get().SingleOrDefault(x => x.OrderNo == orderNo);


            var jsonRequesy = new JsonRequest()
            {
                ApiEndPoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor",
                PartnerCode = "MOMOVYHR20200208",
                AccessKey   = "dIn9mqdLZF6htCr5",
                RequestId   = Guid.NewGuid().ToString(),
                Amount      = ((int)money * 1000).ToString(),
                OrderId     = orderNo.ToString(),
                OrderInfo   = "Thanh toán khách sạn",
                ReturnUrl   = "https://localhost:44338/",
                NotifyUrl   = "https://localhost:5001/api/",
                RequestType = "captureMoMoWallet",
                SecretKey   = "iI0Fg6R7nJUzpda4qbsYd4iFQHE9HDny",
                Signature   = "",
                ExtraData   = ""
            };

            string rawHash = "partnerCode=" +
                             jsonRequesy.PartnerCode + "&accessKey=" +
                             jsonRequesy.AccessKey + "&requestId=" +
                             jsonRequesy.RequestId + "&amount=" +
                             jsonRequesy.Amount + "&orderId=" +
                             jsonRequesy.OrderId + "&orderInfo=" +
                             jsonRequesy.OrderInfo + "&returnUrl=" +
                             jsonRequesy.ReturnUrl + "&notifyUrl=" +
                             jsonRequesy.NotifyUrl + "&extraData=" +
                             jsonRequesy.ExtraData;



            string signature = new MoMoSecurity().signSHA256(rawHash, jsonRequesy.SecretKey);


            JObject message = new JObject
            {
                { "partnerCode", jsonRequesy.PartnerCode },
                { "accessKey", jsonRequesy.AccessKey },
                { "requestId", jsonRequesy.RequestId },
                { "amount", jsonRequesy.Amount },
                { "orderId", jsonRequesy.OrderId },
                { "orderInfo", jsonRequesy.OrderInfo },
                { "returnUrl", jsonRequesy.ReturnUrl },
                { "notifyUrl", jsonRequesy.NotifyUrl },
                { "extraData", jsonRequesy.ExtraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            string  responseFromMomo = PaymentRequest.sendPaymentRequest(jsonRequesy.ApiEndPoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(jmessage.GetValue("payUrl").ToString());
        }
예제 #13
0
        protected string ThanhToanMoMo(string maDonHang, string tongCong)
        {
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMOHDRK20200430";
            string accessKey   = "68tVdaHzCcvtfzwH";
            string serectkey   = "8AWejATXBF96XL3CqeICtqiiKwheEUAv";
            string orderInfo   = "OrderBook";
            string returnUrl   = "https://webbansach17dtha3.cf//Cart/Success";
            string notifyurl   = "https://webbansach17dtha3.cf/";

            string amount    = tongCong;
            string orderid   = maDonHang;
            string requestId = maDonHang;
            string extraData = "";

            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            log.Debug("rawHash = " + rawHash);
            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());

            return(jmessage.GetValue("payUrl").ToString());
        }
예제 #14
0
        public ActionResult PayByMomo(string totalMoney)
        {
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMOBKUN20180529";
            string accessKey   = "klm05TvNBzhg7h7j";
            string serectkey   = "at67qH6mk8w5Y1nAyMoYKMWACiEi2bsa";
            string orderInfo   = "Thanh toán đơn hàng";
            string returnUrl   = "http://localhost:3000/order_success_page";
            string notifyurl   = "https://momo.vn/notify";
            string amount      = totalMoney;
            string orderid     = Guid.NewGuid().ToString();
            string requestId   = Guid.NewGuid().ToString();
            string extraData   = "merchantName=Payment";


            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;



            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);


            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jMessage         = JObject.Parse(responseFromMomo);

            return(Ok(jMessage["payUrl"].ToString()));
        }
예제 #15
0
        //-------------------------------------------------------------------------------------------------------------------------------------------
        public ActionResult PaymentWithMoMo(User user)
        {
            var cart = (List <CartItem>)Session[CartSession];


            string endpoint    = ConfigurationManager.AppSettings["endpoint"].ToString();
            string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString();
            string accessKey   = ConfigurationManager.AppSettings["accessKey"].ToString();
            string serectkey   = ConfigurationManager.AppSettings["serectkey"].ToString();
            string orderInfo   = ConfigurationManager.AppSettings["orderInfo"].ToString();
            string returnUrl   = ConfigurationManager.AppSettings["returnUrl"].ToString();
            string notifyurl   = ConfigurationManager.AppSettings["notifyurl"].ToString();

            string amount    = cart.Sum(n => n.Product.Price).ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;
            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string  signature = crypto.signSHA256(rawHash, serectkey);
            JObject message   = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(Redirect(jmessage.GetValue("payUrl").ToString()));
        }
예제 #16
0
        private static string TransactionOnline(Dictionary <string, string> obj,
                                                string secretKey,
                                                bool test,
                                                string requestType = "")
        {
            string endpoint = test
                                      ? "https://test-payment.momo.vn/gw_payment/transactionProcessor"
                                      : "https://payment.momo.vn/gw_payment/transactionProcessor";

            StringBuilder builder   = new StringBuilder();
            string        condition = string.Empty;

            foreach (var item in obj)
            {
                builder.AppendFormat("{0}{1}={2}",
                                     condition,
                                     item.Key,
                                     item.Value);
                condition = "&";
            }

            var rawHash = builder.ToString();

            var crypto = new MoMoSecurity();
            //sign signature SHA256
            var signature = crypto.signSHA256(rawHash,
                                              secretKey);

            //build body json request
            var message = new JObject();

            foreach (var item in obj)
            {
                message.Add(item.Key,
                            item.Value);
            }

            if (!string.IsNullOrEmpty(requestType))
            {
                message.Add("requestType",
                            requestType);
            }

            message.Add("signature",
                        signature);
            Logger.Debug("Json request to MoMo: " + message);
            var responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint,
                                                                     message.ToString());

            return(responseFromMomo);
        }
예제 #17
0
        /// <summary>
        ///     Thanh toan momo offline bang cach quet ma vach tren app momo
        /// </summary>
        /// <param name="partnerCode">Ma doi tac do momo cung cap</param>
        /// <param name="merchantRefId">Ma don hang luu tren he thong momo</param>
        /// <param name="amount">So tien can thanh toan</param>
        /// <param name="paymentCode">Ma so quet tren app momo cua khach hang</param>
        /// <param name="storeId">Store id cua hang</param>
        /// <param name="storeName">Store name cua hang</param>
        /// <param name="description">Thong tin don hang</param>
        /// <param name="publicKey">Public key do momo cung cap</param>
        /// <param name="test">Test=true la moi truong test, test=false la moi truong production. Mac dinh la false</param>
        /// <returns></returns>
        public static string SendPayOffline(string partnerCode,
                                            string merchantRefId,
                                            string amount,
                                            string paymentCode,
                                            string storeId,
                                            string storeName,
                                            string description,
                                            string publicKey,
                                            bool test = false)
        {
            try
            {
                var endpoint = test
                                       ? "https://test-payment.momo.vn/pay/pos"
                                       : "https://payment.momo.vn/pay/pos";
                var version = CommonConstant.MOMO_VERSION;

                publicKey = RsaKeyConverter.PemToXml(RsaKeyConverter.FormatPem(publicKey,
                                                                               "PUBLIC KEY"));

                //get hash
                var momoCrypto = new MoMoSecurity();
                var hash       = momoCrypto.getHash(partnerCode,
                                                    merchantRefId,
                                                    amount,
                                                    paymentCode,
                                                    storeId,
                                                    storeName,
                                                    publicKey);

                //request to MoMo
                var jsonRequest = "{\"partnerCode\":\"" + partnerCode + "\",\"partnerRefId\":\"" + merchantRefId + "\",\"description\":\"" + description + "\",\"amount\":" + amount + ",\"version\":" + version + ",\"hash\":\"" + hash + "\"}";
                Logger.Debug(jsonRequest);

                //response from MoMo
                var responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint,
                                                                         jsonRequest);
                Logger.Debug(responseFromMomo);

                return(responseFromMomo);
            }
            catch (Exception exception)
            {
                Logger.Debug(exception);
            }

            return(string.Empty);
        }
예제 #18
0
        public ActionResult ThanhToan()
        {
            List <GioHang> gioHang     = Session["Cart"] as List <GioHang>;
            string         endpoint    = ConfigurationManager.AppSettings["endpoint"].ToString();
            string         partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString();
            string         accessKey   = ConfigurationManager.AppSettings["accessKey"].ToString();
            string         serectkey   = ConfigurationManager.AppSettings["serectkey"].ToString();
            string         orderInfo   = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string         returnUrl   = ConfigurationManager.AppSettings["returnUrl"].ToString();
            string         notifyurl   = ConfigurationManager.AppSettings["notifyurl"].ToString();

            string amount    = gioHang.Sum(n => n._ThanhTien).ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //before sign HMAC SHA256 signature abc
            string rawHash = "partnerCode" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo" +
                             orderInfo + "&returnUrl" +
                             returnUrl + "&notifyUrl" +
                             notifyurl + "&extraData" +
                             extraData;
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectkey);
            JObject      message   = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", partnerCode },
                { "returnUrl", partnerCode },
                { "notifyUrl", notifyurl },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(Redirect(jmessage.GetValue("payUrl").ToString()));
        }
예제 #19
0
        public string payment()
        {
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = PARTNER_CODE;
            string accessKey   = ACCESS_KEY;
            string serectKey   = SERECT_KEY;
            string orderInfo   = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string returnUrl   = RETURN_URL;
            string notifyUrl   = NOTIFY_URL;

            string amount    = "10000";
            string orderId   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";
            string rawHash   = "partnerCode=" +
                               partnerCode + "&accessKey=" +
                               accessKey + "&requestId=" +
                               requestId + "&amount=" +
                               amount + "&orderId=" +
                               orderId + "&orderInfo=" +
                               orderInfo + "&returnUrl=" +
                               returnUrl + "&notifyUrl=" +
                               notifyUrl + "&extraData=" +
                               extraData;

            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectKey);

            JObject message = new JObject {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderId },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyUrl },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(jmessage.GetValue("payUrl").ToString());
        }
예제 #20
0
        public JsonResult NotifyUrl()
        {
            string param = ""; // Request.Form.ToString().Substring(0, Request.Form.ToString().IndexOf("signature") -1);

            param = "partner_Code=" + Request["partner_code"] +
                    "&access_key=" + Request["access_key"] +
                    "&amount=" + Request["access_key"] +
                    "&order_id=" + Request["order_id"] +
                    "&order_info=" + Request["order_info"] +
                    "&order_type=" + Request["order_type"] +
                    "&transaction_id=" + Request["transaction_id"] +
                    "&message=" + Request["message"] +
                    "&response_time=" + Request["response_time"] +
                    "&status_code=" + Request["status_code"];
            param = Server.UrlDecode(param);
            MoMoSecurity crypto    = new MoMoSecurity();
            string       serectkey = ConfigurationManager.AppSettings["serectkey"].ToString();
            string       signature = crypto.signSHA256(param, serectkey);

            //Không được phép cập nhật trạng thái đơn khi trạng đơn trong databasse khác trạng đang chờ thanh toán
            //Trạng thái đơn kích nút thanh toán - Đang chờ thanh toán(-1)
            //Trạng thái giao dịch thành công(1)
            //Trạng thái giao dịch thất bại(0)
            if (signature != Request["signature"].ToString())
            {
                //Kiểm tra đơn hàng của các bạn trong database có khác trạng thái đang chờ thanh toán hay không
                //Nếu mà bạn đã cập nhật trạng thái đơn hàng về (1) hoặc 0 rồi thì không cần phải cập nhật nữa
                //Nếu trạng thái đơn hàng của các bạn đang là chờ thanh toán thì các ạn cập nhật trạng thái = 0 là thất bại ở đây

                //Khi nào thì mới cập nhật trạng thái đơn hàng?
            }
            string status_code = Request["status_code"].ToString();

            if ((status_code != "0"))
            {
                //Thất bại - Cập nhật trạng thái đơn hàng
            }
            else
            {
                //Thành công - Cập nhật trạng thái đơn hàng
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
예제 #21
0
        public void ReturnUrl()
        {
            string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1);

            param = WebUtility.UrlDecode(param);
            MoMoSecurity crypto    = new MoMoSecurity();
            string       serectKey = SERECT_KEY;
            string       signature = crypto.signSHA256(param, serectKey);

            if (signature != Request.Query["signature"].ToString())
            {
                Console.WriteLine("Thông tin Request không hợp lệ");
            }
            if (!Request.Query["errorCode"].Equals("0"))
            {
                Console.WriteLine("Thanh toán thất bại");
            }
            else
            {
                Console.WriteLine("Thanh toán thành công");
            }
        }
예제 #22
0
        public JsonResult NotifyUrl()
        {
            string param = "partner_code=" + Request["partner_code"] +
                           "&access_keys=" + Request["access_keys"] +
                           "&amount=" + Request["amount"] +
                           "&order_id=" + Request["order_id"] +
                           "&order_info=" + Request["order_info"] +
                           "&order_type=" + Request["order_type"] +
                           "&transaction_id=" + Request["transaction_id"] +
                           "&message=" + Request["message"] +
                           "&response_time=" + Request["response_time"] +
                           "&status_code=" + Request["status_code"];

            param = Server.UrlDecode(param);
            MoMoSecurity scryto     = new MoMoSecurity();
            string       secretKey  = MomoConfig.SecretKey;
            string       signature  = scryto.signSHA256(param, secretKey);
            string       statusCode = Request["status_code"].ToString();

            /*
             * if (signature != Request["Signature"].ToString())
             * {
             *  ViewBag.message = "Invalid Information";
             *  return ;
             * }
             */

            if (statusCode != "0")
            {
                //Failed
            }
            else
            {
                //Success
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
예제 #23
0
        public string SignatureMomoRequest(string requestId, string amount, string orderId, string orderInfo, string orderType, string transId,
                                           string message, string localMessage, string responseTime, string errorCode, string payType, string extraData)
        {
            string rawHash = string.Format(
                "partnerCode={0}" +
                "&accessKey={1}" +
                "&requestId={2}" +
                "&amount={3}" +
                "&orderId={4}" +
                "&orderInfo={5}" +
                "&orderType={6}" +
                "&transId={7}" +
                "&message={8}" +
                "&localMessage={9}" +
                "&responseTime={10}" +
                "&errorCode={11}" +
                "&payType={12}" +
                "&extraData={13}",
                DefinePaymentMomo.PartnerCode,             //0 partnerCode
                DefinePaymentMomo.AccessKey,               //1 accessKey
                requestId,                                 //2 requestId
                amount,                                    //3 amount
                orderId,                                   //4 orderId
                orderInfo,                                 //5 orderInfo
                orderType,                                 //6 returnUrl
                transId,                                   //7 notifyUrl
                message,                                   //8 extraData
                localMessage,
                responseTime,
                errorCode,
                payType,
                extraData
                );
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey);

            return(signature);
        }
예제 #24
0
        public string SignatureCheckResponseMomo(string requestId, string orderId, string message, string localMessage, string payUrl, string errorCode, string requestType)
        {
            string rawHash = string.Format(
                "requestId={0}" +
                "&orderId={1}" +
                "&message={2}" +
                "&localMessage={3}" +
                "&payUrl={4}" +
                "&errorCode={5}" +
                "&requestType={6}",
                requestId,                            //2 requestId
                orderId,                              //3 amount
                message,                              //4 orderId
                localMessage,                         //5 orderlocalMessageInfo
                payUrl,                               //6 payUrl
                errorCode,                            //7 errorCode
                requestType                           //8 requestType
                );
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, DefinePaymentMomo.SecretKey);

            return(signature);
        }
예제 #25
0
        public ActionResult Index(Morder order)
        {
            Random rand          = new Random((int)DateTime.Now.Ticks);
            int    numIterations = 0;

            numIterations = rand.Next(1, 100000);
            DateTime time = DateTime.Now;

            string orderCode      = numIterations + "" + time;
            string sumOrder       = Request["sumOrder"];
            string payment_method = Request["option_payment"];

            // Neu Ship COde
            if (payment_method.Equals("COD"))
            {
                // cap nhat thong tin sau khi dat hang thanh cong

                saveOrder(order, "COD", 2, orderCode);
                var cart = Session[SessionCart];
                var list = new List <Cart_item>();
                ViewBag.cart           = (List <Cart_item>)cart;
                Session["SessionCart"] = null;
                var listProductOrder = db.Orderdetails.Where(m => m.orderid == order.ID);
                return(View("payment"));
            }
            //Neu Thanh toan MOMO
            else if (payment_method.Equals("MOMO"))
            {
                //request params need to request to MoMo system
                string endpoint    = momoInfo.endpoint;
                string partnerCode = momoInfo.partnerCode;
                string accessKey   = momoInfo.accessKey;
                string serectkey   = momoInfo.serectkey;
                string orderInfo   = momoInfo.orderInfo;
                string returnUrl   = momoInfo.returnUrl;
                string notifyurl   = momoInfo.notifyurl;

                string amount    = sumOrder;
                string orderid   = Guid.NewGuid().ToString();
                string requestId = Guid.NewGuid().ToString();
                string extraData = "";

                //Before sign HMAC SHA256 signature
                string rawHash = "partnerCode=" +
                                 partnerCode + "&accessKey=" +
                                 accessKey + "&requestId=" +
                                 requestId + "&amount=" +
                                 amount + "&orderId=" +
                                 orderid + "&orderInfo=" +
                                 orderInfo + "&returnUrl=" +
                                 returnUrl + "&notifyUrl=" +
                                 notifyurl + "&extraData=" +
                                 extraData;

                log.Debug("rawHash = " + rawHash);

                MoMoSecurity crypto = new MoMoSecurity();
                //sign signature SHA256
                string signature = crypto.signSHA256(rawHash, serectkey);
                log.Debug("Signature = " + signature);

                //build body json request
                JObject message = new JObject
                {
                    { "partnerCode", partnerCode },
                    { "accessKey", accessKey },
                    { "requestId", requestId },
                    { "amount", amount },
                    { "orderId", orderid },
                    { "orderInfo", orderInfo },
                    { "returnUrl", returnUrl },
                    { "notifyUrl", notifyurl },
                    { "extraData", extraData },
                    { "requestType", "captureMoMoWallet" },
                    { "signature", signature }
                };
                log.Debug("Json request to MoMo: " + message.ToString());
                string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
                JObject jmessage         = JObject.Parse(responseFromMomo);

                saveOrder(order, "Cổng thanh toán MOMO", 2, orderid);
                return(Redirect(jmessage.GetValue("payUrl").ToString()));
            }
            //Neu Thanh toan Ngan Luong
            else if (payment_method.Equals("NL"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "Cổng thanh toán Ngân Lượng", 2, orderCode);
                    // chuyen sang trang ngan luong
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            //Neu Thanh Toán ATM online
            else if (payment_method.Equals("ATM_ONLINE"))
            {
                string      str_bankcode = Request["bankcode"];
                RequestInfo info         = new RequestInfo();
                info.Merchant_id       = nganluongInfo.Merchant_id;
                info.Merchant_password = nganluongInfo.Merchant_password;
                info.Receiver_email    = nganluongInfo.Receiver_email;
                info.cur_code          = "vnd";
                info.bank_code         = str_bankcode;
                info.Order_code        = orderCode;
                info.Total_amount      = sumOrder;
                info.fee_shipping      = "0";
                info.Discount_amount   = "0";
                info.order_description = "Thanh toán ngân lượng cho đơn hàng";
                info.return_url        = nganluongInfo.return_url;
                info.cancel_url        = nganluongInfo.cancel_url;
                info.Buyer_fullname    = order.deliveryname;
                info.Buyer_email       = order.deliveryemail;
                info.Buyer_mobile      = order.deliveryphone;
                APICheckoutV3 objNLChecout = new APICheckoutV3();
                ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, payment_method);
                // neu khong gap loi gi
                if (result.Error_code == "00")
                {
                    saveOrder(order, "ATM Online qua ngân lượng", 2, orderCode);
                    return(Redirect(result.Checkout_url));
                }
                else
                {
                    ViewBag.errorPaymentOnline = result.Description;
                    return(View("payment"));
                }
            }
            return(View("payment"));
        }
예제 #26
0
        public ActionResult DatHang()
        {
            //Kiểm tra đăng nhập
            if ((Session["TaiKhoan"] == null) || (Session["TaiKhoan"].ToString() == ""))
            {
                return(RedirectToAction("DangNhap", "NguoiDung"));
            }
            //Kiểm tra giỏ hàng
            if (Session["GioHang"] == null)
            {
                RedirectToAction("Index", "Home");
            }
            //thêm đơn hàng
            DonHang        dh = new DonHang();
            KhachHang      kh = (KhachHang)Session["TaiKhoan"];
            List <GioHang> gh = LayGioHang();

            dh.MaKH              = kh.MaKH;
            dh.DaThanhToan       = Convert.ToInt32(TongTien());
            dh.TinhTrangGiaoHang = 0;
            dh.NgayDat           = DateTime.Now;
            dh.NgayGiao          = DateTime.Now;
            db.DonHangs.Add(dh);
            db.SaveChanges();
            //Thêm chi tiết đơn hàng
            foreach (var item in gh)
            {
                ChiTietDonHang ctdh = new ChiTietDonHang();
                ctdh.MaDonHang = dh.MaDonHang;
                ctdh.MaGiay    = item._MaGiay;
                ctdh.SoLuong   = item._SoLuong;
                ctdh.DonGia    = item._DonGia.ToString();


                Giay giay = db.Giays.SingleOrDefault(n => n.MaGiay == item._MaGiay);
                giay.SoLuongTon -= item._SoLuong;
                db.ChiTietDonHangs.Add(ctdh);
                db.SaveChanges();
                Session["GioHang"] = null;
            }

            //momopay
            string endpoint    = ConfigurationManager.AppSettings["endpoint"].ToString();
            string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString();
            string accessKey   = ConfigurationManager.AppSettings["accessKey"].ToString();
            string serectkey   = ConfigurationManager.AppSettings["serectkey"].ToString();
            string orderInfo   = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string returnUrl   = ConfigurationManager.AppSettings["returnUrl"].ToString();
            string notifyurl   = ConfigurationManager.AppSettings["notifyurl"].ToString();

            string amount    = gh.Sum(n => n._ThanhTien).ToString();
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;
            MoMoSecurity crypto    = new MoMoSecurity();
            string       signature = crypto.signSHA256(rawHash, serectkey);
            JObject      message   = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(Redirect(jmessage.GetValue("payUrl").ToString()));
            //mômopay
        }
예제 #27
0
        public ActionResult Payment(string shipName, string address, string mobile, string email)
        {
            var session = (UserLogin)Session[Common.CommonConstants.USER_SESSION];

            var order = new Order();

            if (session != null)
            {
                order.CustomerID  = session.UserID;
                order.CreateDate  = DateTime.Now;
                order.ShipAddress = address;
                order.ShipEmail   = email;
                order.ShipMobile  = mobile;
                order.ShipName    = shipName;
                order.Status      = false;
            }
            else
            {
                order.CreateDate  = DateTime.Now;
                order.ShipAddress = address;
                order.ShipEmail   = email;
                order.ShipMobile  = mobile;
                order.ShipName    = shipName;
                order.Status      = false;
            }

            try
            {
                var id = new OrderDao().Insert(order);

                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new OrderDetailDao();
                var     orderdao  = new OrderDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderr      = new Order();
                    var orderDetail = new OrderDetail();

                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.OrderID   = id;
                    orderDetail.Quantity  = item.Quantity;
                    total            += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                    orderDetail.Total = total;



                    detailDao.Insert(orderDetail);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/template/neworder.html"));

                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["FromEmailAddress"].ToString();

                /* new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content);
                 * new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);*/

                string endpoint    = ConfigurationManager.AppSettings["endpoint"].ToString();
                string partnerCode = ConfigurationManager.AppSettings["partnerCode"].ToString();
                string accessKey   = ConfigurationManager.AppSettings["accessKey"].ToString();
                string serectKey   = ConfigurationManager.AppSettings["serectKey"].ToString();
                string orderInfo   = "DH" + DateTime.Now.ToString("yyyyMMddHHmmss");
                string returnUrl   = ConfigurationManager.AppSettings["returnUrl"].ToString();
                string notifyUrl   = ConfigurationManager.AppSettings["notifyUrl"].ToString();

                string amount    = total.ToString();
                string orderId   = Guid.NewGuid().ToString();
                string requestId = Guid.NewGuid().ToString();
                string extraData = order.ShipName + "SP" + order.ShipMobile;

                string rawHash = "partnerCode=" +
                                 partnerCode + "&accessKey=" +
                                 accessKey + "&requestId=" +
                                 requestId + "&amount=" +
                                 amount + "&orderId=" +
                                 orderId + "&orderInfo=" +
                                 orderInfo + "&returnUrl=" +
                                 returnUrl + "&notifyUrl=" +
                                 notifyUrl + "&extraData=" +
                                 extraData;


                MoMoSecurity crypto = new MoMoSecurity();
                //sign signature SHA256
                string  signature = crypto.signSHA256(rawHash, serectKey);
                JObject message   = new JObject
                {
                    { "partnerCode", partnerCode },
                    { "accessKey", accessKey },
                    { "requestId", requestId },
                    { "amount", amount },
                    { "orderId", orderId },
                    { "orderInfo", orderInfo },
                    { "returnUrl", returnUrl },
                    { "notifyUrl", notifyUrl },
                    { "extraData", extraData },
                    { "requestType", "captureMoMoWallet" },
                    { "signature", signature }
                };

                string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

                JObject jmessage = JObject.Parse(responseFromMomo);

                return(Redirect(jmessage.GetValue("payUrl").ToString()));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
예제 #28
0
        public async Task <IActionResult> WebPaymentRequest(string orderInfo, string amount)
        {
            //request params need to request to MoMo system
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = configMomo.partnerCode;
            string accessKey   = configMomo.accessKey;
            string serectkey   = configMomo.serectkey;
            string returnUrl   = "https://momo.vn";
            string notifyurl   = "https://momo.vn";

            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            log.Debug("rawHash = " + rawHash);

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());
            //DialogResult result = MessageBox.Show(responseFromMomo, "Open in browser", MessageBoxButtons.OKCancel);
            //if (result == DialogResult.OK)
            //{
            //    //yes...
            //return Ok(System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString()));
            //}
            //else if (result == DialogResult.Cancel)
            //{
            //    //no...
            //}
            return(Ok(jmessage.GetValue("payUrl").ToString()));
        }
예제 #29
0
        public IActionResult MoMo(string Amount)
        {
            int amountInt = Int32.Parse(Amount);

            if (amountInt < 1000 || amountInt > 20000000)
            {
                return(RedirectToAction(nameof(Index)));
            }

            //request params need to request to MoMo system
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string partnerCode = "MOMO3R5720190725";
            string accessKey   = "ZarJz6vwlJUijSih";
            string serectkey   = "XcCyHTwk2JXwXZQkDY3but2On0HKjqyQ";
            string orderInfo   = "Nạp tiền nè các bạn";
            string returnUrl   = "https://localhost:44372/Payment/MomoCallback";
            string notifyurl   = "https://momo.vn/notify";

            string amount    = Amount;
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };
            string  responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());
            JObject jmessage         = JObject.Parse(responseFromMomo);

            return(Redirect(jmessage.GetValue("payUrl").ToString()));

            // return View();
        }
예제 #30
0
        private void doMomoPayment()
        {
            //request params need to request to MoMo system
            string endpoint    = "https://test-payment.momo.vn/gw_payment/transactionProcessor";
            string accessKey   = "M8brj9K6E22vXoDB";
            string partnerCode = "MOMO5RGX20191128";
            string serectkey   = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4";
            string orderInfo   = "Payment by Momo for customer";
            string returnUrl   = "https://momo.vn/return";
            string notifyurl   = "https://momo.vn/notify";

            string amount    = total.ToString();
            string orderId   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderId + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            log.Debug("rawHash = " + rawHash);

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderId },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "extraData", extraData },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            PaymentRequest pq = new PaymentRequest();
            string         responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());

            if (MessageBox.Show("Bạn có muốn thanh toán cho đơn hàng này", "Checkout", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString());
                this.Alert("Đơn hàng của bạn đang được chuẩn bị", Notice.enmType.Waiting);
                updateOrderLine();
            }
        }