Skip to content

Commit aebdf30

Browse files
authored
Add Refund function in insurance service (#329)
1 parent e86307d commit aebdf30

File tree

4 files changed

+263
-0
lines changed

4 files changed

+263
-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+
- Adds `refund` function in Insurance service for requesting a refund for a standalone insurance
6+
37
## v9.1.0 (2024-01-08)
48

59
- Adds `all_children` function to the User service for retrieving paginated lists of children

easypost/services/insurance_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
Optional,
55
)
66

7+
from easypost.easypost_object import convert_to_easypost_object
78
from easypost.models import Insurance
9+
from easypost.requestor import (
10+
RequestMethod,
11+
Requestor,
12+
)
813
from easypost.services.base_service import BaseService
914

1015

@@ -47,3 +52,12 @@ def get_next_page(
4752
params.update(optional_params)
4853

4954
return self.all(**params)
55+
56+
def refund(self, id: str) -> Insurance:
57+
url = f"/insurances/{id}/refund"
58+
response = Requestor(self._client).request(
59+
method=RequestMethod.POST,
60+
url=url,
61+
)
62+
63+
return convert_to_easypost_object(response=response)

tests/cassettes/test_insurance_refund.yaml

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

tests/test_insurance.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ def test_insurance_get_next_page(page_size, test_client):
6464
except Exception as e:
6565
if e.message != NO_MORE_PAGES_ERROR:
6666
raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR)
67+
68+
69+
@pytest.mark.vcr()
70+
def test_insurance_refund(test_client, basic_insurance):
71+
insurance_data = basic_insurance
72+
insurance_data["tracking_code"] = "EZ1000000001"
73+
74+
insurance = test_client.insurance.create(**insurance_data)
75+
cancelled_insurance = test_client.insurance.refund(id=insurance.id)
76+
77+
assert isinstance(cancelled_insurance, Insurance)
78+
assert str.startswith(cancelled_insurance.id, "ins_")
79+
assert cancelled_insurance.status == "cancelled"
80+
assert cancelled_insurance.messages[0] == "Insurance was cancelled by the user."

0 commit comments

Comments
 (0)