Example #1
0
        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);
            }
        }