Skip to content

Commit

Permalink
add refund function in insurance service
Browse files Browse the repository at this point in the history
r#ename docstring
  • Loading branch information
jchen293 committed Apr 4, 2024
1 parent 274f207 commit 50c0724
Show file tree
Hide file tree
Showing 4 changed files with 219 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

## 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
183 changes: 183 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.

19 changes: 19 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,23 @@ 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());
}
}

0 comments on commit 50c0724

Please sign in to comment.