Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `referralCustomer.addCreditCardFromStripe`
- `referralCustomer.addBankAccountFromStripe`
- Adds `tracking_codes` param to tracker index endpoint
- Routes `AmazonShippingAccount` to the correct endpoint
- Fixes error parsing
- Allows for alternative format of `errors` field (previously we deserialized the `errors` field into a list of `Error` objects; however, sometimes the errors are simply a list of strings. This change make the `errors` field a list of `Object` allowing for either the new `FieldError` object or a list of strings. Users will need to check for the type of error returned and handle appropriately)
- Removed the unused `Error` model
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ clean:

## coverage - Test (and build) the project to generate a coverage report
coverage:
mvn verify -Dgpg.skip=true -Dcheckstyle.skip=true -Ddependency-check.skip=true -Djavadoc.skip=true jacoco:report
mvn test -Dgpg.skip=true -Dcheckstyle.skip=true -Ddependency-check.skip=true -Djavadoc.skip=true jacoco:report

## checkstyle - Check if project follows CheckStyle rules (must run install-checkstyle first)
checkstyle:
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/easypost/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ public abstract static class ErrorCodes {
}

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

public static final List<String> UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of(
"UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"
);

public abstract static class UpsAccountTypes {
public static final List<String> UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of("UpsAccount",
"UpsMailInnovationsAccount", "UpsSurepostAccount");
public static final List<String> CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = ImmutableList.of(
"AmazonShippingAccount"
);
}

public abstract static class Http {
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/easypost/service/CarrierAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public CarrierAccount update(String id, final Map<String, Object> params) throws
Map<String, Object> wrappedParams = new HashMap<String, Object>();
wrappedParams.put(selectTopLayerKey(type), params);

String endpoint = (Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(type)
String endpoint = (Constants.CarrierAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(type)
? "ups_oauth_registrations/"
: "carrier_accounts/") + id;

Expand Down Expand Up @@ -121,10 +121,12 @@ public void delete(String id) throws EasyPostException {
* @return The endpoint for the carrier account creation request.
*/
private static String selectCarrierAccountCreationEndpoint(final String carrierAccountType) {
if (Constants.CarrierAccountTypes.CARRIER_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) {
if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) {
return "carrier_accounts/register";
} else if (Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
} else if (Constants.CarrierAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
return "ups_oauth_registrations";
} else if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.contains(carrierAccountType)) {
return "carrier_accounts/register_oauth";
} else {
return "carrier_accounts";
}
Expand All @@ -136,15 +138,20 @@ private static String selectCarrierAccountCreationEndpoint(final String carrierA
*
* @param carrierAccountType The type of carrier account to create.
* @return The top-layer key for the carrier account creation/update request.
* @throws MissingParameterError when the request fails.
*/
private static String selectTopLayerKey(final String carrierAccountType) throws EasyPostException {
private static String selectTopLayerKey(final String carrierAccountType) throws MissingParameterError {
if (carrierAccountType == null) {
throw new MissingParameterError(
String.format(Constants.ErrorMessages.MISSING_REQUIRED_PARAMETER, "carrier account type"));
}

return Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)
? "ups_oauth_registrations"
: "carrier_account";
if (Constants.CarrierAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
return "ups_oauth_registrations";
} else if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.contains(carrierAccountType)) {
return "carrier_account_oauth_registrations";
} else {
return "carrier_account";
}
}
}
263 changes: 263 additions & 0 deletions src/test/cassettes/carrier_account/create_with_amazon.json

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

Loading
Loading