private bool SubmitTransaction() { if(!Convert.ToBoolean(this.TestModeSetting)){ try { ContributionFundCollection selectedFundCollection = this.GetSelectedFundCollection(); decimal totalAmount = Convert.ToDecimal(this.hfTotalContribution.Value); bool result; if (selectedFundCollection.TotalFundAmount != totalAmount) { this.DisplayError("There appears to be a problem with the Funds you selected. Please return to the selection screen and review your choices."); result = false; return result; } StringBuilder stringBuilder = new StringBuilder(); if (this.CommentCaptionSetting == string.Empty) { using (List<ContributionFund>.Enumerator enumerator = selectedFundCollection.GetEnumerator()) { while (enumerator.MoveNext()) { ContributionFund current = enumerator.Current; stringBuilder.AppendFormat("F{0}:{1} ", current.FundId.ToString(), current.Amount.ToString("C2")); } goto IL_F3; } } stringBuilder.Append(this.tbComment.Text); IL_F3: GatewayAccount gatewayAccount; string accountNumber; if (rblPaymentMethod.SelectedValue == "CC") { gatewayAccount = this.ccGatewayAcct; accountNumber = this.MaskAccountNumber(this.tbCCNumber.Text); } else { gatewayAccount = this.achGatewayAcct; accountNumber = this.MaskAccountNumber(this.tbAccountNumber.Text); } Transaction transaction = null; if (gatewayAccount.RequiresPaymentGateway) { string confirmationID = this.hfConfirmationID.ToString(); gatewayAccount.ProcessorClass.PaymentFrequency = PaymentFrequency.One_Time; if (gatewayAccount.Authorize(confirmationID)) { transaction = gatewayAccount.Transaction; transaction.PersonId = this._person.PersonID; } } else { if (rblPaymentMethod.SelectedValue == "CC") { if (gatewayAccount.Authorize(TransactionType.Sale, this.tbCCNumber.Text, this.tbCCCIN.Text, this.ddlExpMonth.SelectedValue, this.ddlExpYear.SelectedValue, -1, this._person.PersonID, this._person.FirstName, this._person.FirstName, this._person.LastName, this._person.PrimaryAddress.StreetLine1, this._person.PrimaryAddress.City, this._person.PrimaryAddress.State, this._person.PostalCode, this._person.Phones.FindByType(276).ToString(), this._person.Emails.FirstActive, totalAmount, stringBuilder.ToString(), DateTime.MinValue, PaymentFrequency.One_Time, 0, this._validateCardNumber)) { transaction = gatewayAccount.Transaction; } } else { if (gatewayAccount.AuthorizeACH(TransactionType.Sale, this.tbAccountNumber.Text.Trim(), this.tbRoutingNumber.Text.Trim(), ddlAccountType.Items[0].Selected, this._person.PersonID, this._person.FirstName, this._person.FirstName, this._person.LastName, this._person.PrimaryAddress.StreetLine1, this._person.PrimaryAddress.City, this._person.PrimaryAddress.State, this._person.PrimaryAddress.PostalCode, this._person.Phones.FindByType(276).ToString(), this._person.Emails.FirstActive, totalAmount, stringBuilder.ToString(), DateTime.MinValue, PaymentFrequency.One_Time, 0)) { transaction = gatewayAccount.Transaction; } } } if (transaction != null) { transaction.Save(this._person.FullName); if (!transaction.Success) { this.DisplayError("Authorization of your information failed for the following reason(s):", gatewayAccount.Messages); result = false; return result; } this.curTrans = transaction; string str = "Online Giving"; if (base.CurrentOrganization.Settings["GivingBatchName"] != null) { str = base.CurrentOrganization.Settings["GivingBatchName"]; } BatchType batchType = Batch.GetBatchType(transaction.PaymentMethod.Guid); Batch batch = new Batch(base.CurrentOrganization.OrganizationID, true, str + " " + Enum.GetName(typeof(BatchType), batchType), transaction.TransactionDate, batchType, gatewayAccount.GatewayAccountId, this._person.FullName); batch.VerifyAmount += transaction.TransactionAmount; batch.Save(this._person.FullName); Contribution contribution = new Contribution(); contribution.PersonId = transaction.PersonId; contribution.TransactionId = transaction.TransactionId; contribution.BatchId = batch.BatchId; contribution.ContributionDate = transaction.TransactionDate; contribution.CurrencyAmount = transaction.TransactionAmount; contribution.TransactionNumber = transaction.TransactionDetail; contribution.CurrencyType = transaction.PaymentMethod; contribution.AccountNumber = transaction.RepeatingPayment.AccountNumber; contribution.ContributionFunds = selectedFundCollection; contribution.Memo = stringBuilder.ToString(); contribution.Save(this._person.FullName); this.ConfirmationNumber = "Confirmation Number: " + contribution.TransactionNumber; try { OnlineGivingContribution onlineGivingContribution = new OnlineGivingContribution(); onlineGivingContribution.Send(base.CurrentOrganization, transaction, selectedFundCollection, accountNumber, this.tbEmail.Text); goto IL_B29; } catch (Exception) { goto IL_B29; } } this.DisplayError("Authorization of your information failed for the following reason(s):", gatewayAccount.Messages); result = false; return result; IL_B29: base.Session.Clear(); } catch (Exception inner) { throw new ArenaApplicationException("Error occurred during Authorization", inner); } } return true; }
protected void btnUpdate_Click(object sender, EventArgs e) { PledgeCollection pledges = new PledgeCollection(); pledges.LoadByPersonAndFundId(GetSelectedPersonId(), Convert.ToInt32(ddlFund.SelectedValue)); if (pledges.Count > 0) { Person person = new Person(GetSelectedPersonId()); lblError.Text = string.Format("Error: {0} already has a {1:c} pledge for the {2} fund.", Utilities.PersonLink(person, Convert.ToInt32(PersonDetailPageSetting)), pledges[0].Amount, pledges[0].Fund.FundName); } else if (dtbStartDate.SelectedDate > dtbEndDate.SelectedDate) { lblError.Text = "Start Date must be less than or equal to End Date"; } else { Pledge pledge = new Pledge(); pledge.PersonId = GetSelectedPersonId(); pledge.FundId = Convert.ToInt32(ddlFund.SelectedValue); pledge.PledgeBeginDate = dtbStartDate.SelectedDate; pledge.PledgeEndDate = dtbEndDate.SelectedDate; pledge.Amount = Convert.ToDecimal(tbAmount.Text); // pledge.Save(CurrentUser.Identity.Name); // Create custom pledge object DataLayer.PledgeData pledgeData = new DataLayer.PledgeData(_pledgeId); pledgeData.PersonID = GetSelectedPersonId(); pledgeData.CampusLUID = Convert.ToInt32(ddlCampus.SelectedValue); pledgeData.FundID = Convert.ToInt32(ddlFund.SelectedValue); pledgeData.StartDate = dtbStartDate.SelectedDate; pledgeData.EndDate = dtbEndDate.SelectedDate; pledgeData.FrequencyAmount = Convert.ToDecimal(tbFrequencyAmt.Text); pledgeData.FrequencyCount = Convert.ToInt32(tbFrequencyCount.Text); pledgeData.TotalAmount = Convert.ToDecimal(tbAmount.Text); pledgeData.SavePledge(CurrentUser.Identity.Name); if (cbCreateRepeatingPayment.Checked) { CurrentPerson.Settings["PledgeQuickEntry_CreateRepeatingPayment"] = cbCreateRepeatingPayment.Checked.ToString(); //Create ACH Repeating Payment string comment = string.Format("F{0}:{1} ", pledge.FundId.ToString(), tbPaymentAmount.Text); try { RepeatingPayment repeatingPayment = null; if (_achGatewayAcct.AuthorizeACH(TransactionType.Repeating, tbAccountNumber.Text.Trim(), tbRoutingNumber.Text.Trim(), rblAccountType.Items[0].Selected, pledge.PersonId, pledge.Person.FirstName, pledge.Person.FirstName, pledge.Person.LastName, pledge.Person.Addresses.PrimaryAddress().Address.StreetLine1, pledge.Person.Addresses.PrimaryAddress().Address.City, pledge.Person.Addresses.PrimaryAddress().Address.State, pledge.Person.Addresses.PrimaryAddress().Address.PostalCode, "", "", Convert.ToDecimal(tbPaymentAmount.Text), comment, dtbStartDate.SelectedDate, (PaymentFrequency)Enum.Parse(typeof(PaymentFrequency), ddlFrequency.SelectedValue), Convert.ToInt32(tbNumOfPayments.Text))) { repeatingPayment = _achGatewayAcct.RepeatingPayment; } if (repeatingPayment != null) { //Save Repeating Payment repeatingPayment.Title = "Pledge for " + pledge.Fund.FundName; repeatingPayment.AccountNumber = MaskAccountNumber(tbAccountNumber.Text.Trim()); repeatingPayment.OrganizationID = CurrentOrganization.OrganizationID; repeatingPayment.RepeatingPaymentFunds.Clear(); RepeatingPaymentFund rpf = new RepeatingPaymentFund(); rpf.Amount = Convert.ToDecimal(tbPaymentAmount.Text); rpf.FundID = pledge.FundId; repeatingPayment.RepeatingPaymentFunds.Add(rpf); repeatingPayment.Save(CurrentUser.Identity.Name); try { OnlineGivingContribution ogcEmail = new OnlineGivingContribution(); ogcEmail.Send(CurrentOrganization, repeatingPayment); } catch (Exception) { } } else { string error = ParseError("Authorization of your information failed for the following reason(s):", _achGatewayAcct.Messages); throw new ArenaApplicationException(error); } } catch (Exception ex) { throw new ArenaApplicationException("Error occurred during Authorization", ex); } } RedirectToPledge(pledge.PledgeId); } ddlCampus.Focus(); }