protected void ibtnPayPalExpressCheckout_Click(object sender, ImageClickEventArgs e)
        {
            UpdateProductQuantities();
            UpdateCheckoutSession();

            OrderController orderController = new OrderController(StoreContext);
            Order           pendingOrder    = orderController.CreateOrder(checkoutOrderInfo, OrderStatusName.PendingOffsite);

            PayPalExpressCheckoutPaymentProvider payPalExpressCheckout = new PayPalExpressCheckoutPaymentProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalExpressCheckout));
            string cancelUrl = StoreUrls.Cart();
            string returnUrl = StoreUrls.CheckoutReview();
            string token     = payPalExpressCheckout.SetExpressCheckoutAndGetToken(pendingOrder, cancelUrl, returnUrl);


            if (!string.IsNullOrEmpty(token))
            {
                string payPalUrl = payPalExpressCheckout.GetExpressCheckoutUrl(token);

                Response.Redirect(payPalUrl);
            }
            else
            {
                // ERROR
                throw new ApplicationException("PayPal Express Token is Null/Empty!");
            }
        }
        protected void btnReviewOrder_Click(object sender, EventArgs e)
        {
            // user-selected payment method (credit card or PayPal)
            string userSelectedPaymentMethod = Request.Form["paymentMethod"] ?? "";

            if (userSelectedPaymentMethod == "payLater")
            {
                checkoutOrderInfo.PaymentProvider = StoreContext.CurrentStore.GetOnsitePaymentProviders().Where(p => p == PaymentProviderName.PayLater).First();
                if (checkoutOrderInfo.PaymentProvider == PaymentProviderName.UNKNOWN)
                {
                    throw new ApplicationException("Unable to determine PaymentProvider for CheckoutOrderInfo!");
                }
                UpdateCheckoutSession(checkoutOrderInfo);

                Response.Redirect(StoreUrls.CheckoutReview());
            }
            else if (userSelectedPaymentMethod == "payPalExpressCheckout")
            {
                OrderController orderController = new OrderController(StoreContext);
                Order           pendingOrder    = orderController.CreateOrder(checkoutOrderInfo, OrderStatusName.PendingOffsite);

                PayPalExpressCheckoutPaymentProvider payPalExpressCheckout = new PayPalExpressCheckoutPaymentProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalExpressCheckout));
                string cancelUrl = StoreUrls.Cart();
                string returnUrl = StoreUrls.CheckoutReview();
                string token     = payPalExpressCheckout.SetExpressCheckoutAndGetToken(pendingOrder, cancelUrl, returnUrl);

                if (!string.IsNullOrEmpty(token))
                {
                    //Session[SessionKeys.CheckoutOrderInfo] = checkoutOrderInfo;
                    //string payPalUrl = string.Format("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}", token);

                    string payPalUrl = payPalExpressCheckout.GetExpressCheckoutUrl(token);

                    Response.Redirect(payPalUrl);
                }
                else
                {
                    // ERROR
                    throw new ApplicationException("PayPal Express Token is Null/Empty!");
                }
            }
            else if (userSelectedPaymentMethod == "creditCard")
            {
                checkoutOrderInfo.PaymentProvider = StoreContext.CurrentStore.GetOnsitePaymentProviders().Where(p => p != PaymentProviderName.PayLater).First();
                if (checkoutOrderInfo.PaymentProvider == PaymentProviderName.UNKNOWN)
                {
                    throw new ApplicationException("Unable to determine PaymentProvider for CheckoutOrderInfo!");
                }

                //---- Credit Card Info
                CreditCardInfo creditCard = new CreditCardInfo()
                {
                    CardType     = WA.Enum <CreditCardType> .TryParseOrDefault(ddlCCType.SelectedValue, CreditCardType.UNKNOWN),
                    CardNumber   = txtCCNumber.Text,
                    ExpireMonth  = WA.Parser.ToShort(ddlCCExpireMonth.SelectedValue),
                    ExpireYear   = WA.Parser.ToShort(ddlCCExpireYear.SelectedValue),
                    NameOnCard   = txtCCNameOnCard.Text,
                    SecurityCode = txtCCSecurityCode.Text.Trim()
                };
                checkoutOrderInfo.CreditCard = creditCard;

                UpdateCheckoutSession(checkoutOrderInfo);

                bool doRedirect = true;
                if (checkoutOrderInfo.Total > 0)
                {
                    CreditCardInfoValidator validator = new CreditCardInfoValidator();
                    ValidationResult        results   = validator.Validate(checkoutOrderInfo.CreditCard);
                    if (!results.IsValid && results.Errors.Count > 0)
                    {
                        doRedirect = false;

                        msgFlash.InnerHtml = "<ul>" + results.Errors.ToList().ConvertAll(err => "<li>" + err.ErrorMessage + "</li>").ToDelimitedString(" ") + "</ul>";
                        msgFlash.Visible   = true;
                    }
                }

                if (doRedirect)
                {
                    Response.Redirect(StoreUrls.CheckoutReview());
                }
            }
            else
            {
                throw new ApplicationException("Unable to determine PaymentProvider for CheckoutOrderInfo!");
            }
        }