Skip to content

Commit

Permalink
Merge pull request #341 from EasyPost/fix_pickup_buy_rate
Browse files Browse the repository at this point in the history
fix: buying a pickup when providing a rate
  • Loading branch information
Justintime50 authored Jan 3, 2025
2 parents dac0266 + e5b4212 commit a631ce9
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 201 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Next Release

- Fixes how params are passed to the API when buying a pickup and providing a pickup rate (closes #340)
- Removes the unusable buy a pickup overload where no params are specified as `carrier` and `service` are required paramaters when buying a pickup
- Removes the deprecated `create_list` tracker endpoint function as it is no longer available via API

## v7.4.3 (2024-09-16)
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/com/easypost/service/PickupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ public Pickup retrieve(final String id) throws EasyPostException {
return Requestor.request(RequestMethod.GET, endpoint, null, Pickup.class, client);
}

/**
* Buy this Pickup.
*
* @param id The ID of pickup.
* @return Pickup object.
* @throws EasyPostException when the request fails.
*/
public Pickup buy(final String id) throws EasyPostException {
// Pass in empty map to avoid method ambiguous.
return this.buy(id, new HashMap<String, Object>());
}

/**
* Buy this Pickup.
*
Expand All @@ -131,7 +119,8 @@ public Pickup buy(final String id, final Map<String, Object> params) throws Easy
*/
public Pickup buy(final String id, final PickupRate pickupRate) throws EasyPostException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("rate", pickupRate);
params.put("carrier", pickupRate.getCarrier());
params.put("service", pickupRate.getService());

return this.buy(id, params);
}
Expand Down
66 changes: 33 additions & 33 deletions src/test/cassettes/pickup/buy.json

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions src/test/cassettes/pickup/buy_with_rate.json

Large diffs are not rendered by default.

89 changes: 43 additions & 46 deletions src/test/cassettes/pickup/cancel.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/test/cassettes/pickup/create.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions src/test/cassettes/pickup/lowest_rate.json

Large diffs are not rendered by default.

67 changes: 35 additions & 32 deletions src/test/cassettes/pickup/retrieve.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/java/com/easypost/Fixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static HashMap<String, Object> basicPickup() {
* If you need to re-record cassettes, increment the date below and ensure it is one day in the future,
* USPS only does "next-day" pickups including Saturday but not Sunday or Holidays.
*/
String pickupDate = "2024-08-18";
String pickupDate = "2025-01-03";

fixture.put("min_datetime", pickupDate);
fixture.put("max_datetime", pickupDate);
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/com/easypost/PickupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ public void testBuy() throws EasyPostException, InterruptedException {

Pickup pickup = createBasicPickup();

Pickup boughtPickup = vcr.client.pickup.buy(pickup.getId());
Map<String, Object> params = new HashMap<String, Object>();
params.put("carrier", Fixtures.usps());
params.put("service", Fixtures.pickupService());

Pickup boughtPickup = vcr.client.pickup.buy(pickup.getId(), params);

assertInstanceOf(Pickup.class, boughtPickup);
assertTrue(boughtPickup.getId().startsWith("pickup_"));
Expand All @@ -154,7 +158,7 @@ public void testBuy() throws EasyPostException, InterruptedException {
}

/**
* Test buying a pickup with lowest rate.
* Test buying a pickup by specifying a pickup rate.
*
* @throws EasyPostException when the request fails.
*/
Expand Down

0 comments on commit a631ce9

Please sign in to comment.