示例#1
0
        public IActionResult EditPickupPoint(PickupPointModel model, bool continueEditing)
        {
            var pickupPoint = _shippingService.GetPickupPointById(model.Id);

            if (pickupPoint == null)
            {
                //No pickup point found with the specified id
                return(RedirectToAction("PickupPoints"));
            }

            if (ModelState.IsValid)
            {
                var address = new Core.Domain.Common.Address {
                    CreatedOnUtc = DateTime.UtcNow
                };
                address             = model.Address.ToEntity(address);
                pickupPoint         = model.ToEntity(pickupPoint);
                pickupPoint.Address = address;
                _shippingService.UpdatePickupPoint(pickupPoint);
                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Updated"));
                return(continueEditing ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id }) : RedirectToAction("PickupPoints"));
            }
            //If we got this far, something failed, redisplay form
            PreparePickupPointModel(model);
            return(View(model));
        }
示例#2
0
 public virtual Address PrepareAddress(Core.Domain.Common.Address address)
 {
     return(new Address
     {
         ContactName = String.Format("{0} {1}", address.FirstName, address.LastName),
         City = address.City,
         Country = address.Country?.Name,
         Description = address.Address1,
         ZipCode = address.ZipPostalCode
     });
 }
 /// <summary>
 /// Convert a NopCommere address to a Stripe API address
 /// </summary>
 /// <param name="nopAddress"></param>
 /// <returns></returns>
 private AddressOptions MapNopAddressToStripe(Core.Domain.Common.Address nopAddress)
 {
     return(new AddressOptions
     {
         Line1 = nopAddress.Address1,
         City = nopAddress.City,
         State = nopAddress.StateProvince.Abbreviation,
         PostalCode = nopAddress.ZipPostalCode,
         Country = nopAddress.Country.ThreeLetterIsoCode
     });
 }
        public virtual Address PrepareAddress(Core.Domain.Common.Address address)
        {
            var country = _countryService.GetCountryById(address.CountryId ?? 0);

            if (country == null)
            {
                throw new NopException("Billing address country not set");
            }

            return(new Address
            {
                ContactName = String.Format("{0} {1}", address.FirstName, address.LastName),
                City = address.City,
                Country = country.Name,
                Description = address.Address1,
                ZipCode = address.ZipPostalCode
            });
        }
