protected void btnSaveOnlinePayment_Click(object sender, EventArgs e) { Common.AccountInformation accountInfo = new Common.AccountInformation(); Common.Fish fish = new Common.Fish(); string result = string.Empty; try { if (rdbMellat.Checked) { if (Helper.GetGuid(rdbMellat.Value) == Guid.Empty) { throw new Exception(Language.GetString("AccountInvalid")); } accountInfo = Facade.AccountInformation.LoadAccountInformation(Helper.GetGuid(rdbMellat.Value)); } else if (rdbParsian.Checked) { if (Helper.GetGuid(rdbParsian.Value) == Guid.Empty) { throw new Exception(Language.GetString("AccountInvalid")); } accountInfo = Facade.AccountInformation.LoadAccountInformation(Helper.GetGuid(rdbParsian.Value)); } Common.User parent = Facade.User.LoadUser(ParentGuid); if (!parent.IsMainAdmin && parent.Credit < Helper.GetLong(txtOnlineSmsCount.Text)) { throw new Exception(Language.GetString("SystemUnableAssignCredit")); } switch (accountInfo.Bank) { case (int)Banks.Mellat: BehPardakhtMellat behPardakht = new BehPardakhtMellat(); if (Helper.CheckDataConditions(accountInfo.TerminalID).IsEmpty || Helper.CheckDataConditions(accountInfo.UserName).IsEmpty || Helper.CheckDataConditions(accountInfo.Password).IsEmpty) { throw new Exception(Language.GetString("OnlineGatewayInfoIncorrect")); } behPardakht.TerminalID = Helper.GetLong(accountInfo.TerminalID); behPardakht.UserName = accountInfo.UserName; behPardakht.Password = accountInfo.Password; behPardakht.Amount = Helper.GetLong(txtOnlineAmount.Text); behPardakht.CallBackUrl = string.Format("{0}/{1}/{2}", "http://" + Helper.GetLocalDomain(Request.Url.Authority), "PaymentReport", (int)Arad.SMS.Gateway.Business.Banks.Mellat); string refID = behPardakht.Request(ref result); if (Helper.CheckDataConditions(refID).IsEmpty) { throw new Exception(Language.GetString("DontAccessToOnlineGateway")); } #region InsertFish fish.ReferenceID = refID; fish.CreateDate = DateTime.Now; fish.PaymentDate = DateTime.Now; fish.SmsCount = Helper.GetLong(txtOnlineSmsCount.Text); fish.Amount = Helper.GetDecimal(txtOnlineAmount.Text); fish.OrderID = behPardakht.OrderID.ToString(); fish.Type = (int)Arad.SMS.Gateway.Business.TypeFish.OnLine; fish.Status = (int)Arad.SMS.Gateway.Business.FishStatus.Checking; fish.AccountInformationGuid = accountInfo.AccountInfoGuid; fish.UserGuid = UserGuid; Facade.Fish.InsertOnlinePayment(fish); #endregion ClientSideScript = behPardakht.GotoGateway(refID); break; case (int)Banks.Parsian: ParsianPaymentGateway parsian = new ParsianPaymentGateway(); if (Helper.CheckDataConditions(accountInfo.PinCode).IsEmpty) { throw new Exception(Language.GetString("OnlineGatewayInfoIncorrect")); } parsian.Pin = accountInfo.PinCode; parsian.Amount = Helper.GetInt(txtOnlineAmount.Text); parsian.CallBackUrl = string.Format("{0}/{1}/{2}", "http://" + Helper.GetLocalDomain(Request.Url.Authority), "PaymentReport", (int)Arad.SMS.Gateway.Business.Banks.Parsian); string authority = parsian.Request(); if (Helper.CheckDataConditions(authority).IsEmpty) { throw new Exception(Language.GetString("DontAccessToOnlineGateway")); } #region InsertFish fish.ReferenceID = authority; fish.CreateDate = DateTime.Now; fish.PaymentDate = DateTime.Now; fish.SmsCount = Helper.GetLong(txtOnlineSmsCount.Text); fish.Amount = Helper.GetDecimal(txtOnlineAmount.Text); fish.OrderID = parsian.OrderID.ToString(); fish.Type = (int)TypeFish.OnLine; fish.Status = (int)FishStatus.Checking; fish.AccountInformationGuid = accountInfo.AccountInfoGuid; fish.UserGuid = UserGuid; Facade.Fish.InsertOnlinePayment(fish); #endregion var redirectUrl = string.Format(parsian.PostUrl, authority); //Response.Redirect(redirectUrl, true); Response.Write("<script language='javascript'>self.parent.location='" + redirectUrl + "';</script>"); break; } } catch (Exception ex) { ClientSideScript = string.Format("saveResult('online','error','{0}')", ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InitializePage(); } Common.FailedOnlinePayment failedOnlinePayment = new Common.FailedOnlinePayment(); StringBuilder result = new StringBuilder(); btnReturn.Text = Language.GetString(btnReturn.Text); DataTable fishInfo = new DataTable(); try { string errorMessage = string.Empty; fishInfo = Facade.AccountInformation.GetAccountOfReferenceID(dicParams[OnlinePaymentParams.ReferenceId]); if (fishInfo.Rows.Count == 0) { throw new Exception(); } switch (Helper.GetInt(Request["bank"])) { case (int)Banks.Mellat: BehPardakhtMellat behPardakht = new BehPardakhtMellat(); //if (dicParams[OnlinePaymentParams.Ip] != behPardakht.GatewayPaymentIP) // throw new Exception(string.Format("{0},InputIP={1},ValidIp={2}", Language.GetString("IPIsInvalid"), dicParams[OnlinePaymentParams.Ip], behPardakht.GatewayPaymentIP)); foreach (BehPardakhtMellat.ResCode resCodeList in Enum.GetValues(typeof(BehPardakhtMellat.ResCode))) { if (Helper.GetInt(dicParams[OnlinePaymentParams.ResCode]) == (int)resCodeList && resCodeList != (int)BehPardakhtMellat.ResCode.TransactionWasSuccessful) { throw new Exception(Language.GetString(resCodeList.ToString())); } } behPardakht.TerminalID = Helper.GetLong(fishInfo.Rows[0]["TerminalID"]); behPardakht.UserName = fishInfo.Rows[0]["UserName"].ToString(); behPardakht.Password = fishInfo.Rows[0]["Password"].ToString(); behPardakht.OrderID = Helper.GetLong(dicParams[OnlinePaymentParams.SaleOrderId]); behPardakht.VerifyRequest(Helper.GetLong(dicParams[OnlinePaymentParams.SaleReferenceId])); isPaymentSuccessful = true; break; case (int)Banks.Parsian: ParsianPaymentGateway parsian = new ParsianPaymentGateway(); if (dicParams[OnlinePaymentParams.status] != ((int)ParsianPaymentGateway.Status.Successful).ToString()) { throw new Exception(); } parsian.Pin = fishInfo.Rows[0]["PinCode"].ToString(); parsian.VerifyRequest(Helper.GetLong(dicParams[OnlinePaymentParams.Token])); dicParams[OnlinePaymentParams.SaleReferenceId] = dicParams[OnlinePaymentParams.RRN].ToString(); isPaymentSuccessful = true; break; } if (!isPaymentSuccessful) { throw new Exception(); } if (Helper.GetBool(dicParams[OnlinePaymentParams.IsExtendedPanel])) { Facade.Fish.UpdateDescription(Helper.GetGuid(fishInfo.Rows[0]["FishGuid"]), Language.GetString("ExtendedPanel"), FishStatus.Confirmed); if (!Facade.User.UpdateExpireDate(Helper.GetGuid(fishInfo.Rows[0]["UserGuid"]), DateTime.Now.AddYears(1))) { throw new Exception(Language.GetString("ErrorRecord")); } } else if (Helper.GetBool(dicParams[OnlinePaymentParams.IsExtendedNumber])) { Common.PrivateNumber privateNumber = Facade.PrivateNumber.LoadNumber(Helper.GetGuid(fishInfo.Rows[0]["ReferenceGuid"])); Facade.Fish.UpdateDescription(Helper.GetGuid(fishInfo.Rows[0]["FishGuid"]), string.Format("{0}-{1}", Language.GetString("ExtendedNumber"), privateNumber.Number), FishStatus.Confirmed); if (!Facade.PrivateNumber.UpdateExpireDate(privateNumber.NumberGuid, DateTime.Now.AddYears(1))) { throw new Exception(Language.GetString("ErrorRecord")); } } else if (Helper.GetInt(dicParams[OnlinePaymentParams.SalePackageId]) != 0) { Facade.Fish.UpdateDescription(Helper.GetGuid(fishInfo.Rows[0]["FishGuid"]), Language.GetString("BuyPanel"), FishStatus.Confirmed); DataTable dtRole = Facade.Role.GetPackage(Helper.GetInt(dicParams[OnlinePaymentParams.SalePackageId])); Facade.User.UpdateUserRole(Helper.GetGuid(fishInfo.Rows[0]["UserGuid"]), Helper.GetGuid(dtRole.Rows[0]["Guid"])); } else { Facade.Fish.ConfirmOnlineFish(Helper.GetGuid(fishInfo.Rows[0]["UserGuid"]), Helper.GetLong(fishInfo.Rows[0]["SmsCount"]), TypeCreditChanges.OnlinePayment, string.Format(Language.GetString("OnlinePaymentTransaction"), dicParams[OnlinePaymentParams.SaleReferenceId]), Helper.GetGuid(fishInfo.Rows[0]["FishGuid"]), Helper.GetLong(dicParams[OnlinePaymentParams.SaleReferenceId])); } lblAmount.Text = fishInfo.Rows[0]["Amount"].ToString(); lblBillNumber.Text = dicParams[OnlinePaymentParams.SaleReferenceId]; lblDatePayment.Text = DateManager.GetSolarDate(DateTime.Now); pnlFailedPayment.Visible = false; pnlSuccessfulPayment.Visible = true; } catch (Exception ex) { Log log = new Log(); Guid refenceGuid = fishInfo.Rows.Count > 0 ? Helper.GetGuid(fishInfo.Rows[0]["FishGuid"]) : Guid.Empty; log.Type = (int)LogType.Error; log.ReferenceGuid = refenceGuid; log.Source = "RegisterFish"; log.Name = "OnlinePayment"; log.Text = ex.Message; log.CreateDate = DateTime.Now; log.IPAddress = Request.UserHostAddress; log.Browser = Request.Browser.Browser; SQLHelper.InsertLogInfo(log); if (refenceGuid != Guid.Empty) { Facade.Fish.UpdateDescription(refenceGuid, ex.Message, FishStatus.Rejected); } pnlSuccessfulPayment.Visible = false; pnlFailedPayment.Visible = true; Label1.Text += "//" + ex.Message.ToString(); } }