easypost 2.0.11 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Gemfile.lock +3 -3
- data/VERSION +1 -1
- data/lib/easypost.rb +3 -0
- data/lib/easypost/container.rb +4 -0
- data/lib/easypost/item.rb +10 -0
- data/lib/easypost/order.rb +19 -0
- data/lib/easypost/shipment.rb +3 -9
- data/lib/easypost/util.rb +6 -0
- data/spec/address_spec.rb +16 -38
- data/spec/batch_spec.rb +24 -70
- data/spec/container_spec.rb +87 -0
- data/spec/fedex/domestic_spec.rb +170 -0
- data/spec/fedex/international_spec.rb +64 -0
- data/spec/item_spec.rb +102 -0
- data/spec/order_spec.rb +120 -0
- data/spec/shipment_spec.rb +22 -83
- data/spec/spec_helper.rb +83 -70
- data/spec/ups/domestic_spec.rb +64 -0
- data/spec/ups/international_spec.rb +64 -0
- data/spec/usps/domestic_spec.rb +66 -0
- data/spec/usps/electronic_merchandise_returns.rb +94 -0
- data/spec/usps/merchant_returns.rb +0 -0
- metadata +15 -4
- data/spec/refund_spec.rb +0 -65
- data/spec/scan_form_spec.rb +0 -63
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easypost (2.0.
|
4
|
+
easypost (2.0.11)
|
5
5
|
multi_json (>= 1.0.4, < 2)
|
6
6
|
rest-client (~> 1.4)
|
7
7
|
|
@@ -9,8 +9,8 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
diff-lcs (1.2.4)
|
12
|
-
mime-types (1.
|
13
|
-
multi_json (1.
|
12
|
+
mime-types (1.25.1)
|
13
|
+
multi_json (1.8.4)
|
14
14
|
rest-client (1.6.7)
|
15
15
|
mime-types (>= 1.16)
|
16
16
|
rspec (2.13.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.12
|
data/lib/easypost.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
module EasyPost
|
2
|
+
class Item < Resource
|
3
|
+
|
4
|
+
def self.retrieve_reference(params={})
|
5
|
+
response, api_key = EasyPost.request(:get, url + '/retrieve_reference', @api_key, params)
|
6
|
+
return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module EasyPost
|
2
|
+
class Order < Resource
|
3
|
+
|
4
|
+
def buy(params={})
|
5
|
+
if params.instance_of?(EasyPost::Rate)
|
6
|
+
temp = params.clone
|
7
|
+
params = {}
|
8
|
+
params[:carrier] = temp.carrier
|
9
|
+
params[:service] = temp.service
|
10
|
+
end
|
11
|
+
|
12
|
+
response, api_key = EasyPost.request(:post, url + '/buy', @api_key, params)
|
13
|
+
self.refresh_from(response, @api_key, true)
|
14
|
+
|
15
|
+
return self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/easypost/shipment.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
module EasyPost
|
2
2
|
class Shipment < Resource
|
3
3
|
|
4
|
-
def self.track_with_code(params={})
|
5
|
-
response, api_key = EasyPost.request(:get, url + '/track', @api_key, params)
|
6
|
-
|
7
|
-
return response
|
8
|
-
end
|
9
|
-
|
10
4
|
def get_rates(params={})
|
11
5
|
response, api_key = EasyPost.request(:get, url + '/rates', @api_key, params)
|
12
6
|
self.refresh_from(response, @api_key, true)
|
@@ -76,7 +70,7 @@ module EasyPost
|
|
76
70
|
lowest = nil
|
77
71
|
|
78
72
|
self.get_rates unless self.rates
|
79
|
-
|
73
|
+
|
80
74
|
if !carriers.is_a?(Array)
|
81
75
|
carriers = carriers.split(',')
|
82
76
|
end
|
@@ -125,13 +119,13 @@ module EasyPost
|
|
125
119
|
next
|
126
120
|
end
|
127
121
|
|
128
|
-
if lowest == nil || k.rate.to_f < lowest.rate.to_f
|
122
|
+
if lowest == nil || k.rate.to_f < lowest.rate.to_f
|
129
123
|
lowest = k
|
130
124
|
end
|
131
125
|
end
|
132
126
|
|
133
127
|
raise Error.new('No rates found.') if lowest == nil
|
134
|
-
|
128
|
+
|
135
129
|
return lowest
|
136
130
|
end
|
137
131
|
|
data/lib/easypost/util.rb
CHANGED
@@ -27,6 +27,9 @@ module EasyPost
|
|
27
27
|
'Event' => Event,
|
28
28
|
'Batch' => Batch,
|
29
29
|
'Tracker' => Tracker,
|
30
|
+
'Item' => Item,
|
31
|
+
'Container' => Container,
|
32
|
+
'Order' => Order,
|
30
33
|
'PostageLabel' => PostageLabel }
|
31
34
|
|
32
35
|
prefixes = { 'adr' => Address,
|
@@ -40,6 +43,9 @@ module EasyPost
|
|
40
43
|
'evt' => Event,
|
41
44
|
'batch' => Batch,
|
42
45
|
'trk' => Tracker,
|
46
|
+
'item' => Item,
|
47
|
+
'container' => Container,
|
48
|
+
'order' => Order,
|
43
49
|
'pl' => PostageLabel }
|
44
50
|
|
45
51
|
case response
|
data/spec/address_spec.rb
CHANGED
@@ -1,36 +1,26 @@
|
|
1
|
-
require '
|
2
|
-
EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe EasyPost::Address do
|
5
4
|
describe '#create' do
|
6
5
|
it 'creates an address object' do
|
7
|
-
address = EasyPost::Address.create(
|
8
|
-
|
9
|
-
:street1 => '1A Larkspur Cres.',
|
10
|
-
:city => 'St. Albert',
|
11
|
-
:state => 'AB',
|
12
|
-
:zip => 't8n2m4',
|
13
|
-
:country => 'CA'
|
14
|
-
)
|
6
|
+
address = EasyPost::Address.create(ADDRESS[:california])
|
7
|
+
|
15
8
|
expect(address).to be_an_instance_of(EasyPost::Address)
|
16
|
-
expect(address.
|
9
|
+
expect(address.company).to eq('EasyPost')
|
17
10
|
end
|
18
11
|
end
|
12
|
+
|
19
13
|
describe '#verify' do
|
20
14
|
it 'verifies an address with message' do
|
21
|
-
address = EasyPost::Address.create(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:state => 'CA',
|
26
|
-
:zip => '94107'
|
27
|
-
)
|
28
|
-
expect(address.company).to eq('Simpler Postage Inc')
|
29
|
-
expect(address.street1).to eq('388 Townsend Street')
|
15
|
+
address = EasyPost::Address.create(ADDRESS[:california].reject {|k,v| k == :street2})
|
16
|
+
|
17
|
+
expect(address.company).to eq('EasyPost')
|
18
|
+
expect(address.street1).to eq('164 Townsend Street')
|
30
19
|
expect(address.city).to eq('San Francisco')
|
31
20
|
expect(address.state).to eq('CA')
|
32
21
|
expect(address.zip).to eq('94107')
|
33
22
|
expect(address.country).to eq('US')
|
23
|
+
expect(address.street2).to be_nil
|
34
24
|
|
35
25
|
verified_address = address.verify()
|
36
26
|
expect(verified_address).to be_an_instance_of(EasyPost::Address)
|
@@ -38,21 +28,9 @@ describe EasyPost::Address do
|
|
38
28
|
end
|
39
29
|
|
40
30
|
it 'verifies an address without message' do
|
41
|
-
address = EasyPost::Address.create(
|
42
|
-
|
43
|
-
|
44
|
-
:street2 => 'Apt 20',
|
45
|
-
:city => 'San Francisco',
|
46
|
-
:state => 'CA',
|
47
|
-
:zip => '94107'
|
48
|
-
)
|
49
|
-
expect(address.company).to eq('Simpler Postage Inc')
|
50
|
-
expect(address.street1).to eq('388 Townsend Street')
|
51
|
-
expect(address.street2).to eq('Apt 20')
|
52
|
-
expect(address.city).to eq('San Francisco')
|
53
|
-
expect(address.state).to eq('CA')
|
54
|
-
expect(address.zip).to eq('94107')
|
55
|
-
expect(address.country).to eq('US')
|
31
|
+
address = EasyPost::Address.create(ADDRESS[:california])
|
32
|
+
|
33
|
+
expect(address.street2).to be
|
56
34
|
|
57
35
|
verified_address = address.verify()
|
58
36
|
expect(verified_address).to be_an_instance_of(EasyPost::Address)
|
@@ -64,9 +42,9 @@ describe EasyPost::Address do
|
|
64
42
|
:company => 'Simpler Postage Inc',
|
65
43
|
:street1 => '388 Junk Teerts',
|
66
44
|
:street2 => 'Apt 20',
|
67
|
-
:city
|
68
|
-
:state
|
69
|
-
:zip
|
45
|
+
:city => 'San Francisco',
|
46
|
+
:state => 'CA',
|
47
|
+
:zip => '941abc07'
|
70
48
|
)
|
71
49
|
|
72
50
|
expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Address Not Found./)
|
data/spec/batch_spec.rb
CHANGED
@@ -4,42 +4,21 @@ describe EasyPost::Batch do
|
|
4
4
|
|
5
5
|
describe '#create' do
|
6
6
|
it 'creates a batch object' do
|
7
|
-
from_address = EasyPost::Address.create(
|
8
|
-
:name => "Benchmark Merchandising",
|
9
|
-
:street1 => "329 W 18th Street",
|
10
|
-
:city => "Chicago",
|
11
|
-
:state => "IL",
|
12
|
-
:zip => "60616"
|
13
|
-
)
|
14
|
-
to_address = EasyPost::Address.create(
|
15
|
-
:street1 => "902 Broadway 4th Floor",
|
16
|
-
:city => "New York",
|
17
|
-
:state => "NY",
|
18
|
-
:zip => "10010"
|
19
|
-
)
|
20
|
-
parcel = EasyPost::Parcel.create(
|
21
|
-
:weight => 7.2,
|
22
|
-
:height => 2,
|
23
|
-
:width => 7.5,
|
24
|
-
:length => 10.5
|
25
|
-
)
|
26
|
-
|
27
7
|
batch = EasyPost::Batch.create({
|
28
8
|
:shipment => [{
|
29
|
-
:from_address =>
|
30
|
-
:to_address =>
|
31
|
-
:parcel =>
|
9
|
+
:from_address => ADDRESS[:california],
|
10
|
+
:to_address => ADDRESS[:missouri],
|
11
|
+
:parcel => PARCEL[:dimensions]
|
32
12
|
}, {
|
33
|
-
:from_address =>
|
34
|
-
:to_address =>
|
35
|
-
:parcel =>
|
36
|
-
:reference => 'refnum9173'
|
13
|
+
:from_address => ADDRESS[:california],
|
14
|
+
:to_address => ADDRESS[:canada],
|
15
|
+
:parcel => PARCEL[:dimensions],
|
37
16
|
}],
|
38
|
-
:reference => "
|
39
|
-
|
17
|
+
:reference => "batch123456789"
|
18
|
+
})
|
40
19
|
expect(batch).to be_an_instance_of(EasyPost::Batch)
|
41
20
|
expect(batch.num_shipments).to eq(2)
|
42
|
-
expect(batch.reference).to eq("
|
21
|
+
expect(batch.reference).to eq("batch123456789")
|
43
22
|
expect(batch.state).to eq("creating")
|
44
23
|
|
45
24
|
# sleeps_left = 10
|
@@ -57,46 +36,21 @@ describe EasyPost::Batch do
|
|
57
36
|
|
58
37
|
describe '#create_and_buy' do
|
59
38
|
it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
|
60
|
-
|
61
|
-
:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
parcel = EasyPost::Parcel.create(
|
76
|
-
:weight => 7.2,
|
77
|
-
:height => 2,
|
78
|
-
:width => 7.5,
|
79
|
-
:length => 10.5
|
80
|
-
)
|
81
|
-
|
82
|
-
batch = EasyPost::Batch.create_and_buy({:shipment =>
|
83
|
-
[
|
84
|
-
{
|
85
|
-
:from_address => from_address,
|
86
|
-
:to_address => to_address,
|
87
|
-
:parcel => parcel,
|
88
|
-
:carrier => 'USPS',
|
89
|
-
:service => 'Priority'
|
90
|
-
},
|
91
|
-
{
|
92
|
-
:from_address => from_address,
|
93
|
-
:to_address => to_address,
|
94
|
-
:parcel => parcel,
|
95
|
-
:reference => 'refnum9173',
|
96
|
-
:carrier => 'UPS',
|
97
|
-
:service => '2ndDayAir'
|
98
|
-
}
|
99
|
-
]
|
39
|
+
batch = EasyPost::Batch.create({
|
40
|
+
:shipment => [{
|
41
|
+
:from_address => ADDRESS[:california],
|
42
|
+
:to_address => ADDRESS[:missouri],
|
43
|
+
:parcel => PARCEL[:dimensions],
|
44
|
+
:carrier => "usps",
|
45
|
+
:service => "priority"
|
46
|
+
}, {
|
47
|
+
:from_address => ADDRESS[:california],
|
48
|
+
:to_address => ADDRESS[:canada],
|
49
|
+
:parcel => PARCEL[:dimensions],
|
50
|
+
:carrier => "usps",
|
51
|
+
:service => "prioritymailinternational"
|
52
|
+
}],
|
53
|
+
:reference => "batch123456789"
|
100
54
|
})
|
101
55
|
expect(batch).to be_an_instance_of(EasyPost::Batch)
|
102
56
|
expect(batch.state).to eq("creating")
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EasyPost::Container do
|
4
|
+
|
5
|
+
describe '#create' do
|
6
|
+
it 'creates a container object' do
|
7
|
+
container = EasyPost::Container.create(
|
8
|
+
name: "Spec Box 1",
|
9
|
+
length: 6.2,
|
10
|
+
width: 12.8,
|
11
|
+
height: 13.5,
|
12
|
+
max_weight: 40.55,
|
13
|
+
reference: "SPECBOX",
|
14
|
+
)
|
15
|
+
expect(container).to be_an_instance_of(EasyPost::Container)
|
16
|
+
expect(container.max_weight).to eq(40.55)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'fails to create a container object' do
|
20
|
+
expect { EasyPost::Container.create(
|
21
|
+
name: "Missing dimension",
|
22
|
+
length: 6,
|
23
|
+
width: 12,
|
24
|
+
max_weight: 40
|
25
|
+
) }.to raise_exception(EasyPost::Error, /Invalid request, if one dimension is provided all three are required./)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates a container object with default values' do
|
29
|
+
container = EasyPost::Container.create(name: "Defaults Box")
|
30
|
+
expect(container).to be_an_instance_of(EasyPost::Container)
|
31
|
+
expect(container.id).to be
|
32
|
+
expect(container.name).to eq("Defaults Box")
|
33
|
+
expect(container.length).to eq(0.0)
|
34
|
+
expect(container.width).to eq(0.0)
|
35
|
+
expect(container.height).to eq(0.0)
|
36
|
+
expect(container.max_weight).to eq(0.0)
|
37
|
+
expect(container.type).to eq("BOX")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#retrieve' do
|
42
|
+
it 'retrieves a user created container by public_id' do
|
43
|
+
container_1 = EasyPost::Container.create(
|
44
|
+
name: "My Box",
|
45
|
+
length: 6.2,
|
46
|
+
width: 12.8,
|
47
|
+
height: 13.5,
|
48
|
+
max_weight: 40.55,
|
49
|
+
reference: "SPECBOX",
|
50
|
+
type: "BAG",
|
51
|
+
)
|
52
|
+
container_2 = EasyPost::Container.retrieve(container_1.id)
|
53
|
+
|
54
|
+
expect(container_1).to be_an_instance_of(EasyPost::Container)
|
55
|
+
expect(container_2).to be_an_instance_of(EasyPost::Container)
|
56
|
+
expect(container_2.id).to eq(container_1.id)
|
57
|
+
expect(container_1.type).to eq("BAG")
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'retrieves a user created container by reference' do
|
61
|
+
container_1 = EasyPost::Container.create(
|
62
|
+
name: "Spec Box 2",
|
63
|
+
length: 6.2,
|
64
|
+
width: 12.8,
|
65
|
+
height: 133.94,
|
66
|
+
max_weight: 40.55,
|
67
|
+
reference: "SPECBOX4",
|
68
|
+
)
|
69
|
+
container_2 = EasyPost::Container.retrieve("SPECBOX4")
|
70
|
+
|
71
|
+
expect(container_1).to be_an_instance_of(EasyPost::Container)
|
72
|
+
expect(container_2).to be_an_instance_of(EasyPost::Container)
|
73
|
+
expect(container_2.height).to eq(container_1.height)
|
74
|
+
expect(container_1.type).to eq("BOX")
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'retrieves global containers' do
|
78
|
+
container_1 = EasyPost::Container.retrieve("container_USPSFR03")
|
79
|
+
container_2 = EasyPost::Container.retrieve("container_USPSFR02")
|
80
|
+
|
81
|
+
expect(container_1).to be_an_instance_of(EasyPost::Container)
|
82
|
+
expect(container_2).to be_an_instance_of(EasyPost::Container)
|
83
|
+
expect(container_1.reference).to eq(container_2.reference)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'fedex domestic' do
|
4
|
+
before(:all) do
|
5
|
+
@rates = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'buys a commercial ground label' do
|
9
|
+
shipment = EasyPost::Shipment.create(
|
10
|
+
:to_address => ADDRESS[:california],
|
11
|
+
:from_address => ADDRESS[:missouri],
|
12
|
+
:parcel => PARCEL[:dimensions]
|
13
|
+
)
|
14
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "FEDEX_GROUND"))
|
15
|
+
label = open(shipment.postage_label.label_url)
|
16
|
+
|
17
|
+
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
18
|
+
expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
|
19
|
+
expect(shipment.selected_rate.service).to eq("FEDEX_GROUND")
|
20
|
+
expect(shipment.postage_label.label_url).to end_with(".png")
|
21
|
+
expect(shipment.tracking_code).to start_with("8000")
|
22
|
+
expect(label.size).to be > 5000
|
23
|
+
|
24
|
+
@rates[:commercial] = shipment.selected_rate
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'buys a residential ground label' do
|
28
|
+
shipment = EasyPost::Shipment.create(
|
29
|
+
:to_address => ADDRESS[:california],
|
30
|
+
:from_address => ADDRESS[:missouri],
|
31
|
+
:parcel => PARCEL[:dimensions],
|
32
|
+
:options => {:residential_to_address => true}
|
33
|
+
)
|
34
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
|
35
|
+
label = open(shipment.postage_label.label_url)
|
36
|
+
|
37
|
+
expect(shipment.selected_rate.service).to eq("GROUND_HOME_DELIVERY")
|
38
|
+
expect(shipment.tracking_code).to start_with("8000")
|
39
|
+
expect(label.size).to be > 5000
|
40
|
+
|
41
|
+
@rates[:residential] = shipment.selected_rate
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'buys a ground evening delivery label' do
|
45
|
+
shipment = EasyPost::Shipment.create(
|
46
|
+
:to_address => ADDRESS[:california],
|
47
|
+
:from_address => ADDRESS[:missouri],
|
48
|
+
:parcel => PARCEL[:dimensions],
|
49
|
+
:options => {:residential_to_address => true,
|
50
|
+
:delivery_time_preference => "evening"}
|
51
|
+
)
|
52
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
|
53
|
+
|
54
|
+
expect(shipment.postage_label.label_url).to end_with(".png")
|
55
|
+
|
56
|
+
@rates[:residential_evening] = shipment.selected_rate
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'raises error without recipient phone number' do
|
60
|
+
shipment = EasyPost::Shipment.create(
|
61
|
+
:to_address => ADDRESS[:california_no_phone],
|
62
|
+
:from_address => ADDRESS[:missouri],
|
63
|
+
:parcel => PARCEL[:dimensions]
|
64
|
+
)
|
65
|
+
|
66
|
+
expect { shipment.buy(rate: shipment.lowest_rate("fedex")) }.to raise_error(EasyPost::Error, /Unable to buy FedEx shipment without recipient phone number./)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'buys a label for an alcoholic shipment with epl2 label' do
|
70
|
+
shipment = EasyPost::Shipment.create(
|
71
|
+
:to_address => ADDRESS[:california],
|
72
|
+
:from_address => ADDRESS[:missouri],
|
73
|
+
:parcel => PARCEL[:dimensions],
|
74
|
+
:options => {
|
75
|
+
:alcohol => 1,
|
76
|
+
:label_format => "epl2"
|
77
|
+
}
|
78
|
+
)
|
79
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
|
80
|
+
|
81
|
+
expect(shipment.postage_label.label_url).to end_with(".epl2")
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'buys a label for a ground cod shipment' do
|
85
|
+
shipment = EasyPost::Shipment.create(
|
86
|
+
:to_address => ADDRESS[:california],
|
87
|
+
:from_address => ADDRESS[:missouri],
|
88
|
+
:parcel => PARCEL[:dimensions]
|
89
|
+
)
|
90
|
+
shipment_cod = EasyPost::Shipment.create(
|
91
|
+
:to_address => ADDRESS[:california],
|
92
|
+
:from_address => ADDRESS[:missouri],
|
93
|
+
:parcel => PARCEL[:dimensions],
|
94
|
+
:options => {cod_amount: 19.99}
|
95
|
+
)
|
96
|
+
shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "FEDEX_GROUND"))
|
97
|
+
|
98
|
+
expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
|
99
|
+
expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
|
100
|
+
expect(shipment_cod.postage_label.label_url).to be
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'buys a label for a ground multi-parcel cod shipment' do
|
104
|
+
order = EasyPost::Order.create(
|
105
|
+
to_address: ADDRESS[:california],
|
106
|
+
from_address: ADDRESS[:missouri],
|
107
|
+
shipments: [{
|
108
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12},
|
109
|
+
options: {cod_amount: 14.99}
|
110
|
+
},{
|
111
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12},
|
112
|
+
options: {cod_amount: 18.75}
|
113
|
+
}]
|
114
|
+
)
|
115
|
+
order.buy(carrier: "fedex", service: "FEDEX_GROUND")
|
116
|
+
|
117
|
+
expect(order).to be_an_instance_of(EasyPost::Order)
|
118
|
+
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
119
|
+
expect(order.shipments[0].postage_label.label_url).to be
|
120
|
+
expect(order.shipments[1].postage_label.label_url).to be
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'buys a label for an express cod shipment' do
|
124
|
+
shipment = EasyPost::Shipment.create(
|
125
|
+
:to_address => ADDRESS[:california],
|
126
|
+
:from_address => ADDRESS[:missouri],
|
127
|
+
:parcel => PARCEL[:dimensions]
|
128
|
+
)
|
129
|
+
shipment_cod = EasyPost::Shipment.create(
|
130
|
+
:to_address => ADDRESS[:california],
|
131
|
+
:from_address => ADDRESS[:missouri],
|
132
|
+
:parcel => PARCEL[:dimensions],
|
133
|
+
:options => {cod_amount: 19.99}
|
134
|
+
)
|
135
|
+
shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
|
136
|
+
|
137
|
+
expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
|
138
|
+
expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
|
139
|
+
expect(shipment_cod.postage_label.label_url).to be
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'buys a label for an express multi-parcel cod shipment' do
|
143
|
+
order = EasyPost::Order.create(
|
144
|
+
to_address: ADDRESS[:california],
|
145
|
+
from_address: ADDRESS[:missouri],
|
146
|
+
shipments: [{
|
147
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12},
|
148
|
+
options: {cod_amount: 14.99}
|
149
|
+
},{
|
150
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12},
|
151
|
+
options: {cod_amount: 18.75}
|
152
|
+
}]
|
153
|
+
)
|
154
|
+
order.buy(carrier: "fedex", service: "PRIORITY_OVERNIGHT")
|
155
|
+
|
156
|
+
expect(order).to be_an_instance_of(EasyPost::Order)
|
157
|
+
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
158
|
+
expect(order.shipments[0].postage_label.label_url).to be
|
159
|
+
expect(order.shipments[1].postage_label.label_url).to be
|
160
|
+
end
|
161
|
+
|
162
|
+
after(:all) do
|
163
|
+
begin
|
164
|
+
expect(@rates[:residential_evening].rate.to_i).to be > @rates[:residential].rate.to_i
|
165
|
+
expect(@rates[:residential].rate.to_i).to be > @rates[:commercial].rate.to_i
|
166
|
+
rescue
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|