Permalink
Browse files

Handling case where rates aren't returned for shipping labels.

  • Loading branch information...
1 parent 7a7ec3c commit 2027ed5207030127c4011ad535d04748e0701ae2 @jimmybaker committed Feb 21, 2012
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/shippinglogic/fedex/ship.rb
@@ -310,16 +310,19 @@ def build_request
# Making sense of the reponse and grabbing the information we need.
def parse_response(response)
details = response[:completed_shipment_detail]
+ shipment = Shipment.new
- rate_details = details[:shipment_rating][:shipment_rate_details]
- rate_details = rate_details.kind_of?(Array) ? rate_details.first : rate_details
+ # In case a label is returned without rates
+ if details.has_key?(:shipment_rating)
+ rate_details = details[:shipment_rating][:shipment_rate_details]
+ rate_details = rate_details.kind_of?(Array) ? rate_details.first : rate_details
- rate = rate_details[:total_net_charge] || rate_details.first[:total_net_charge]
- package_details = details[:completed_package_details]
+ rate = rate_details[:total_net_charge] || rate_details.first[:total_net_charge]
+ shipment.rate = BigDecimal.new(rate[:amount])
+ shipment.currency = rate[:currency]
+ end
- shipment = Shipment.new
- shipment.rate = BigDecimal.new(rate[:amount])
- shipment.currency = rate[:currency]
+ package_details = details[:completed_package_details]
shipment.delivery_date = Date.parse(details[:routing_detail][:delivery_date]) if details[:routing_detail][:delivery_date]
shipment.tracking_numbers = {}

0 comments on commit 2027ed5

Please sign in to comment.