Skip to content

Commit 863fd47

Browse files
committed
feat(fedex): add convenience methods for MFA endpoints
Add method overloads that accept individual parameters instead of requiring manual nested Map construction. This simplifies the API for users: - registerAddress: accepts individual address fields - requestPin: accepts just the PIN method option string - validatePin: accepts pinCode, name, and carrierAccountId - submitInvoice: accepts individual invoice fields Each convenience method delegates to the advanced Map-based method internally, maintaining backward compatibility and flexibility.
1 parent 161ad2a commit 863fd47

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,43 @@ public class FedexRegistrationService {
2323

2424
/**
2525
* Register the billing address for a FedEx account.
26+
* Convenience method that automatically wraps parameters in the required structure.
27+
*
28+
* @param fedexAccountNumber The FedEx account number.
29+
* @param name The account name (use a unique identifier).
30+
* @param street1 Street address line 1.
31+
* @param city City.
32+
* @param state State/province code.
33+
* @param postalCode Postal/ZIP code.
34+
* @param countryCode Country code (e.g., "US").
35+
* @param carrierAccountId EasyPost carrier account ID to update.
36+
* @return FedexRegistration object.
37+
* @throws EasyPostException when the request fails.
38+
*/
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 {
42+
Map<String, Object> addressValidation = new HashMap<>();
43+
addressValidation.put("name", name);
44+
addressValidation.put("street1", street1);
45+
addressValidation.put("city", city);
46+
addressValidation.put("state", state);
47+
addressValidation.put("postal_code", postalCode);
48+
addressValidation.put("country_code", countryCode);
49+
50+
Map<String, Object> easypostDetails = new HashMap<>();
51+
easypostDetails.put("carrier_account_id", carrierAccountId);
52+
53+
Map<String, Object> params = new HashMap<>();
54+
params.put("address_validation", addressValidation);
55+
params.put("easypost_details", easypostDetails);
56+
57+
return registerAddress(fedexAccountNumber, params);
58+
}
59+
60+
/**
61+
* Register the billing address for a FedEx account.
62+
* Advanced method for custom parameter structures.
2663
*
2764
* @param fedexAccountNumber The FedEx account number.
2865
* @param params Map of parameters containing "address_validation" with address fields
@@ -43,6 +80,27 @@ public FedexRegistration registerAddress(final String fedexAccountNumber, final
4380

4481
/**
4582
* Request a PIN for FedEx account verification.
83+
* Convenience method that automatically wraps the PIN method in the required structure.
84+
*
85+
* @param fedexAccountNumber The FedEx account number.
86+
* @param pinMethodOption The PIN delivery method: "SMS", "CALL", or "EMAIL".
87+
* @return FedexRegistration object.
88+
* @throws EasyPostException when the request fails.
89+
*/
90+
public FedexRegistration requestPin(final String fedexAccountNumber, final String pinMethodOption)
91+
throws EasyPostException {
92+
Map<String, Object> pinMethod = new HashMap<>();
93+
pinMethod.put("option", pinMethodOption);
94+
95+
Map<String, Object> params = new HashMap<>();
96+
params.put("pin_method", pinMethod);
97+
98+
return requestPin(fedexAccountNumber, params);
99+
}
100+
101+
/**
102+
* Request a PIN for FedEx account verification.
103+
* Advanced method for custom parameter structures.
46104
*
47105
* @param fedexAccountNumber The FedEx account number.
48106
* @param params Map of parameters containing "pin_method" with "option" field.
@@ -60,6 +118,34 @@ public FedexRegistration requestPin(final String fedexAccountNumber, final Map<S
60118

61119
/**
62120
* Validate the PIN entered by the user for FedEx account verification.
121+
* Convenience method that automatically wraps parameters in the required structure.
122+
*
123+
* @param fedexAccountNumber The FedEx account number.
124+
* @param pinCode The PIN code received by the user.
125+
* @param name The account name (use a unique identifier).
126+
* @param carrierAccountId EasyPost carrier account ID to update.
127+
* @return FedexRegistration object.
128+
* @throws EasyPostException when the request fails.
129+
*/
130+
public FedexRegistration validatePin(final String fedexAccountNumber, final String pinCode, final String name,
131+
final String carrierAccountId) throws EasyPostException {
132+
Map<String, Object> pinValidation = new HashMap<>();
133+
pinValidation.put("pin_code", pinCode);
134+
pinValidation.put("name", name);
135+
136+
Map<String, Object> easypostDetails = new HashMap<>();
137+
easypostDetails.put("carrier_account_id", carrierAccountId);
138+
139+
Map<String, Object> params = new HashMap<>();
140+
params.put("pin_validation", pinValidation);
141+
params.put("easypost_details", easypostDetails);
142+
143+
return validatePin(fedexAccountNumber, params);
144+
}
145+
146+
/**
147+
* Validate the PIN entered by the user for FedEx account verification.
148+
* Advanced method for custom parameter structures.
63149
*
64150
* @param fedexAccountNumber The FedEx account number.
65151
* @param params Map of parameters containing "pin_validation" with "pin_code" and
@@ -79,6 +165,41 @@ public FedexRegistration validatePin(final String fedexAccountNumber, final Map<
79165

80166
/**
81167
* Submit invoice information to complete FedEx account registration.
168+
* Convenience method that automatically wraps parameters in the required structure.
169+
*
170+
* @param fedexAccountNumber The FedEx account number.
171+
* @param name The account name (use a unique identifier).
172+
* @param invoiceNumber The invoice number.
173+
* @param invoiceDate The invoice date (format: YYYY-MM-DD).
174+
* @param invoiceAmount The invoice amount (e.g., "100.00").
175+
* @param invoiceCurrency The invoice currency code (e.g., "USD").
176+
* @param carrierAccountId EasyPost carrier account ID to update.
177+
* @return FedexRegistration object.
178+
* @throws EasyPostException when the request fails.
179+
*/
180+
public FedexRegistration submitInvoice(final String fedexAccountNumber, final String name,
181+
final String invoiceNumber, final String invoiceDate, final String invoiceAmount,
182+
final String invoiceCurrency, final String carrierAccountId) throws EasyPostException {
183+
Map<String, Object> invoiceValidation = new HashMap<>();
184+
invoiceValidation.put("name", name);
185+
invoiceValidation.put("invoice_number", invoiceNumber);
186+
invoiceValidation.put("invoice_date", invoiceDate);
187+
invoiceValidation.put("invoice_amount", invoiceAmount);
188+
invoiceValidation.put("invoice_currency", invoiceCurrency);
189+
190+
Map<String, Object> easypostDetails = new HashMap<>();
191+
easypostDetails.put("carrier_account_id", carrierAccountId);
192+
193+
Map<String, Object> params = new HashMap<>();
194+
params.put("invoice_validation", invoiceValidation);
195+
params.put("easypost_details", easypostDetails);
196+
197+
return submitInvoice(fedexAccountNumber, params);
198+
}
199+
200+
/**
201+
* Submit invoice information to complete FedEx account registration.
202+
* Advanced method for custom parameter structures.
82203
*
83204
* @param fedexAccountNumber The FedEx account number.
84205
* @param params Map of parameters containing "invoice_validation" with invoice fields

0 commit comments

Comments
 (0)