active_fulfillment 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/active_fulfillment/fulfillment/service.rb +13 -6
- data/lib/active_fulfillment/fulfillment/services/amazon.rb +62 -51
- data/lib/active_fulfillment/fulfillment/services/amazon_mws.rb +35 -23
- data/lib/active_fulfillment/fulfillment/services/shipwire.rb +8 -6
- data/lib/active_fulfillment/fulfillment/services/webgistix.rb +76 -66
- data/lib/active_fulfillment/fulfillment/version.rb +1 -1
- data/test/remote/amazon_mws_test.rb +17 -10
- data/test/remote/amazon_test.rb +22 -15
- data/test/remote/shipwire_test.rb +36 -28
- data/test/remote/webgistix_test.rb +25 -16
- data/test/unit/services/amazon_mws_test.rb +36 -11
- data/test/unit/services/amazon_test.rb +46 -36
- data/test/unit/services/shipwire_test.rb +22 -22
- data/test/unit/services/webgistix_test.rb +45 -33
- metadata +1 -1
@@ -3,30 +3,32 @@ module ActiveMerchant
|
|
3
3
|
class WebgistixService < Service
|
4
4
|
SERVICE_URLS = {
|
5
5
|
:fulfillment => 'https://www.webgistix.com/XML/CreateOrder.asp',
|
6
|
-
:inventory
|
7
|
-
:tracking
|
8
|
-
}
|
6
|
+
:inventory => 'https://www.webgistix.com/XML/GetInventory.asp',
|
7
|
+
:tracking => 'https://www.webgistix.com/XML/GetTracking.asp'
|
8
|
+
}
|
9
9
|
TEST_URLS = SERVICE_URLS.merge({
|
10
10
|
:fulfillment => 'https://www.webgistix.com/XML/CreateOrderTest.asp'
|
11
11
|
})
|
12
|
-
|
12
|
+
|
13
13
|
SUCCESS, DUPLICATE, FAILURE = 'True', 'Duplicate', 'False'
|
14
14
|
|
15
15
|
SUCCESS_MESSAGE = 'Successfully submitted the order'
|
16
16
|
FAILURE_MESSAGE = 'Failed to submit the order'
|
17
17
|
DUPLICATE_MESSAGE = 'This order has already been successfully submitted'
|
18
|
-
|
18
|
+
|
19
19
|
INVALID_LOGIN = 'Invalid Credentials'
|
20
20
|
NOT_SHIPPED = 'Not Shipped'
|
21
21
|
|
22
|
-
|
22
|
+
TRACKING_COMPANIES = %w(UPS FedEx USPS)
|
23
|
+
|
24
|
+
# If a request is detected as a duplicate only the original data will be
|
23
25
|
# used by Webgistix, and the subsequent responses will have a
|
24
26
|
# :duplicate parameter set in the params hash.
|
25
27
|
self.retry_safe = true
|
26
|
-
|
28
|
+
|
27
29
|
# The first is the label, and the last is the code
|
28
30
|
def self.shipping_methods
|
29
|
-
[
|
31
|
+
[
|
30
32
|
["UPS Ground Shipping", "Ground"],
|
31
33
|
["UPS Ground", "Ground"],
|
32
34
|
["UPS Standard Shipping (Canada Only)", "Standard"],
|
@@ -63,7 +65,7 @@ module ActiveMerchant
|
|
63
65
|
["USPS Media Mail", "Media Mail"]
|
64
66
|
].inject(ActiveSupport::OrderedHash.new){|h, (k,v)| h[k] = v; h}
|
65
67
|
end
|
66
|
-
|
68
|
+
|
67
69
|
# Pass in the login and password for the shipwire account.
|
68
70
|
# Optionally pass in the :test => true to force test mode
|
69
71
|
def initialize(options = {})
|
@@ -71,8 +73,8 @@ module ActiveMerchant
|
|
71
73
|
super
|
72
74
|
end
|
73
75
|
|
74
|
-
def fulfill(order_id, shipping_address, line_items, options = {})
|
75
|
-
requires!(options, :shipping_method)
|
76
|
+
def fulfill(order_id, shipping_address, line_items, options = {})
|
77
|
+
requires!(options, :shipping_method)
|
76
78
|
commit :fulfillment, build_fulfillment_request(order_id, shipping_address, line_items, options)
|
77
79
|
end
|
78
80
|
|
@@ -80,60 +82,60 @@ module ActiveMerchant
|
|
80
82
|
commit :inventory, build_inventory_request(options)
|
81
83
|
end
|
82
84
|
|
83
|
-
def
|
85
|
+
def fetch_tracking_data(order_ids, options = {})
|
84
86
|
commit :tracking, build_tracking_request(order_ids, options)
|
85
87
|
end
|
86
|
-
|
88
|
+
|
87
89
|
def valid_credentials?
|
88
90
|
response = fulfill('', {}, [], :shipping_method => '')
|
89
91
|
response.message != INVALID_LOGIN
|
90
92
|
end
|
91
|
-
|
93
|
+
|
92
94
|
def test_mode?
|
93
95
|
true
|
94
96
|
end
|
95
97
|
|
96
98
|
private
|
97
|
-
#<?xml version="1.0"?>
|
98
|
-
# <OrderXML>
|
99
|
-
# <Password>Webgistix</Password>
|
100
|
-
# <CustomerID>3</CustomerID>
|
101
|
-
# <Order>
|
102
|
-
# <ReferenceNumber></ReferenceNumber>
|
103
|
-
# <Company>Test Company</Company>
|
104
|
-
# <Name>Joe Smith</Name>
|
105
|
-
# <Address1>123 Main St.</Address1>
|
106
|
-
# <Address2></Address2>
|
107
|
-
# <Address3></Address3>
|
108
|
-
# <City>Olean</City>
|
109
|
-
# <State>NY</State>
|
110
|
-
# <ZipCode>14760</ZipCode>
|
111
|
-
# <Country>United States</Country>
|
112
|
-
# <Email>info@webgistix.com</Email>
|
113
|
-
# <Phone>1-123-456-7890</Phone>
|
114
|
-
# <ShippingInstructions>Ground</ShippingInstructions>
|
115
|
-
# <OrderComments>Test Order</OrderComments>
|
116
|
-
# <Approve>0</Approve>
|
117
|
-
# <Item>
|
118
|
-
# <ItemID>testitem</ItemID>
|
119
|
-
# <ItemQty>2</ItemQty>
|
120
|
-
# </Item>
|
121
|
-
# </Order>
|
99
|
+
#<?xml version="1.0"?>
|
100
|
+
# <OrderXML>
|
101
|
+
# <Password>Webgistix</Password>
|
102
|
+
# <CustomerID>3</CustomerID>
|
103
|
+
# <Order>
|
104
|
+
# <ReferenceNumber></ReferenceNumber>
|
105
|
+
# <Company>Test Company</Company>
|
106
|
+
# <Name>Joe Smith</Name>
|
107
|
+
# <Address1>123 Main St.</Address1>
|
108
|
+
# <Address2></Address2>
|
109
|
+
# <Address3></Address3>
|
110
|
+
# <City>Olean</City>
|
111
|
+
# <State>NY</State>
|
112
|
+
# <ZipCode>14760</ZipCode>
|
113
|
+
# <Country>United States</Country>
|
114
|
+
# <Email>info@webgistix.com</Email>
|
115
|
+
# <Phone>1-123-456-7890</Phone>
|
116
|
+
# <ShippingInstructions>Ground</ShippingInstructions>
|
117
|
+
# <OrderComments>Test Order</OrderComments>
|
118
|
+
# <Approve>0</Approve>
|
119
|
+
# <Item>
|
120
|
+
# <ItemID>testitem</ItemID>
|
121
|
+
# <ItemQty>2</ItemQty>
|
122
|
+
# </Item>
|
123
|
+
# </Order>
|
122
124
|
# </OrderXML>
|
123
125
|
def build_fulfillment_request(order_id, shipping_address, line_items, options)
|
124
126
|
xml = Builder::XmlMarkup.new :indent => 2
|
125
127
|
xml.instruct!
|
126
128
|
xml.tag! 'OrderXML' do
|
127
129
|
add_credentials(xml)
|
128
|
-
add_order(xml, order_id, shipping_address, line_items, options)
|
130
|
+
add_order(xml, order_id, shipping_address, line_items, options)
|
129
131
|
end
|
130
132
|
xml.target!
|
131
133
|
end
|
132
|
-
|
133
|
-
#<?xml version="1.0"?>
|
134
|
-
# <InventoryXML>
|
135
|
-
# <Password>Webgistix</Password>
|
136
|
-
# <CustomerID>3</CustomerID>
|
134
|
+
|
135
|
+
#<?xml version="1.0"?>
|
136
|
+
# <InventoryXML>
|
137
|
+
# <Password>Webgistix</Password>
|
138
|
+
# <CustomerID>3</CustomerID>
|
137
139
|
# </InventoryXML>
|
138
140
|
def build_inventory_request(options)
|
139
141
|
xml = Builder::XmlMarkup.new :indent => 2
|
@@ -145,8 +147,8 @@ module ActiveMerchant
|
|
145
147
|
|
146
148
|
#<?xml version="1.0"?>
|
147
149
|
# <TrackingXML>
|
148
|
-
# <Password>Webgistix</Password>
|
149
|
-
# <CustomerID>3</CustomerID>
|
150
|
+
# <Password>Webgistix</Password>
|
151
|
+
# <CustomerID>3</CustomerID>
|
150
152
|
# <Tracking>
|
151
153
|
# <Order>AB12345</Order>
|
152
154
|
# </Tracking>
|
@@ -159,7 +161,7 @@ module ActiveMerchant
|
|
159
161
|
xml.instruct!
|
160
162
|
xml.tag! 'TrackingXML' do
|
161
163
|
add_credentials(xml)
|
162
|
-
|
164
|
+
|
163
165
|
order_ids.each do |o_id|
|
164
166
|
xml.tag! 'Tracking' do
|
165
167
|
xml.tag! 'Order', o_id
|
@@ -179,7 +181,7 @@ module ActiveMerchant
|
|
179
181
|
xml.tag! 'ShippingInstructions', options[:shipping_method]
|
180
182
|
xml.tag! 'Approve', 1
|
181
183
|
xml.tag! 'OrderComments', options[:comment] unless options[:comment].blank?
|
182
|
-
|
184
|
+
|
183
185
|
add_address(xml, shipping_address, options)
|
184
186
|
|
185
187
|
Array(line_items).each_with_index do |line_item, index|
|
@@ -187,7 +189,7 @@ module ActiveMerchant
|
|
187
189
|
end
|
188
190
|
end
|
189
191
|
end
|
190
|
-
|
192
|
+
|
191
193
|
def add_address(xml, address, options)
|
192
194
|
xml.tag! 'Name', address[:name]
|
193
195
|
xml.tag! 'Address1', address[:address1]
|
@@ -197,12 +199,12 @@ module ActiveMerchant
|
|
197
199
|
xml.tag! 'State', address[:state]
|
198
200
|
xml.tag! 'ZipCode', address[:zip]
|
199
201
|
xml.tag! 'Company', address[:company]
|
200
|
-
|
202
|
+
|
201
203
|
unless address[:country].blank?
|
202
204
|
country = Country.find(address[:country])
|
203
205
|
xml.tag! 'Country', country.name
|
204
206
|
end
|
205
|
-
|
207
|
+
|
206
208
|
xml.tag! 'Phone', address[:phone]
|
207
209
|
xml.tag! 'Email', options[:email] unless options[:email].blank?
|
208
210
|
end
|
@@ -216,20 +218,20 @@ module ActiveMerchant
|
|
216
218
|
|
217
219
|
def commit(action, request)
|
218
220
|
url = test? ? TEST_URLS[action] : SERVICE_URLS[action]
|
219
|
-
|
221
|
+
|
220
222
|
data = ssl_post(url, request,
|
221
223
|
'EndPointURL' => url,
|
222
224
|
'Content-Type' => 'text/xml; charset="utf-8"'
|
223
225
|
)
|
224
|
-
|
226
|
+
|
225
227
|
response = parse_response(action, data)
|
226
228
|
Response.new(success?(response), message_from(response), response, :test => test?)
|
227
229
|
end
|
228
|
-
|
230
|
+
|
229
231
|
def success?(response)
|
230
232
|
response[:success] == SUCCESS || response[:success] == DUPLICATE
|
231
233
|
end
|
232
|
-
|
234
|
+
|
233
235
|
def message_from(response)
|
234
236
|
if response[:duplicate]
|
235
237
|
DUPLICATE_MESSAGE
|
@@ -241,9 +243,9 @@ module ActiveMerchant
|
|
241
243
|
FAILURE_MESSAGE
|
242
244
|
end
|
243
245
|
end
|
244
|
-
|
246
|
+
|
245
247
|
def parse_response(action, xml)
|
246
|
-
begin
|
248
|
+
begin
|
247
249
|
document = REXML::Document.new("<response>#{xml}</response>")
|
248
250
|
rescue REXML::ParseException
|
249
251
|
return {:success => FAILURE}
|
@@ -260,10 +262,10 @@ module ActiveMerchant
|
|
260
262
|
raise ArgumentError, "Unknown action #{action}"
|
261
263
|
end
|
262
264
|
end
|
263
|
-
|
265
|
+
|
264
266
|
def parse_fulfillment_response(document)
|
265
267
|
response = parse_errors(document)
|
266
|
-
|
268
|
+
|
267
269
|
# Check if completed
|
268
270
|
if completed = REXML::XPath.first(document, '//Completed')
|
269
271
|
completed.elements.each do |e|
|
@@ -272,9 +274,9 @@ module ActiveMerchant
|
|
272
274
|
else
|
273
275
|
response[:success] = FAILURE
|
274
276
|
end
|
275
|
-
|
277
|
+
|
276
278
|
response[:duplicate] = response[:success] == DUPLICATE
|
277
|
-
|
279
|
+
|
278
280
|
response
|
279
281
|
end
|
280
282
|
|
@@ -295,6 +297,8 @@ module ActiveMerchant
|
|
295
297
|
def parse_tracking_response(document)
|
296
298
|
response = parse_errors(document)
|
297
299
|
response[:tracking_numbers] = {}
|
300
|
+
response[:tracking_companies] = {}
|
301
|
+
response[:tracking_urls] = {}
|
298
302
|
|
299
303
|
document.root.each_element('//Shipment') do |node|
|
300
304
|
# {InvoiceNumber => 'SOME-ID', ShipmentTrackingNumber => 'SOME-TRACKING-NUMBER'}
|
@@ -306,21 +310,27 @@ module ActiveMerchant
|
|
306
310
|
response[:tracking_numbers][params['InvoiceNumber']] ||= []
|
307
311
|
response[:tracking_numbers][params['InvoiceNumber']] << tracking
|
308
312
|
end
|
313
|
+
|
314
|
+
company = params['Method'].split[0] if params['Method']
|
315
|
+
if TRACKING_COMPANIES.include? company
|
316
|
+
response[:tracking_companies][params['InvoiceNumber']] ||= []
|
317
|
+
response[:tracking_companies][params['InvoiceNumber']] << company
|
318
|
+
end
|
309
319
|
end
|
310
320
|
|
311
321
|
response
|
312
322
|
end
|
313
|
-
|
323
|
+
|
314
324
|
def parse_errors(document)
|
315
325
|
response = {}
|
316
|
-
|
326
|
+
|
317
327
|
REXML::XPath.match(document, "//Errors/Error").to_a.each_with_index do |e, i|
|
318
328
|
response["error_#{i}".to_sym] = e.text
|
319
329
|
end
|
320
|
-
|
330
|
+
|
321
331
|
response[:success] = response.empty? ? SUCCESS : FAILURE
|
322
332
|
response
|
323
|
-
end
|
333
|
+
end
|
324
334
|
end
|
325
335
|
end
|
326
336
|
end
|
@@ -20,7 +20,7 @@ class RemoteAmazonMarketplaceWebservicesTest < Test::Unit::TestCase
|
|
20
20
|
:country => 'US',
|
21
21
|
:zip => '90210'
|
22
22
|
}
|
23
|
-
|
23
|
+
|
24
24
|
@line_items = [
|
25
25
|
{ :sku => 'SETTLERS',
|
26
26
|
:quantity => 1 #,
|
@@ -50,13 +50,13 @@ class RemoteAmazonMarketplaceWebservicesTest < Test::Unit::TestCase
|
|
50
50
|
:login => 'y',
|
51
51
|
:password => 'p',
|
52
52
|
:seller_id => 'o')
|
53
|
-
|
53
|
+
|
54
54
|
response = service.fulfill(ActiveMerchant::Utils.generate_unique_id, @address, @line_items, @options)
|
55
55
|
assert !response.success?
|
56
|
-
|
56
|
+
|
57
57
|
assert_equal "InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.", response.response_comment
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def test_list_orders
|
61
61
|
response = @service.fetch_current_orders
|
62
62
|
assert response.success?
|
@@ -73,23 +73,30 @@ class RemoteAmazonMarketplaceWebservicesTest < Test::Unit::TestCase
|
|
73
73
|
assert response.success?
|
74
74
|
assert_equal 0, response.stock_levels['SETTLERS']
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
|
+
def test_fetch_tracking_data
|
78
|
+
response = @service.fetch_tracking_data(['123456']) # an actual order
|
79
|
+
assert response.success?
|
80
|
+
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
81
|
+
assert_equal Hash.new, response.tracking_companies
|
82
|
+
end
|
83
|
+
|
77
84
|
def test_fetch_tracking_numbers
|
78
85
|
response = @service.fetch_tracking_numbers(['123456']) # an actual order
|
79
86
|
assert response.success?
|
80
87
|
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
81
88
|
end
|
82
|
-
|
89
|
+
|
83
90
|
def test_fetch_tracking_numbers_ignores_not_found
|
84
91
|
response = @service.fetch_tracking_numbers(['1337-1'])
|
85
92
|
assert response.success?
|
86
93
|
assert_equal Hash.new, response.tracking_numbers
|
87
94
|
end
|
88
|
-
|
95
|
+
|
89
96
|
def test_valid_credentials
|
90
97
|
assert @service.valid_credentials?
|
91
98
|
end
|
92
|
-
|
99
|
+
|
93
100
|
def test_invalid_credentials
|
94
101
|
service = AmazonMarketplaceWebService.new(
|
95
102
|
:login => 'your@email.com',
|
@@ -97,7 +104,7 @@ class RemoteAmazonMarketplaceWebservicesTest < Test::Unit::TestCase
|
|
97
104
|
:seller_id => 'SellerNumber1')
|
98
105
|
assert !service.valid_credentials?
|
99
106
|
end
|
100
|
-
|
107
|
+
|
101
108
|
def test_get_status_does_not_require_valid_credentials
|
102
109
|
service = AmazonMarketplaceWebService.new(
|
103
110
|
:login => 'your@email.com',
|
@@ -105,7 +112,7 @@ class RemoteAmazonMarketplaceWebservicesTest < Test::Unit::TestCase
|
|
105
112
|
response = service.status
|
106
113
|
assert response.success?
|
107
114
|
end
|
108
|
-
|
115
|
+
|
109
116
|
def test_get_status
|
110
117
|
service = AmazonMarketplaceWebService.new(fixtures(:amazon))
|
111
118
|
response = service.status
|
data/test/remote/amazon_test.rb
CHANGED
@@ -9,12 +9,12 @@ class RemoteAmazonTest < Test::Unit::TestCase
|
|
9
9
|
def setup
|
10
10
|
@service = AmazonService.new( fixtures(:amazon) )
|
11
11
|
|
12
|
-
@options = {
|
12
|
+
@options = {
|
13
13
|
:shipping_method => 'Standard',
|
14
14
|
:order_date => Time.now.utc.yesterday,
|
15
15
|
:comment => "Delayed due to tornados"
|
16
16
|
}
|
17
|
-
|
17
|
+
|
18
18
|
@address = { :name => 'Johnny Chase',
|
19
19
|
:address1 => '100 Information Super Highway',
|
20
20
|
:address2 => 'Suite 66',
|
@@ -23,7 +23,7 @@ class RemoteAmazonTest < Test::Unit::TestCase
|
|
23
23
|
:country => 'US',
|
24
24
|
:zip => '90210'
|
25
25
|
}
|
26
|
-
|
26
|
+
|
27
27
|
@line_items = [
|
28
28
|
{ :sku => 'SETTLERS8',
|
29
29
|
:quantity => 1 #,
|
@@ -37,28 +37,28 @@ class RemoteAmazonTest < Test::Unit::TestCase
|
|
37
37
|
assert response.success?
|
38
38
|
assert !response.test?
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_order_multiple_line_items
|
42
42
|
@line_items.push(
|
43
43
|
{ :sku => 'CARCASSONNE',
|
44
44
|
:quantity => 2
|
45
45
|
}
|
46
46
|
)
|
47
|
-
|
47
|
+
|
48
48
|
response = @service.fulfill(ActiveMerchant::Utils.generate_unique_id, @address, @line_items, @options)
|
49
49
|
assert response.success?
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def test_invalid_credentials_during_fulfillment
|
53
53
|
service = AmazonService.new(
|
54
54
|
:login => 'y',
|
55
55
|
:password => 'p')
|
56
|
-
|
56
|
+
|
57
57
|
response = service.fulfill(ActiveMerchant::Utils.generate_unique_id, @address, @line_items, @options)
|
58
58
|
assert !response.success?
|
59
59
|
assert_equal "aws:Client.InvalidClientTokenId The AWS Access Key Id you provided does not exist in our records.", response.message
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_list_orders
|
63
63
|
response = @service.fetch_current_orders
|
64
64
|
assert response.success?
|
@@ -75,30 +75,37 @@ class RemoteAmazonTest < Test::Unit::TestCase
|
|
75
75
|
assert response.success?
|
76
76
|
assert_equal 0, response.stock_levels['SETTLERS']
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
|
+
def test_fetch_tracking_numbers
|
80
|
+
response = @service.fetch_tracking_data['123456']) # an actual order
|
81
|
+
assert response.success?
|
82
|
+
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
83
|
+
assert_equal Hash.new, response.tracking_companies
|
84
|
+
end
|
85
|
+
|
79
86
|
def test_fetch_tracking_numbers
|
80
87
|
response = @service.fetch_tracking_numbers(['123456']) # an actual order
|
81
88
|
assert response.success?
|
82
89
|
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
83
90
|
end
|
84
|
-
|
91
|
+
|
85
92
|
def test_fetch_tracking_numbers_ignores_not_found
|
86
93
|
response = @service.fetch_tracking_numbers(['#1337-1'])
|
87
94
|
assert response.success?
|
88
95
|
assert_equal Hash.new, response.tracking_numbers
|
89
96
|
end
|
90
|
-
|
97
|
+
|
91
98
|
def test_valid_credentials
|
92
99
|
assert @service.valid_credentials?
|
93
100
|
end
|
94
|
-
|
101
|
+
|
95
102
|
def test_invalid_credentials
|
96
103
|
service = AmazonService.new(
|
97
104
|
:login => 'your@email.com',
|
98
105
|
:password => 'password')
|
99
106
|
assert !service.valid_credentials?
|
100
107
|
end
|
101
|
-
|
108
|
+
|
102
109
|
def test_get_status_fails
|
103
110
|
service = AmazonService.new(
|
104
111
|
:login => 'your@email.com',
|
@@ -107,11 +114,11 @@ class RemoteAmazonTest < Test::Unit::TestCase
|
|
107
114
|
assert !response.success?
|
108
115
|
assert_equal "aws:Client.InvalidClientTokenId The AWS Access Key Id you provided does not exist in our records.", response.message
|
109
116
|
end
|
110
|
-
|
117
|
+
|
111
118
|
def test_get_status
|
112
119
|
service = AmazonService.new(fixtures(:amazon))
|
113
120
|
response = service.status
|
114
121
|
assert response.success?
|
115
122
|
end
|
116
|
-
|
123
|
+
|
117
124
|
end
|
@@ -5,14 +5,14 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
5
5
|
Base.mode = :test
|
6
6
|
|
7
7
|
@shipwire = ShipwireService.new( fixtures(:shipwire) )
|
8
|
-
|
9
|
-
@options = {
|
8
|
+
|
9
|
+
@options = {
|
10
10
|
:warehouse => 'LAX',
|
11
11
|
:shipping_method => 'UPS Ground',
|
12
12
|
:email => 'cody@example.com'
|
13
13
|
}
|
14
|
-
|
15
|
-
@us_address = {
|
14
|
+
|
15
|
+
@us_address = {
|
16
16
|
:name => 'Steve Jobs',
|
17
17
|
:company => 'Apple Computer Inc.',
|
18
18
|
:address1 => '1 Infinite Loop',
|
@@ -22,8 +22,8 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
22
22
|
:zip => '95014',
|
23
23
|
:email => 'steve@apple.com'
|
24
24
|
}
|
25
|
-
|
26
|
-
@uk_address = {
|
25
|
+
|
26
|
+
@uk_address = {
|
27
27
|
:name => 'Bob Diamond',
|
28
28
|
:company => 'Barclays Bank PLC',
|
29
29
|
:address1 => '1 Churchill Place',
|
@@ -32,22 +32,22 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
32
32
|
:zip => 'E14 5HP',
|
33
33
|
:email => 'bob@barclays.co.uk'
|
34
34
|
}
|
35
|
-
|
35
|
+
|
36
36
|
@line_items = [ { :sku => 'AF0001', :quantity => 25 } ]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def test_invalid_credentials_during_fulfillment
|
40
40
|
shipwire = ShipwireService.new(
|
41
41
|
:login => 'your@email.com',
|
42
42
|
:password => 'password')
|
43
|
-
|
43
|
+
|
44
44
|
response = shipwire.fulfill('123456', @us_address, @line_items, @options)
|
45
45
|
assert !response.success?
|
46
46
|
assert response.test?
|
47
47
|
assert_equal 'Error', response.params['status']
|
48
48
|
assert_equal "Could not verify Username/EmailAddress and Password combination", response.message
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def test_successful_order_submission_to_us
|
52
52
|
response = @shipwire.fulfill('123456', @us_address, @line_items, @options)
|
53
53
|
assert response.success?
|
@@ -58,7 +58,7 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
58
58
|
assert_equal '0', response.params['status']
|
59
59
|
assert_equal 'Successfully submitted the order', response.message
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_successful_order_submission_to_uk
|
63
63
|
response = @shipwire.fulfill('123456', @uk_address, @line_items, @options)
|
64
64
|
assert response.success?
|
@@ -69,10 +69,10 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
69
69
|
assert_equal '0', response.params['status']
|
70
70
|
assert_equal 'Successfully submitted the order', response.message
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def test_order_multiple_line_items
|
74
74
|
@line_items.push({ :sku => 'AF0002', :quantity => 25 })
|
75
|
-
|
75
|
+
|
76
76
|
response = @shipwire.fulfill('123456', @us_address, @line_items, @options)
|
77
77
|
assert response.success?
|
78
78
|
assert response.test?
|
@@ -80,41 +80,41 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
80
80
|
assert_equal '1', response.params['total_orders']
|
81
81
|
assert_equal '2', response.params['total_items']
|
82
82
|
assert_equal '0', response.params['status']
|
83
|
-
assert_equal 'Successfully submitted the order', response.message
|
83
|
+
assert_equal 'Successfully submitted the order', response.message
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def test_no_sku_is_sent_with_fulfillment
|
87
|
-
options = {
|
87
|
+
options = {
|
88
88
|
:shipping_method => 'UPS Ground'
|
89
89
|
}
|
90
|
-
|
90
|
+
|
91
91
|
line_items = [ { :quantity => 1, :description => 'Libtech Snowboard' } ]
|
92
|
-
|
92
|
+
|
93
93
|
response = @shipwire.fulfill('123456', @us_address, line_items, options)
|
94
|
-
|
94
|
+
|
95
95
|
assert response.success?
|
96
96
|
assert response.test?
|
97
97
|
assert_not_nil response.params['transaction_id']
|
98
98
|
assert_equal "1", response.params['total_orders']
|
99
99
|
assert_equal "0", response.params['total_items']
|
100
100
|
assert_equal "0", response.params['status']
|
101
|
-
assert_equal 'Successfully submitted the order', response.message
|
101
|
+
assert_equal 'Successfully submitted the order', response.message
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
def test_invalid_credentials_during_inventory
|
105
105
|
shipwire = ShipwireService.new(
|
106
106
|
:login => 'your@email.com',
|
107
107
|
:password => 'password'
|
108
108
|
)
|
109
|
-
|
109
|
+
|
110
110
|
response = shipwire.fetch_stock_levels
|
111
|
-
|
111
|
+
|
112
112
|
assert !response.success?
|
113
113
|
assert response.test?
|
114
114
|
assert_equal 'Error', response.params['status']
|
115
115
|
assert_equal "Error with Valid Username/EmailAddress and Password Required. There is an error in XML document.", response.message
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def test_get_inventory
|
119
119
|
response = @shipwire.fetch_stock_levels
|
120
120
|
assert response.success?
|
@@ -123,18 +123,26 @@ class RemoteShipwireTest < Test::Unit::TestCase
|
|
123
123
|
assert_equal 32, response.stock_levels["GD201-500"]
|
124
124
|
assert_equal "2", response.params["total_products"]
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
|
+
def test_fetch_tracking_data
|
128
|
+
response = @shipwire.fetch_tracking_data(['123456'])
|
129
|
+
assert response.success?
|
130
|
+
assert response.test?
|
131
|
+
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
132
|
+
assert_equal Hash.new, response.tracking_companies
|
133
|
+
end
|
134
|
+
|
127
135
|
def test_fetch_tracking_numbers
|
128
136
|
response = @shipwire.fetch_tracking_numbers(['123456'])
|
129
|
-
assert response.success?
|
137
|
+
assert response.success?
|
130
138
|
assert response.test?
|
131
139
|
assert_equal Hash.new, response.tracking_numbers # no tracking numbers in testing
|
132
140
|
end
|
133
|
-
|
141
|
+
|
134
142
|
def test_valid_credentials
|
135
143
|
assert @shipwire.valid_credentials?
|
136
144
|
end
|
137
|
-
|
145
|
+
|
138
146
|
def test_invalid_credentials
|
139
147
|
service = ShipwireService.new(
|
140
148
|
:login => 'your@email.com',
|