示例#5
0
        private Guid AddUpdateAddressToNebimByCustomerCode(string customerCode, Core.Domain.Common.Address address, string addressType = null)
        {
            var nebimIntegrationProvider = LoadNebimIntegrationServiceBySystemName("Misc.Nebim");

            string type = address.IsEnterprise ? "2" : "1";
            //fatura basýmý için dandik çözüm
            // fatura adresi için 7, teslimat adresi için 6 nolu adres tipleri atanýr.
            //string type = addressType == "F" ? "7" : "6";

            string firstName = address.FirstName;
            string lastName  = address.LastName;

            if (address.IsEnterprise)//þirket adresi
            {
                if (!string.IsNullOrEmpty(address.Company))
                {
                    firstName = address.Company;
                    lastName  = string.Empty;
                }
            }
            string addressLine = address.Address1 + " " + address.Address2;
            string district    = address.City;
            string city        = address.StateProvince == null ? "" : this.GetAPICityCode(address.StateProvince.Id.ToString());
            string zipCode     = address.ZipPostalCode;
            string countryCode = address.Country == null ? "TR" : address.Country.TwoLetterIsoCode.ToUpper();
            string taxNumber   = address.TaxNo;
            string taxOffice   = address.TaxOffice;

            try
            {
                //shipping address
                return(nebimIntegrationProvider.AddUpdateCustomerAddressToNebimByCustomerCode(customerCode,
                                                                                              type, firstName, lastName, addressLine,
                                                                                              district, city, zipCode,
                                                                                              countryCode, taxNumber, taxOffice));
            }
            catch (Exception ex)
            {
                throw new Exception("AddUpdateAddressToNebimByCustomerCode: customerId='" + customerCode + ". Inner message: " + ex.Message, ex);
            }
        }
        private void ProcessNewOrderNotification(string xmlData)
        {
            try
            {
                var newOrderNotification = (NewOrderNotification)EncodeHelper.Deserialize(xmlData, typeof(NewOrderNotification));
                string googleOrderNumber = newOrderNotification.googleordernumber;

                XmlNode customerInfo = newOrderNotification.shoppingcart.merchantprivatedata.Any[0];
                int customerId = Convert.ToInt32(customerInfo.Attributes["CustomerID"].Value);
                //int customerLanguageId = Convert.ToInt32(customerInfo.Attributes["CustomerLanguageID"].Value);
                //int customerCurrencyId = Convert.ToInt32(customerInfo.Attributes["CustomerCurrencyID"].Value);
                var customer = _customerService.GetCustomerById(customerId);

                if (customer == null)
                {
                    LogMessage("Could not load a customer");
                    return;
                }

                var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

                _workContext.CurrentCustomer = customer;

                if (cart.Count == 0)
                {
                    LogMessage("Cart is empty");
                    return;
                }

                //validate cart
                foreach (var sci in cart)
                {
                    bool ok = false;
                    foreach (Item item in newOrderNotification.shoppingcart.items)
                    {
                        if (!String.IsNullOrEmpty(item.merchantitemid))
                        {
                            if ((Convert.ToInt32(item.merchantitemid) == sci.Id) && (item.quantity == sci.Quantity))
                            {
                                ok = true;
                                break;
                            }
                        }
                    }

                    if (!ok)
                    {
                        LogMessage(string.Format("Shopping Cart item has been changed. {0}. {1}", sci.Id, sci.Quantity));
                        return;
                    }
                }

                string[] billingFullname = newOrderNotification.buyerbillingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string billingFirstName = billingFullname[0];
                string billingLastName = string.Empty;
                if (billingFullname.Length > 1)
                    billingLastName = billingFullname[1];
                string billingEmail = newOrderNotification.buyerbillingaddress.email.Trim();
                string billingAddress1 = newOrderNotification.buyerbillingaddress.address1.Trim();
                string billingAddress2 = newOrderNotification.buyerbillingaddress.address2.Trim();
                string billingPhoneNumber = newOrderNotification.buyerbillingaddress.phone.Trim();
                string billingCity = newOrderNotification.buyerbillingaddress.city.Trim();
                int? billingStateProvinceId = null;
                var billingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyerbillingaddress.region.Trim());
                if (billingStateProvince != null)
                    billingStateProvinceId = billingStateProvince.Id;
                string billingZipPostalCode = newOrderNotification.buyerbillingaddress.postalcode.Trim();
                int? billingCountryId = null;
                var billingCountry = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyerbillingaddress.countrycode.Trim());
                if (billingCountry != null)
                    billingCountryId = billingCountry.Id;

                var billingAddress = customer.Addresses.ToList().FindAddress(
                    billingFirstName, billingLastName, billingPhoneNumber,
                    billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                    billingStateProvinceId, billingZipPostalCode, billingCountryId);

                if (billingAddress == null)
                {
                    billingAddress = new Core.Domain.Common.Address()
                    {
                        FirstName = billingFirstName,
                        LastName = billingLastName,
                        PhoneNumber = billingPhoneNumber,
                        Email = billingEmail,
                        Address1 = billingAddress1,
                        Address2 = billingAddress2,
                        City = billingCity,
                        StateProvinceId = billingStateProvinceId,
                        ZipPostalCode = billingZipPostalCode,
                        CountryId = billingCountryId,
                        CreatedOnUtc = DateTime.UtcNow,
                    };
                    customer.Addresses.Add(billingAddress);
                }
                //set default billing address
                customer.BillingAddress = billingAddress;
                _customerService.UpdateCustomer(customer);

                _genericAttributeService.SaveAttribute<ShippingOption>(customer, SystemCustomerAttributeNames.LastShippingOption, null);

                bool shoppingCartRequiresShipping = cart.RequiresShipping();
                if (shoppingCartRequiresShipping)
                {
                    string[] shippingFullname = newOrderNotification.buyershippingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    string shippingFirstName = shippingFullname[0];
                    string shippingLastName = string.Empty;
                    if (shippingFullname.Length > 1)
                        shippingLastName = shippingFullname[1];
                    string shippingEmail = newOrderNotification.buyershippingaddress.email.Trim();
                    string shippingAddress1 = newOrderNotification.buyershippingaddress.address1.Trim();
                    string shippingAddress2 = newOrderNotification.buyershippingaddress.address2.Trim();
                    string shippingPhoneNumber = newOrderNotification.buyershippingaddress.phone.Trim();
                    string shippingCity = newOrderNotification.buyershippingaddress.city.Trim();
                    int? shippingStateProvinceId = null;
                    var shippingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyershippingaddress.region.Trim());
                    if (shippingStateProvince != null)
                        shippingStateProvinceId = shippingStateProvince.Id;
                    int? shippingCountryId = null;
                    string shippingZipPostalCode = newOrderNotification.buyershippingaddress.postalcode.Trim();
                    var shippingCountry = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyershippingaddress.countrycode.Trim());
                    if (shippingCountry != null)
                        shippingCountryId = shippingCountry.Id;

                    var shippingAddress = customer.Addresses.ToList().FindAddress(
                        shippingFirstName, shippingLastName, shippingPhoneNumber,
                        shippingEmail, string.Empty, string.Empty,
                        shippingAddress1, shippingAddress2, shippingCity,
                        shippingStateProvinceId, shippingZipPostalCode, shippingCountryId);
                    if (shippingAddress == null)
                    {
                        shippingAddress = new Core.Domain.Common.Address()
                        {
                            FirstName = shippingFirstName,
                            LastName = shippingLastName,
                            PhoneNumber = shippingPhoneNumber,
                            Email = shippingEmail,
                            Address1 = shippingAddress1,
                            Address2 = shippingAddress2,
                            City = shippingCity,
                            StateProvinceId = shippingStateProvinceId,
                            ZipPostalCode = shippingZipPostalCode,
                            CountryId = shippingCountryId,
                            CreatedOnUtc = DateTime.UtcNow,
                        };
                        customer.Addresses.Add(shippingAddress);
                    }
                    //set default shipping address
                    customer.ShippingAddress = shippingAddress;
                    _customerService.UpdateCustomer(customer);

                    if (newOrderNotification.orderadjustment != null &&
                        newOrderNotification.orderadjustment.shipping != null &&
                        newOrderNotification.orderadjustment.shipping.Item != null)
                    {
                        var shippingMethod = (FlatRateShippingAdjustment)newOrderNotification.orderadjustment.shipping.Item;
                        var shippingOption = new ShippingOption();
                        shippingOption.Name = shippingMethod.shippingname;
                        shippingOption.Rate = shippingMethod.shippingcost.Value;
                        _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastShippingOption, shippingOption);
                    }
                }

                //customer.LastCalculatedTax = decimal.Zero;

                var paymentInfo = new ProcessPaymentRequest()
                {
                    PaymentMethodSystemName = "Payments.GoogleCheckout",
                    CustomerId = customer.Id,
                    GoogleOrderNumber = googleOrderNumber
                };
                //TODO set customer language and currency
                //paymentInfo.CustomerLanguage = IoC.Resolve<ILanguageService>().GetLanguageById(CustomerLanguageID);
                //paymentInfo.CustomerCurrency = IoC.Resolve<ICurrencyService>().GetCurrencyById(CustomerCurrencyID);
                var result = _orderProcessingService.PlaceOrder(paymentInfo);
                if (!result.Success)
                {
                    LogMessage("new-order-notification received. CreateOrder() error: Order Number " + googleOrderNumber + ". " + result);
                    return;
                }

                var order = result.PlacedOrder;
                if (order != null)
                {
                    LogMessage("new-order-notification received and saved: Order Number " + order.Id);
                }
            }
            catch (Exception exc)
            {
                LogMessage("processNewOrderNotification Exception: " + exc.Message + ": " + exc.StackTrace);
            }
        }
