Skip to content

Commit

Permalink
add Refund function in insurance service
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Mar 28, 2024
1 parent f8e5997 commit cc310ce
Show file tree
Hide file tree
Showing 4 changed files with 260 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

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

## v9.1.0 (2024-01-08)

- Adds `all_children` function to the User service for retrieving paginated lists of children
Expand Down
15 changes: 15 additions & 0 deletions easypost/services/insurance_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Optional,
)

from easypost.easypost_object import convert_to_easypost_object
from easypost.models import Insurance
from easypost.requestor import (
RequestMethod,
Requestor,
)
from easypost.services.base_service import BaseService


Expand Down Expand Up @@ -47,3 +52,13 @@ def get_next_page(
params.update(optional_params)

return self.all(**params)

def refund(self, id: str) -> Insurance:
url = f"/insurances/{id}/refund"
response = Requestor(self._client).request(
method=RequestMethod.POST,
url=url,
beta=True, # Remove beta when endpoint is in GA.
)

return convert_to_easypost_object(response=response)
228 changes: 228 additions & 0 deletions tests/cassettes/test_insurance_refund.yaml

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

13 changes: 13 additions & 0 deletions tests/test_insurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,16 @@ def test_insurance_get_next_page(page_size, test_client):
except Exception as e:
if e.message != NO_MORE_PAGES_ERROR:
raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR)


@pytest.mark.vcr()
def test_insurance_refund(test_client, basic_insurance):
insurance_data = basic_insurance
insurance_data["tracking_code"] = "EZ1000000001"

insurance = test_client.insurance.create(**insurance_data)
cancelled_insurance = test_client.insurance.refund(id=insurance.id)

assert isinstance(cancelled_insurance, Insurance)
assert str.startswith(cancelled_insurance.id, "ins_")
assert cancelled_insurance.status == "cancelled"

0 comments on commit cc310ce

Please sign in to comment.