Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Bugfix/extract all tracking numbers from amazon mws #18

Merged
merged 2 commits into from over 1 year ago

3 participants

Christopher Saunders John Duff Denis Odorcic
Christopher Saunders
Collaborator

Major change to the API so bump version to 2.0.0

All calls to tracking_numbers returns arrays. This also fixes up an issue where the MWS integration was only returning a single tracking number even tough, multiple tracking numbers could be returned from Amazons fulfillment API.

please review @jduff @odorcicd

csaunders added some commits
Christopher Saunders csaunders Ensure that all tracking numbers for a fulfillment are retrieved
In order to not fully hose the API, we return all tracking numbers
as a comma separated string.  This should fix any issues related with
having an order be fulfilled via multiple fulfillment centers (hence
the requirement for different tracking numbers)
4383e43
Christopher Saunders csaunders Extract tracking number information into arrays
Instead of giving back a string for tracking numbers we
return arrays instead.  This is a backwards-incompatible change,
and as such requires a major version update.  All current fulfillment
providers, and future providers will need to providing tracking
numbers as arrays, even if it is guaranteed that they only provide
a single tracking number.
096eb12
Christopher Saunders
Collaborator

last commit was a force push, hence the same commit message. apologies.

John Duff
Owner

Nothing jumps out to me.

Denis Odorcic
Collaborator

me neither

Christopher Saunders csaunders merged commit 3eb12cc into from
Christopher Saunders csaunders deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Oct 04, 2012
Christopher Saunders csaunders Ensure that all tracking numbers for a fulfillment are retrieved
In order to not fully hose the API, we return all tracking numbers
as a comma separated string.  This should fix any issues related with
having an order be fulfilled via multiple fulfillment centers (hence
the requirement for different tracking numbers)
4383e43
Christopher Saunders csaunders Extract tracking number information into arrays
Instead of giving back a string for tracking numbers we
return arrays instead.  This is a backwards-incompatible change,
and as such requires a major version update.  All current fulfillment
providers, and future providers will need to providing tracking
numbers as arrays, even if it is guaranteed that they only provide
a single tracking number.
096eb12
This page is out of date. Refresh to see the latest.
2  VERSION
... ... @@ -1 +1 @@
1   -1.0.3
  1 +2.0.0
2  active_fulfillment.gemspec
@@ -5,7 +5,7 @@
5 5
6 6 Gem::Specification.new do |s|
7 7 s.name = %q{active_fulfillment}
8   - s.version = "1.0.3"
  8 + s.version = "2.0.0"
9 9
10 10 s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11 11 s.authors = ["Cody Fauser", "James MacAulay"]
2  lib/active_fulfillment/fulfillment/services/amazon.rb
@@ -342,7 +342,7 @@ def parse_tracking_response(document)
342 342 track_node = REXML::XPath.first(document, '//ns1:FulfillmentShipmentPackage/ns1:TrackingNumber')
343 343 if track_node
344 344 id_node = REXML::XPath.first(document, '//ns1:MerchantFulfillmentOrderId')
345   - response[:tracking_numbers][id_node.text] = track_node.text
  345 + response[:tracking_numbers][id_node.text] = [track_node.text]
