using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Controls_Payment : WebBlockUserControl { private string _ValidationGroup = ""; public string ValidationGroup { get { return _ValidationGroup; } set { _ValidationGroup = value; custPayment.ValidationGroup = value; } } public bool ShowCreditCardForm { get { return pnlCreditCard.Visible; } set { pnlCreditCard.Visible = value; } } public bool ShowPurchaseOrderForm { get { return pnlPurchaseOrder.Visible; } set { pnlPurchaseOrder.Visible = value; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Utilities.PopulateExpirationMonths(ddlExpMonth); Utilities.PopulateExpirationYears(ddlExpYear); string acceptedcards = Configuration.Get("Payment.AcceptedCards"); if (acceptedcards == null) throw new Exception("Server misconfiguration. There is an error with the configuration variable 'AcceptedCards'."); else foreach (string s in acceptedcards.Split(',')) ddlCardType.Items.Add(new ListItem(s, s)); if (Session["OrderInfo"] != null) { OrderInfo oi = (OrderInfo)Session["OrderInfo"]; if (oi.PaymentMethod == "Credit Card") { rbCreditCard.Checked = true; if (oi.CardName.Length > 0) { ddlCardType.SelectedValue = oi.CardName; txtCardNumber.Text = "************" + oi.CardNumber.Substring(oi.CardNumber.Length - 4); ddlExpMonth.SelectedValue = oi.ExpMonth; ddlExpYear.SelectedValue = oi.ExpYear; txtSecurityCode.Text = "***"; } } else if (oi.PaymentMethod == "PO Number") { rbPurchaseOrder.Checked = true; txtPONumber.Text = oi.PurchaseOrderNumber; } } if (pnlCreditCard.Visible) rbCreditCard.Checked = true; else if (pnlPurchaseOrder.Visible) rbPurchaseOrder.Checked = true; } } public void SavePaymentInformation() { OrderInfo oi = (OrderInfo)Session["OrderInfo"]; if (rbCreditCard.Checked) { oi.PaymentMethod = "Credit Card"; // set card info oi.CardName = ddlCardType.SelectedValue; if (!txtCardNumber.Text.StartsWith("************")) oi.CardNumber = txtCardNumber.Text; oi.ExpMonth = ddlExpMonth.SelectedValue; oi.ExpYear = ddlExpYear.SelectedValue; if (!txtSecurityCode.Text.Equals("***")) oi.SecurityCode = txtSecurityCode.Text; } else if (rbPurchaseOrder.Checked) { oi.PaymentMethod = "PO Number"; oi.PurchaseOrderNumber = txtPONumber.Text; } } protected void custPayment_ServerValidate(object source, ServerValidateEventArgs args) { if (rbCreditCard.Checked) { // validate credit card Page.Validate("creditcard"); args.IsValid = Page.IsValid; } else if (rbPurchaseOrder.Checked) { Page.Validate("purchaseorder"); args.IsValid = Page.IsValid; } } protected void custExpDate_ServerValidate(object source, ServerValidateEventArgs args) { DateTime thisDate = new DateTime(Int32.Parse(ddlExpYear.SelectedValue), Int32.Parse(ddlExpMonth.SelectedValue), 1); thisDate.AddMonths(1); if (thisDate <= DateTime.Now.Date) args.IsValid = false; else args.IsValid = true; } }