/// <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); }
/// <summary> /// If current user is registered user, try to save the OrderAddress to its Contact. /// </summary> /// <param name="orderAddress">The modified order address.</param> /// <param name="customerAddressType">The customer address type.</param> private static void TrySaveCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType) { if (HttpContext.Current == null) { return; } var httpProfile = HttpContext.Current.Profile; var profile = httpProfile == null ? null : new CustomerProfileWrapper(httpProfile); if (profile == null || profile.IsAnonymous) { return; } // Add to contact address var customerContact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); if (customerContact != null) { var customerAddress = CustomerAddress.CreateForApplication(); customerAddress.Name = orderAddress.Id; customerAddress.AddressType = customerAddressType; customerAddress.City = orderAddress.City; customerAddress.CountryCode = orderAddress.CountryCode; customerAddress.CountryName = orderAddress.CountryName; customerAddress.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; customerAddress.Email = orderAddress.Email; customerAddress.EveningPhoneNumber = orderAddress.EveningPhoneNumber; customerAddress.FirstName = orderAddress.FirstName; customerAddress.LastName = orderAddress.LastName; customerAddress.Line1 = orderAddress.Line1; customerAddress.Line2 = orderAddress.Line2; customerAddress.PostalCode = orderAddress.PostalCode; customerAddress.RegionName = orderAddress.RegionName; customerAddress.RegionCode = orderAddress.RegionCode; #pragma warning disable 618 if (customerContact.ContactAddresses == null || !IsAddressInCollection(customerContact.ContactAddresses, customerAddress)) #pragma warning restore 618 { // If there is an address has the same name with new address, // rename new address by appending the index to the name. var addressCount = customerContact.ContactAddresses.Count(a => a.Name == customerAddress.Name); customerAddress.Name = $"{customerAddress.Name}{(addressCount == 0 ? string.Empty : "-" + addressCount.ToString())}"; customerContact.AddContactAddress(customerAddress); customerContact.SaveChanges(); } } }
public virtual void MapAddress( CustomerContact currentContact, CustomerAddressTypeEnum addressType, VippsAddress vippsAddress, string phoneNumber) { if (currentContact == null) { throw new ArgumentNullException(nameof(currentContact)); } if (vippsAddress == null) { throw new ArgumentNullException(nameof(vippsAddress)); } // Vipps addresses don't have an ID // They can be identified by Vipps address type var address = currentContact.ContactAddresses.FindVippsAddress(vippsAddress.AddressType); var isNewAddress = address == null; if (isNewAddress) { address = CustomerAddress.CreateInstance(); address.AddressType = addressType; } // Maps fields onto customer address: // Vipps address type, street, city, postalcode, countrycode MapVippsAddressFields(address, vippsAddress); if (!string.IsNullOrWhiteSpace(phoneNumber)) { address.DaytimePhoneNumber = address.EveningPhoneNumber = phoneNumber; } if (isNewAddress) { currentContact.AddContactAddress(address); } else { currentContact.UpdateContactAddress(address); } }
private CustomerAddress CreateCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum addressType) { var address = CustomerAddress.CreateInstance(); address.Name = orderAddress.Id; address.AddressType = addressType; address.PostalCode = orderAddress.PostalCode; address.City = orderAddress.City; address.CountryCode = orderAddress.CountryCode; address.CountryName = orderAddress.CountryName; address.State = orderAddress.RegionName; address.Email = orderAddress.Email; address.FirstName = orderAddress.FirstName; address.LastName = orderAddress.LastName; address.Line1 = orderAddress.Line1; address.Line2 = orderAddress.Line2; address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; address.EveningPhoneNumber = orderAddress.EveningPhoneNumber; address.RegionCode = orderAddress.RegionCode; address.RegionName = orderAddress.RegionName; return(address); }
/// <summary> /// Processes the checkout details from PayPal, update changed addresses appropriately. /// </summary> /// <param name="payerInfo">The PayPal payer info.</param> /// <param name="payPalAddress">The PayPal address.</param> /// <param name="orderAddress">The order address to process.</param> /// <param name="customerAddressType">The order address to process.</param> /// <param name="emptyAddressMsgKey">The empty address message language key in lang.xml file.</param> public string ProcessOrderAddress(PayerInfoType payerInfo, AddressType payPalAddress, IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType, string emptyAddressMsgKey) { if (payPalAddress == null) { return(_localizationService.GetString(emptyAddressMsgKey)); } if (orderAddress == null) { return(_localizationService.GetString("/Commerce/Checkout/PayPal/CommitTranErrorCartReset")); } if (string.IsNullOrEmpty(payPalAddress.Phone) && !string.IsNullOrEmpty(payerInfo?.ContactPhone)) { payPalAddress.Phone = payerInfo.ContactPhone; } AddressHandling.UpdateOrderAddress(orderAddress, customerAddressType, payPalAddress, payerInfo.Payer); return(string.Empty); }
private CustomerAddress CreateCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum addressType) { var address = CustomerAddress.CreateInstance(); address.Name = orderAddress.Id; address.AddressType = addressType; address.PostalCode = orderAddress.PostalCode; address.City = orderAddress.City; address.CountryCode = orderAddress.CountryCode; address.CountryName = orderAddress.CountryName; address.State = orderAddress.RegionName; address.Email = orderAddress.Email; address.FirstName = orderAddress.FirstName; address.LastName = orderAddress.LastName; address.Line1 = orderAddress.Line1; address.Line2 = orderAddress.Line2; address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; address.EveningPhoneNumber = orderAddress.EveningPhoneNumber; address.RegionCode = orderAddress.RegionCode; address.RegionName = orderAddress.RegionName; return address; }