active_fulfillment 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +26 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/active_fulfillment.gemspec +74 -0
- data/init.rb +1 -0
- data/lib/active_fulfillment/fulfillment/base.rb +12 -0
- data/lib/active_fulfillment/fulfillment/response.rb +32 -0
- data/lib/active_fulfillment/fulfillment/service.rb +31 -0
- data/lib/active_fulfillment/fulfillment/services/amazon.rb +230 -0
- data/lib/active_fulfillment/fulfillment/services/shipwire.rb +236 -0
- data/lib/active_fulfillment/fulfillment/services/webgistix.rb +207 -0
- data/lib/active_fulfillment/fulfillment/services.rb +3 -0
- data/lib/active_fulfillment.rb +50 -0
- data/lib/active_merchant/common/connection.rb +172 -0
- data/lib/active_merchant/common/country.rb +319 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +47 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +18 -0
- data/lib/active_merchant/common/validateable.rb +76 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/certs/cacert.pem +7815 -0
- data/test/fixtures.yml +11 -0
- data/test/remote/amazon_test.rb +93 -0
- data/test/remote/shipwire_test.rb +145 -0
- data/test/remote/webgistix_test.rb +80 -0
- data/test/test_helper.rb +60 -0
- data/test/unit/base_test.rb +17 -0
- data/test/unit/services/amazon_test.rb +187 -0
- data/test/unit/services/shipwire_test.rb +164 -0
- data/test/unit/services/webgistix_test.rb +145 -0
- metadata +106 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShipwireTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Base.mode = :test
|
6
|
+
|
7
|
+
@shipwire = ShipwireService.new(
|
8
|
+
:login => 'cody@example.com',
|
9
|
+
:password => 'test'
|
10
|
+
)
|
11
|
+
|
12
|
+
@options = {
|
13
|
+
:warehouse => '01',
|
14
|
+
:shipping_method => 'UPS Ground'
|
15
|
+
}
|
16
|
+
|
17
|
+
@address = {
|
18
|
+
:name => 'Fred Brooks',
|
19
|
+
:address1 => '1234 Penny Lane',
|
20
|
+
:city => 'Jonsetown',
|
21
|
+
:state => 'NC',
|
22
|
+
:country => 'US',
|
23
|
+
:zip => '23456',
|
24
|
+
:email => 'buyer@jadedpallet.com'
|
25
|
+
}
|
26
|
+
|
27
|
+
@line_items = [ { :sku => '9999', :quantity => 25 } ]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_missing_login
|
31
|
+
assert_raise(ArgumentError) do
|
32
|
+
ShipwireService.new(:password => 'test')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_missing_password
|
37
|
+
assert_raise(ArgumentError) do
|
38
|
+
ShipwireService.new(:login => 'cody')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_missing_credentials
|
43
|
+
assert_raise(ArgumentError) do
|
44
|
+
ShipwireService.new(:password => 'test')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_credentials_present
|
49
|
+
assert_nothing_raised do
|
50
|
+
ShipwireService.new(
|
51
|
+
:login => 'cody',
|
52
|
+
:password => 'test'
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_country_format
|
58
|
+
xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
|
59
|
+
country_node = REXML::XPath.first(xml, "//Country")
|
60
|
+
assert_equal 'US', country_node.text
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_no_tracking_numbers_available
|
64
|
+
@shipwire.expects(:ssl_post).returns(successful_empty_tracking_response)
|
65
|
+
response = @shipwire.fetch_tracking_numbers
|
66
|
+
assert response.success?
|
67
|
+
assert_equal Hash.new, response.tracking_numbers
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_successful_tracking
|
72
|
+
expected = { "2986" => "1ZW682E90326614239",
|
73
|
+
"2987" => "1ZW682E90326795080" }
|
74
|
+
|
75
|
+
@shipwire.expects(:ssl_post).returns(successful_tracking_response)
|
76
|
+
response = @shipwire.fetch_tracking_numbers
|
77
|
+
assert response.success?
|
78
|
+
assert_equal "3", response.params["total_orders"]
|
79
|
+
assert_equal "Test", response.params["status"]
|
80
|
+
assert_equal "2", response.params["total_shipped_orders"]
|
81
|
+
|
82
|
+
assert_equal expected, response.tracking_numbers
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_successful_tracking_with_live_data
|
86
|
+
@shipwire.expects(:ssl_post).returns(successful_live_tracking_response)
|
87
|
+
response = @shipwire.fetch_tracking_numbers
|
88
|
+
assert response.success?
|
89
|
+
assert_equal "15", response.params["total_orders"]
|
90
|
+
assert_equal "0", response.params["status"]
|
91
|
+
assert_equal "13", response.params["total_shipped_orders"]
|
92
|
+
|
93
|
+
assert_equal 13, response.tracking_numbers.size
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_valid_credentials
|
97
|
+
@shipwire.expects(:ssl_post).returns(successful_empty_tracking_response)
|
98
|
+
assert @shipwire.valid_credentials?
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_invalid_credentials
|
102
|
+
@shipwire.expects(:ssl_post).returns(invalid_login_response)
|
103
|
+
assert !@shipwire.valid_credentials?
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def successful_empty_tracking_response
|
108
|
+
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<TrackingUpdateResponse><Status>Test</Status><TotalOrders></TotalOrders><TotalShippedOrders></TotalShippedOrders><TotalProducts></TotalProducts><Bookmark></Bookmark></TrackingUpdateResponse>"
|
109
|
+
end
|
110
|
+
|
111
|
+
def successful_tracking_response
|
112
|
+
<<-XML
|
113
|
+
<?xml version="1.0"?>
|
114
|
+
<TrackingUpdateResponse>
|
115
|
+
<Status>Test</Status>
|
116
|
+
<Order id="2986" shipped="YES" trackingNumber="1ZW682E90326614239" shipper="UPS GD" handling="1.00" shipping="13.66" total="14.66"/>
|
117
|
+
<Order id="2987" shipped="YES" trackingNumber="1ZW682E90326795080" shipper="UPS GD" handling="1.50" shipping="9.37" total="10.87"/>
|
118
|
+
<Order id="2988" shipped="NO" trackingNumber="" shipper="UPS GD" handling="" shipping="" total=""/>
|
119
|
+
<TotalOrders>3</TotalOrders>
|
120
|
+
<TotalShippedOrders>2</TotalShippedOrders>
|
121
|
+
<Bookmark>2006-04-28 20:35:45</Bookmark>
|
122
|
+
</TrackingUpdateResponse>
|
123
|
+
XML
|
124
|
+
end
|
125
|
+
|
126
|
+
def successful_live_tracking_response
|
127
|
+
<<-XML
|
128
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
129
|
+
<TrackingUpdateResponse>
|
130
|
+
<Status>0</Status>
|
131
|
+
<Order id="21" shipped="YES" trackingNumber="1Z6296VW0398500001" shipper="5" handling="0.00" shipping="6.58" total="6.58"/>
|
132
|
+
<Order id="22" shipped="YES" trackingNumber="1Z6296VW0390790002" shipper="5" handling="0.00" shipping="8.13" total="8.13"/>
|
133
|
+
<Order id="23" shipped="YES" trackingNumber="1Z6296VW0396490003" shipper="5" handling="0.00" shipping="7.63" total="7.63"/>
|
134
|
+
<Order id="24" shipped="YES" trackingNumber="1Z6296VW0390200004" shipper="5" handling="0.00" shipping="8.97" total="8.97"/>
|
135
|
+
<Order id="25" shipped="YES" trackingNumber="1Z6296VW0393240005" shipper="5" handling="0.00" shipping="8.42" total="8.42"/>
|
136
|
+
<Order id="26" shipped="YES" trackingNumber="1Z6296VW0396400006" shipper="5" handling="0.00" shipping="8.42" total="8.42"/>
|
137
|
+
<Order id="2581" shipped="YES" trackingNumber="1Z6296VW0391160007" shipper="5" handling="0.00" shipping="8.21" total="8.21"/>
|
138
|
+
<Order id="2576" shipped="YES" trackingNumber="CJ3026000018US" shipper="43" handling="0.00" shipping="18.60" total="18.60"/>
|
139
|
+
<Order id="2593" shipped="YES" trackingNumber="1Z6296VW0398660008" shipper="5" handling="0.00" shipping="7.63" total="7.63"/>
|
140
|
+
<Order id="2598" shipped="YES" trackingNumber="1Z6296VW0391610009" shipper="5" handling="0.00" shipping="9.84" total="9.84"/>
|
141
|
+
<Order id="2610" shipped="YES" trackingNumber="1Z6296VW0395650010" shipper="5" handling="0.00" shipping="7.63" total="7.63"/>
|
142
|
+
<Order id="2611" shipped="YES" trackingNumber="1Z6296VW0397050011" shipper="5" handling="0.00" shipping="7.13" total="7.13"/>
|
143
|
+
<Order id="2613" shipped="YES" trackingNumber="1Z6296VW0398970012" shipper="5" handling="0.00" shipping="8.97" total="8.97"/>
|
144
|
+
<Order id="2616" shipped="NO" trackingNumber="" shipper="5" handling="0.00" shipping="9.84" total="9.84"/>
|
145
|
+
<Order id="2631" shipped="NO" trackingNumber="" shipper="" handling="" shipping="" total=""/>
|
146
|
+
<TotalOrders>15</TotalOrders>
|
147
|
+
<TotalShippedOrders>13</TotalShippedOrders>
|
148
|
+
<TotalProducts/>
|
149
|
+
<Bookmark/>
|
150
|
+
</TrackingUpdateResponse>
|
151
|
+
|
152
|
+
XML
|
153
|
+
end
|
154
|
+
|
155
|
+
def invalid_login_response
|
156
|
+
<<-XML
|
157
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
158
|
+
<TrackingUpdateResponse><Status>Error</Status><ErrorMessage>
|
159
|
+
Error with EmailAddress, valid email is required.
|
160
|
+
There is an error in XML document.
|
161
|
+
</ErrorMessage></TrackingUpdateResponse>
|
162
|
+
XML
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WebgistixTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Base.mode = :test
|
6
|
+
|
7
|
+
@service = WebgistixService.new(
|
8
|
+
:login => 'cody@example.com',
|
9
|
+
:password => 'test'
|
10
|
+
)
|
11
|
+
|
12
|
+
@options = {
|
13
|
+
:shipping_method => 'UPS Ground'
|
14
|
+
}
|
15
|
+
|
16
|
+
@address = { :name => 'Fred Brooks',
|
17
|
+
:address1 => '1234 Penny Lane',
|
18
|
+
:city => 'Jonsetown',
|
19
|
+
:state => 'NC',
|
20
|
+
:country => 'US',
|
21
|
+
:zip => '23456',
|
22
|
+
:email => 'buyer@jadedpallet.com'
|
23
|
+
}
|
24
|
+
|
25
|
+
@line_items = [
|
26
|
+
{ :sku => '9999',
|
27
|
+
:quantity => 25
|
28
|
+
}
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_missing_login
|
33
|
+
assert_raise(ArgumentError) do
|
34
|
+
WebgistixService.new(:password => 'test')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_missing_password
|
39
|
+
assert_raise(ArgumentError) do
|
40
|
+
WebgistixService.new(:login => 'cody')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_missing_credentials
|
45
|
+
assert_raise(ArgumentError) do
|
46
|
+
WebgistixService.new(:password => 'test')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_credentials_present
|
51
|
+
assert_nothing_raised do
|
52
|
+
WebgistixService.new(
|
53
|
+
:login => 'cody',
|
54
|
+
:password => 'test'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_successful_fulfillment
|
60
|
+
@service.expects(:ssl_post).returns(successful_response)
|
61
|
+
|
62
|
+
response = @service.fulfill('123456', @address, @line_items, @options)
|
63
|
+
assert response.success?
|
64
|
+
assert response.test?
|
65
|
+
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
66
|
+
assert_equal '619669', response.params['order_id']
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_minimal_successful_fulfillment
|
70
|
+
@service.expects(:ssl_post).returns(minimal_successful_response)
|
71
|
+
|
72
|
+
response = @service.fulfill('123456', @address, @line_items, @options)
|
73
|
+
assert response.success?
|
74
|
+
assert response.test?
|
75
|
+
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
76
|
+
assert_nil response.params['order_id']
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_failed_fulfillment
|
80
|
+
@service.expects(:ssl_post).returns(failure_response)
|
81
|
+
|
82
|
+
response = @service.fulfill('123456', @address, @line_items, @options)
|
83
|
+
assert !response.success?
|
84
|
+
assert response.test?
|
85
|
+
assert_equal WebgistixService::FAILURE_MESSAGE, response.message
|
86
|
+
assert_nil response.params['order_id']
|
87
|
+
|
88
|
+
assert_equal 'No Address Line 1', response.params['error_0']
|
89
|
+
assert_equal 'Unknown ItemID: testitem', response.params['error_1']
|
90
|
+
assert_equal 'Unknown ItemID: WX-01-1000', response.params['error_2']
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_failed_login
|
94
|
+
@service.expects(:ssl_post).returns(invalid_login_response)
|
95
|
+
|
96
|
+
response = @service.fulfill('123456', @address, @line_items, @options)
|
97
|
+
assert !response.success?
|
98
|
+
assert response.test?
|
99
|
+
assert_equal 'Access Denied', response.message
|
100
|
+
assert_nil response.params['order_id']
|
101
|
+
|
102
|
+
assert_equal 'Access Denied', response.params['error_0']
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_garbage_response
|
106
|
+
@service.expects(:ssl_post).returns(garbage_response)
|
107
|
+
|
108
|
+
response = @service.fulfill('123456', @address, @line_items, @options)
|
109
|
+
assert !response.success?
|
110
|
+
assert response.test?
|
111
|
+
assert_equal WebgistixService::FAILURE_MESSAGE, response.message
|
112
|
+
assert_nil response.params['order_id']
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_valid_credentials
|
116
|
+
@service.expects(:ssl_post).returns(failure_response)
|
117
|
+
assert @service.valid_credentials?
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_invalid_credentials
|
121
|
+
@service.expects(:ssl_post).returns(invalid_login_response)
|
122
|
+
assert !@service.valid_credentials?
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
def minimal_successful_response
|
127
|
+
'<Completed><Success>True</Success></Completed>'
|
128
|
+
end
|
129
|
+
|
130
|
+
def successful_response
|
131
|
+
'<Completed><Success>True</Success><OrderID>619669</OrderID></Completed>'
|
132
|
+
end
|
133
|
+
|
134
|
+
def invalid_login_response
|
135
|
+
'<Error>Access Denied</Error>'
|
136
|
+
end
|
137
|
+
|
138
|
+
def failure_response
|
139
|
+
'<Error>No Address Line 1</Error><Error>Unknown ItemID: testitem</Error><Error>Unknown ItemID: WX-01-1000</Error>'
|
140
|
+
end
|
141
|
+
|
142
|
+
def garbage_response
|
143
|
+
'<font face="Arial" size=2>/XML/shippingTest.asp</font><font face="Arial" size=2>, line 39</font>'
|
144
|
+
end
|
145
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_fulfillment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 55
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
- 0
|
10
|
+
version: 0.10.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Cody Fauser
|
14
|
+
- James MacAulay
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-07-06 00:00:00 -04:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description:
|
24
|
+
email: cody@shopify.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- CHANGELOG
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- active_fulfillment.gemspec
|
36
|
+
- init.rb
|
37
|
+
- lib/active_fulfillment.rb
|
38
|
+
- lib/active_fulfillment/fulfillment/base.rb
|
39
|
+
- lib/active_fulfillment/fulfillment/response.rb
|
40
|
+
- lib/active_fulfillment/fulfillment/service.rb
|
41
|
+
- lib/active_fulfillment/fulfillment/services.rb
|
42
|
+
- lib/active_fulfillment/fulfillment/services/amazon.rb
|
43
|
+
- lib/active_fulfillment/fulfillment/services/shipwire.rb
|
44
|
+
- lib/active_fulfillment/fulfillment/services/webgistix.rb
|
45
|
+
- lib/active_merchant/common.rb
|
46
|
+
- lib/active_merchant/common/connection.rb
|
47
|
+
- lib/active_merchant/common/country.rb
|
48
|
+
- lib/active_merchant/common/error.rb
|
49
|
+
- lib/active_merchant/common/post_data.rb
|
50
|
+
- lib/active_merchant/common/posts_data.rb
|
51
|
+
- lib/active_merchant/common/requires_parameters.rb
|
52
|
+
- lib/active_merchant/common/utils.rb
|
53
|
+
- lib/active_merchant/common/validateable.rb
|
54
|
+
- lib/certs/cacert.pem
|
55
|
+
- test/fixtures.yml
|
56
|
+
- test/remote/amazon_test.rb
|
57
|
+
- test/remote/shipwire_test.rb
|
58
|
+
- test/remote/webgistix_test.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
- test/unit/base_test.rb
|
61
|
+
- test/unit/services/amazon_test.rb
|
62
|
+
- test/unit/services/shipwire_test.rb
|
63
|
+
- test/unit/services/webgistix_test.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/shopify/active_fulfillment
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Framework and tools for dealing with shipping, tracking and order fulfillment services.
|
98
|
+
test_files:
|
99
|
+
- test/remote/amazon_test.rb
|
100
|
+
- test/remote/shipwire_test.rb
|
101
|
+
- test/remote/webgistix_test.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
- test/unit/base_test.rb
|
104
|
+
- test/unit/services/amazon_test.rb
|
105
|
+
- test/unit/services/shipwire_test.rb
|
106
|
+
- test/unit/services/webgistix_test.rb
|