Skip to content

Commit

Permalink
Add refund function in insurance service (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 authored Apr 8, 2024
1 parent e74fff0 commit 1490eae
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next release

- Add `refund` function in Insurance service for requesting a refund for standalone insurance.

## v6.1.1 (2024-01-23)

- Fix issues funding wallet due to invalid internal function call
Expand Down
7 changes: 7 additions & 0 deletions lib/easypost/services/insurance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ def get_next_page(collection, page_size = nil)

all(params)
end

# Refund an Insurance object
def refund(id)
response = @client.make_request(:post, "insurances/#{id}/refund")

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'spec_helper'
require 'faraday'
require 'typhoeus'
require 'ostruct'

describe EasyPost::Client do
describe 'client object' do
Expand Down
15 changes: 15 additions & 0 deletions spec/insurance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@
end
end
end

describe '.refund' do
it 'cancels an insurance' do
insurance_data = Fixture.basic_insurance
insurance_data[:tracking_code] = 'EZ1000000001'

insurance = client.insurance.create(insurance_data)
cancelled_insurance = client.insurance.refund(insurance.id)

expect(cancelled_insurance).to be_an_instance_of(EasyPost::Models::Insurance)
expect(cancelled_insurance.id).to match('ins_')
expect(cancelled_insurance.status).to eq('cancelled')
expect(cancelled_insurance.messages[0]).to eq('Insurance was cancelled by the user.')
end
end
end

0 comments on commit 1490eae

Please sign in to comment.