Skip to content

Commit 7154698

Browse files
authored
Improve javadoc (#1493)
1 parent a098453 commit 7154698

File tree

10 files changed

+218
-61
lines changed

10 files changed

+218
-61
lines changed

src/main/java/com/adyen/ApiKeyAuthenticatedService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
package com.adyen;
2222

2323
/**
24-
* The ApiKeyAuthenticatedService is an interface to enable a child service to support API key authentication feature.
25-
*/
26-
public class ApiKeyAuthenticatedService extends Service {
24+
* A service base class that enforces API key authentication.
25+
* <p>
26+
* This class extends Service and ensures that any extending service
27+
* requires an API key for authentication.
28+
* </p>
29+
*/public class ApiKeyAuthenticatedService extends Service {
2730

2831
protected ApiKeyAuthenticatedService(Client client) {
2932
super(client);

src/main/java/com/adyen/Service.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import com.adyen.enums.Environment;
2424

25+
/**
26+
* Parent class for all Service implementations
27+
*/
2528
public class Service {
2629
private boolean isApiKeyRequired = false;
2730
private Client client;

src/main/java/com/adyen/builders/terminal/TerminalAPIRequestBuilder.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@
5858

5959
import static com.adyen.constants.ApiConstants.TerminalAPI.PROTOCOL_VERSION;
6060

61+
/**
62+
* Builder for constructing a TerminalAPIRequest using the fluent interface pattern.
63+
* <p>
64+
* This builder allows you to configure and create various types of Terminal API requests by setting
65+
* the appropriate request object and associated metadata such as MessageClassType and
66+
* MessageCategoryType.
67+
* </p>
68+
*
69+
* <p>
70+
* Each type of Terminal API request (e.g. PaymentRequest, BalanceInquiryRequest, etc.)
71+
* has a dedicated `withXRequest` method that sets the necessary fields and message types internally.
72+
* Once all necessary fields are set, call build() to generate the TerminalAPIRequest.
73+
* </p>
74+
*
75+
* <p>
76+
* Example usage:
77+
* </p>
78+
* <pre>{@code
79+
* TerminalAPIRequest request = new TerminalAPIRequestBuilder("Sale001", "Service001", "POI001")
80+
* .withPaymentRequest(paymentRequest)
81+
* .withSecurityTrailer(contentInformation)
82+
* .build();
83+
* }</pre>
84+
*
85+
*/
6186
public final class TerminalAPIRequestBuilder {
6287

6388
// MessageHeader

src/main/java/com/adyen/httpclient/AdyenHttpClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
import static com.adyen.constants.ApiConstants.RequestProperty.REQUESTED_VERIFICATION_CODE_HEADER;
6464
import static com.adyen.constants.ApiConstants.RequestProperty.USER_AGENT;
6565

66+
/**
67+
* HTTP client implementation to invoke the Adyen APIs.
68+
* Built on top of org.apache.hc.client5
69+
*/
6670
public class AdyenHttpClient implements ClientInterface {
6771

6872
private static final String CHARSET = "UTF-8";

src/main/java/com/adyen/httpclient/TerminalLocalAPIHostnameVerifier.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,48 @@
88
import javax.net.ssl.SSLSession;
99
import java.security.cert.X509Certificate;
1010

11+
/**
12+
* A custom HostnameVerifier implementation for verifying SSL connections to
13+
* Adyen Terminal Local APIs. This verifier ensures the peer certificate's common name (CN)
14+
* matches expected patterns based on the current Environment.
15+
* <p>
16+
* This is typically used to verify secure connections to payment terminals on local networks.
17+
*
18+
* <p>It validates the hostname by inspecting the leaf certificate (first in the chain)
19+
* and checking it against allowed CNs using TerminalCommonNameValidator.
20+
*
21+
* @see TerminalCommonNameValidator
22+
* @see Environment
23+
*/
1124
public final class TerminalLocalAPIHostnameVerifier implements HostnameVerifier {
25+
26+
/**
27+
* The Adyen environment (e.g., TEST, LIVE) that determines which hostnames are valid.
28+
*/
1229
private final Environment environment;
1330

31+
/**
32+
* Constructs a new {@code TerminalLocalAPIHostnameVerifier} with the specified environment.
33+
*
34+
* @param environment The Adyen environment used for validating terminal hostnames.
35+
*/
1436
public TerminalLocalAPIHostnameVerifier(Environment environment) {
1537
this.environment = environment;
1638
}
1739

40+
/**
41+
* Verifies the hostname of an SSL session by inspecting the peer's certificate
42+
* and validating its common name against expected values for the given environment.
43+
*
44+
* @param hostname the hostname to verify.
45+
* @param session the SSL session associated with the connection.
46+
* @return {@code true} if the hostname is valid for the given environment; {@code false} otherwise.
47+
*/
1848
@Override
1949
public boolean verify(String hostname, SSLSession session) {
2050
try {
2151
if (session.getPeerCertificates() != null && session.getPeerCertificates().length > 0) {
22-
// Assume the first certificate is the leaf, since chain will be ordered, according to Java documentation:
23-
// https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLSession.html#getPeerCertificates()
52+
// Assume the first certificate is the leaf, since chain will be ordered.
2453
X509Certificate certificate = (X509Certificate) session.getPeerCertificates()[0];
2554
return TerminalCommonNameValidator.validateCertificate(certificate, environment);
2655
}

src/main/java/com/adyen/util/CertificateUtil.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,29 @@
3232
import java.security.cert.CertificateException;
3333
import java.security.cert.CertificateFactory;
3434

35+
/**
36+
* Utility class for loading X.509 certificates and Java KeyStores.
37+
*/
3538
public final class CertificateUtil {
3639

3740
private CertificateUtil() {
3841
}
3942

4043
/**
41-
* Load Certificate from system file path
42-
* @param filePath Path of certificate file
43-
* @return Certificate
44+
* Loads an X.509 certificate from the given file path.
45+
* @param filePath Filepath of the certificate
46+
* @return instance of the certificate
4447
* @throws FileNotFoundException if file is not found
45-
* @throws CertificateException if any error occurred while reading certificate
48+
* @throws CertificateException if any error occurred while reading the certificate
4649
*/
4750
public static Certificate loadCertificate(String filePath) throws FileNotFoundException, CertificateException {
4851
return loadCertificate(new FileInputStream(filePath));
4952
}
5053

5154
/**
52-
* Load Certificate from a input stream
53-
* @param inputStream InputStream containing certificate data
54-
* @return Certificate
55+
* Loads an X.509 certificate from an input stream.
56+
* @param inputStream InputStream containing the certificate.
57+
* @return instance of the certificate
5558
* @throws CertificateException if any error occurred while reading certificate from stream
5659
*/
5760
public static Certificate loadCertificate(InputStream inputStream) throws CertificateException {
@@ -60,15 +63,15 @@ public static Certificate loadCertificate(InputStream inputStream) throws Certif
6063
}
6164

6265
/**
63-
* Load KeyStore from given path and type
66+
* Loads a KeyStore from the specified file path using the given type and password.
6467
* @param keyStorePath file path
6568
* @param keyStoreType keystore type (JKS/PKCS12 etc)
6669
* @param keyStorePassword keystore password
67-
* @return
68-
* @throws KeyStoreException
69-
* @throws CertificateException
70-
* @throws NoSuchAlgorithmException
71-
* @throws IOException
70+
* @return the loaded KeyStore instance.
71+
* @throws KeyStoreException if the keystore type is invalid.
72+
* @throws CertificateException if a certificate in the keystore could not be loaded.
73+
* @throws NoSuchAlgorithmException if the algorithm for checking the keystore integrity cannot be found.
74+
* @throws IOException if there is an I/O or format problem with the keystore data.
7275
*/
7376
public static KeyStore loadKeyStore(String keyStorePath, String keyStoreType, String keyStorePassword) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
7477

@@ -90,9 +93,10 @@ public static KeyStore loadKeyStore(String keyStorePath, String keyStoreType, St
9093
throw new FileNotFoundException("Keystore file not found at path " + keyStorePath);
9194
}
9295

93-
FileInputStream inputStream = new FileInputStream(file);
94-
keyStore.load(inputStream, password);
95-
inputStream.close();
96+
try (FileInputStream inputStream = new FileInputStream(file)) {
97+
keyStore.load(inputStream, password);
98+
}
99+
96100
return keyStore;
97101
}
98102
}

src/main/java/com/adyen/util/DateUtil.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,23 @@
2626
import java.util.Locale;
2727
import java.util.TimeZone;
2828

29+
/**
30+
* Utility class for parsing date strings into java.util.Date objects using specified formats.
31+
*/
2932
public final class DateUtil {
33+
34+
// Private constructor to prevent instantiation
3035
private DateUtil() {
3136
}
3237

38+
/**
39+
* Parses a date string using the given date format.
40+
* Returns {@code null} if the input is {@code null} or parsing fails.
41+
*
42+
* @param dateString the date string to parse
43+
* @param format the format pattern to use for parsing (e.g., {@code "yyyy-MM-dd"})
44+
* @return the parsed Date, or {@code null} if parsing fails
45+
*/
3346
public static Date parseDateToFormat(String dateString, String format) {
3447
if (dateString == null) {
3548
return null;
@@ -46,10 +59,24 @@ public static Date parseDateToFormat(String dateString, String format) {
4659
return null;
4760
}
4861

62+
/**
63+
* Parses a date string in {@code yyyy-MM-dd} format.
64+
* Returns {@code null} if the input is {@code null} or parsing fails.
65+
*
66+
* @param dateString the date string to parse
67+
* @return the parsed {@link Date}, or {@code null} if parsing fails
68+
*/
4969
public static Date parseYmdDate(String dateString) {
5070
return parseDateToFormat(dateString, "yyyy-MM-dd");
5171
}
5272

73+
/**
74+
* Parses a date string in {@code M/yyyy} format.
75+
* Returns {@code null} if the input is {@code null} or parsing fails.
76+
*
77+
* @param dateString the date string to parse
78+
* @return the parsed {@link Date}, or {@code null} if parsing fails
79+
*/
5380
public static Date parseMYDate(String dateString) {
5481
return parseDateToFormat(dateString, "M/yyyy");
5582
}

0 commit comments

Comments
 (0)