/// <summary>
        /// Updates order address information from PayPal address type model.
        /// </summary>
        /// <param name="orderAddress">The order address.</param>
        /// <param name="customerAddressType">The customer address type.</param>
        /// <param name="addressType">The PayPal address type.</param>
        /// <param name="payerEmail">The PayPal payer email.</param>
        public static void UpdateOrderAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType, AddressType addressType, string payerEmail)
        {
            var name = Utilities.StripPreviewText(addressType.Name.Trim(), 46);

            orderAddress.Id                 = name;
            orderAddress.City               = addressType.CityName;
            orderAddress.CountryCode        = CountriesAndStates.GetAlpha3CountryCode(addressType.Country.ToString().ToUpperInvariant());
            orderAddress.DaytimePhoneNumber = addressType.Phone;
            orderAddress.EveningPhoneNumber = addressType.Phone;
            orderAddress.Line1              = addressType.Street1;
            orderAddress.Line2              = addressType.Street2;
            orderAddress.PostalCode         = addressType.PostalCode;
            orderAddress.Email              = payerEmail;
            var index = name.IndexOf(' ');

            orderAddress.FirstName  = index >= 0 ? name.Substring(0, index) : name;
            orderAddress.LastName   = index >= 0 ? name.Substring(index + 1) : string.Empty;
            orderAddress.RegionCode = addressType.StateOrProvince;
            orderAddress.RegionName = CountriesAndStates.GetStateName(addressType.StateOrProvince);
            var address = orderAddress as OrderAddress;

            if (address != null)
            {
                address.State = orderAddress.RegionName;
            }

            TrySaveCustomerAddress(orderAddress, customerAddressType);
        }
 /// <summary>
 /// Determines whether the address is changed.
 /// </summary>
 /// <param name="orderAddress">The order address.</param>
 /// <param name="addressType">The PayPal address type.</param>
 /// <returns>
 ///     <c>true</c> if [is address changed] [the specified order address]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsAddressChanged(IOrderAddress orderAddress, AddressType addressType)
 {
     return(!string.Equals(orderAddress.City, addressType.CityName, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.CountryCode, CountriesAndStates.GetAlpha3CountryCode(addressType.Country.ToString().ToUpperInvariant()), StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.Line1, addressType.Street1, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.Line2 ?? string.Empty, addressType.Street2 ?? string.Empty, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.PostalCode, addressType.PostalCode, StringComparison.OrdinalIgnoreCase));
 }
        /// <summary>
        /// Gets the PayPal address type model from a specific IOrderAddress.
        /// </summary>
        /// <value>The PayPal address type model.</value>
        public static AddressType ToAddressType(IOrderAddress orderAddress)
        {
            var addressType = new AddressType();

            addressType.CityName    = orderAddress.City;
            addressType.Country     = CountriesAndStates.GetAlpha2CountryCode(orderAddress.CountryCode);
            addressType.CountryName = orderAddress.CountryName;
            addressType.Street1     = orderAddress.Line1;
            addressType.Street2     = orderAddress.Line2;
            addressType.PostalCode  = orderAddress.PostalCode;
            addressType.Phone       = (string.IsNullOrEmpty(orderAddress.DaytimePhoneNumber) ? orderAddress.EveningPhoneNumber : orderAddress.DaytimePhoneNumber);
            addressType.Name        = orderAddress.FirstName + " " + orderAddress.LastName;

            var stateName = orderAddress.RegionName;
            var address   = orderAddress as OrderAddress;

            if (!string.IsNullOrEmpty(address?.State))
            {
                stateName = address.State;
            }

            addressType.StateOrProvince = CountriesAndStates.GetStateCode(stateName);
            return(addressType);
        }