346 346 end
347 347
348 348 response[:response_status] = SUCCESS
8 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
@@ -228,10 +228,10 @@ def parse_tracking_response(document)
228 228 response = {}
229 229 response[:tracking_numbers] = {}
230 230
231   - tracking_node = REXML::XPath.first(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
232   - if tracking_node
233   - id_node = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId")
234   - response[:tracking_numbers][id_node.text.strip] = tracking_node.text.strip
  231 + tracking_numbers = REXML::XPath.match(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
  232 + if tracking_numbers.present?
  233 + order_id = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId").text.strip
  234 + response[:tracking_numbers][order_id] = tracking_numbers.map{ |t| t.text.strip }
235 235 end
236 236
237 237 response[:response_status] = SUCCESS
2  lib/active_fulfillment/fulfillment/services/shipwire.rb
@@ -234,7 +234,7 @@ def parse_tracking_response(xml)
234 234 if node.name == 'Order'
235 235 if node.attributes["shipped"] == "YES" && node.elements['TrackingNumber']
236 236 tracking_number = node.elements['TrackingNumber'].text
237   - response[:tracking_numbers][node.attributes['id']] = tracking_number
  237 + response[:tracking_numbers][node.attributes['id']] = [tracking_number]
238 238 end
239 239 else
240 240 response[node.name.underscore.to_sym] = node.text
2  lib/active_fulfillment/fulfillment/services/webgistix.rb
@@ -301,7 +301,7 @@ def parse_tracking_response(document)
301 301 params = node.elements.to_a.each_with_object({}) {|elem, hash| hash[elem.name] = elem.text}
302 302
303 303 tracking = params['ShipmentTrackingNumber']
304   - response[:tracking_numbers][params['InvoiceNumber']] = tracking unless tracking == NOT_SHIPPED
  304 + response[:tracking_numbers][params['InvoiceNumber']] = [tracking] unless tracking == NOT_SHIPPED
305 305 end
306 306
307 307 response
121 test/fixtures/xml/amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers.xml
... ... @@ -0,0 +1,121 @@
  1 +<?xml version="1.0"?>
  2 +<GetFulfillmentOrderResponse
  3 + xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
  4 + <GetFulfillmentOrderResult>
  5 + <FulfillmentOrderItem>
  6 + <member>
  7 + <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
  8 + <GiftMessage>test_giftwrap_message</GiftMessage>
  9 + <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
  10 + </SellerFulfillmentOrderItemId>
  11 + <EstimatedShipDateTime>2008-03-08T07:07:53Z
  12 + </EstimatedShipDateTime>
  13 + <DisplayableComment>test_displayable_comment</DisplayableComment>
  14 + <OrderItemDisposition>Sellable</OrderItemDisposition>
  15 + <UnfulfillableQuantity>0</UnfulfillableQuantity>
  16 + <CancelledQuantity>1</CancelledQuantity>
  17 + <Quantity>5</Quantity>
  18 + <EstimatedArrivalDateTime>2008-03-08T08:07:53Z
  19 + </EstimatedArrivalDateTime>
  20 + </member>
  21 + <member>
  22 + <SellerSKU>ssof_dev_drt_keep_this_afn_always</SellerSKU>
  23 + <GiftMessage>test_giftwrap_message</GiftMessage>
  24 + <SellerFulfillmentOrderItemId>test_merchant_order_item_id_1
  25 + </SellerFulfillmentOrderItemId>
  26 + <EstimatedShipDateTime>2008-03-09T07:07:53Z
  27 + </EstimatedShipDateTime>
  28 + <DisplayableComment>test_displayable_comment
  29 + </DisplayableComment>
  30 + <OrderItemDisposition>Sellable</OrderItemDisposition>
  31 + <UnfulfillableQuantity>2</UnfulfillableQuantity>
  32 + <CancelledQuantity>1</CancelledQuantity>
  33 + <Quantity>5</Quantity>
  34 + <EstimatedArrivalDateTime>2008-03-09T08:07:53Z
  35 + </EstimatedArrivalDateTime>
  36 + </member>
  37 + </FulfillmentOrderItem>
  38 + <FulfillmentOrder>
  39 + <ShippingSpeedCategory>Standard</ShippingSpeedCategory>
  40 + <NotificationEmailList>
  41 + <member>o8c2EXAMPLsfr7o@marketplace.amazon.com</member>
  42 + </NotificationEmailList>
  43 + <StatusUpdatedDateTime>2006-09-28T23:48:48Z
  44 + </StatusUpdatedDateTime>
  45 + <SellerFulfillmentOrderId>extern_id_1154539615776
  46 + </SellerFulfillmentOrderId>
  47 + <DestinationAddress>
  48 + <PostalCode>98101</PostalCode>
  49 + <PhoneNumber>206-555-1928</PhoneNumber>
  50 + <Name>Greg Miller</Name>
  51 + <CountryCode>US</CountryCode>
  52 + <Line1>123 Some St.</Line1>
  53 + <StateOrProvinceCode>WA</StateOrProvinceCode>
  54 + <City>Seattle</City>
  55 + <Line2>Apt. 321</Line2>
  56 + </DestinationAddress>
  57 + <FulfillmentMethod>Consumer</FulfillmentMethod>
  58 + <DisplayableOrderDateTime>2006-08-02T17:26:56Z
  59 + </DisplayableOrderDateTime>
  60 + <FulfillmentPolicy>FillOrKill</FulfillmentPolicy>
  61 + <ReceivedDateTime>2006-08-02T17:26:56Z</ReceivedDateTime>
  62 + <DisplayableOrderId>test_displayable_id</DisplayableOrderId>
  63 + <DisplayableOrderComment>Sample comment.
  64 + </DisplayableOrderComment>
  65 + <FulfillmentOrderStatus>PROCESSING</FulfillmentOrderStatus>
  66 + </FulfillmentOrder>
  67 + <FulfillmentShipment>
  68 + <member>
  69 + <FulfillmentShipmentStatus>SHIPPED</FulfillmentShipmentStatus>
  70 + <FulfillmentShipmentItem>
  71 + <member>
  72 + <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
  73 + <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
  74 + </SellerFulfillmentOrderItemId>
  75 + <Quantity>2</Quantity>
  76 + <PackageNumber>0</PackageNumber>
  77 + </member>
  78 + </FulfillmentShipmentItem>
  79 + <AmazonShipmentId>DnMDLWJWN</AmazonShipmentId>
  80 + <ShippingDateTime>2006-08-04T07:00:00Z</ShippingDateTime>
  81 + <FulfillmentShipmentPackage>
  82 + <member>
  83 + <TrackingNumber>93YY00</TrackingNumber>
  84 + <CarrierCode>UPS</CarrierCode>
  85 + <PackageNumber>1</PackageNumber>
  86 + </member>
  87 + </FulfillmentShipmentPackage>
  88 + <FulfillmentCenterId>RNO1</FulfillmentCenterId>
  89 + <EstimatedArrivalDateTime>2006-08-12T07:00:00Z
  90 + </EstimatedArrivalDateTime>
  91 + </member>
  92 + <member>
  93 + <FulfillmentShipmentStatus>SHIPPED</FulfillmentShipmentStatus>
  94 + <FulfillmentShipmentItem>
  95 + <member>
  96 + <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
  97 + <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
  98 + </SellerFulfillmentOrderItemId>
  99 + <Quantity>1</Quantity>
  100 + <PackageNumber>1</PackageNumber>
  101 + </member>
  102 + </FulfillmentShipmentItem>
  103 + <AmazonShipmentId>DKMKLXJmN</AmazonShipmentId>
  104 + <ShippingDateTime>2006-08-03T07:00:00Z</ShippingDateTime>
  105 + <FulfillmentShipmentPackage>
  106 + <member>
  107 + <TrackingNumber>93ZZ00</TrackingNumber>
  108 + <CarrierCode>UPS</CarrierCode>
  109 + <PackageNumber>1</PackageNumber>
  110 + </member>
  111 + </FulfillmentShipmentPackage>
  112 + <FulfillmentCenterId>TST1</FulfillmentCenterId>
  113 + <EstimatedArrivalDateTime>2006-08-12T07:00:00Z
  114 + </EstimatedArrivalDateTime>
  115 + </member>
  116 + </FulfillmentShipment>
  117 + </GetFulfillmentOrderResult>
  118 + <ResponseMetadata>
  119 + <RequestId>5e5e5694-8e76-11df-929f-87c80302f8f6</RequestId>
  120 + </ResponseMetadata>
  121 +</GetFulfillmentOrderResponse>
4 test/remote/webgistix_test.rb
@@ -79,8 +79,8 @@ def test_fetch_tracking_numbers
79 79 '1254658', 'FAItest123', 'Flat Rate Test Order 4'
80 80 ])
81 81 assert response.success?
82   - assert_equal '4209073191018052136352154', response.tracking_numbers['1254658']
83   - assert_equal '9101805213907472080032', response.tracking_numbers['Flat Rate Test Order 4']
  82 + assert_equal ['4209073191018052136352154'], response.tracking_numbers['1254658']
  83 + assert_equal ['9101805213907472080032'], response.tracking_numbers['Flat Rate Test Order 4']
