Skip to content

Commit acb3031

Browse files
committed
feat(fedex): add two response models for MFA workflow
Created two separate model classes to properly deserialize different response types in the FedEx MFA workflow: 1. FedExAccountValidationResponse - returned by registerAddress and requestPin endpoints when further validation is required. Contains email_address, phone_number, and options for PIN delivery methods. 2. FedexRegistration - returned by validatePin and submitInvoice endpoints when validation is complete. Contains type and credentials for the registered account. Updated VCR cassettes with realistic response structures matching the actual API responses. Added comprehensive test assertions that verify both response types deserialize correctly and contain expected fields.
1 parent 863fd47 commit acb3031

File tree

8 files changed

+60
-26
lines changed

8 files changed

+60
-26
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.easypost.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.util.Map;
5+
import lombok.Getter;
6+
7+
@Getter
8+
public final class FedExAccountValidationResponse extends EasyPostResource {
9+
@SerializedName("email_address")
10+
private String emailAddress;
11+
private Map<String, String> options;
12+
@SerializedName("phone_number")
13+
private String phoneNumber;
14+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.easypost.model;
22

3+
import java.util.Map;
34
import lombok.Getter;
45

56
@Getter
67
public final class FedexRegistration extends EasyPostResource {
7-
private String status;
8-
private String message;
8+
private String type;
9+
private Map<String, String> credentials;
910
}

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.easypost.exception.EasyPostException;
44
import com.easypost.http.Requestor;
55
import com.easypost.http.Requestor.RequestMethod;
6+
import com.easypost.model.FedExAccountValidationResponse;
67
import com.easypost.model.FedexRegistration;
78

89
import java.util.HashMap;
@@ -33,12 +34,12 @@ public class FedexRegistrationService {
3334
* @param postalCode Postal/ZIP code.
3435
* @param countryCode Country code (e.g., "US").
3536
* @param carrierAccountId EasyPost carrier account ID to update.
36-
* @return FedexRegistration object.
37+
* @return FedExAccountValidationResponse object with next steps (PIN or invoice validation).
3738
* @throws EasyPostException when the request fails.
3839
*/
39-
public FedexRegistration registerAddress(final String fedexAccountNumber, final String name, final String street1,
40-
final String city, final String state, final String postalCode, final String countryCode,
41-
final String carrierAccountId) throws EasyPostException {
40+
public FedExAccountValidationResponse registerAddress(final String fedexAccountNumber, final String name,
41+
final String street1, final String city, final String state, final String postalCode,
42+
final String countryCode, final String carrierAccountId) throws EasyPostException {
4243
Map<String, Object> addressValidation = new HashMap<>();
4344
addressValidation.put("name", name);
4445
addressValidation.put("street1", street1);
@@ -67,15 +68,16 @@ public FedexRegistration registerAddress(final String fedexAccountNumber, final
6768
* If "address_validation.name" is not provided, a UUID will be
6869
* auto-generated.
6970
* Optional: "easypost_details" object with "carrier_account_id".
70-
* @return FedexRegistration object.
71+
* @return FedExAccountValidationResponse object with next steps (PIN or invoice validation).
7172
* @throws EasyPostException when the request fails.
7273
*/
73-
public FedexRegistration registerAddress(final String fedexAccountNumber, final Map<String, Object> params)
74-
throws EasyPostException {
74+
public FedExAccountValidationResponse registerAddress(final String fedexAccountNumber,
75+
final Map<String, Object> params) throws EasyPostException {
7576
Map<String, Object> wrappedParams = wrapAddressValidation(params);
7677
String endpoint = String.format("fedex_registrations/%s/address", fedexAccountNumber);
7778

78-
return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, FedexRegistration.class, client);
79+
return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, FedExAccountValidationResponse.class,
80+
client);
7981
}
8082

8183
/**
@@ -84,10 +86,10 @@ public FedexRegistration registerAddress(final String fedexAccountNumber, final
8486
*
8587
* @param fedexAccountNumber The FedEx account number.
8688
* @param pinMethodOption The PIN delivery method: "SMS", "CALL", or "EMAIL".
87-
* @return FedexRegistration object.
89+
* @return FedExAccountValidationResponse object confirming PIN was sent.
8890
* @throws EasyPostException when the request fails.
8991
*/
90-
public FedexRegistration requestPin(final String fedexAccountNumber, final String pinMethodOption)
92+
public FedExAccountValidationResponse requestPin(final String fedexAccountNumber, final String pinMethodOption)
9193
throws EasyPostException {
9294
Map<String, Object> pinMethod = new HashMap<>();
9395
pinMethod.put("option", pinMethodOption);
@@ -106,14 +108,14 @@ public FedexRegistration requestPin(final String fedexAccountNumber, final Strin
106108
* @param params Map of parameters containing "pin_method" with "option" field.
107109
* The "option" value must be one of "SMS", "CALL", or "EMAIL".
108110
* Example: {"pin_method": {"option": "SMS"}}
109-
* @return FedexRegistration object.
111+
* @return FedExAccountValidationResponse object confirming PIN was sent.
110112
* @throws EasyPostException when the request fails.
111113
*/
112-
public FedexRegistration requestPin(final String fedexAccountNumber, final Map<String, Object> params)
114+
public FedExAccountValidationResponse requestPin(final String fedexAccountNumber, final Map<String, Object> params)
113115
throws EasyPostException {
114116
String endpoint = String.format("fedex_registrations/%s/pin", fedexAccountNumber);
115117

116-
return Requestor.request(RequestMethod.POST, endpoint, params, FedexRegistration.class, client);
118+
return Requestor.request(RequestMethod.POST, endpoint, params, FedExAccountValidationResponse.class, client);
117119
}
118120

119121
/**

src/test/cassettes/fedex_registration/register_address.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/fedex_registration/request_pin.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/fedex_registration/submit_invoice.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/fedex_registration/validate_pin.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/com/easypost/FedexRegistrationTest.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.easypost;
22

33
import com.easypost.exception.EasyPostException;
4+
import com.easypost.model.FedExAccountValidationResponse;
45
import com.easypost.model.FedexRegistration;
56
import org.junit.jupiter.api.BeforeAll;
67
import org.junit.jupiter.api.Test;
78

89
import java.util.HashMap;
910
import java.util.Map;
1011

12+
import static org.junit.jupiter.api.Assertions.assertEquals;
1113
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1214
import static org.junit.jupiter.api.Assertions.assertNotNull;
1315

@@ -49,11 +51,16 @@ public void testRegisterAddress() throws EasyPostException {
4951
params.put("address_validation", addressValidation);
5052
params.put("easypost_details", easypostDetails);
5153

52-
FedexRegistration registration = vcr.client.fedexRegistration.registerAddress(TEST_FEDEX_ACCOUNT_NUMBER,
53-
params);
54+
FedExAccountValidationResponse response = vcr.client.fedexRegistration
55+
.registerAddress(TEST_FEDEX_ACCOUNT_NUMBER, params);
5456

55-
assertInstanceOf(FedexRegistration.class, registration);
56-
assertNotNull(registration.getId());
57+
assertInstanceOf(FedExAccountValidationResponse.class, response);
58+
assertNotNull(response.getId());
59+
assertNotNull(response.getEmailAddress());
60+
assertNotNull(response.getPhoneNumber());
61+
assertNotNull(response.getOptions());
62+
assertEquals("test@example.com", response.getEmailAddress());
63+
assertEquals("+1234567890", response.getPhoneNumber());
5764
}
5865

5966
/**
@@ -71,10 +78,14 @@ public void testRequestPin() throws EasyPostException {
7178
Map<String, Object> params = new HashMap<>();
7279
params.put("pin_method", pinMethod);
7380

74-
FedexRegistration registration = vcr.client.fedexRegistration.requestPin(TEST_FEDEX_ACCOUNT_NUMBER, params);
81+
FedExAccountValidationResponse response = vcr.client.fedexRegistration.requestPin(TEST_FEDEX_ACCOUNT_NUMBER,
82+
params);
7583

76-
assertInstanceOf(FedexRegistration.class, registration);
77-
assertNotNull(registration.getId());
84+
assertInstanceOf(FedExAccountValidationResponse.class, response);
85+
assertNotNull(response.getId());
86+
assertNotNull(response.getEmailAddress());
87+
assertNotNull(response.getPhoneNumber());
88+
assertNotNull(response.getOptions());
7889
}
7990

8091
/**
@@ -101,6 +112,9 @@ public void testValidatePin() throws EasyPostException {
101112

102113
assertInstanceOf(FedexRegistration.class, registration);
103114
assertNotNull(registration.getId());
115+
assertEquals("FedexAccount", registration.getType());
116+
assertNotNull(registration.getCredentials());
117+
assertEquals("123456789", registration.getCredentials().get("account_number"));
104118
}
105119

106120
/**
@@ -130,6 +144,9 @@ public void testSubmitInvoice() throws EasyPostException {
130144

131145
assertInstanceOf(FedexRegistration.class, registration);
132146
assertNotNull(registration.getId());
147+
assertEquals("FedexAccount", registration.getType());
148+
assertNotNull(registration.getCredentials());
149+
assertEquals("123456789", registration.getCredentials().get("account_number"));
133150
}
134151

135152
}

0 commit comments

Comments
 (0)