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 #308

Merged
merged 2 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

## v7.1.1 (2024-03-21)

- Fix `EasyPostTimeInTransitData` class and `easypostTimeInTransitData` property of `EstimatedDeliveryDate` class being publicly inaccessible
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/easypost/service/InsuranceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public InsuranceCollection all(final Map<String, Object> params) throws EasyPost
return Requestor.request(RequestMethod.GET, endpoint, params, InsuranceCollection.class, client);
}

/**
* Refund an Insurance from the API.
*
* @param id The ID of the Insurance to refund.
* @return Insurance object
* @throws EasyPostException when the request fails.
*/
public Insurance refund(final String id) throws EasyPostException {
String endpoint = String.format("insurances/%s/refund", id);

return Requestor.request(RequestMethod.POST, endpoint, null, Insurance.class, client);
}

/**
* Get the next page of an InsuranceCollection.
*
Expand Down
186 changes: 186 additions & 0 deletions src/test/cassettes/insurance/refund.json

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

20 changes: 20 additions & 0 deletions src/test/java/com/easypost/InsuranceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,24 @@ public void testGetNextPage() throws EasyPostException {
fail();
}
}

/**
* Test refunding an insurance.
*
* @throws EasyPostException when the request fails.
*/
@Test
public void testRefundInsurance() throws EasyPostException {
vcr.setUpTest("refund");

HashMap<String, Object> params = Fixtures.basicInsurance();
params.put("tracking_code", "EZ1000000001");
Insurance insurance = vcr.client.insurance.create(params);
Insurance cancelledInsurance = vcr.client.insurance.refund(insurance.getId());

assertInstanceOf(Insurance.class, cancelledInsurance);
assertTrue(insurance.getId().startsWith("ins_"));
assertEquals("cancelled", cancelledInsurance.getStatus());
assertEquals("Insurance was cancelled by the user.", cancelledInsurance.getMessages().get(0));
}
}
Loading