protected void SelectBillingAddress(Address billingAddress)
        {
            if (billingAddress == null)
            {
                //set default billing address
                NopContext.Current.User.BillingAddressId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);
                var args1 = new CheckoutStepEventArgs() { BillingAddressSelected = true };
                OnCheckoutStepChanged(args1);

                return;
            }

            if (billingAddress.AddressId == 0)
            {
                //check if address already exists
                var billingAddress2 = NopContext.Current.User.BillingAddresses.FindAddress(billingAddress.FirstName,
                     billingAddress.LastName, billingAddress.PhoneNumber, billingAddress.Email,
                     billingAddress.FaxNumber, billingAddress.Company,
                     billingAddress.Address1, billingAddress.Address2,
                     billingAddress.City, billingAddress.StateProvinceId, billingAddress.ZipPostalCode,
                     billingAddress.CountryId);

                if (billingAddress2 != null)
                {
                    billingAddress = billingAddress2;
                }
                else
                {
                    billingAddress.CustomerId = NopContext.Current.User.CustomerId;
                    billingAddress.IsBillingAddress = true;
                    billingAddress.CreatedOn = DateTime.UtcNow;
                    billingAddress.UpdatedOn = DateTime.UtcNow;

                    this.CustomerService.InsertAddress(billingAddress);
                }
            }
            //set default billing address
            NopContext.Current.User.BillingAddressId = billingAddress.AddressId;
            this.CustomerService.UpdateCustomer(NopContext.Current.User);
            var args2 = new CheckoutStepEventArgs() { BillingAddressSelected = true };
            OnCheckoutStepChanged(args2);
            //if (!this.OnePageCheckout)
            //    Response.Redirect("~/checkoutshippingmethod.aspx");
        }
 protected virtual void OnCheckoutStepChanged(CheckoutStepEventArgs e)
 {
     if (handler != null)
     {
         handler(this, e);
     }
 }
        protected void SelectAddress(Address shippingAddress)
        {
            if (shippingAddress == null)
            {
                //set default shipping address
                NopContext.Current.User.ShippingAddressId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);

                var args1 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
                OnCheckoutStepChanged(args1);

                return;
            }

            if (shippingAddress.AddressId == 0)
            {
                //check if address already exists
                var shippingAddress2 = NopContext.Current.User.ShippingAddresses.FindAddress(shippingAddress.FirstName,
                    shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                    shippingAddress.FaxNumber, shippingAddress.Company,
                    shippingAddress.Address1, shippingAddress.Address2,
                    shippingAddress.City, shippingAddress.StateProvinceId, shippingAddress.ZipPostalCode,
                    shippingAddress.CountryId);

                if (shippingAddress2 != null)
                {
                    shippingAddress = shippingAddress2;
                }
                else
                {
                    shippingAddress.CustomerId = NopContext.Current.User.CustomerId;
                    shippingAddress.IsBillingAddress = false;
                    shippingAddress.CreatedOn = DateTime.UtcNow;
                    shippingAddress.UpdatedOn = DateTime.UtcNow;

                    this.CustomerService.InsertAddress(shippingAddress);
                }
            }

            //set default shipping address
            NopContext.Current.User.ShippingAddressId = shippingAddress.AddressId;
            this.CustomerService.UpdateCustomer(NopContext.Current.User);

            var args2 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
            OnCheckoutStepChanged(args2);
        }
        public void ExecutePayStatus(string paykey, string strmaxAmount)
        {
            StringBuilder dataToSend = new StringBuilder();
            string strRequest = null;
            strRequest = strRequest + "requestEnvelope.errorLanguage=" + NopContext.Current.WorkingLanguage.LanguageCulture;
            strRequest = strRequest + "&requestEnvelope.detailLevel=ReturnAll";
            strRequest = strRequest + "&payKey=" + paykey;
            strRequest = strRequest + "&returnUrl=" + ConfigurationManager.AppSettings["returnUrl"];// "https://localhost:8091/SewbieDemo/PaypalAPRedirect.aspx";
            dataToSend.Append(strRequest);
            string Execute_strEndpointURL = ConfigurationManager.AppSettings["ExecuteDetails_strEndpointURL"];
            try
            {
                string strResponse = this.GetResponce(dataToSend, Execute_strEndpointURL);
                string[] strSplited = strResponse.Split('&');
                string strPayKey = null;
                string strTmp = strSplited[1];
                strTmp = strTmp.Substring(21, 7);
                if (strTmp == "Success")
                {
                    strPayKey = strSplited[4];
                    strPayKey = strPayKey.Substring(7, 20);
                    int j = 0;
                    string strTransactionIds = "";
                    string strStatus = "";
                    for (int i = 0; i < strSplited.Length; i++)
                    {
                        if (strSplited[i].Contains("paymentInfoList.paymentInfo(" + j.ToString() + ").senderTransactionId="))
                        {
                            if (string.IsNullOrEmpty(strTransactionIds))
                                strTransactionIds = strSplited[i].Split('=')[1].ToString();
                            else
                                strTransactionIds += "," + strSplited[i].Split('=')[1].ToString();
                            j++;
                        }
                        if (strSplited[i].Contains("status="))
                            strStatus = strSplited[i].Split('=')[1].ToString();
                    }
                    if (strStatus == "CREATED")
                    {
                        Response.Redirect(ConfigurationManager.AppSettings["returnUrl"] + strmaxAmount + "&strTransactionIds=" + strTransactionIds + "&strStatus=" + strStatus);
                    }
                    var paymentInfo = this.PaymentInfo;
                    paymentInfo = new BusinessLogic.Payment.PaymentInfo();
                    paymentInfo.BillingAddress = NopContext.Current.User.BillingAddress;
                    paymentInfo.ShippingAddress = NopContext.Current.User.ShippingAddress;
                    paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                    paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;
                    paymentInfo.PaymentMethodId = 43;
                    int orderId = 0;

                    string result = this.OrderService.PlaceOrder(paymentInfo, NopContext.Current.User, out orderId);

                    this.PaymentInfo = null;
                    var order = this.OrderService.GetOrderById(orderId);

                    if (txtNoteToSeller.Value.Trim().Length > 0)
                    {
                        OrderService.InsertOrderNote(orderId, txtNoteToSeller.Value.Trim(), DateTime.Now);
                    }

                    if (!String.IsNullOrEmpty(result))
                    {
                        lConfirmOrderError.Text = Server.HtmlEncode(result);
                        return;
                    }
                    else
                    {
                        // hidPaypalURL.Value = this.PaymentService.PostProcessPayment(order);
                    }

                    var args2 = new CheckoutStepEventArgs() { OrderConfirmed = true };
                    if (hidPaypalURL.Value != String.Empty)
                    {
                        //redirect via javascript, directly into the frame.
                        //Response.Redirect(hidPaypalURL.Value, false);
                    }
                    else
                    {
                        OnCheckoutStepChanged(args2);
                    }

                    Response.Redirect(ConfigurationManager.AppSettings["returnUrl"] + strmaxAmount + "&strTransactionIds=" + strTransactionIds + "&strStatus=" + strStatus);
                }
            }
            catch (Exception ex)
            {
                Response.Redirect(ConfigurationManager.AppSettings["returnUrl"] + strmaxAmount + "&strStatus=Failed" + "&strTransactionIds=");
            }
        }
        public void BindShippingInfoData()
        {
            bool shoppingCartRequiresShipping = this.ShippingService.ShoppingCartRequiresShipping(Cart);
            if (!shoppingCartRequiresShipping)
            {
                NopContext.Current.User.LastShippingOption = null;
                var args1 = new CheckoutStepEventArgs() { ShippingMethodSelected = true };
                OnCheckoutStepChanged(args1);
                //if (!this.OnePageCheckout)
                //    Response.Redirect("~/checkoutpaymentmethod.aspx");
            }
            else
            {
                string error = string.Empty;
                Address address = NopContext.Current.User.ShippingAddress;
                var shippingOptions = this.ShippingService.GetShippingOptions(Cart, NopContext.Current.User, address, ref error);
                if (!String.IsNullOrEmpty(error))
                {
                    this.LogService.InsertLog(LogTypeEnum.ShippingError, error, error);
                    phSelectShippingMethod.Visible = false;
                    lShippingMethodsError.Text = Server.HtmlEncode(error);
                }
                else
                {
                    if (shippingOptions.Count > 0)
                    {
                        phSelectShippingMethod.Visible = true;
                        dlShippingOptions.DataSource = shippingOptions;
                        dlShippingOptions.DataBind();

                        //select a default shipping option
                        if (dlShippingOptions.Items.Count > 0)
                        {
                            if (NopContext.Current.User != null &&
                                NopContext.Current.User.LastShippingOption != null)
                            {
                                //already selected shipping option
                                this.SelectedShippingOption = NopContext.Current.User.LastShippingOption;
                            }
                            else
                            {
                                //otherwise, the first shipping option
                                var tmp1 = dlShippingOptions.Items[0];
                                var rdShippingOption = tmp1.FindControl("rdShippingOption") as RadioButton;
                                if (rdShippingOption != null)
                                {
                                    rdShippingOption.Checked = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        phSelectShippingMethod.Visible = false;
                        lShippingMethodsError.Text = GetLocaleResourceString("Checkout.ShippingIsNotAllowed");
                    }
                }
            }
        }
 void rdShippingOption_CheckedChanged(object sender, EventArgs e)
 {
     var shippingOption = this.SelectedShippingOption;
     if (shippingOption != null)
     {
         NopContext.Current.User.LastShippingOption = shippingOption;
         var args1 = new CheckoutStepEventArgs() { ShippingMethodSelected = true };
         OnCheckoutStepChanged(args1);
         NopSolutions.NopCommerce.Controls.GlobalRadioButton rdShippingOption = new Controls.GlobalRadioButton();
         rdShippingOption.CheckedChanged += new EventHandler(rdShippingOption_CheckedChanged);
     }
 }
        protected void dlShippingOptions_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                var shippingOption = this.SelectedShippingOption;
                if (shippingOption != null)
                {
                    NopContext.Current.User.LastShippingOption = shippingOption;
                    var args1 = new CheckoutStepEventArgs() { ShippingMethodSelected = true };
                    OnCheckoutStepChanged(args1);

                }
            }
        }
 protected void ctrlCheckoutShippingMethod_CheckoutStepChanged(object sender, CheckoutStepEventArgs e)
 {
     if (e.ShippingMethodSelected)
     {
         // ctrlCheckoutShippingMethod.BindData();
     }
 }