84 84 assert_nil response.tracking_numbers['FAItest123'] # 'Not Shipped'
85 85 end
86 86
13 test/unit/services/amazon_mws_test.rb
@@ -217,10 +217,19 @@ def test_fetch_tracking_numbers
217 217
218 218 response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'extern_id_1154539615777'])
219 219 assert response.success?
220   - assert_equal '93ZZ00', response.tracking_numbers['extern_id_1154539615776']
  220 + assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
221 221 assert_nil response.tracking_numbers['extern_id_1154539615777']
222 222 end
223 223
  224 +
  225 + def test_fetch_multiple_tracking_numbers
  226 + @service.expects(:ssl_post).returns(xml_fixture('amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers'))
  227 +
  228 + response = @service.fetch_tracking_numbers(['extern_id_1154539615776'])
  229 + assert response.success?
  230 + assert_equal %w{93YY00 93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
  231 + end
  232 +
224 233 def test_that_generated_requests_do_not_double_escape_spaces
225 234 fulfillment_request = @service.send(:build_fulfillment_request, "12345", @address, @line_items, @options)
226 235 result = @service.build_full_query(:post, URI.parse("http://example.com/someservice/2011"), fulfillment_request)
@@ -241,7 +250,7 @@ def test_fetch_tracking_numbers_ignores_not_found
241 250
242 251 response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'dafdfafsdafdafasdfa', 'extern_id_1154539615777'])
243 252 assert response.success?
244   - assert_equal '93ZZ00', response.tracking_numbers['extern_id_1154539615776']
  253 + assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
