Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Refund function in insurance service #329

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 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,12 @@ 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,
)

return convert_to_easypost_object(response=response)
231 changes: 231 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.

14 changes: 14 additions & 0 deletions tests/test_insurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ 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"
assert cancelled_insurance.messages[0] == "Insurance was cancelled by the user."
Loading