示例#7
0
        public ProcessPaymentRequest SetCheckoutDetails(ProcessPaymentRequest processPaymentRequest, GetExpressCheckoutDetailsResponseDetailsType checkoutDetails)
        {
            int customerId = Convert.ToInt32(Services.WorkContext.CurrentCustomer.Id.ToString());
            var customer   = _customerService.GetCustomerById(customerId);
            var settings   = Services.Settings.LoadSetting <PayPalExpressPaymentSettings>(Services.StoreContext.CurrentStore.Id);

            Services.WorkContext.CurrentCustomer = customer;

            //var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            var cart = Services.WorkContext.CurrentCustomer.GetCartItems(ShoppingCartType.ShoppingCart, Services.StoreContext.CurrentStore.Id);

            // get/update billing address
            string billingFirstName       = checkoutDetails.PayerInfo.PayerName.FirstName;
            string billingLastName        = checkoutDetails.PayerInfo.PayerName.LastName;
            string billingEmail           = checkoutDetails.PayerInfo.Payer;
            string billingAddress1        = checkoutDetails.PayerInfo.Address.Street1;
            string billingAddress2        = checkoutDetails.PayerInfo.Address.Street2;
            string billingPhoneNumber     = checkoutDetails.PayerInfo.ContactPhone;
            string billingCity            = checkoutDetails.PayerInfo.Address.CityName;
            int?   billingStateProvinceId = null;
            var    billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince);

            if (billingStateProvince != null)
            {
                billingStateProvinceId = billingStateProvince.Id;
            }
            string billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode;
            int?   billingCountryId     = null;
            var    billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString());

            if (billingCountry != null)
            {
                billingCountryId = billingCountry.Id;
            }

            var billingAddress = customer.Addresses.FindAddress(
                billingFirstName, billingLastName, billingPhoneNumber,
                billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                billingStateProvinceId, billingZipPostalCode, billingCountryId);

            if (billingAddress == null)
            {
                billingAddress = new Core.Domain.Common.Address()
                {
                    FirstName       = billingFirstName,
                    LastName        = billingLastName,
                    PhoneNumber     = billingPhoneNumber,
                    Email           = billingEmail,
                    FaxNumber       = string.Empty,
                    Company         = string.Empty,
                    Address1        = billingAddress1,
                    Address2        = billingAddress2,
                    City            = billingCity,
                    StateProvinceId = billingStateProvinceId,
                    ZipPostalCode   = billingZipPostalCode,
                    CountryId       = billingCountryId,
                    CreatedOnUtc    = DateTime.UtcNow,
                };
                customer.Addresses.Add(billingAddress);
            }

            //set default billing address
            customer.BillingAddress = billingAddress;
            _customerService.UpdateCustomer(customer);

            var genericAttributeService = EngineContext.Current.Resolve <IGenericAttributeService>();

            genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null);

            bool shoppingCartRequiresShipping = cart.RequiresShipping();

            if (shoppingCartRequiresShipping)
            {
                var      paymentDetails    = checkoutDetails.PaymentDetails.FirstOrDefault();
                string[] shippingFullname  = paymentDetails.ShipToAddress.Name.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string   shippingFirstName = shippingFullname[0];
                string   shippingLastName  = string.Empty;
                if (shippingFullname.Length > 1)
                {
                    shippingLastName = shippingFullname[1];
                }
                string shippingEmail           = checkoutDetails.PayerInfo.Payer;
                string shippingAddress1        = paymentDetails.ShipToAddress.Street1;
                string shippingAddress2        = paymentDetails.ShipToAddress.Street2;
                string shippingPhoneNumber     = paymentDetails.ShipToAddress.Phone;
                string shippingCity            = paymentDetails.ShipToAddress.CityName;
                int?   shippingStateProvinceId = null;
                var    shippingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(paymentDetails.ShipToAddress.StateOrProvince);
                if (shippingStateProvince != null)
                {
                    shippingStateProvinceId = shippingStateProvince.Id;
                }
                int?   shippingCountryId     = null;
                string shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode;
                var    shippingCountry       = _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString());
                if (shippingCountry != null)
                {
                    shippingCountryId = shippingCountry.Id;
                }

                var shippingAddress = customer.Addresses.FindAddress(
                    shippingFirstName, shippingLastName, shippingPhoneNumber,
                    shippingEmail, string.Empty, string.Empty,
                    shippingAddress1, shippingAddress2, shippingCity,
                    shippingStateProvinceId, shippingZipPostalCode, shippingCountryId);

                if (shippingAddress == null)
                {
                    shippingAddress = new Core.Domain.Common.Address()
                    {
                        FirstName       = shippingFirstName,
                        LastName        = shippingLastName,
                        PhoneNumber     = shippingPhoneNumber,
                        Email           = shippingEmail,
                        FaxNumber       = string.Empty,
                        Company         = string.Empty,
                        Address1        = shippingAddress1,
                        Address2        = shippingAddress2,
                        City            = shippingCity,
                        StateProvinceId = shippingStateProvinceId,
                        ZipPostalCode   = shippingZipPostalCode,
                        CountryId       = shippingCountryId,
                        CreatedOnUtc    = DateTime.UtcNow,
                    };
                    customer.Addresses.Add(shippingAddress);
                }

                customer.ShippingAddress = shippingAddress;
                _customerService.UpdateCustomer(customer);
            }

            bool isShippingSet = false;
            GetShippingOptionResponse getShippingOptionResponse = _shippingService.GetShippingOptions(cart, customer.ShippingAddress);

            if (checkoutDetails.UserSelectedOptions != null)
            {
                if (getShippingOptionResponse.Success && getShippingOptionResponse.ShippingOptions.Count > 0)
                {
                    foreach (var shippingOption in getShippingOptionResponse.ShippingOptions)
                    {
                        if (checkoutDetails.UserSelectedOptions.ShippingOptionName.Contains(shippingOption.Name) &&
                            checkoutDetails.UserSelectedOptions.ShippingOptionName.Contains(shippingOption.Description))
                        {
                            _genericAttributeService.SaveAttribute(Services.WorkContext.CurrentCustomer, SystemCustomerAttributeNames.SelectedShippingOption, shippingOption);
                            isShippingSet = true;
                            break;
                        }
                    }
                }

                if (!isShippingSet)
                {
                    var shippingOption = new ShippingOption();
                    shippingOption.Name = checkoutDetails.UserSelectedOptions.ShippingOptionName;
                    decimal shippingPrice = settings.DefaultShippingPrice;
                    decimal.TryParse(checkoutDetails.UserSelectedOptions.ShippingOptionAmount.Value, out shippingPrice);
                    shippingOption.Rate = shippingPrice;
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.SelectedShippingOption, shippingOption);
                }
            }

            processPaymentRequest.PaypalPayerId = checkoutDetails.PayerInfo.PayerID;


            return(processPaymentRequest);
        }
        private void ProcessNewOrderNotification(string xmlData)
        {
            try
            {
                var    newOrderNotification = (NewOrderNotification)EncodeHelper.Deserialize(xmlData, typeof(NewOrderNotification));
                string googleOrderNumber    = newOrderNotification.googleordernumber;

                XmlNode customerInfo       = newOrderNotification.shoppingcart.merchantprivatedata.Any[0];
                int     customerId         = Convert.ToInt32(customerInfo.Attributes["CustomerID"].Value);
                int     customerLanguageId = Convert.ToInt32(customerInfo.Attributes["CustomerLanguageID"].Value);
                int     customerCurrencyId = Convert.ToInt32(customerInfo.Attributes["CustomerCurrencyID"].Value);
                var     customer           = _customerService.GetCustomerById(customerId);

                if (customer == null)
                {
                    LogMessage("Could not load a customer");
                    return;
                }

                var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

                _workContext.CurrentCustomer = customer;

                if (cart.Count == 0)
                {
                    LogMessage("Cart is empty");
                    return;
                }

                //validate cart
                foreach (var sci in cart)
                {
                    bool ok = false;
                    foreach (Item item in newOrderNotification.shoppingcart.items)
                    {
                        if (!String.IsNullOrEmpty(item.merchantitemid))
                        {
                            if ((Convert.ToInt32(item.merchantitemid) == sci.Id) && (item.quantity == sci.Quantity))
                            {
                                ok = true;
                                break;
                            }
                        }
                    }

                    if (!ok)
                    {
                        LogMessage(string.Format("Shopping Cart item has been changed. {0}. {1}", sci.Id, sci.Quantity));
                        return;
                    }
                }


                string[] billingFullname  = newOrderNotification.buyerbillingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string   billingFirstName = billingFullname[0];
                string   billingLastName  = string.Empty;
                if (billingFullname.Length > 1)
                {
                    billingLastName = billingFullname[1];
                }
                string billingEmail           = newOrderNotification.buyerbillingaddress.email.Trim();
                string billingAddress1        = newOrderNotification.buyerbillingaddress.address1.Trim();
                string billingAddress2        = newOrderNotification.buyerbillingaddress.address2.Trim();
                string billingPhoneNumber     = newOrderNotification.buyerbillingaddress.phone.Trim();
                string billingCity            = newOrderNotification.buyerbillingaddress.city.Trim();
                int?   billingStateProvinceId = null;
                var    billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyerbillingaddress.region.Trim());
                if (billingStateProvince != null)
                {
                    billingStateProvinceId = billingStateProvince.Id;
                }
                string billingZipPostalCode = newOrderNotification.buyerbillingaddress.postalcode.Trim();
                int?   billingCountryId     = null;
                var    billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyerbillingaddress.countrycode.Trim());
                if (billingCountry != null)
                {
                    billingCountryId = billingCountry.Id;
                }

                var billingAddress = customer.Addresses.ToList().FindAddress(
                    billingFirstName, billingLastName, billingPhoneNumber,
                    billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                    billingStateProvinceId, billingZipPostalCode, billingCountryId);

                if (billingAddress == null)
                {
                    billingAddress = new Core.Domain.Common.Address()
                    {
                        FirstName       = billingFirstName,
                        LastName        = billingLastName,
                        PhoneNumber     = billingPhoneNumber,
                        Email           = billingEmail,
                        Address1        = billingAddress1,
                        Address2        = billingAddress2,
                        City            = billingCity,
                        StateProvinceId = billingStateProvinceId,
                        ZipPostalCode   = billingZipPostalCode,
                        CountryId       = billingCountryId,
                        CreatedOnUtc    = DateTime.UtcNow,
                    };
                    customer.Addresses.Add(billingAddress);
                }
                //set default billing address
                customer.SetBillingAddress(billingAddress);
                _customerService.UpdateCustomer(customer);

                _customerService.SaveCustomerAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.LastShippingOption, null);

                bool shoppingCartRequiresShipping = cart.RequiresShipping();
                if (shoppingCartRequiresShipping)
                {
                    string[] shippingFullname  = newOrderNotification.buyershippingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    string   shippingFirstName = shippingFullname[0];
                    string   shippingLastName  = string.Empty;
                    if (shippingFullname.Length > 1)
                    {
                        shippingLastName = shippingFullname[1];
                    }
                    string shippingEmail           = newOrderNotification.buyershippingaddress.email.Trim();
                    string shippingAddress1        = newOrderNotification.buyershippingaddress.address1.Trim();
                    string shippingAddress2        = newOrderNotification.buyershippingaddress.address2.Trim();
                    string shippingPhoneNumber     = newOrderNotification.buyershippingaddress.phone.Trim();
                    string shippingCity            = newOrderNotification.buyershippingaddress.city.Trim();
                    int?   shippingStateProvinceId = null;
                    var    shippingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyershippingaddress.region.Trim());
                    if (shippingStateProvince != null)
                    {
                        shippingStateProvinceId = shippingStateProvince.Id;
                    }
                    int?   shippingCountryId     = null;
                    string shippingZipPostalCode = newOrderNotification.buyershippingaddress.postalcode.Trim();
                    var    shippingCountry       = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyershippingaddress.countrycode.Trim());
                    if (shippingCountry != null)
                    {
                        shippingCountryId = shippingCountry.Id;
                    }

                    var shippingAddress = customer.Addresses.ToList().FindAddress(
                        shippingFirstName, shippingLastName, shippingPhoneNumber,
                        shippingEmail, string.Empty, string.Empty,
                        shippingAddress1, shippingAddress2, shippingCity,
                        shippingStateProvinceId, shippingZipPostalCode, shippingCountryId);
                    if (shippingAddress == null)
                    {
                        shippingAddress = new Core.Domain.Common.Address()
                        {
                            FirstName       = shippingFirstName,
                            LastName        = shippingLastName,
                            PhoneNumber     = shippingPhoneNumber,
                            Email           = shippingEmail,
                            Address1        = shippingAddress1,
                            Address2        = shippingAddress2,
                            City            = shippingCity,
                            StateProvinceId = shippingStateProvinceId,
                            ZipPostalCode   = shippingZipPostalCode,
                            CountryId       = shippingCountryId,
                            CreatedOnUtc    = DateTime.UtcNow,
                        };
                        customer.Addresses.Add(shippingAddress);
                    }
                    //set default shipping address
                    customer.SetShippingAddress(shippingAddress);
                    _customerService.UpdateCustomer(customer);

                    if (newOrderNotification.orderadjustment != null &&
                        newOrderNotification.orderadjustment.shipping != null &&
                        newOrderNotification.orderadjustment.shipping.Item != null)
                    {
                        var shippingMethod = (FlatRateShippingAdjustment)newOrderNotification.orderadjustment.shipping.Item;
                        var shippingOption = new ShippingOption();
                        shippingOption.Name = shippingMethod.shippingname;
                        shippingOption.Rate = shippingMethod.shippingcost.Value;
                        _customerService.SaveCustomerAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.LastShippingOption, shippingOption);
                    }
                }

                //customer.LastCalculatedTax = decimal.Zero;

                var paymentInfo = new ProcessPaymentRequest()
                {
                    PaymentMethodSystemName = "Payments.GoogleCheckout",
                    Customer          = customer,
                    GoogleOrderNumber = googleOrderNumber
                };
                //TODO set customer language and currency
                //paymentInfo.CustomerLanguage = IoC.Resolve<ILanguageService>().GetLanguageById(CustomerLanguageID);
                //paymentInfo.CustomerCurrency = IoC.Resolve<ICurrencyService>().GetCurrencyById(CustomerCurrencyID);
                var result = _orderProcessingService.PlaceOrder(paymentInfo);
                if (!result.Success)
                {
                    LogMessage("new-order-notification received. CreateOrder() error: Order Number " + googleOrderNumber + ". " + result);
                    return;
                }

                var order = result.PlacedOrder;
                if (order != null)
                {
                    LogMessage("new-order-notification received and saved: Order Number " + order.Id);
                }
            }
            catch (Exception exc)
            {
                LogMessage("processNewOrderNotification Exception: " + exc.Message + ": " + exc.StackTrace);
            }
        }
        public ProcessPaymentRequest SetCheckoutDetails(GetExpressCheckoutDetailsResponseDetailsType checkoutDetails)
        {
            // get customer & cart
            //var customer = customer;
            int customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString());
            var customer   = _customerService.GetCustomerById(customerId);

            _workContext.CurrentCustomer = customer;

            var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

            // get/update billing address
            string billingFirstName   = checkoutDetails.PayerInfo.PayerName.FirstName;
            string billingLastName    = checkoutDetails.PayerInfo.PayerName.LastName;
            string billingEmail       = checkoutDetails.PayerInfo.Payer;
            string billingAddress1    = checkoutDetails.PayerInfo.Address.Street1;
            string billingAddress2    = checkoutDetails.PayerInfo.Address.Street2;
            string billingPhoneNumber = string.IsNullOrEmpty(checkoutDetails.PayerInfo.ContactPhone) ? checkoutDetails.ContactPhone : checkoutDetails.PayerInfo.ContactPhone;              //check if customer has entered the phone number, if not, get the contact phone number

            string billingCity            = checkoutDetails.PayerInfo.Address.CityName;
            int?   billingStateProvinceId = null;
            var    billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince);

            if (billingStateProvince != null)
            {
                billingStateProvinceId = billingStateProvince.Id;
            }
            string billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode;
            int?   billingCountryId     = null;
            var    billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString());

            if (billingCountry != null)
            {
                billingCountryId = billingCountry.Id;
            }

            var billingAddress = customer.Addresses.ToList().FindAddress(
                billingFirstName, billingLastName, billingPhoneNumber,
                billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                billingStateProvinceId, billingZipPostalCode, billingCountryId,
                //TODO process custom attributes
                null);

            if (billingAddress == null)
            {
                billingAddress = new Core.Domain.Common.Address()
                {
                    FirstName       = billingFirstName,
                    LastName        = billingLastName,
                    PhoneNumber     = billingPhoneNumber,
                    Email           = billingEmail,
                    FaxNumber       = string.Empty,
                    Company         = string.Empty,
                    Address1        = billingAddress1,
                    Address2        = billingAddress2,
                    City            = billingCity,
                    StateProvinceId = billingStateProvinceId,
                    ZipPostalCode   = billingZipPostalCode,
                    CountryId       = billingCountryId,
                    CreatedOnUtc    = DateTime.UtcNow,
                };
                customer.Addresses.Add(billingAddress);
            }

            //set default billing address
            customer.BillingAddress = billingAddress;
            _customerService.UpdateCustomer(customer);

            _genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null);

            bool shoppingCartRequiresShipping = cart.RequiresShipping();

            if (shoppingCartRequiresShipping)
            {
                var      paymentDetails   = checkoutDetails.PaymentDetails.FirstOrDefault();
                string[] shippingFullname = paymentDetails.ShipToAddress.Name.Trim()
                                            .Split(new char[] { ' ' }, 2,
                                                   StringSplitOptions.RemoveEmptyEntries);
                string shippingFirstName = shippingFullname[0];
                string shippingLastName  = string.Empty;
                if (shippingFullname.Length > 1)
                {
                    shippingLastName = shippingFullname[1];
                }
                string shippingEmail       = checkoutDetails.PayerInfo.Payer;
                string shippingAddress1    = paymentDetails.ShipToAddress.Street1;
                string shippingAddress2    = paymentDetails.ShipToAddress.Street2;
                string shippingPhoneNumber = string.IsNullOrEmpty(paymentDetails.ShipToAddress.Phone) ? checkoutDetails.ContactPhone : paymentDetails.ShipToAddress.Phone; //check if customer has entered the shipping phone, if not, get the contact phone number

                string shippingCity            = paymentDetails.ShipToAddress.CityName;
                int?   shippingStateProvinceId = null;
                var    shippingStateProvince   =
                    _stateProvinceService.GetStateProvinceByAbbreviation(
                        paymentDetails.ShipToAddress.StateOrProvince);
                if (shippingStateProvince != null)
                {
                    shippingStateProvinceId = shippingStateProvince.Id;
                }
                int?   shippingCountryId     = null;
                string shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode;
                var    shippingCountry       =
                    _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString());
                if (shippingCountry != null)
                {
                    shippingCountryId = shippingCountry.Id;
                }

                var shippingAddress = customer.Addresses.ToList().FindAddress(
                    shippingFirstName, shippingLastName, shippingPhoneNumber,
                    shippingEmail, string.Empty, string.Empty,
                    shippingAddress1, shippingAddress2, shippingCity,
                    shippingStateProvinceId, shippingZipPostalCode, shippingCountryId,
                    //TODO process custom attributes
                    null);

                if (shippingAddress == null)
                {
                    shippingAddress = new Core.Domain.Common.Address()
                    {
                        FirstName       = shippingFirstName,
                        LastName        = shippingLastName,
                        PhoneNumber     = shippingPhoneNumber,
                        Email           = shippingEmail,
                        FaxNumber       = string.Empty,
                        Company         = string.Empty,
                        Address1        = shippingAddress1,
                        Address2        = shippingAddress2,
                        City            = shippingCity,
                        StateProvinceId = shippingStateProvinceId,
                        ZipPostalCode   = shippingZipPostalCode,
                        CountryId       = shippingCountryId,
                        CreatedOnUtc    = DateTime.UtcNow,
                    };
                    customer.Addresses.Add(shippingAddress);
                }

                //set default shipping address
                customer.ShippingAddress = shippingAddress;
                _customerService.UpdateCustomer(customer);
            }

            var processPaymentRequest = new ProcessPaymentRequest {
                CustomerId = customerId
            };

            processPaymentRequest.CustomValues["PaypalToken"]   = checkoutDetails.Token;
            processPaymentRequest.CustomValues["PaypalPayerId"] = checkoutDetails.PayerInfo.PayerID;
            return(processPaymentRequest);
        }
