protected virtual void CreateCustomerButtonClick(object sender, EventArgs e) { if (Page.IsValid) { try { EnsureChildControls(); // get customer from session controller... Monaco.Billing.Provider.Customer customer = Controller.Customer; // load values from controls customer.FirstName = FirstNameTextBox.Text; customer.LastName = LastNameTextBox.Text; customer.EmailAddress = EmailTextBox.Text; customer.ShippingAddress.State = StateDropDownList.SelectedValue; customer.ShippingAddress.Country = CountryDropDownList.SelectedValue; customer.BillingAddress.State = StateDropDownList.SelectedValue; customer.BillingAddress.Country = CountryDropDownList.SelectedValue; customer.EmailAddress = EmailTextBox.Text; customer.Save(); // save to db // dont worry about saving back to session, this event handler take care of that... OnCustomerCreated(new CustomerCreatedEventArgs(customer)); } catch (WebException ex) { // ssl certificate expired , any http exception OnCustomerError(new CustomerErrorEventArgs("Http Error")); } catch (SqlException ex) { LandingPageErrorEvent evnt = new LandingPageErrorEvent(ex.Message, "Sql Server Error", this, ex); evnt.Raise(); OnCustomerError(new CustomerErrorEventArgs("Sql Server Error")); } catch (Exception ex) { LandingPageErrorEvent evnt = new LandingPageErrorEvent(ex.Message, "An error occured", this, ex); evnt.Raise(); OnCustomerError(new CustomerErrorEventArgs("An error occured")); } } }
void SubmitButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { bool testMode = CardNumberTextBox.Text == TEST_CC_NUMBER; OrderItemList<OrderItem> items = new OrderItemList<OrderItem>(); // you cant add the item if it already exists... foreach (OfferItem item in Controller.Offer.Items) { // Override Add for Duplicate Checks if (item.OfferItemType == OfferItemType.Standard || item.OfferItemType == OfferItemType.ForcedUpsell) { items.Add ( new OrderItem ( item.Sku, Controller.Customer.ID, testMode, Controller.LandingPage.ID, Controller.SessionID, item.ProductTypeID ) ); } } // Controller.Order.Save(); // save the order items to the database foreach (OrderItem item in items) { ICreditCard card = new CreditCard(); item.OrderSucceeded += new EventHandler(item_OrderSucceeded); item.OrderFailed += new EventHandler(item_OrderFailed); // new Products.Provider.ProductProcessor(item).Process(); if (item.Passed) { item.IsQueued = false; Controller.Order.Items.Add(item); } else { item.IsQueued = true; Controller.Queue.Items.Add(item); } /* * Lets say we are processing 3 items, 1 standard and 2 forced upsell * if the standard passes, and foced upsells fail, allow order * to continue processing..., but put failed orderitems in queue * * Lets say we are process 3 items, 1 standard and 2 forced.. * and standard fails... do not even attempt to process forced. * * Lets say there are 2 standard.. one failes and one passes * keep processing... and put one in queue */ } Controller.Order.Save(); // save the order items to the database Controller.Queue.Save(); // save the failed item queue to the database // OnOrderCreated(new OrderCreatedEventArgs(new Order(items), testMode)); } catch (WebException ex) { // indicative of a timeout or some sort of http error... OnOrderError(new OrderErrorEventArgs("Http Error", ex)); } catch (SqlException ex) { OnOrderError(new OrderErrorEventArgs("Sql Error", ex)); } catch (Exception ex) { // Log the error... LandingPageErrorEvent evnt = new LandingPageErrorEvent( ex.Message, "Unknown Error : " + ex.Message.ToString(), this, ex); evnt.Raise(); OnOrderError(new OrderErrorEventArgs("Unknown Error", ex)); } } }