Skip to content

Commit

Permalink
#81 Use CustomerClassification for all shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeybusygin authored Sep 30, 2024
1 parent c0b8f19 commit fff9a81
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void UpsRatingRequestBuilder_CustomerClassificationDefaults()
var shipmentNL = new Shipment(fromNL, AddressTo, Packages);

var internationalRequest = regularRatesBuilder.Build(shipmentNL);
Assert.That(internationalRequest?.RateRequest?.CustomerClassification, Is.Null);
Assert.That(regularRatesRequest?.RateRequest?.CustomerClassification, Is.Not.Null);
Assert.That(regularRatesRequest?.RateRequest?.CustomerClassification.Code, Is.EqualTo("00"));
}


Expand Down
36 changes: 19 additions & 17 deletions ShippingRates/Models/UPS/UpsRatingRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public UpsRatingRequest Build(Shipment shipment)
ShipTo = new ShipAddress(new UpsAddress(shipment.DestinationAddress)),
NumOfPieces = shipment.Packages.Count,
Package = shipment.Packages.Select(p => new UpsPackage(p, unitsSystem)).ToArray()
}
},
CustomerClassification = GetCustomerClassification()
}
};
if (!string.IsNullOrEmpty(_configuration.ServiceDescription))
Expand Down Expand Up @@ -80,22 +81,6 @@ public UpsRatingRequest Build(Shipment shipment)
NegotiatedRatesIndicator = "Y"
};
}
if (shipFromUS) // Valid if ship from US
{
var customerClassification = _configuration.CustomerClassification;

if (_configuration.UseRetailRates)
customerClassification = UPSCustomerClassification.RetailRates;
if (_configuration.UseDailyRates)
customerClassification = UPSCustomerClassification.DailyRates;

var code = ((int)customerClassification).ToString("D2");

request.RateRequest.CustomerClassification = new CustomerClassification()
{
Code = code,
};
}
if (shipment.Options.ShippingDate != null)
{
request.RateRequest.Shipment.DeliveryTimeInformation = new DeliveryTimeInformation()
Expand All @@ -112,6 +97,23 @@ public UpsRatingRequest Build(Shipment shipment)
return request;
}

CustomerClassification GetCustomerClassification()
{
var customerClassification = _configuration.CustomerClassification;

if (_configuration.UseRetailRates)
customerClassification = UPSCustomerClassification.RetailRates;
if (_configuration.UseDailyRates)
customerClassification = UPSCustomerClassification.DailyRates;

var code = ((int)customerClassification).ToString("D2");

return new CustomerClassification()
{
Code = code,
};
}

static string GetServiceCode(string serviceDescription)
{
if (serviceDescription.Length == 2)
Expand Down
12 changes: 10 additions & 2 deletions ShippingRates/ShippingProviders/UPSProviderConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public class UPSProviderConfiguration
/// </summary>
public string ServiceDescription { get; set; }
/// <summary>
/// Use retails rates (for shipping from a UPS retail location)
/// Use retails rates (for shipping from a UPS retail location).
/// Overrides CustomerClassification.
/// </summary>
public bool UseRetailRates { get; set; }
/// <summary>
/// Use daily rates (for customers who have a scheduled pickup and/or an account that provides you with daily rates)
/// Use daily rates (for customers who have a scheduled pickup and/or an account that provides you with daily rates).
/// Overrides CustomerClassification.
/// </summary>
public bool UseDailyRates { get; set; }
/// <summary>
Expand All @@ -47,7 +49,13 @@ public class UPSProviderConfiguration
public enum UPSCustomerClassification
{
ShipperNumberRates = 0,
/// <summary>
/// Daily rates, for customers who have a scheduled pickup and/or an account that provides you with daily rates
/// </summary>
DailyRates = 1,
/// <summary>
/// Retails rates, for shipping from a UPS retail location
/// </summary>
RetailRates = 4,
RegionalRates = 5,
GeneralListRates = 6,
Expand Down

0 comments on commit fff9a81

Please sign in to comment.