lib/active_shipping/carriers/fedex.rb in active_shipping-1.6.1 vs lib/active_shipping/carriers/fedex.rb in active_shipping-1.6.2
- old
+ new
@@ -141,32 +141,32 @@
def requirements
[:key, :password, :account, :login]
end
def find_rates(origin, destination, packages, options = {})
- options = @options.update(options)
+ options = @options.merge(options)
packages = Array(packages)
rate_request = build_rate_request(origin, destination, packages, options)
xml = commit(save_request(rate_request), (options[:test] || false))
parse_rate_response(origin, destination, packages, xml, options)
end
def find_tracking_info(tracking_number, options = {})
- options = @options.update(options)
+ options = @options.merge(options)
tracking_request = build_tracking_request(tracking_number, options)
xml = commit(save_request(tracking_request), (options[:test] || false))
parse_tracking_response(xml, options)
end
# Get Shipping labels
def create_shipment(origin, destination, packages, options = {})
- options = @options.update(options)
+ options = @options.merge(options)
packages = Array(packages)
raise Error, "Multiple packages are not supported yet." if packages.length > 1
request = build_shipment_request(origin, destination, packages, options)
logger.debug(request) if logger
@@ -296,11 +296,15 @@
# Returns saturday delivery shipping options when available
xml.VariableOptions('SATURDAY_DELIVERY')
xml.RequestedShipment do
- xml.ShipTimestamp(ship_timestamp(options[:turn_around_time]).iso8601(0))
+ if options[:pickup_date]
+ xml.ShipTimestamp(options[:pickup_date].to_time.iso8601(0))
+ else
+ xml.ShipTimestamp(ship_timestamp(options[:turn_around_time]).iso8601(0))
+ end
freight = has_freight?(options)
unless freight
# fedex api wants this up here otherwise request returns an error
@@ -477,13 +481,12 @@
transit_time = rated_shipment.at('TransitTime').text if ["FEDEX_GROUND", "GROUND_HOME_DELIVERY"].include?(service_code)
max_transit_time = rated_shipment.at('MaximumTransitTime').try(:text) if service_code == "FEDEX_GROUND"
delivery_timestamp = rated_shipment.at('DeliveryTimestamp').try(:text)
+ delivery_range = delivery_range_from(transit_time, max_transit_time, delivery_timestamp, (service_code == "GROUND_HOME_DELIVERY"), options)
- delivery_range = delivery_range_from(transit_time, max_transit_time, delivery_timestamp, options)
-
currency = rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Currency').text
RateEstimate.new(origin, destination, @@name,
self.class.service_name_for_code(service_type),
:service_code => service_code,
:total_price => rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Amount').text.to_f,
@@ -501,17 +504,19 @@
end
RateResponse.new(success, message, Hash.from_xml(response), :rates => rate_estimates, :xml => response, :request => last_request, :log_xml => options[:log_xml])
end
- def delivery_range_from(transit_time, max_transit_time, delivery_timestamp, options)
+ def delivery_range_from(transit_time, max_transit_time, delivery_timestamp, is_home_delivery, options)
delivery_range = [delivery_timestamp, delivery_timestamp]
# if there's no delivery timestamp but we do have a transit time, use it
if delivery_timestamp.blank? && transit_time.present?
transit_range = parse_transit_times([transit_time, max_transit_time.presence || transit_time])
- delivery_range = transit_range.map { |days| business_days_from(ship_date(options[:turn_around_time]), days) }
+ pickup_date = options[:pickup_date] || ship_date(options[:turn_around_time])
+
+ delivery_range = transit_range.map { |days| business_days_from(pickup_date, days, is_home_delivery) }
end
delivery_range
end
@@ -526,23 +531,33 @@
labels = [Label.new(tracking_number, Base64.decode64(base_64_image))]
LabelResponse.new(success, message, response_info, {labels: labels})
end
- def business_days_from(date, days)
+ def business_days_from(date, days, is_home_delivery=false)
future_date = date
count = 0
while count < days
future_date += 1.day
- count += 1 if business_day?(future_date)
+ if is_home_delivery
+ count += 1 if home_delivery_business_day?(future_date)
+ else
+ count += 1 if business_day?(future_date)
+ end
end
future_date
end
+ #Transit times for FedEx® Ground do not include Saturdays, Sundays, or holidays.
def business_day?(date)
(1..5).include?(date.wday)
+ end
+
+ #Transit times for FedEx® Home Delivery, do not include Sundays, Mondays, or holidays.
+ def home_delivery_business_day?(date)
+ (2..6).include?(date.wday)
end
def parse_tracking_response(response, options)
xml = build_document(response, 'TrackReply')