Esempio n. 1
0
        /// <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.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);
            if (orderAddress is OrderAddress address)
            {
                address.State = orderAddress.RegionName;
            }

            TrySaveCustomerAddress(orderAddress, customerAddressType);
        }
Esempio n. 2
0
        /// <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
            {
                CityName    = orderAddress.City,
                Country     = CountriesAndStates.GetAlpha2CountryCode(orderAddress.CountryCode),
                CountryName = orderAddress.CountryName,
                Street1     = orderAddress.Line1,
                Street2     = orderAddress.Line2,
                PostalCode  = orderAddress.PostalCode,
                Phone       = string.IsNullOrEmpty(orderAddress.DaytimePhoneNumber)
                    ? orderAddress.EveningPhoneNumber
                    : orderAddress.DaytimePhoneNumber,
                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);
        }
Esempio n. 3
0
 /// <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));
 }