protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SponsorshipPaymentFormOptionsOCM2 options = (SponsorshipPaymentFormOptionsOCM2)this.Content.GetContent(typeof(SponsorshipPaymentFormOptionsOCM2));
                if (options.DemoLongReferralMode)
                {
                    Session[c_Referrer] += "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
                }
                lblReferrer.Text    = "v7 - " + (Session[c_Referrer] == null ? String.Empty : Session[c_Referrer].ToString());
                lblReferrer.Visible = options.DemoMode;

                if (this.total == 0)
                {
                    //    Response.Redirect("/");
                }
                try
                {
                    this.populateYears();
                    this.populateHearAbout();
                    this.showTotal();
                }
                catch
                {
                    //ignore
                }
            }
        }
        public override bool OnSaveContent(bool bDialogIsClosing = true)
        {
            SponsorshipPaymentFormOptionsOCM2 options = new SponsorshipPaymentFormOptionsOCM2();

            MyContent.ThankYouPage         = this.txtThankYouPage.Text;
            MyContent.DemoMode             = this.chkDemo.Checked;
            MyContent.DemoLongReferralMode = this.chkDemoLongReferral.Checked;
            MyContent.EmailOptions         = GetEmailOptions();

            this.Content.SaveContent(MyContent);
            return(true);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SponsorshipPaymentFormOptionsOCM2 options = (SponsorshipPaymentFormOptionsOCM2)this.Content.GetContent(typeof(SponsorshipPaymentFormOptionsOCM2));

            if (options != null)
            {
                //try
                //{

                if (validCard())
                {
                    Guid searchId      = this.findConstituent();
                    Guid constituentId = searchId == Guid.Empty ? this.createConsitutent() : searchId;      //new Guid("AB7BD96E-F277-4C5F-B9FE-2D5E9DB1F9E7"); //
                    //this.addGift(constituentId);
                    this.createSponsorship(constituentId);
                    if (this.radPayment.SelectedValue == "Check")
                    {
                        Session["CartData"] = null;
                        Response.Redirect(options.ThankYouPage);
                    }
                    else
                    {
                        if (this.radCcRecurrence.SelectedValue == "OneTimeGIft")
                        {
                            if (this.processPayment())
                            {
                                Session["CartData"] = null;
                                Response.Redirect(options.ThankYouPage);
                            }
                        }
                        else
                        {
                            Session["CartData"] = null;
                            Response.Redirect(options.ThankYouPage);
                        }
                    }
                }

                //catch (Exception ex)
                //{
                //    this.lblError.Visible = true;
                //    this.lblError.Text = ex.Message + "<br /><br />" + ex.StackTrace;
                //}
                //}
            }
        }
        private bool processPayment()
        {
            // CSM - This method should only be called when making a one time gift.
            //		 This needs to be changed to use the same processing as the sponsorship payment part instead of going into the web donation batch, since it can't link it to the specific recurring gift

            SponsorshipPaymentFormOptionsOCM2 options = (SponsorshipPaymentFormOptionsOCM2)this.Content.GetContent(typeof(SponsorshipPaymentFormOptionsOCM2));

            BBPSPaymentInfo payment = new BBPSPaymentInfo();

            payment.DemoMode           = options.DemoMode;
            payment.MerchantAcctID     = 14;
            payment.Bbpid              = Utility.GetBbbid(14, this.API.Transactions.MerchantAccounts);
            payment.SkipCardValidation = false;
            foreach (DataRow dr in this.cartData.Rows)
            {
                int     designationId = Utility.GetBbncDesignationIdFromSponsorshipOpportunity(dr["Id"].ToString());
                decimal amount        = Convert.ToInt32(dr["Months"]) * Convert.ToDecimal(dr["Amount"]);

                payment.AddDesignationInfo(amount, "BBIS Child Sponsorship Transaction", designationId);
            }

            payment.AppealID = 1;
            payment.Comments = "";

            if (this.radPayment.SelectedValue == "Check")
            {
                // CSM - Since this method is only called when a person makes a one time credit card payment, it should never get here.
                payment.PaymentMethod = BBNCExtensions.API.Transactions.PaymentArgs.ePaymentMethod.Check;
            }
            else
            {
                payment.PaymentMethod = BBNCExtensions.API.Transactions.PaymentArgs.ePaymentMethod.CreditCard;

                payment.CreditCardCSC             = this.txtCcSecurityCode.Text;
                payment.CreditCardExpirationMonth = Convert.ToInt32(this.cmbCcExpMonth.SelectedValue);
                payment.CreditCardExpirationYear  = Convert.ToInt32(this.cmbCcExpYear.SelectedValue);
                payment.CreditCardHolderName      = this.txtCcName.Text;
                payment.CreditCardNumber          = this.txtCcNumber.Text;
                payment.CreditCardType            = (BBNCExtensions.Interfaces.Services.CreditCardType)Enum.Parse(typeof(BBNCExtensions.Interfaces.Services.CreditCardType), this.cmbCcType.SelectedValue);

                if (this.radBilling.SelectedValue == "Yes")
                {
                    payment.DonorStreetAddress = this.txtAddress.Text;
                    payment.DonorCity          = this.txtCity.Text;
                    payment.DonorStateProvince = this.cmbCountry.SelectedValue == "US" ? this.cmbState.SelectedValue : this.txtRegion.Text;
                    payment.DonorZIP           = this.txtZip.Text;
                }
                else
                {
                    payment.DonorStreetAddress = this.txtBillingAddress.Text;
                    payment.DonorCity          = this.txtBillingCity.Text;
                    payment.DonorStateProvince = this.cmbCountry.SelectedValue == "US" ? this.cmbBillingState.SelectedValue : this.txtBillingRegion.Text;
                    payment.DonorZIP           = this.txtBillingZip.Text;
                }
            }

            payment.EmailAddress = this.txtEmail.Text;
            BBNCExtensions.API.Transactions.Donations.RecordDonationReply reply = this.API.Transactions.RecordDonation(payment.GeneratePaymentArgs());
            if (!payment.InterpretPaymentReply(reply).Success)
            {
                this.lblError.Visible = true;
                this.lblError.Text    = payment.InterpretPaymentReply(reply).Message;
                return(false);
            }
            else
            {
                return(true);
            }
        }