Skip to content

Commit 173fa21

Browse files
committed
feat(fedex): add multi-factor authentication support
Add FedexRegistrationService to enable programmatic FedEx carrier account registration through 2FA workflow. Includes registerAddress, requestPin, validatePin, and submitInvoice endpoints. Auto-generates UUID for name parameter when not provided. Integrates service into EasyPostClient with comprehensive test coverage.
1 parent f6745b7 commit 173fa21

9 files changed

Lines changed: 435 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.easypost.model;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public final class FedexRegistration extends EasyPostResource {
7+
private String status;
8+
private String message;
9+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class EasyPostClient {
2626
public final BillingService billing = new BillingService(this);
2727
public final CarrierAccountService carrierAccount = new CarrierAccountService(this);
2828
public final CarrierMetadataService carrierMetadata = new CarrierMetadataService(this);
29+
public final FedexRegistrationService fedexRegistration = new FedexRegistrationService(this);
2930
public final CarrierTypeService carrierType = new CarrierTypeService(this);
3031
public final ClaimService claim = new ClaimService(this);
3132
public final CustomerPortalService customerPortal = new CustomerPortalService(this);
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.easypost.service;
2+
3+
import com.easypost.exception.EasyPostException;
4+
import com.easypost.http.Requestor;
5+
import com.easypost.http.Requestor.RequestMethod;
6+
import com.easypost.model.FedexRegistration;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.UUID;
11+
12+
public class FedexRegistrationService {
13+
private final EasyPostClient client;
14+
15+
/**
16+
* FedexRegistrationService constructor.
17+
*
18+
* @param client The client object.
19+
*/
20+
FedexRegistrationService(EasyPostClient client) {
21+
this.client = client;
22+
}
23+
24+
/**
25+
* Register the billing address for a FedEx account.
26+
*
27+
* @param fedexAccountNumber The FedEx account number.
28+
* @param params Map of parameters for address registration.
29+
* If params does not contain "name", a UUID will be auto-generated.
30+
* Optional: "easypost_details" object for additional metadata like
31+
* "reference" or "description".
32+
* @return FedexRegistration object.
33+
* @throws EasyPostException when the request fails.
34+
*/
35+
public FedexRegistration registerAddress(final String fedexAccountNumber, final Map<String, Object> params)
36+
throws EasyPostException {
37+
Map<String, Object> processedParams = ensureNameParameter(params);
38+
String endpoint = String.format("fedex_registrations/%s/address", fedexAccountNumber);
39+
40+
return Requestor.request(RequestMethod.POST, endpoint, processedParams, FedexRegistration.class, client);
41+
}
42+
43+
/**
44+
* Request a PIN for FedEx account verification.
45+
*
46+
* @param fedexAccountNumber The FedEx account number.
47+
* @param params Map of parameters for PIN request.
48+
* Required: "pin_method" - one of "SMS", "CALL", or "EMAIL".
49+
* If params does not contain "name", a UUID will be auto-generated.
50+
* Optional: "easypost_details" object for additional metadata.
51+
* @return FedexRegistration object.
52+
* @throws EasyPostException when the request fails.
53+
*/
54+
public FedexRegistration requestPin(final String fedexAccountNumber, final Map<String, Object> params)
55+
throws EasyPostException {
56+
Map<String, Object> processedParams = ensureNameParameter(params);
57+
String endpoint = String.format("fedex_registrations/%s/pin", fedexAccountNumber);
58+
59+
return Requestor.request(RequestMethod.POST, endpoint, processedParams, FedexRegistration.class, client);
60+
}
61+
62+
/**
63+
* Validate the PIN entered by the user for FedEx account verification.
64+
*
65+
* @param fedexAccountNumber The FedEx account number.
66+
* @param params Map of parameters for PIN validation.
67+
* Required: PIN value provided by the user.
68+
* If params does not contain "name", a UUID will be auto-generated.
69+
* Optional: "easypost_details" object for additional metadata.
70+
* @return FedexRegistration object.
71+
* @throws EasyPostException when the request fails.
72+
*/
73+
public FedexRegistration validatePin(final String fedexAccountNumber, final Map<String, Object> params)
74+
throws EasyPostException {
75+
Map<String, Object> processedParams = ensureNameParameter(params);
76+
String endpoint = String.format("fedex_registrations/%s/pin/validate", fedexAccountNumber);
77+
78+
return Requestor.request(RequestMethod.POST, endpoint, processedParams, FedexRegistration.class, client);
79+
}
80+
81+
/**
82+
* Submit invoice information to complete FedEx account registration.
83+
*
84+
* @param fedexAccountNumber The FedEx account number.
85+
* @param params Map of parameters for invoice submission.
86+
* Required: Invoice information.
87+
* If params does not contain "name", a UUID will be auto-generated.
88+
* Optional: "easypost_details" object for additional metadata.
89+
* @return FedexRegistration object.
90+
* @throws EasyPostException when the request fails.
91+
*/
92+
public FedexRegistration submitInvoice(final String fedexAccountNumber, final Map<String, Object> params)
93+
throws EasyPostException {
94+
Map<String, Object> processedParams = ensureNameParameter(params);
95+
String endpoint = String.format("fedex_registrations/%s/invoice", fedexAccountNumber);
96+
97+
return Requestor.request(RequestMethod.POST, endpoint, processedParams, FedexRegistration.class, client);
98+
}
99+
100+
/**
101+
* Ensures the "name" parameter exists in the params map.
102+
* If not present, generates a UUID (with hyphens removed) as the name.
103+
* This follows the pattern used in the web UI implementation.
104+
*
105+
* @param params The original parameters map.
106+
* @return A new map with the "name" parameter ensured.
107+
*/
108+
private Map<String, Object> ensureNameParameter(final Map<String, Object> params) {
109+
Map<String, Object> processedParams = new HashMap<>(params);
110+
if (!processedParams.containsKey("name") || processedParams.get("name") == null) {
111+
String uuid = UUID.randomUUID().toString().replace("-", "");
112+
processedParams.put("name", uuid);
113+
}
114+
return processedParams;
115+
}
116+
}

src/test/cassettes/fedex_registration/auto_generate_name.json

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

src/test/cassettes/fedex_registration/register_address.json

Lines changed: 38 additions & 0 deletions
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: 38 additions & 0 deletions
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: 38 additions & 0 deletions
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: 38 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)