示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int sectionId = Int32.Parse(Request.QueryString["SectionId"]);

            Section = (Section)CoreRepository.GetObjectById(typeof(Section), sectionId);

            string SECURE_SECRET      = "6D0870CDE5F24F34F3915FB0045120DB";
            string hashvalidateResult = "";
            // Khoi tao lop thu vien
            VPCRequest conn = new VPCRequest("http://onepay.vn");

            conn.SetSecureSecret(SECURE_SECRET);
            // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
            hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);
            // Lay gia tri tham so tra ve tu cong thanh toan
            String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
            string amount          = conn.GetResultField("vpc_Amount", "Unknown");
            string localed         = conn.GetResultField("vpc_Locale", "Unknown");
            string command         = conn.GetResultField("vpc_Command", "Unknown");
            string version         = conn.GetResultField("vpc_Version", "Unknown");
            string cardType        = conn.GetResultField("vpc_Card", "Unknown");
            string orderInfo       = conn.GetResultField("vpc_OrderInfo", "Unknown");
            string merchantID      = conn.GetResultField("vpc_Merchant", "Unknown");
            string authorizeID     = conn.GetResultField("vpc_AuthorizeId", "Unknown");
            string merchTxnRef     = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
            string transactionNo   = conn.GetResultField("vpc_TransactionNo", "Unknown");
            string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown");
            string txnResponseCode = vpc_TxnResponseCode;
            string message         = conn.GetResultField("vpc_Message", "Unknown");

            var bookingId  = merchTxnRef;
            var pBookingId = Int32.Parse(bookingId);

            if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
            {
                SendSuccessEmail();
                NSession.Save(new CheckingTransaction()
                {
                    MerchTxnRef = merchTxnRef, Processed = true
                });
                Response.Write("responsecode=1&desc=confirm-success");
            }
            else
            {
                SendFailedEmail();
                NSession.Save(new CheckingTransaction()
                {
                    MerchTxnRef = merchTxnRef, Processed = true
                });
                Response.Write("responsecode=0&desc=confirm-fail");
            }
        }
