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"] + "&message=" + Request["message"] + "&respone_time=" + Request["respone_time"] + "&status_code=" + Request["status_code"]; param = Server.UrlDecode(param); MomoPayment crypto = new MomoPayment(); string serectkey = "UVkryZe6tEZfWSrnKvQapJjgBzKROh9V"; string signature = crypto.signSHA256(param, serectkey); //k dc cap nhat trang thai don, khi status trong db != status WAIT if (signature != Request["signature"].ToString()) { //cap nhat that bai vi chu ky k hop le // } else { //success } return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult ReturnUrl() { string param = Request.QueryString.ToString().Substring(0, Request.QueryString.ToString().IndexOf("signature") - 1); param = Server.UrlDecode(param); MomoPayment crypto = new MomoPayment(); string serectkey = "UVkryZe6tEZfWSrnKvQapJjgBzKROh9V"; string signature = crypto.signSHA256(param, serectkey); if (signature != Request["signature"].ToString()) { ViewBag.message = "Thông tin Request không hợp lệ"; } if (Request.QueryString["errorCode"].Equals("-2") || Request.QueryString["errorCode"].Equals("0")) { ViewBag.message = "Thanh toán thành công"; } else { ViewBag.message = "Thanh toán thất bại"; } return(View()); }
public ActionResult ThanhToanMomo() { Cart cart = Session["Cart"] as Cart; //momo payment VND string endpoint = "https://test-payment.momo.vn/gw_payment/transactionProcessor"; string partnerCode = "MOMOVMY620201214"; string accessKey = "YJ3tiYJsEj7DiR8h"; string serectkey = "UVkryZe6tEZfWSrnKvQapJjgBzKROh9V"; string orderInfo = "Đơn hàng từ SHOP TMD04"; string returnUrl = "https://localhost:44354/Orders/ReturnUrl"; string notifyurl = "https://localhost:44354/Orders/NotifyUrl"; string amount = cart.Items.Sum(n => n._shopping_product.BookPrice * n._shopping_quantity).ToString(); string orderid = Guid.NewGuid().ToString(); string requestId = Guid.NewGuid().ToString(); string extraData = "payment"; //Before sign HMAC SHA256 signature string rawHash = "partnerCode=" + partnerCode + "&accessKey=" + accessKey + "&requestId=" + requestId + "&amount=" + amount + "&orderId=" + orderid + "&orderInfo=" + orderInfo + "&returnUrl=" + returnUrl + "¬ifyUrl=" + notifyurl + "&extraData=" + extraData; log.Debug("rawHash = " + rawHash); MomoPayment crypto = new MomoPayment(); //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(Redirect(jmessage.GetValue("payUrl").ToString())); }