public string Request() { try { //long authority = 0; // byte status = 0; System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((o, xc, xch, sslP) => true); ir.shaparak.pec.ClientSaleRequestData clientRequestData = new ir.shaparak.pec.ClientSaleRequestData(); clientRequestData.Amount = Amount; clientRequestData.LoginAccount = Pin; clientRequestData.OrderId = OrderID; clientRequestData.CallBackUrl = CallBackUrl; var clientResponse = saleService.SalePaymentRequest(clientRequestData); // service.PinPaymentRequest(Pin, Amount, OrderID, CallBackUrl, ref authority, ref status); //throw new Exception(clientResponse.Token + " $ " + clientResponse.Status + " $ " + clientResponse.Message); foreach (Status result in Enum.GetValues(typeof(Status))) { if (clientResponse.Status == (int)result && result != Status.Successful) { throw new Exception(Language.GetString(result.ToString())); } } if (clientResponse.Token == -1) { throw new Exception(Language.GetString("InvalidAuthority")); } TokenThis = clientResponse.Token.ToString(); return(clientResponse.Token.ToString()); } catch (Exception ex) { throw ex; } }
protected void btnPay_Click(object sender, EventArgs e) { int OrderCode = 0; int TotalOrderCost = 0; string OrderID = ""; int UserCode = Convert.ToInt32(Session["UserCode"]); int HCPayMethodCode = 1; if (rbPayOnline.Checked) { HCPayMethodCode = 1; } else { HCPayMethodCode = 2; } string strDeliverType = "1"; if (Session["DeliverType"] != null) { strDeliverType = Session["DeliverType"].ToString(); } //if (strDeliverType == "2")//Sefareshi //{ // OtherCosts = 65000; //} //else //{ // OtherCosts = 75000; //} Tools tools = new Tools(); SendPrice = 0; BOLOrders OrdersBOL = new BOLOrders(); if (ViewState["OrderID"] == null) { if (Session["dtOrders"] != null) { DataTable dt = (DataTable)Session["dtOrders"]; if (dt.Rows.Count > 0) { TotalAmount = 0; int NetTotal = CalcTotalAmount(dt); } } int intDeliverType = Convert.ToInt32(Session["DeliverType"]); int intAddressCode = Convert.ToInt32(Session["AddressCode"]); OtherCosts = 0; if (Session["dtOrders"] != null) { DataTable dt = (DataTable)Session["dtOrders"]; for (int i = 0; i < dt.Rows.Count; i++) { int ItemCount = Convert.ToInt32(dt.Rows[i]["ItemCount"]); int SendPishtazPrice = Convert.ToInt32(dt.Rows[i]["SendPishtazPrice"]); int SendSefareshiPrice = Convert.ToInt32(dt.Rows[i]["SendSefareshiPrice"]); if (strDeliverType == "2")//Sefareshi { OtherCosts += SendSefareshiPrice * ItemCount; } else { OtherCosts += SendPishtazPrice * ItemCount; } } } //BOLHardCode HardCodeBOL = new BOLHardCode(); //HardCodeBOL.TableOrViewName = "HCSendTypes"; BOLUserAddresses UserAddressesBOL = new BOLUserAddresses(UserCode); vUserAddresses CurAddress = UserAddressesBOL.GetFullDetails(intAddressCode); string FullAddress = CurAddress.Province + " " + CurAddress.City + " " + CurAddress.Address; TotalOrderCost = TotalAmount + SendPrice + OtherCosts - CouponDiscount; string FullName = CurAddress.FullName; string Tel = CurAddress.Tel; string PostalCode = CurAddress.PostalCode; string Description = ""; string PostOrderCode = ""; string CellPhone = CurAddress.CellPhone; string Email = Session["Email"].ToString(); string Address = CurAddress.Province + " " + CurAddress.City + " " + CurAddress.Address; int HCSendTypeCode = 1; int HCGenderCode = 1; int CityCode = CurAddress.CityCode; int ProvinceCode = CurAddress.ProvinceCode; #region Save To Orders OrderID = tools.GetRandString(10).ToUpper(); int?RefUserCode = null; if (Session["RefUserCode"] != null) { RefUserCode = Convert.ToInt32(Session["RefUserCode"]); } if (Session["UserCode"] != null) { UserCode = Convert.ToInt32(Session["UserCode"]); } OrderCode = OrdersBOL.InsertRecord(FullName, Email, CityCode, ProvinceCode, Tel, CellPhone, PostalCode, Address, HCGenderCode, Description, HCSendTypeCode, 1, 0, SendPrice, TotalAmount, OtherCosts, TotalOrderCost, OrderID, false, RefUserCode, UserCode, HCPayMethodCode); #endregion #region Save to Order Products if (Session["dtOrders"] != null) { BOLOrderProducts OrderProductsBOL = new BOLOrderProducts(OrderCode); DataTable dt = (DataTable)Session["dtOrders"]; for (int i = 0; i < dt.Rows.Count; i++) { int ProductCode = Convert.ToInt32(dt.Rows[i]["ProductCode"]); int ProductPrice = Convert.ToInt32(dt.Rows[i]["ProductPrice"]); int ItemCount = Convert.ToInt32(dt.Rows[i]["ItemCount"]); OrderProductsBOL.InsertRecord(OrderCode, ProductCode, ProductPrice, 1, ItemCount); } } #endregion } else { vOrders CurOrder = OrdersBOL.GetOrderByID(ViewState["OrderID"].ToString()); if (CurOrder == null) { msgMessage.Text = "کد سفارش معتبر نیست"; msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; return; } else { OrderCode = CurOrder.Code; TotalOrderCost = Convert.ToInt32(CurOrder.TotalOrderCost); } OrderID = CurOrder.ID; } //if (OrderCode != -1 && !string.IsNullOrEmpty( CellPhone) ) //{ // try // { // long intCelPhone = 0; // if(CellPhone.Length == 11) // { // if(CellPhone.StartsWith("0")) // { // intCelPhone = Convert.ToInt64( CellPhone.Substring(1, CellPhone.Length - 1)); // SMSHelper sHelper = new SMSHelper(); // sHelper.SendSingleSMS(intCelPhone, "خرید شما در سایت سایت اثبات با موفقیت انجام شد. کد پیگیری:" + ); // } // } // } // catch // { // } //} pnlPayTools.Visible = false; Session["dtOrders"] = null; if (rbPayOnline.Checked) { string UserIP = ""; try { ///////////////////////bank long Authority = 0; //byte Status = 1; int BankCode = 1;//Parsian string errMessage = ""; BOLUserTransactions UserTransactionsBOL = new BOLUserTransactions(UserCode); //int UserTransactionCode = 1;// UserTransactionsBOL.Insert(UserCode, DateTime.Now, 1, 1, UserIP, TotalOrderCost, 1); int UserTransactionCode = UserTransactionsBOL.Insert(UserCode, DateTime.Now, 1, 1, UserIP, TotalOrderCost, 1, BankCode, "", 0, out errMessage); bool UpdateTransCodeResult = OrdersBOL.UpdateTransactionCode(OrderCode, UserTransactionCode); if (!UpdateTransCodeResult) { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "بروز خطا"; return; } long BankOrderId = Convert.ToInt64(UserTransactionCode); string AdditionalData = ""; string requestKey; // request key string AfterBuyUrl = "http://www.hadiranjbaran.com/Checkout.aspx"; //Ranjbaran.ParsianBankWS.EShopService ParsianService = new Ranjbaran.ParsianBankWS.EShopService(); //ParsianService.PinPaymentRequest(ConfigurationManager.AppSettings["ParsianPin"], TotalOrderCost, UserTransactionCode, AfterBuyUrl, ref Authority, ref Status); ir.shaparak.pec.SaleService SaleService = new ir.shaparak.pec.SaleService(); ir.shaparak.pec.ClientSaleRequestData DataInfo = new ir.shaparak.pec.ClientSaleRequestData(); DataInfo.LoginAccount = "EAi722c7td6881cPnysp"; DataInfo.Amount = TotalOrderCost; DataInfo.OrderId = UserTransactionCode; DataInfo.CallBackUrl = AfterBuyUrl; ir.shaparak.pec.ClientSaleResponseData ResponseData = SaleService.SalePaymentRequest(DataInfo); Authority = ResponseData.Token; short Status = ResponseData.Status; if (Status == 0) { int UpdateResult = UserTransactionsBOL.UpdateAuthority(UserTransactionCode, Authority.ToString(), out errMessage); if (UpdateResult == 0) { Response.Redirect("https://pec.shaparak.ir/NewIPG/?Token=" + Authority); return; } else { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "بروز خطا در ذخیره داده های تراکنش بانک پارسیان" + " کد خطا: " + errMessage; return; } } else { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "خطا در برقراری ارتباط با بانک پارسیان" + " کد خطا: " + Status; return; } } catch (Exception err) { msgMessage.Text = "خطا در برقراری ارتباط با سرور بانک ملی" + err.Message; msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; return; } } else { Response.Redirect("~/Checkout.aspx?ID=" + OrderID); return; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (ViewState["ItemType"] == null || ViewState["Code"] == null) { return; } string ItemType = ViewState["ItemType"].ToString(); int Code = Convert.ToInt32(ViewState["Code"]); int TotalCost = 0; #region Parsian long Authority = 0; //byte Status = 1; int BankCode = 1;//Parsian string UserIP = ""; if (ItemType == "Booklet") { BOLBooklets BookletsBOL = new BOLBooklets(); Ranjbaran.Old_App_Code.DAL.Booklets CurBooklet = BookletsBOL.GetDetail(Code); if (CurBooklet != null) { TotalCost = (int)CurBooklet.Price; } } else if (ItemType == "Exam") { BOLExams ExamsBOL = new BOLExams(); Ranjbaran.Old_App_Code.DAL.Exams CurExam = ExamsBOL.GetDetail(Code); if (CurExam != null) { TotalCost = (int)CurExam.Price; } } else if (ItemType == "Course") { BOLCourses CoursesBOL = new BOLCourses(); Ranjbaran.Old_App_Code.DAL.Courses CurExam = CoursesBOL.GetDetail(Code); if (CurExam != null) { TotalCost = (int)CurExam.Fee; } } int UserCode = Convert.ToInt32(Session["UserCode"]); string errMessage = ""; string AfterBuyUrl = "http://www.hadiranjbaran.com/PayStep2.aspx"; BOLUserTransactions UserTransactionsBOL = new BOLUserTransactions(UserCode); int UserTransactionCode = UserTransactionsBOL.Insert(UserCode, DateTime.Now, 1, 1, UserIP, TotalCost, 1, BankCode, ItemType, Code, out errMessage); if (UserTransactionCode == -1) { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "بروز خطا" + errMessage; return; } else { Response.Write(UserTransactionCode); } ir.shaparak.pec.SaleService SaleService = new ir.shaparak.pec.SaleService(); //Ranjbaran.ParsianBankWS.EShopService ParsianService = new Ranjbaran.ParsianBankWS.EShopService(); //ParsianService.PinPaymentRequest(ConfigurationManager.AppSettings["ParsianPin"], TotalCost, UserTransactionCode, AfterBuyUrl, ref Authority, ref Status); ir.shaparak.pec.ClientSaleRequestData DataInfo = new ir.shaparak.pec.ClientSaleRequestData(); DataInfo.LoginAccount = "EAi722c7td6881cPnysp"; DataInfo.Amount = TotalCost; DataInfo.OrderId = UserTransactionCode; DataInfo.CallBackUrl = AfterBuyUrl; ir.shaparak.pec.ClientSaleResponseData ResponseData = SaleService.SalePaymentRequest(DataInfo); Authority = ResponseData.Token; short Status = ResponseData.Status; if (Status == 0) { int UpdateResult = UserTransactionsBOL.UpdateAuthority(UserTransactionCode, Authority.ToString(), out errMessage); if (UpdateResult == 0) { Response.Redirect("https://pec.shaparak.ir/NewIPG/?Token=" + Authority); return; } else { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "بروز خطا در ذخیره داده های تراکنش بانک پارسیان" + " کد خطا: " + errMessage; return; } } else { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "خطا در برقراری ارتباط با بانک پارسیان" + " کد خطا: " + Status; return; } #endregion }