Skip to content

Commit 005aa7d

Browse files
authored
Merge pull request #348 from EasyPost/amazon_account
amazon account
2 parents 2b52734 + ed70e8d commit 005aa7d

File tree

6 files changed

+323
-29
lines changed

6 files changed

+323
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `referralCustomer.addCreditCardFromStripe`
1010
- `referralCustomer.addBankAccountFromStripe`
1111
- Adds `tracking_codes` param to tracker index endpoint
12+
- Routes `AmazonShippingAccount` to the correct endpoint
1213
- Fixes error parsing
1314
- 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)
1415
- Removed the unused `Error` model

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clean:
1212

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

1717
## checkstyle - Check if project follows CheckStyle rules (must run install-checkstyle first)
1818
checkstyle:

src/main/java/com/easypost/Constants.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ public abstract static class ErrorCodes {
6161
}
6262

6363
public abstract static class CarrierAccountTypes {
64-
public static final List<String> CARRIER_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of("FedexAccount",
65-
"FedexSmartpostAccount");
66-
}
64+
public static final List<String> CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of(
65+
"FedexAccount", "FedexSmartpostAccount"
66+
);
67+
68+
public static final List<String> UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of(
69+
"UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"
70+
);
6771

68-
public abstract static class UpsAccountTypes {
69-
public static final List<String> UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of("UpsAccount",
70-
"UpsMailInnovationsAccount", "UpsSurepostAccount");
72+
public static final List<String> CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = ImmutableList.of(
73+
"AmazonShippingAccount"
74+
);
7175
}
7276

7377
public abstract static class Http {

src/main/java/com/easypost/service/CarrierAccountService.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public CarrierAccount update(String id, final Map<String, Object> params) throws
9393
Map<String, Object> wrappedParams = new HashMap<String, Object>();
9494
wrappedParams.put(selectTopLayerKey(type), params);
9595

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

@@ -121,10 +121,12 @@ public void delete(String id) throws EasyPostException {
121121
* @return The endpoint for the carrier account creation request.
122122
*/
123123
private static String selectCarrierAccountCreationEndpoint(final String carrierAccountType) {
124-
if (Constants.CarrierAccountTypes.CARRIER_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) {
124+
if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW.contains(carrierAccountType)) {
125125
return "carrier_accounts/register";
126-
} else if (Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
126+
} else if (Constants.CarrierAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
127127
return "ups_oauth_registrations";
128+
} else if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.contains(carrierAccountType)) {
129+
return "carrier_accounts/register_oauth";
128130
} else {
129131
return "carrier_accounts";
130132
}
@@ -136,15 +138,20 @@ private static String selectCarrierAccountCreationEndpoint(final String carrierA
136138
*
137139
* @param carrierAccountType The type of carrier account to create.
138140
* @return The top-layer key for the carrier account creation/update request.
141+
* @throws MissingParameterError when the request fails.
139142
*/
140-
private static String selectTopLayerKey(final String carrierAccountType) throws EasyPostException {
143+
private static String selectTopLayerKey(final String carrierAccountType) throws MissingParameterError {
141144
if (carrierAccountType == null) {
142145
throw new MissingParameterError(
143146
String.format(Constants.ErrorMessages.MISSING_REQUIRED_PARAMETER, "carrier account type"));
144147
}
145148

146-
return Constants.UpsAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)
147-
? "ups_oauth_registrations"
148-
: "carrier_account";
149+
if (Constants.CarrierAccountTypes.UPS_OAUTH_CARRIER_ACCOUNT_TYPES.contains(carrierAccountType)) {
150+
return "ups_oauth_registrations";
151+
} else if (Constants.CarrierAccountTypes.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.contains(carrierAccountType)) {
152+
return "carrier_account_oauth_registrations";
153+
} else {
154+
return "carrier_account";
155+
}
149156
}
150157
}

src/test/cassettes/carrier_account/create_with_amazon.json

Lines changed: 263 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)