Skip to content

Commit ee43727

Browse files
benschoolmatt423
authored andcommitted
Total charge and currency code added to ship accept parser
Add the total charge with and without negotiated rates and currency code for VQ-13107
1 parent 279a023 commit ee43727

5 files changed

Lines changed: 104 additions & 4 deletions

File tree

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ups-ruby (0.17.0)
4+
ups-ruby (0.18.1)
55
excon (~> 0.45, >= 0.45.3)
66
insensitive_hash (~> 0.3.3)
77
levenshtein-ffi (~> 1.1)
@@ -14,7 +14,7 @@ GEM
1414
simplecov
1515
docile (1.1.5)
1616
excon (0.73.0)
17-
ffi (1.12.2)
17+
ffi (1.13.1)
1818
insensitive_hash (0.3.3)
1919
json (1.8.6)
2020
levenshtein-ffi (1.1.0)

lib/ups/parsers/ship_accept_parser.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,30 @@ def packages
4242
[UPS::Models::PackageResult.new(package_results)]
4343
end
4444

45+
def total_charge
46+
return shipment_charge unless negotiated_rate
47+
48+
negotiated_rate
49+
end
50+
51+
def negotiated_rate
52+
negotiated_rate_response && negotiated_rate_response[:NetSummaryCharges][:GrandTotal][:MonetaryValue].to_f
53+
end
54+
55+
def currency_code
56+
shipment_results[:ShipmentCharges][:TotalCharges][:CurrencyCode]
57+
end
58+
4559
private
4660

61+
def negotiated_rate_response
62+
shipment_results[:NegotiatedRates]
63+
end
64+
65+
def shipment_charge
66+
shipment_results[:ShipmentCharges][:TotalCharges][:MonetaryValue].to_f
67+
end
68+
4769
def form_graphic
4870
shipment_results[:Form]
4971
end

lib/ups/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module UPS
22
module Version
33
MAJOR = 0
4-
MINOR = 17
4+
MINOR = 18
55
PATCH = 1
66
BUILD = nil
77

spec/stubs/ship_accept_success_without_negotiated_price.xml

Lines changed: 59 additions & 0 deletions
Large diffs are not rendered by default.

spec/ups/connection/ship_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
let(:stub_path) { File.expand_path("../../../stubs", __FILE__) }
1717
let(:server) { UPS::Connection.new(test_mode: true) }
18+
let(:ship_accept_stub_file) { 'ship_accept_success' }
1819

1920
describe 'if requesting a shipment' do
2021
describe 'single package shipment' do
@@ -27,7 +28,7 @@
2728
}
2829
when UPS::Connection::SHIP_ACCEPT_PATH
2930
{
30-
body: File.read("#{stub_path}/ship_accept_success.xml"), status: 200
31+
body: File.read("#{stub_path}/#{ship_accept_stub_file}.xml"), status: 200
3132
}
3233
end
3334
end
@@ -80,6 +81,24 @@
8081
it 'should return the tracking number' do
8182
subject.tracking_number.must_equal '1Z2220060292353829'
8283
end
84+
85+
describe 'total shipment cost' do
86+
describe 'with negotiated rates' do
87+
it 'returns the total shipment cost' do
88+
subject.total_charge.must_equal 115.14
89+
subject.currency_code.must_equal 'USD'
90+
end
91+
end
92+
93+
describe 'without negotiated rates' do
94+
let(:ship_accept_stub_file) { 'ship_accept_success_without_negotiated_price' }
95+
96+
it 'returns the total shipment cost' do
97+
subject.total_charge.must_equal 118.48
98+
subject.currency_code.must_equal 'USD'
99+
end
100+
end
101+
end
83102
end
84103

85104
describe 'when packaging type is specified' do

0 commit comments

Comments
 (0)