示例#10
0
        public ProcessPaymentRequest SetCheckoutDetails(GetExpressCheckoutDetailsResponseDetailsType checkoutDetails)
        {
            // get customer & cart
            var customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString());
            var customer   = _customerService.GetCustomerById(customerId);

            _workContext.CurrentCustomer = customer;

            var cart = _shoppingCartService.GetShoppingCart(customer, ShoppingCartType.ShoppingCart).ToList();

            // get/update billing address
            var billingFirstName       = checkoutDetails.PayerInfo.PayerName.FirstName;
            var billingLastName        = checkoutDetails.PayerInfo.PayerName.LastName;
            var billingEmail           = checkoutDetails.PayerInfo.Payer;
            var billingAddress1        = checkoutDetails.PayerInfo.Address.Street1;
            var billingAddress2        = checkoutDetails.PayerInfo.Address.Street2;
            var billingPhoneNumber     = checkoutDetails.PayerInfo.ContactPhone;
            var billingCity            = checkoutDetails.PayerInfo.Address.CityName;
            int?billingStateProvinceId = null;
            var billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(checkoutDetails.PayerInfo.Address.StateOrProvince);

            if (billingStateProvince != null)
            {
                billingStateProvinceId = billingStateProvince.Id;
            }
            var billingZipPostalCode = checkoutDetails.PayerInfo.Address.PostalCode;
            int?billingCountryId     = null;
            var billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(checkoutDetails.PayerInfo.Address.Country.ToString());

            if (billingCountry != null)
            {
                billingCountryId = billingCountry.Id;
            }

            var billingAddress = _addressService.FindAddress(_customerService.GetAddressesByCustomerId(_workContext.CurrentCustomer.Id).ToList(),
                                                             billingFirstName, billingLastName, billingPhoneNumber,
                                                             billingEmail, string.Empty, string.Empty,
                                                             billingAddress1, billingAddress2, billingCity,
                                                             billingCountry?.Name, billingStateProvinceId, billingZipPostalCode,
                                                             billingCountryId, null); //TODO process custom attributes

            if (billingAddress == null)
            {
                billingAddress = new Core.Domain.Common.Address
                {
                    FirstName       = billingFirstName,
                    LastName        = billingLastName,
                    PhoneNumber     = billingPhoneNumber,
                    Email           = billingEmail,
                    FaxNumber       = string.Empty,
                    Company         = string.Empty,
                    Address1        = billingAddress1,
                    Address2        = billingAddress2,
                    City            = billingCity,
                    StateProvinceId = billingStateProvinceId,
                    ZipPostalCode   = billingZipPostalCode,
                    CountryId       = billingCountryId,
                    CreatedOnUtc    = DateTime.UtcNow
                };

                _addressService.InsertAddress(billingAddress);
                _customerService.InsertCustomerAddress(customer, billingAddress);
            }

            //set default billing address
            customer.BillingAddressId = billingAddress.Id;
            _customerService.UpdateCustomer(customer);

            _genericAttributeService.SaveAttribute <ShippingOption>(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, null, customer.RegisteredInStoreId);

            var shoppingCartRequiresShipping = _shoppingCartService.ShoppingCartRequiresShipping(cart);

            if (shoppingCartRequiresShipping)
            {
                var paymentDetails   = checkoutDetails.PaymentDetails.FirstOrDefault() ?? new PaymentDetailsType();
                var shippingFullname = paymentDetails.ShipToAddress.Name.Trim()
                                       .Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                var shippingFirstName = shippingFullname[0];
                var shippingLastName  = string.Empty;
                if (shippingFullname.Length > 1)
                {
                    shippingLastName = shippingFullname[1];
                }
                var shippingEmail           = checkoutDetails.PayerInfo.Payer;
                var shippingAddress1        = paymentDetails.ShipToAddress.Street1;
                var shippingAddress2        = paymentDetails.ShipToAddress.Street2;
                var shippingPhoneNumber     = paymentDetails.ShipToAddress.Phone;
                var shippingCity            = paymentDetails.ShipToAddress.CityName;
                int?shippingStateProvinceId = null;
                var shippingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(paymentDetails.ShipToAddress.StateOrProvince);
                if (shippingStateProvince != null)
                {
                    shippingStateProvinceId = shippingStateProvince.Id;
                }
                int?shippingCountryId     = null;
                var shippingZipPostalCode = paymentDetails.ShipToAddress.PostalCode;
                var shippingCountry       =
                    _countryService.GetCountryByTwoLetterIsoCode(paymentDetails.ShipToAddress.Country.ToString());
                if (shippingCountry != null)
                {
                    shippingCountryId = shippingCountry.Id;
                }

                var shippingAddress = _addressService.FindAddress(_customerService.GetAddressesByCustomerId(_workContext.CurrentCustomer.Id).ToList(),
                                                                  shippingFirstName, shippingLastName, shippingPhoneNumber,
                                                                  shippingEmail, string.Empty, string.Empty,
                                                                  shippingAddress1, shippingAddress2, shippingCity,
                                                                  shippingCountry?.Name, shippingStateProvinceId, shippingZipPostalCode,
                                                                  shippingCountryId, null); //TODO process custom attributes

                if (shippingAddress == null)
                {
                    shippingAddress = new Core.Domain.Common.Address
                    {
                        FirstName       = shippingFirstName,
                        LastName        = shippingLastName,
                        PhoneNumber     = shippingPhoneNumber,
                        Email           = shippingEmail,
                        FaxNumber       = string.Empty,
                        Company         = string.Empty,
                        Address1        = shippingAddress1,
                        Address2        = shippingAddress2,
                        City            = shippingCity,
                        StateProvinceId = shippingStateProvinceId,
                        ZipPostalCode   = shippingZipPostalCode,
                        CountryId       = shippingCountryId,
                        CreatedOnUtc    = DateTime.UtcNow
                    };

                    _addressService.InsertAddress(shippingAddress);
                    _customerService.InsertCustomerAddress(customer, shippingAddress);
                }

                //set default shipping address
                customer.ShippingAddressId = shippingAddress.Id;
                _customerService.UpdateCustomer(customer);
            }

            var processPaymentRequest = new ProcessPaymentRequest
            {
                CustomerId   = customerId,
                CustomValues =
                {
                    [Defaults.PaypalTokenKey]   = checkoutDetails.Token,
                    [Defaults.PaypalPayerIdKey] = checkoutDetails.PayerInfo.PayerID
                }
            };

            return(processPaymentRequest);
        }
        public ProcessPaymentRequest SetCheckoutDetails(StripeSource stripeSource)
        {
            // get customer & cart
            //var customer = customer;
            int customerId = Convert.ToInt32(_workContext.CurrentCustomer.Id.ToString());
            var customer   = _customerService.GetCustomerById(customerId);

            _workContext.CurrentCustomer = customer;

            var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();

            if (customer.BillingAddress == null)
            {
                // get/update billing address
                string name                   = stripeSource.Owner.Name;
                string billingEmail           = customer.Email;
                string billingAddress1        = stripeSource.Owner.Address.Line1;
                string billingAddress2        = stripeSource.Owner.Address.Line2;
                string billingCity            = stripeSource.Owner.Address.City;
                int?   billingStateProvinceId = null;
                var    billingStateProvince   = _stateProvinceService.GetStateProvinceByAbbreviation(stripeSource.Owner.Address.State);
                if (billingStateProvince != null)
                {
                    billingStateProvinceId = billingStateProvince.Id;
                }
                string billingZipPostalCode = stripeSource.Owner.Address.PostalCode;
                int?   billingCountryId     = null;
                var    billingCountry       = _countryService.GetCountryByTwoLetterIsoCode(stripeSource.Owner.Address.Country);
                if (billingCountry != null)
                {
                    billingCountryId = billingCountry.Id;
                }

                var billingAddress = customer.Addresses.ToList().FindAddress(
                    null, null, null,
                    billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                    billingStateProvinceId, billingZipPostalCode, billingCountryId,
                    //TODO process custom attributes
                    null);

                billingAddress = new Core.Domain.Common.Address()
                {
                    FirstName       = null,
                    LastName        = null,
                    PhoneNumber     = null,
                    Email           = billingEmail,
                    FaxNumber       = string.Empty,
                    Company         = string.Empty,
                    Address1        = billingAddress1,
                    Address2        = billingAddress2,
                    City            = billingCity,
                    StateProvinceId = billingStateProvinceId,
                    ZipPostalCode   = billingZipPostalCode,
                    CountryId       = billingCountryId,
                    CreatedOnUtc    = DateTime.UtcNow,
                };
                customer.Addresses.Add(billingAddress);

                //set default billing address
                customer.BillingAddress = billingAddress;

                _customerService.UpdateCustomer(customer);
            }


            _genericAttributeService.SaveAttribute <ShippingOption>(customer, SystemCustomerAttributeNames.SelectedShippingOption, null);

            var processPaymentRequest = new ProcessPaymentRequest {
                CustomerId = customerId
            };

            processPaymentRequest.CustomValues["StripeSourceId"] = stripeSource.Id;
            return(processPaymentRequest);
        }