示例#2
0
        protected void btnPayment_Click(object sender, EventArgs e)
        {
            var startdate      = Request.QueryString["sd"];
            var tripId         = Request.QueryString["i"];
            var ptripId        = Int32.Parse(tripId);
            var trip           = NSession.QueryOver <SailsTrip>().Where(x => x.Id == ptripId).SingleOrDefault();
            var sectionId      = Request.QueryString["SectionId"];
            var cruiseId       = Request.QueryString["c"];
            var pcruiseId      = Int32.Parse(cruiseId);
            var cruise         = NSession.QueryOver <Cruise>().Where(x => x.Id == pcruiseId).SingleOrDefault();
            var paymentMethod  = Request.Params["paymentmethod"];
            var pPaymentMethod = Int32.Parse(paymentMethod);

            var lBookedRoom          = GetListBookedRoom();
            var lSingleRoom          = GetListSingleRoom();
            var lChildren            = GetListChildren();
            var lFullRoom            = GetListFullRoom();
            var fullRoomPrice        = GetRoomPrice(lFullRoom, cruise, trip);
            var singleRoomPrice      = GetSingleRoomPrice(lSingleRoom, cruise, trip);
            var childrenPrice        = GetChildrenPrice(lChildren, cruise, trip);
            var exchangeRate         = GetExchangeRate();
            var totalAmount          = fullRoomPrice + singleRoomPrice + childrenPrice;
            var exchangedTotalAmount = totalAmount * exchangeRate;

            var lRoomInCruise = JsonConvert.DeserializeObject <List <JsonModel.RoomInCruise> >(BookingTour.CheckAvaiable(startdate, tripId, sectionId));

            bool canAddBooking = false;

            foreach (var roomInCruise in lRoomInCruise)
            {
                if (roomInCruise.JCruise.CruiseId.ToString() != cruiseId)
                {
                    continue;
                }
                var lavaiableRoom = roomInCruise.LJAvaiableRoom;
                foreach (var avaiableRoom in lavaiableRoom)
                {
                    foreach (var bookedRoom in lBookedRoom)
                    {
                        if (avaiableRoom.JRoomClass.RoomClassId == bookedRoom.RoomClass.Id &&
                            avaiableRoom.JRoomType.RoomTypeId == bookedRoom.RoomType.Id)
                        {
                            if (bookedRoom.Quantity > avaiableRoom.LJRoom.Count())
                            {
                                canAddBooking = false;
                                continue;
                            }
                            canAddBooking = true;
                        }
                    }
                }
            }

            if (!canAddBooking)
            {
                return;
            }


            var booking = new Booking()
            {
                Trip         = trip,
                Cruise       = cruise,
                StartDate    = DateTime.ParseExact(startdate, "MM/dd/yyyy", CultureInfo.InvariantCulture),
                CreatedDate  = DateTime.Now,
                Status       = StatusType.Pending,
                ModifiedDate = DateTime.Now,
                IsTotalUsd   = false,
                Total        = exchangedTotalAmount,
                IsPaid       = true,
            };

            booking.EndDate = booking.StartDate.AddDays(booking.Trip.NumberOfDay - 1);
            NSession.Save(booking);

            lBookedRoom.OrderBy(x => x.RoomClass).ThenBy(x => x.RoomType);
            foreach (var bookedRoom in lBookedRoom)
            {
                var childrenCount = 0;

                foreach (var singleRoom in lSingleRoom)
                {
                    if (bookedRoom.RoomClass == singleRoom.RoomClass && bookedRoom.RoomType == singleRoom.RoomType)
                    {
                        foreach (var children in lChildren)
                        {
                            if (singleRoom.RoomClass == children.RoomClass && singleRoom.RoomType == children.RoomType)
                            {
                                int singleRoomCount = 0;
                                while (singleRoomCount < singleRoom.Quantity)
                                {
                                    var bookingRoom = new BookingRoom()
                                    {
                                        Book      = booking,
                                        RoomType  = bookedRoom.RoomType,
                                        RoomClass = bookedRoom.RoomClass,
                                        IsSingle  = true,
                                    };
                                    Customer customer = new Customer()
                                    {
                                        BookingRoom = bookingRoom,
                                        Booking     = booking,
                                    };
                                    NSession.Save(customer);

                                    if (childrenCount < children.Quantity)
                                    {
                                        bookingRoom.HasChild = true;
                                        Customer childCustomer = new Customer()
                                        {
                                            IsChild     = true,
                                            BookingRoom = bookingRoom,
                                            Booking     = booking,
                                        };
                                        NSession.Save(childCustomer);
                                        childrenCount++;
                                    }
                                    NSession.Save(bookingRoom);
                                    singleRoomCount++;
                                }
                            }
                        }
                    }
                }

                foreach (var fullRoom in lFullRoom)
                {
                    if (bookedRoom.RoomClass == fullRoom.RoomClass && bookedRoom.RoomType == fullRoom.RoomType)
                    {
                        foreach (var children in lChildren)
                        {
                            if (fullRoom.RoomClass == children.RoomClass && fullRoom.RoomType == children.RoomType)
                            {
                                int fullRoomCount = 0;
                                while (fullRoomCount < fullRoom.Quantity)
                                {
                                    var bookingRoom = new BookingRoom()
                                    {
                                        Book      = booking,
                                        RoomType  = bookedRoom.RoomType,
                                        RoomClass = bookedRoom.RoomClass,
                                        IsSingle  = false,
                                    };
                                    NSession.Save(bookingRoom);
                                    Customer customer = new Customer()
                                    {
                                        BookingRoom = bookingRoom,
                                        Booking     = booking,
                                    };
                                    NSession.Save(customer);
                                    if (childrenCount < children.Quantity)
                                    {
                                        bookingRoom.HasChild = true;
                                        Customer childCustomer = new Customer()
                                        {
                                            IsChild     = true,
                                            BookingRoom = bookingRoom,
                                            Booking     = booking,
                                        };
                                        NSession.Save(childCustomer);
                                        childrenCount++;
                                    }
                                    NSession.Update(bookingRoom);
                                    fullRoomCount++;
                                }
                            }
                        }
                    }
                }
            }

            string SECURE_SECRET    = "A3EFDFABA8653DF2342E8DAC29B51AF0";
            string vpcMerchant      = "ONEPAY";
            string vpcAccessCode    = "D67342C2";
            string vpcRequestString = "https://mtf.onepay.vn/onecomm-pay/vpc.op";
            string vpcReturnUrl     = "http://localhost:1988/Modules/Sails/Admin/Bo/ResultPayment.aspx?NodeId=1&SectionId=15&module=noidia";

            if (pPaymentMethod == 1)
            {
                vpcRequestString = "" + vpcRequestString;
                SECURE_SECRET    = "" + SECURE_SECRET;
                vpcMerchant      = "" + vpcMerchant;
                vpcAccessCode    = "" + vpcAccessCode;
                vpcReturnUrl     = "" + vpcReturnUrl;
            }//config module noi dia

            if (pPaymentMethod == 2)
            {
                vpcRequestString = "https://mtf.onepay.vn/vpcpay/vpcpay.op";
                SECURE_SECRET    = "6D0870CDE5F24F34F3915FB0045120DB";
                vpcMerchant      = "TESTONEPAY";
                vpcAccessCode    = "6BEB2546";
                vpcReturnUrl     = "http://localhost:1988/Modules/Sails/Admin/Bo/ResultPayment.aspx?NodeId=1&SectionId=15&module=quocte";
            }//config module quoc te
            VPCRequest conn = new VPCRequest(vpcRequestString);

            conn.SetSecureSecret(SECURE_SECRET);
            // Add the Digital Order Fields for the functionality you wish to use
            // Core Transaction Fields
            conn.AddDigitalOrderField("AgainLink", "http://onepay.vn");
            conn.AddDigitalOrderField("Title", "OnePAY PAYMENT GATEWAY");
            conn.AddDigitalOrderField("vpc_Locale", "en");//Chon ngon ngu hien thi tren cong thanh toan (vn/en)
            conn.AddDigitalOrderField("vpc_Version", "2");
            conn.AddDigitalOrderField("vpc_Command", "pay");

            if (pPaymentMethod == 1)
            {
                conn.AddDigitalOrderField("vpc_Currency", "VND");
            }

            conn.AddDigitalOrderField("vpc_Merchant", vpcMerchant);              //Thay đổi
            conn.AddDigitalOrderField("vpc_AccessCode", vpcAccessCode);          //Thay đổi
            conn.AddDigitalOrderField("vpc_MerchTxnRef", booking.Id.ToString()); // Thay đổi
            conn.AddDigitalOrderField("vpc_OrderInfo", "Pay for booking " + booking.Id.ToString());
            conn.AddDigitalOrderField("vpc_Amount", (exchangedTotalAmount * 100).ToString());
            conn.AddDigitalOrderField("vpc_ReturnURL", vpcReturnUrl);

            // Dia chi IP cua khach hang
            conn.AddDigitalOrderField("vpc_TicketNo", GetIPAddress());
            // Chuyen huong trinh duyet sang cong thanh toan
            String url = conn.Create3PartyQueryString();

            Page.Response.Redirect(url);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int sectionId = Int32.Parse(Request.QueryString["SectionId"]);

            Section = (Section)CoreRepository.GetObjectById(typeof(Section), sectionId);

            string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";

            if (Request.QueryString["module"] == "noidia")
            {
                SECURE_SECRET = "" + SECURE_SECRET;
            }

            if (Request.QueryString["module"] == "quocte")
            {
                SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";
            }

            string hashvalidateResult = "";
            // Khoi tao lop thu vien
            VPCRequest conn = new VPCRequest("http://onepay.vn");

            conn.SetSecureSecret(SECURE_SECRET);
            // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
            hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);
            // Lay gia tri tham so tra ve tu cong thanh toan
            String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
            string amount          = conn.GetResultField("vpc_Amount", "Unknown");
            string localed         = conn.GetResultField("vpc_Locale", "Unknown");
            string command         = conn.GetResultField("vpc_Command", "Unknown");
            string version         = conn.GetResultField("vpc_Version", "Unknown");
            string cardType        = conn.GetResultField("vpc_Card", "Unknown");
            string orderInfo       = conn.GetResultField("vpc_OrderInfo", "Unknown");
            string merchantID      = conn.GetResultField("vpc_Merchant", "Unknown");
            string authorizeID     = conn.GetResultField("vpc_AuthorizeId", "Unknown");
            string merchTxnRef     = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
            string transactionNo   = conn.GetResultField("vpc_TransactionNo", "Unknown");
            string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown");
            string txnResponseCode = vpc_TxnResponseCode;
            string message         = conn.GetResultField("vpc_Message", "Unknown");

            var bookingId           = merchTxnRef;
            var pBookingId          = Int32.Parse(bookingId);
            var checkingTransaction = NSession.QueryOver <CheckingTransaction>().Where(x => x.MerchTxnRef == merchTxnRef).SingleOrDefault();

            if (checkingTransaction != null)
            {
                if (checkingTransaction.Processed)
                {
                    Page.Response.Redirect("./TransactionResult.aspx?NodeId=1&SectionId=15&status=1&tid=" + transactionNo + "&oi=" + orderInfo + "&ta=" + amount + "&bid=" + merchTxnRef + "&trc=" + txnResponseCode);
                }
            }
            if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
            {
                SendSuccessEmail();
                NSession.Save(new CheckingTransaction()
                {
                    MerchTxnRef = merchTxnRef, Processed = true
                });
                Page.Response.Redirect("./TransactionResult.aspx?NodeId=1&SectionId=15&status=1&tid=" + transactionNo + "&oi=" + orderInfo + "&ta=" + amount + "&bid=" + merchTxnRef + "&trc=" + txnResponseCode);
            }
            else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
            {
                Page.Response.Redirect("./Pending.aspx");
            }
            else
            {
                SendFailedEmail();
                DeleteBooking(pBookingId);
                NSession.Save(new CheckingTransaction()
                {
                    MerchTxnRef = merchTxnRef, Processed = true
                });
                Page.Response.Redirect("./TransactionResult.aspx?NodeId=1&SectionId=157status=2&b=" + bookingId + "&responsecode=" + txnResponseCode);
            }
        }