public bool ValidateCheckout()
    {
        string transaction_info = Request.QueryString["transaction_info"].ToSafetyString();
        string order_code       = Request.QueryString["order_code"].ToSafetyString();
        string payment_id       = Request.QueryString["payment_id"].ToSafetyString();
        string payment_type     = Request.QueryString["payment_type"].ToSafetyString();
        string secure_code      = Request.QueryString["secure_code"].ToSafetyString();
        string price            = Request.QueryString["price"].ToSafetyString();
        string error_text       = Request.QueryString["error_text"].ToSafetyString();

        NL_Checkout nl           = new NL_Checkout();
        bool        isCheckoutOk = nl.verifyPaymentUrl(transaction_info, order_code, price, payment_id, payment_type, error_text, secure_code);

        // (String transaction_info, String order_code, String price, String payment_id, String payment_type, String error_text, String secure_code)
        if (isCheckoutOk && error_text == string.Empty)
        {
            isCheckoutOk = true;
            ucMessage.ShowSuccess("Xin chúc mừng, đơn hàng đã được thanh toán thanh công. Chúng tôi sẽ giao hàng trong thời gian sớm nhất. <a href='OderDetail.aspx'>xem Đơn Hàng</a>");
        }
        else
        {
            isCheckoutOk = false;
            ucMessage.ShowError("Rất tiếc, đơn hàng chưa được thanh toán thanh công. Vui lòng kiểm tra lại hoặc <a href='OderDetail.aspx'>xem Đơn Hàng</a>");
        }

        return(isCheckoutOk);
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         String      return_url       = Request["return_url"];
         String      receiver         = Request["receiver"];
         String      transaction_info = Request["transaction_info"];
         String      order_code       = Request["order_code"];
         String      price            = Request["price"];
         String      payment_id       = Request["payment_id"];
         String      payment_type     = Request["payment_type"];
         String      error_text       = Request["error_text"];
         String      secure_code      = Request["secure_code"];
         NL_Checkout checkOut         = new NL_Checkout();
         bool        rs = checkOut.verifyPaymentUrl(transaction_info, order_code, price, payment_id, payment_type, error_text, secure_code);
         if (rs)
         {
             Response.Write("Thanh toán thành công !");
         }
         else
         {
             Response.Write("Thanh toán không thành công");
         }
     }
     catch (Exception ex) {
         Response.Write(ex.ToString());
     }
 }
Ejemplo n.º 3
0
        public ActionResult verifyOrder(object sender, EventArgs e, string orderCode)
        {
            String      transaction_info = Request.QueryString["transaction_info"];
            String      order_code       = Request.QueryString["order_code"];
            String      payment_id       = Request.QueryString["payment_id"];
            String      payment_type     = Request.QueryString["payment_type"];
            String      secure_code      = Request.QueryString["secure_code"];
            String      price            = Request.QueryString["price"];
            String      error_text       = Request.QueryString["error_text"];
            NL_Checkout nl    = new NL_Checkout();
            bool        check = nl.verifyPaymentUrl(transaction_info, order_code, price, payment_id, payment_type, error_text, secure_code);

            if (check)
            {
                var _orderService = this.Service <IOrderService>();
                var order         = _orderService.FirstOrDefaultActive(p => p.OrderCode == orderCode);
                if (order != null)
                {
                    order.PaidType = (int)OrderPaidType.PaidOnline;
                    _orderService.Update(order);
                    var _userService = this.Service <IAspNetUserService>();
                    var userId       = User.Identity.GetUserId();
                    var user         = _userService.FirstOrDefaultActive(p => p.Id == userId);
                    if (user == null)
                    {
                        return(RedirectToAction("PageNotFound", "Errors"));
                    }
                    string subject = "[SSN] - Thông tin thanh toán";
                    string body    = "Hi <strong>" + user.FullName + "</strong>" +
                                     ",<br/><br/>Bạn đã thanh toán đơn đặt sân: " + order.OrderCode + " thành công" +
                                     "<br/><strong>Thông tin hóa đơn:</strong><ul> " +
                                     "<li> Tên sân: " + order.Field.Name + "</li>" +
                                     "<li> Tại địa điểm: " + order.Field.Place.Name + "</li>" +
                                     "<li> Thời gian: " + order.StartTime.ToString("HH:mm") + " - " +
                                     order.EndTime.ToString("HH:mm") + ", ngày " + order.StartTime.ToString("dd/MM/yyyy") + "</li>" +
                                     "<li> Giá tiền : " + order.Price.ToString("n0") + " đồng</li></ul>" +
                                     "<br/> Cảm ơn bạn đã sử dụng dịch vụ của SSN. Chúc bạn có những giờ phút thoải mái chơi thể thao!";
                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { order.PayerEmail }, null, null, subject, body, true);
                    var url = Url.Action("PaymentSuccessful", "Order",
                                         new { area = "", orderCode = order_code }, Request.Url.Scheme);
                    return(Redirect(url));
                }
                else
                {
                    return(RedirectToAction("PageNotFound", "Errors"));
                }
            }
            else
            {
                return(RedirectToAction("PaymentFail", "Order"));
            }
        }
Ejemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        String      return_url       = Request["return_url"];
        String      receiver         = Request["receiver"];
        String      transaction_info = Request["transaction_info"];
        String      order_code       = Request["order_code"];
        String      price            = Request["price"];
        String      payment_id       = Request["payment_id"];
        String      payment_type     = Request["payment_type"];
        String      error_text       = Request["error_text"];
        String      secure_code      = Request["secure_code"];
        NL_Checkout checkOut         = new NL_Checkout();
        bool        rs = checkOut.verifyPaymentUrl(transaction_info, order_code, price, payment_id, payment_type, error_text, secure_code);

        subtitle.InnerHtml = "Đơn hàng " + order_code.ToString() + " đã xử lý thành công<br/> Tổng cộng : <span style='color:red;' >" + price.ToString() + "</span> vnđ <br/> <small>Trình duyệt sẽ tự chuyển trong 3s nữa</small>";
        //if (rs)
        //{
        //    title.InnerHtml = "Thanh toán thành công !";
        //}
        //else
        //{
        //    title.InnerHtml = "Thanh toán không thành công !";
        //}
    }
Ejemplo n.º 5
0
        public IHttpActionResult Get(string query, string transaction_info, string order_code, string price, string payment_id, string payment_type, string error_text, string secure_code, [FromUri] double longtitude, [FromUri] double latitude, string id_shipper = null)
        {
            //Get URL from Ngan luong
            //var uri = new Uri(url);
            //var query = HttpUtility.ParseQueryString(uri.Query);
            //var transaction_info = query.Get("transaction_info");
            //var order_code = query.Get("order_code");
            //var price = query.Get("price");
            //var payment_id = query.Get("payment_id");
            //var payment_type = query.Get("payment_type");
            //var error_text = query.Get("error_text");
            //var secure_code = query.Get("secure_code");
            //var return_url = query.Get("return_url");

            //Customer from order
            var customer = _context.Orders.Select(x => x.Account);

            //Shipper from order
            var shipper = _context.Orders.Select(x => x.Account1);

            //order từ order_code
            var order_fcm = _context.Orders.Find(order_code);


            try
            {
                NL_Checkout checkOut = new NL_Checkout();
                bool        rs       = checkOut.verifyPaymentUrl(transaction_info, order_code, price, payment_id, payment_type, error_text, secure_code);
                byte[]      buffer   = Guid.NewGuid().ToByteArray();
                var         trans_id = BitConverter.ToInt64(buffer, 0).ToString();
                rs = true;
                #region rs:OK Shipper:tìm thấy
                if (rs)
                {
                    _context.Transactions.Add(new Transaction
                    {
                        id_transaction = trans_id,
                        id_order       = order_code,
                        money          = double.Parse(price),
                        created_time   = DateTime.Today
                    });
                    _context.SaveChanges();
                    try
                    {
                        var sCoord  = new GeoCoordinate(latitude, longtitude);
                        var address = _context.Accounts.AsEnumerable().Where(x => x.id_role == "1").Select(x => new ShipperVM
                        {
                            id          = x.id_account,
                            username    = x.username,
                            lat         = x.GroupAddress.Addresses.FirstOrDefault().lat,
                            @long       = x.GroupAddress.Addresses.FirstOrDefault().@long,
                            levels      = x.Levels.Select(xx => xx.point).FirstOrDefault(),
                            fcm_token   = x.fcm_token,
                            id_order    = order_code,
                            getDistance = sCoord.GetDistanceTo(new GeoCoordinate(x.GroupAddress.Addresses.FirstOrDefault().lat ?? 0, x.GroupAddress.Addresses.FirstOrDefault().@long ?? 0))
                        }).ToList().OrderBy(x => x.getDistance);

                        var list  = new List <ShipperVM>();
                        var list1 = new List <ShipperVM>();
                        var list2 = new List <ShipperVM>();
                        foreach (var item in address)
                        {
                            if (item.getDistance <= 3000)
                            {
                                list.Add(item);
                            }
                        }

                        foreach (var item in list.OrderBy(x => x.levels).Take(5))
                        {
                            list1.Add(item);
                        }
                        list1.Reverse();

                        if (list.Count == 0)
                        {
                            WebRequest ftRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                            ftRequest.Method = "post";
                            //serverKey - Key from Firebase cloud messaging server
                            ftRequest.Headers.Add(string.Format("Authorization: key={0}", "AIzaSyDN6yImcd7eWPRiN86cn1C7iecVNaF945M"));
                            //Sender Id - From firebase project setting
                            ftRequest.Headers.Add(string.Format("Sender: id={0}", "462404511537"));
                            ftRequest.ContentType = "application/json";

                            var fcm_ss = "eg8nUQs-lbQ:APA91bHPgVKmMy8d0vnpt-u0UMJPivSvU9kaGPyttY1-ZP-gcu6qkt7VuJ9MG-uDPOPCIkDxpgWJ0TfdP_axotwn-mZEcBOpkEXpn1QfD_HeueUMt-myWeS3ZATw_R11s5D2-N83Sq6U";

                            Account _customer = _context.Accounts.Find(order_fcm.id_customer);
                            fcm_ss = _context.Accounts.AsEnumerable().Where(x => x.id_role == "2" && x.id_account == _customer.id_account).Select(x => x.fcm_token).FirstOrDefault();
                            var payload2 = new
                            {
                                //to = customer.Select(x => x.fcm_token).FirstOrDefault().ToString(),
                                to                = fcm_ss,
                                priority          = "high",
                                content_available = true,
                                notification      = new
                                {
                                    body  = "Không tìm thấy Shipper gần Market!",
                                    title = "Test",
                                    badge = 1
                                },
                            };

                            string postbody2  = JsonConvert.SerializeObject(payload2).ToString();
                            Byte[] byteArray2 = Encoding.UTF8.GetBytes(postbody2);
                            ftRequest.ContentLength = byteArray2.Length;
                            using (Stream dataStream = ftRequest.GetRequestStream())
                            {
                                dataStream.Write(byteArray2, 0, byteArray2.Length);
                                using (WebResponse tResponse = ftRequest.GetResponse())
                                {
                                    using (Stream dataStreamResponse = tResponse.GetResponseStream())
                                    {
                                        if (dataStreamResponse != null)
                                        {
                                            using (StreamReader tReader = new StreamReader(dataStreamResponse))
                                            {
                                                String sResponseFromServer = tReader.ReadToEnd();
                                                //result.Response = sResponseFromServer;
                                            }
                                        }
                                    }
                                }
                            }
                            return(NotFound());
                        }


                        WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                        tRequest.Method = "post";
                        //serverKey - Key from Firebase cloud messaging server
                        tRequest.Headers.Add(string.Format("Authorization: key={0}", "AIzaSyDN6yImcd7eWPRiN86cn1C7iecVNaF945M"));
                        //Sender Id - From firebase project setting
                        tRequest.Headers.Add(string.Format("Sender: id={0}", "462404511537"));
                        tRequest.ContentType = "application/json";



                        var fcm_s = "eg8nUQs-lbQ:APA91bHPgVKmMy8d0vnpt-u0UMJPivSvU9kaGPyttY1-ZP-gcu6qkt7VuJ9MG-uDPOPCIkDxpgWJ0TfdP_axotwn-mZEcBOpkEXpn1QfD_HeueUMt-myWeS3ZATw_R11s5D2-N83Sq6U";

                        ShipperVM shipperr = list1.First();
                        fcm_s = _context.Accounts.AsEnumerable().Where(x => x.id_role == "1" && x.id_account == shipperr.id).Select(x => x.fcm_token).FirstOrDefault();

                        var payload = new
                        {
                            //Bỏ vô để test cho vui chứ chưa có FCM token nó trả ra lỗi BAD request(400) từ firebase server
                            to                = "eg8nUQs-lbQ:APA91bHPgVKmMy8d0vnpt-u0UMJPivSvU9kaGPyttY1-ZP-gcu6qkt7VuJ9MG-uDPOPCIkDxpgWJ0TfdP_axotwn-mZEcBOpkEXpn1QfD_HeueUMt-myWeS3ZATw_R11s5D2-N83Sq6U",
                            priority          = "high",
                            content_available = true,
                            notification      = new
                            {
                                body  = "Bạn có một đơn hàng!",
                                title = "Test",
                                badge = 1
                            },
                        };

                        string postbody  = JsonConvert.SerializeObject(payload).ToString();
                        Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
                        tRequest.ContentLength = byteArray.Length;
                        using (Stream dataStream = tRequest.GetRequestStream())
                        {
                            dataStream.Write(byteArray, 0, byteArray.Length);
                            using (WebResponse tResponse = tRequest.GetResponse())
                            {
                                using (Stream dataStreamResponse = tResponse.GetResponseStream())
                                {
                                    if (dataStreamResponse != null)
                                    {
                                        using (StreamReader tReader = new StreamReader(dataStreamResponse))
                                        {
                                            String sResponseFromServer = tReader.ReadToEnd();
                                            //result.Response = sResponseFromServer;
                                        }
                                    }
                                }
                            }
                        }

                        if (list1.Count > 0)
                        {
                            order_fcm.id_shipper = list1.First().id;
                            _context.SaveChanges();
                            return(Ok(list1));
                        }
                        #endregion

                        #region rs:OK Shipper: không tìm thấy

                        return(NotFound());
                    }
                    catch (Exception ex)
                    {
                        return(InternalServerError(ex));
                    }
                }

                #endregion

                #region rs:không thành công
                else
                {
                    WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                    tRequest.Method = "post";
                    //serverKey - Key from Firebase cloud messaging server
                    tRequest.Headers.Add(string.Format("Authorization: key={0}", "AIzaSyDN6yImcd7eWPRiN86cn1C7iecVNaF945M"));
                    //Sender Id - From firebase project setting
                    tRequest.Headers.Add(string.Format("Sender: id={0}", "462404511537"));
                    tRequest.ContentType = "application/json";

                    var fcm_ss = "eg8nUQs-lbQ:APA91bHPgVKmMy8d0vnpt-u0UMJPivSvU9kaGPyttY1-ZP-gcu6qkt7VuJ9MG-uDPOPCIkDxpgWJ0TfdP_axotwn-mZEcBOpkEXpn1QfD_HeueUMt-myWeS3ZATw_R11s5D2-N83Sq6U";

                    Account _customer = _context.Accounts.FirstOrDefault(x => x.id_account == order_fcm.id_customer);
                    fcm_ss = _context.Accounts.AsEnumerable().Where(x => x.id_role == "2" && x.id_account == _customer.id_account).Select(x => x.fcm_token).FirstOrDefault();

                    var payload3 = new
                    {
                        // to
                        to                = fcm_ss,
                        priority          = "high",
                        content_available = true,
                        notification      = new
                        {
                            body  = "Giao dịch thất bại!",
                            title = "Test",
                            badge = 1
                        },
                    };

                    string postbody3  = JsonConvert.SerializeObject(payload3).ToString();
                    Byte[] byteArray3 = Encoding.UTF8.GetBytes(postbody3);
                    tRequest.ContentLength = byteArray3.Length;
                    using (Stream dataStream = tRequest.GetRequestStream())
                    {
                        dataStream.Write(byteArray3, 0, byteArray3.Length);
                        using (WebResponse tResponse = tRequest.GetResponse())
                        {
                            using (Stream dataStreamResponse = tResponse.GetResponseStream())
                            {
                                if (dataStreamResponse != null)
                                {
                                    using (StreamReader tReader = new StreamReader(dataStreamResponse))
                                    {
                                        String sResponseFromServer = tReader.ReadToEnd();
                                        //result.Response = sResponseFromServer;
                                    }
                                }
                            }
                        }
                    }
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            #endregion
        }