Skip to content

Commit

Permalink
Add new updateUps function for UPS account update in CarrierAccountSe…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
jchen293 committed Jul 8, 2024
1 parent 8ab823a commit 3af6fd1
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Next Release

- Adds new `updateUps` function under `CarrierAccountService`
- Starting `2024-08-05`, UPS accounts can no longer be updated through the normal update function and must use the UPS specific `updateUps` function

## v7.2.1 (2024-04-12)

- Fix `Fields` serialization bug causing carrier account operations to fail
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 194 files
2 changes: 1 addition & 1 deletion src/main/java/com/easypost/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract static class ErrorCodes {

public abstract static class CarrierAccountTypes {
public static final List<String> CARRIER_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of("FedexAccount",
"UpsAccount", "FedexSmartpostAccount");
"FedexSmartpostAccount");
}

public abstract static class Http {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/easypost/service/CarrierAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ public class CarrierAccountService {
*/
public CarrierAccount create(final Map<String, Object> params) throws EasyPostException {
String type = (String) params.get("type");
Map<String, Object> wrappedParams = new HashMap<String, Object>();

if (type == null) {
throw new MissingParameterError(
String.format(Constants.ErrorMessages.MISSING_REQUIRED_PARAMETER, "carrier account type"));
} else if (type.equals("UpsAccount")) {
wrappedParams.put("ups_oauth_registrations", params);
} else {
wrappedParams.put("carrier_account", params);
}

Map<String, Object> wrappedParams = new HashMap<String, Object>();
wrappedParams.put("carrier_account", params);

String endpoint = selectCarrierAccountCreationEndpoint(type);

return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, CarrierAccount.class, client);
Expand Down Expand Up @@ -103,6 +106,20 @@ public CarrierAccount update(String id, final Map<String, Object> params) throws
client);
}

/**
* Update UPS carrier account.
*
* @param params parameters to update.
* @param id The ID of carrier account
* @return updated CarrierAccount object.
* @throws EasyPostException when the request fails.
*/
public CarrierAccount updateUps(String id, final Map<String, Object> params) throws EasyPostException {
String endpoint = "ups_oauth_registrations/" + id;

return Requestor.request(RequestMethod.PUT, endpoint, params, CarrierAccount.class, client);
}

/**
* Delete this carrier account.
*
Expand All @@ -125,6 +142,8 @@ public void delete(String id) throws EasyPostException {
private static String selectCarrierAccountCreationEndpoint(final String carrierAccountType) {
if (Constants.CarrierAccountTypes.CARRIER_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) {
return "carrier_accounts/register";
} else if (carrierAccountType.equals("UpsAccount")) {
return "ups_oauth_registrations";
} else {
return "carrier_accounts";
}
Expand Down
91 changes: 91 additions & 0 deletions src/test/cassettes/carrier_account/create_with_ups.json

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

Loading

0 comments on commit 3af6fd1

Please sign in to comment.