Skip to content

Commit 1490eae

Browse files
authored
Add refund function in insurance service (#299)
1 parent e74fff0 commit 1490eae

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next release
4+
5+
- Add `refund` function in Insurance service for requesting a refund for standalone insurance.
6+
37
## v6.1.1 (2024-01-23)
48

59
- Fix issues funding wallet due to invalid internal function call

lib/easypost/services/insurance.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ def get_next_page(collection, page_size = nil)
3434

3535
all(params)
3636
end
37+
38+
# Refund an Insurance object
39+
def refund(id)
40+
response = @client.make_request(:post, "insurances/#{id}/refund")
41+
42+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
43+
end
3744
end

spec/cassettes/insurance/EasyPost_Services_Insurance_refund_cancels_an_insurance.yml

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/client_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'spec_helper'
44
require 'faraday'
55
require 'typhoeus'
6+
require 'ostruct'
67

78
describe EasyPost::Client do
89
describe 'client object' do

spec/insurance_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@
7272
end
7373
end
7474
end
75+
76+
describe '.refund' do
77+
it 'cancels an insurance' do
78+
insurance_data = Fixture.basic_insurance
79+
insurance_data[:tracking_code] = 'EZ1000000001'
80+
81+
insurance = client.insurance.create(insurance_data)
82+
cancelled_insurance = client.insurance.refund(insurance.id)
83+
84+
expect(cancelled_insurance).to be_an_instance_of(EasyPost::Models::Insurance)
85+
expect(cancelled_insurance.id).to match('ins_')
86+
expect(cancelled_insurance.status).to eq('cancelled')
87+
expect(cancelled_insurance.messages[0]).to eq('Insurance was cancelled by the user.')
88+
end
89+
end
7590
end

0 commit comments

Comments
 (0)