protected void BuyButton_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } try { Customer customer = GetLoggedCustomer(); if (customer == null) { customer = AddCustomer(); } Order order = AddOrder(customer); //Take credit card payment if (ChargeCreditCard(order.OrderNumber)) { //Expire any coupons, clear the cart and redirect to Receipt.aspx Cart.CartCoupons.Where(c => c.IsCouponUnique).All((c) => { Coupons.DeactivateCoupon(c.CouponID); return(true); }); Cart = null; Response.Redirect("Receipt.aspx?CustomerID=" + WebUtility.EncodeParamForQueryString(customer.CustomerID.ToString()) + "&OrderID=" + WebUtility.EncodeParamForQueryString(order.OrderID.ToString())); } else { //Log in the customer and set the transaction to error FormsAuthentication.SetAuthCookie(customer.Email, true); Orders.UpdateOrderStatus(order.OrderID, (int)OrderStatusEnum.PaymentError); } } catch (Exception ex) { MessageLabel.Text = "Transaction error: " + ex.Message; } }