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

Update CarrierService create and update methods #317

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
27 changes: 23 additions & 4 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")) {
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -88,8 +91,8 @@ public List<CarrierAccount> all(final Map<String, Object> params) throws EasyPos
/**
* Update this carrier account.
*
* @param params parameters to update.
* @param id The ID of carrier account
* @param params parameters to update.
* @return updated CarrierAccount object.
* @throws EasyPostException when the request fails.
*/
Expand All @@ -103,6 +106,20 @@ public CarrierAccount update(String id, final Map<String, Object> params) throws
client);
}

/**
* Update UPS carrier account.
*
* @param id The ID of UPS account
* @param params parameters to update.
* @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")) {
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading