/// <summary> /// Maps an <see cref="CheckoutAddress"/> to <see cref="IAddress"/>, handy for Shipping an Billing. No customer key so no way to link back to customer /// </summary> /// <param name="address"> /// The address. /// </param> /// <returns> /// The <see cref="IAddress"/>. /// </returns> public static IAddress ToAddress(this CheckoutAddress address) { return(new Address() { Address1 = address.Address1, Address2 = address.Address2, CountryCode = address.CountryCode, Email = address.Email, IsCommercial = address.IsCommercial, Locality = address.City, Name = address.Fullname, Organization = address.Organization, Phone = address.Phone, PostalCode = address.PostalCode, Region = address.Region }); }
public ShippingRateQuotes GetShippingMethodQuotes(CheckoutAddress address) { var customer = Services.CustomerService.GetAnyByKey(address.CustomerKey); if (customer == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var basket = Basket.GetBasket(customer); // for this version there is only ever a single shipment var destination = address.ToAddress(); // validate we can estimate shipping if (string.IsNullOrEmpty(destination.CountryCode) || AllowableShipCounties.FirstOrDefault(x => x.CountryCode == destination.CountryCode) == null) { throw new InvalidOperationException("The shipping destination's country code is either null or contains a country code that is not associated with any shipping provider."); } var shipment = basket.PackageBasket(address.ToAddress()).FirstOrDefault(); if (shipment == null) { return new ShippingRateQuotes() { Status = ShipQuoteStatus.NoShippableItems.ToString() } } ; var providerQuotes = shipment.ShipmentRateQuotes(); return(new ShippingRateQuotes(providerQuotes.ToShipMethodQuotes()) { Status = ShipQuoteStatus.Ok.ToString() }); }