pbshipping 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tracking.rb
16
+ # Description: shipment tracking functions
17
+ #
18
+
19
+ module PBShipping
20
+ class Tracking < ShippingApiResource
21
+
22
+ #
23
+ # TRACKING
24
+ # API: GET /tracking/{trackingNumber}
25
+ # API signature: get/tracking/...
26
+ #
27
+ # Shipment labels that are printed using the Pitney Bowes APIs are
28
+ # automatically tracked and their package status can be easily retrieved
29
+ # using this implementation of the GET operation.
30
+ #
31
+ def updateStatus(auth_obj)
32
+ if self.key?(:trackingNumber) == false
33
+ raise MissingResourceAttribute.new(:trackingNumber)
34
+ end
35
+ if self.key?(:packageIdentifierType) == false
36
+ self[:packageIdentifierType] = "TrackingNumber"
37
+ end
38
+ if self.key?(:carrier) == false
39
+ self[:carrier] = "USPS"
40
+ end
41
+ params = {
42
+ :carrier => self[:carrier],
43
+ :packageIdentifierType => self[:packageIdentifierType]
44
+ }
45
+ api_sig = "get/tracking/..."
46
+ api_version = PBShipping::get_api_version(api_sig)
47
+ api_path = "/tracking/" + self[:trackingNumber]
48
+ json_resp = PBShipping::api_request(
49
+ auth_obj, :get, api_version, api_path, {}, params, {})
50
+ self.update(json_resp)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: transactiondetails.rb
16
+ # Description: transaction detail objects
17
+ #
18
+
19
+ module PBShipping
20
+ class TransactionDetails < ShippingApiResource
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module PBShipping
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tc_address.rb
16
+ # Description: unit test for address verification
17
+ #
18
+
19
+ require "test/unit"
20
+ require "pbshipping"
21
+ require_relative "test_util"
22
+
23
+ class TestAddress < Test::Unit::TestCase
24
+
25
+ def setup
26
+ @auth_obj = PBShipping::AuthenticationToken.new(
27
+ PBShippingTestUtil::api_key, PBShippingTestUtil::api_secret)
28
+ end
29
+
30
+ def teardown
31
+ end
32
+
33
+ def test_address
34
+ puts "Testing get countries call ..."
35
+ usps_carrier = PBShipping::Carrier.new({:name => "usps"})
36
+ usps_carrier.getCountries(@auth_obj, "US")
37
+
38
+ puts "Testing address verification ..."
39
+ # expect the address is cleansed and changed
40
+ address = PBShipping::Address.new(PBShippingTestUtil::my_origin_addr);
41
+ address.verify(@auth_obj, false)
42
+ assert_equal(address[:status].downcase, "validated_changed")
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tc_manifest.rb
16
+ # Description: unit test for manifest manipulation
17
+ #
18
+
19
+ require "test/unit"
20
+ require "pbshipping"
21
+
22
+ class TestManifest < Test::Unit::TestCase
23
+
24
+ def setup
25
+ @auth_obj = PBShipping::AuthenticationToken.new(
26
+ PBShippingTestUtil::api_key, PBShippingTestUtil::api_secret)
27
+ @developer = PBShippingTestUtil::setup_developer(@auth_obj)
28
+ merchant, @acct_num = PBShippingTestUtil::setup_merchant(
29
+ @auth_obj, @developer)
30
+ @shipper_id = merchant.postalReportingNumber
31
+
32
+ end
33
+
34
+ def teardown
35
+ end
36
+
37
+ def test_manifest
38
+
39
+ shipment1, txid1 = PBShippingTestUtil::create_single_shipment(
40
+ @auth_obj, @developer, @shipper_id)
41
+ shipment2, txid2 = PBShippingTestUtil::create_single_shipment(
42
+ @auth_obj, @developer, @shipper_id)
43
+
44
+ carrier = PBShippingTestUtil::my_rate_request_carrier_usps[:carrier]
45
+ trk_nums = [shipment1.parcelTrackingNumber,
46
+ shipment2.parcelTrackingNumber]
47
+
48
+ manifest = PBShipping::Manifest.new( {
49
+ :carrier => carrier,
50
+ :submissionDate => Time.now.utc.strftime("%Y-%m-%d"),
51
+ :parcelTrackingNumbers => trk_nums,
52
+ :fromAddress => shipment1.fromAddress
53
+ } )
54
+
55
+ puts "Testing manifest creation ..."
56
+ original_txid = PBShippingTestUtil::get_pb_tx_id()
57
+ manifest.create(@auth_obj, original_txid)
58
+ assert_equal(manifest.key?(:manifestId), true)
59
+
60
+ puts "Testing reprint manifest ..."
61
+ manifest.reprint(@auth_obj)
62
+
63
+ puts "Testing retry manifest ..."
64
+ txid = PBShippingTestUtil::get_pb_tx_id()
65
+ manifest.retry(@auth_obj, txid, original_txid)
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tc_merchant.rb
16
+ # Description: unit test for merchant account query and registration
17
+ #
18
+
19
+ require "test/unit"
20
+ require "pbshipping"
21
+ require_relative "test_util"
22
+
23
+ class TestMerchant < Test::Unit::TestCase
24
+
25
+ def setup
26
+ @auth_obj = PBShipping::AuthenticationToken.new(
27
+ PBShippingTestUtil::api_key, PBShippingTestUtil::api_secret)
28
+ puts ""
29
+ end
30
+
31
+ def teardown
32
+ end
33
+
34
+ def test_Merchant
35
+ developer = PBShippingTestUtil::setup_developer(@auth_obj)
36
+
37
+ puts "Testing merchant registration ..."
38
+ merchant, acct_num = PBShippingTestUtil::setup_merchant(@auth_obj, developer)
39
+
40
+ puts "Testing account balance query ..."
41
+ balance = PBShipping::Account.getBalanceByAccountNumber(@auth_obj, acct_num)
42
+ end
43
+
44
+ end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tc_shipment.rb
16
+ # Description: unit test for shipment creation and management
17
+ #
18
+
19
+ require "test/unit"
20
+ require "pbshipping"
21
+
22
+ class TestShipment < Test::Unit::TestCase
23
+
24
+ def setup
25
+ @auth_obj = PBShipping::AuthenticationToken.new(
26
+ PBShippingTestUtil::api_key, PBShippingTestUtil::api_secret)
27
+ @developer = PBShippingTestUtil::setup_developer(@auth_obj)
28
+ merchant, @acct_num = PBShippingTestUtil::setup_merchant(
29
+ @auth_obj, @developer)
30
+ @shipper_id = merchant.postalReportingNumber
31
+ end
32
+
33
+ def teardown
34
+
35
+ end
36
+
37
+ def test_shipment
38
+
39
+ puts "Testing rate query and purchasing shipment label ..."
40
+
41
+ start_balance = PBShipping::Account.getBalanceByAccountNumber(
42
+ @auth_obj, @acct_num)
43
+ PBShippingTestUtil::check_shipment_rate(@auth_obj, @developer)
44
+ shipment, orig_txid = PBShippingTestUtil::create_single_shipment(
45
+ @auth_obj, @developer, @shipper_id)
46
+ end_balance = PBShipping::Account.getBalanceByAccountNumber(
47
+ @auth_obj, @acct_num)
48
+
49
+ assert_equal(shipment.key?(:shipmentId), true)
50
+ assert_equal(PBShippingTestUtil::verify_ledger_balance_after_txn(
51
+ shipment, start_balance, end_balance), true)
52
+
53
+ puts "Testing get tracking status ..."
54
+ tracking = PBShipping::Tracking.new(
55
+ { :trackingNumber => shipment.parcelTrackingNumber } )
56
+ begin
57
+ tracking.updateStatus(@auth_obj)
58
+ rescue => e
59
+ case e
60
+ when PBShipping::ApiError
61
+ if PBShipping::configuration[:is_production] == true
62
+ raise e
63
+ elsif e.error_info.length < 1
64
+ raise e
65
+ elsif e.error_info[0][:errorCode] != "PB-TRKPKG-ERR-7600"
66
+ raise e
67
+ else
68
+ puts " no tracking information in sandbox environment"
69
+ end
70
+ else
71
+ raise e
72
+ end
73
+ end
74
+
75
+ puts "Testing reprint shipment label ..."
76
+ shipment.reprintLabel(@auth_obj)
77
+
78
+ puts "Testing retry shipment ..."
79
+ txid = PBShippingTestUtil::get_pb_tx_id()
80
+ shipment.retry(@auth_obj, txid, orig_txid)
81
+
82
+ puts "Testing canceling shipment ..."
83
+ cancel_result = shipment.cancel(@auth_obj, orig_txid,
84
+ shipment.rates[0].carrier)
85
+ assert_equal(cancel_result.key?(:status), true)
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,93 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: tc_transactionreport.rb
16
+ # Description: unit test for querying for transaction history
17
+ #
18
+
19
+ require 'bigdecimal'
20
+ require "test/unit"
21
+ require "pbshipping"
22
+ require_relative "test_util"
23
+
24
+ class TestTransactionReport < Test::Unit::TestCase
25
+
26
+ def setup
27
+ @auth_obj = PBShipping::AuthenticationToken.new(
28
+ PBShippingTestUtil::api_key, PBShippingTestUtil::api_secret)
29
+ @developer = PBShippingTestUtil::setup_developer(@auth_obj)
30
+ merchant, acct_num = PBShippingTestUtil::setup_merchant(
31
+ @auth_obj, @developer)
32
+ @shipper_id = merchant.postalReportingNumber
33
+ end
34
+
35
+ def teardown
36
+ end
37
+
38
+ def verifyAndPrintReport(report, query)
39
+ puts " Total matching records = " + report.totalElements.to_s
40
+ puts " Total number of pages = " + report.totalPages.to_s
41
+ puts " Current page number is " + report.number.to_s
42
+ puts " Page size is " + report.size.to_s
43
+ puts " Sort by " + report[:sort][0][:property]
44
+
45
+ if report[:sort][0][:ascending] == true
46
+ sort_dir = "asc"
47
+ else
48
+ sort_dir = "desc"
49
+ end
50
+ sort_info = report[:sort][0][:property] + "," + sort_dir
51
+ assert_equal(sort_info, query[:sort])
52
+
53
+ rate_benchmark = PBShippingTestUtil::check_shipment_rate(
54
+ @auth_obj, @developer)
55
+
56
+ for next_row in report.content
57
+ txn = PBShipping::TransactionDetails.new(next_row)
58
+
59
+ if (txn.transactionType.include?("POSTAL PRINT"))
60
+ assert_equal(BigDecimal(txn.developerRateAmount, 3), BigDecimal(rate_benchmark, 3))
61
+ end
62
+
63
+ txn_detail = " timestamp: " + txn.transactionDateTime
64
+ txn_detail += " txid: " + txn.transactionId
65
+ txn_detail += " type: " + txn.transactionType
66
+ txn_detail += " rate: " + txn.developerRateAmount.to_s
67
+ txn_detail += " balance: " + txn.shipperPostagePaymentAccountBalance.to_s
68
+ puts txn_detail
69
+ end
70
+ end
71
+
72
+ def test_trasnsactionreport
73
+ puts "Testing get transaction report ..."
74
+
75
+ # limit to past 28 days
76
+ time_now = Time.now.utc
77
+ seven_days_ago = time_now - 28 * 60 * 60 * 24
78
+ query = {:fromDate => seven_days_ago.iso8601, :toDate => time_now.iso8601}
79
+ # limit to transactions originating from this test suite
80
+ query[:transactionId] = "%%" + PBShippingTestUtil::test_suite_txid_prefix + "%%"
81
+ # limit to test suite merchant
82
+ query[:merchantId] = @shipper_id
83
+ # sort according to transaction id in descending order
84
+ query[:sort] = "transactionId,desc"
85
+
86
+ # paging control can be configured through these parameters
87
+ # query[:page] = 0 # control the page to query for
88
+ # query[:size] = 20 # control the page size
89
+ report = @developer.getTransactionReport(@auth_obj, query)
90
+ verifyAndPrintReport(report, query)
91
+ end
92
+
93
+ end
@@ -0,0 +1,222 @@
1
+ #
2
+ # Copyright 2016 Pitney Bowes Inc.
3
+ #
4
+ # Licensed under the MIT License (the "License"); you may not use this file
5
+ # except in compliance with the License. You may obtain a copy of the License
6
+ # in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # File: test_util.rb
16
+ # Description: helper classes and functions supporting unit test
17
+ #
18
+
19
+ require 'bigdecimal'
20
+
21
+ module PBShippingTestUtil
22
+
23
+ @api_key = ENV["PBSHIPPING_KEY"]
24
+ @api_secret = ENV["PBSHIPPING_SECRET"]
25
+ @dev_id = ENV["PBSHIPPING_DEVID"]
26
+ @merchant_email = ENV["PBSHIPPING_MERCHANT"]
27
+
28
+ @my_bulk_merchant_addr = {
29
+ :addressLines => ["27 Waterview Drive"],
30
+ :cityTown => "Shelton",
31
+ :stateProvince => "Connecticut",
32
+ :postalCode => "06484",
33
+ :countryCode => "US",
34
+ :company => "Pitney Bowes",
35
+ :name => "John Doe",
36
+ :email => "dummy@pbshipping.com",
37
+ :phone => "203-792-1600",
38
+ :residential => false
39
+ }
40
+
41
+ @my_origin_addr = {
42
+ :addressLines => ["37 Executive Drive"],
43
+ :cityTown => "Danbury",
44
+ :stateProvince => "Connecticut",
45
+ :postalCode => "06810",
46
+ :countryCode => "US"
47
+ }
48
+
49
+ @my_dest_addr = {
50
+ :addressLines => ["27 Waterview Drive"],
51
+ :cityTown => "Shelton",
52
+ :stateProvince => "Connecticut",
53
+ :postalCode => "06484",
54
+ :countryCode => "US"
55
+ }
56
+
57
+ @my_parcel = {
58
+ :weight => {
59
+ :unitOfMeasurement => "OZ",
60
+ :weight => 1
61
+ },
62
+ :dimension => {
63
+ :unitOfMeasurement => "IN",
64
+ :length => 6,
65
+ :width => 0.25,
66
+ :height => 4,
67
+ :irregularParcelGirth => 0.002
68
+ }
69
+ }
70
+
71
+ @my_rate_request_carrier_usps = {
72
+ :carrier => "usps",
73
+ :serviceId => "PM",
74
+ :parcelType => "PKG",
75
+ :specialServices => [
76
+ {
77
+ :specialServiceId => "Ins",
78
+ :inputParameters => [
79
+ {
80
+ :name => "INPUT_VALUE",
81
+ :value => "50"
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ :specialServiceId => "DelCon",
87
+ :inputParameters => [
88
+ {
89
+ :name => "INPUT_VALUE",
90
+ :value => "0"
91
+ }
92
+ ]
93
+ }
94
+ ],
95
+ :inductionPostalCode => "06810"
96
+ }
97
+
98
+ @my_shipment_document = {
99
+ :type => "SHIPPING_LABEL",
100
+ :contentType => "URL",
101
+ :size => "DOC_8X11",
102
+ :fileFormat => "PDF",
103
+ :printDialogOption => "NO_PRINT_DIALOG"
104
+ }
105
+
106
+ # this helps to identify transactions originating from the test suite
107
+ @test_suite_txid_prefix = "KYCB"
108
+
109
+ class << self
110
+ attr_accessor :api_key, :api_secret, :dev_id, :merchant_email
111
+ attr_accessor :my_bulk_merchant_addr, :my_origin_addr, :my_dest_addr
112
+ attr_accessor :my_parcel, :my_rate_request_carrier_usps, :my_shipment_document
113
+ attr_accessor :test_suite_txid_prefix
114
+ end
115
+
116
+ def self.get_pb_tx_id()
117
+ return @test_suite_txid_prefix + Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
118
+ end
119
+
120
+ def self.setup_developer(auth_obj)
121
+ developer = PBShipping::Developer.new(
122
+ { :developerId => PBShippingTestUtil::dev_id} )
123
+ developer.refresh(auth_obj)
124
+ return developer
125
+ end
126
+
127
+ def self.setup_merchant(auth_obj, developer)
128
+ if developer.bulkMode == false
129
+ merchant = developer.registerMerchantIndividualAccount(
130
+ auth_obj, @merchant_email)
131
+ acct_num = merchant.paymentAccountNumber
132
+ else
133
+ begin
134
+ @my_bulk_merchant_addr[:email] = @merchant_email
135
+ merchant = developer.registerMerchantBulkAccount(
136
+ auth_obj, @my_bulk_merchant_addr)
137
+ rescue => e
138
+ case e
139
+ when PBShipping::ApiError
140
+ if e.error_info.length < 1
141
+ raise e
142
+ elsif !(e.error_info[0][:message].include?("Duplicate entry"))
143
+ raise e
144
+ end
145
+ merchant = developer.getMerchantBulkAccount(auth_obj, @merchant_email)
146
+ else
147
+ raise e
148
+ end
149
+ end
150
+ acct_num = developer.paymentAccount
151
+ end
152
+ return merchant, acct_num
153
+ end
154
+
155
+ def self.check_shipment_rate(auth_obj, developer)
156
+ rates = [ PBShipping::Rate.new(@my_rate_request_carrier_usps) ]
157
+ parcel = PBShipping::Parcel.new(@my_parcel)
158
+ shipment = PBShipping::Shipment.new({
159
+ :fromAddress => PBShippingTestUtil::my_origin_addr,
160
+ :toAddress => PBShippingTestUtil::my_dest_addr,
161
+ :parcel => parcel,
162
+ :rates => rates
163
+ })
164
+ txid = PBShippingTestUtil::get_pb_tx_id()
165
+ xtra_hdrs = nil
166
+ if developer.bulkMode == true and developer.useShipperRate == true
167
+ xtra_hdrs = {"X-PB-Shipper-Rate-Plan" => "PP_SRP_NEWBLUE"}
168
+ end
169
+ rates = shipment.getRates(auth_obj, txid, true, xtra_hdrs)
170
+ return rates[0].totalCarrierCharge
171
+ end
172
+
173
+ def self.create_single_shipment(auth_obj, developer, shipper_id)
174
+ rates = [ PBShipping::Rate.new(@my_rate_request_carrier_usps) ]
175
+ parcel = PBShipping::Parcel.new(@my_parcel)
176
+ documents = [ PBShipping::Document.new(@my_shipment_document)]
177
+ shipmentOptions = [
178
+ PBShipping::ShipmentOptions.new(
179
+ { :name => "SHIPPER_ID", :value => shipper_id }),
180
+ PBShipping::ShipmentOptions.new(
181
+ { :name => "ADD_TO_MANIFEST", :value => true })
182
+ ]
183
+ shipment = PBShipping::Shipment.new({
184
+ :fromAddress => PBShippingTestUtil::my_origin_addr,
185
+ :toAddress => PBShippingTestUtil::my_dest_addr,
186
+ :parcel => parcel,
187
+ :rates => rates,
188
+ :documents => documents,
189
+ :shipmentOptions => shipmentOptions
190
+ })
191
+ txid = PBShippingTestUtil::get_pb_tx_id()
192
+ xtra_hdrs = nil
193
+ if developer.bulkMode == true and developer.useShipperRate == true
194
+ xtra_hdrs = {"X-PB-Shipper-Rate-Plan" => "PP_SRP_NEWBLUE"}
195
+ end
196
+ shipment.createAndPurchase(auth_obj, txid, true, xtra_hdrs)
197
+ return shipment, txid
198
+ end
199
+
200
+ # verify the ledger balance is correct after shipment label purchase
201
+ def self.verify_ledger_balance_after_txn(shipment, start_balance, end_balance)
202
+
203
+ balance_delta = BigDecimal(start_balance.balance - end_balance.balance, 3)
204
+ # if account has been replenished using auto-refill, skip this case
205
+ if balance_delta < 0
206
+ puts " ending balance increases, probably due to auto reload, skip check"
207
+ return true
208
+ end
209
+
210
+ txn_charge = BigDecimal(shipment.rates[0].totalCarrierCharge, 3)
211
+
212
+ is_same = (txn_charge == balance_delta)
213
+ if is_same == false
214
+ delta = txn_charge - balance_delta
215
+ msg = " verify balance failed: difference is " + delta.to_s
216
+ puts msg
217
+ end
218
+
219
+ return is_same
220
+ end
221
+
222
+ end