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

fix: buying a pickup when providing a rate #341

Merged
merged 1 commit into from
Jan 3, 2025
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
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
Loading