245 254 end
246 255
247 256 def test_fetch_tracking_numbers_aborts_on_error
4 test/unit/services/amazon_test.rb
@@ -98,7 +98,7 @@ def test_fetch_tracking_numbers
98 98
99 99 response = @service.fetch_tracking_numbers(['TEST-00000001', 'TEST-00000002'])
100 100 assert response.success?
101   - assert_equal 'UPS00000001', response.tracking_numbers['TEST-00000001']
  101 + assert_equal %w{UPS00000001}, response.tracking_numbers['TEST-00000001']
102 102 assert_nil response.tracking_numbers['TEST-00000002']
103 103 end
104 104
@@ -115,7 +115,7 @@ def test_fetch_tracking_numbers_ignores_not_found
115 115
116 116 response = @service.fetch_tracking_numbers(['TEST-00000001', '#1337-1', 'TEST-00000002'])
117 117 assert response.success?
118   - assert_equal 'UPS00000001', response.tracking_numbers['TEST-00000001']
  118 + assert_equal %w{UPS00000001}, response.tracking_numbers['TEST-00000001']
119 119 end
120 120
121 121 def test_fetch_tracking_numbers_aborts_on_error
4 test/unit/services/shipwire_test.rb
@@ -105,8 +105,8 @@ def test_no_tracking_numbers_available
105 105 end
106 106
107 107 def test_successful_tracking
108   - expected = { "2986" => "1ZW682E90326614239",
109   - "2987" => "1ZW682E90326795080" }
  108 + expected = { "2986" => ["1ZW682E90326614239"],
  109 + "2987" => ["1ZW682E90326795080"] }
110 110
111 111 @shipwire.expects(:ssl_post).returns(successful_tracking_response)
112 112 response = @shipwire.fetch_tracking_numbers(["2986", "2987"])
2  test/unit/services/webgistix_test.rb
@@ -106,7 +106,7 @@ def test_tracking_numbers
106 106 response = @service.fetch_tracking_numbers(['AB12345', 'XY4567'])
107 107 assert response.success?
108 108 assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
109   - assert_equal '1Z8E5A380396682872', response.tracking_numbers['AB12345']
  109 + assert_equal ['1Z8E5A380396682872'], response.tracking_numbers['AB12345']
110 110 assert_nil response.tracking_numbers['XY4567']
111 111 end
112 112

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.