Skip to content

Commit

Permalink
Merge pull request #593 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 16.0.0
  • Loading branch information
Aleffio authored Jul 22, 2021
2 parents 5e32c5d + 19eda45 commit 94e9415
Show file tree
Hide file tree
Showing 217 changed files with 2,828 additions and 1,044 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can use Maven and add this dependency to your project's POM:
<dependency>
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<version>15.1.0</version>
<version>16.0.0</version>
</dependency>
```

Expand Down Expand Up @@ -107,17 +107,17 @@ Checkout checkout = new Checkout(client);


### Proxy configuration
You can configure a proxy connection by injecting your own HttpURLConnectionClient on your client instance.
You can configure a proxy connection by injecting your own AdyenHttpClient on your client instance.

Example:
~~~~ java
...
HttpURLConnectionClient httpURLConnectionClientWithProxy = new HttpURLConnectionClient();
AdyenHttpClient adyenHttpClientWithProxy = new AdyenHttpClient();

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("PROXY_HOST", PROXY_PORT));
httpURLConnectionClientWithProxy.setProxy(proxy);
adyenHttpClientWithProxy.setProxy(proxy);

client.setHttpClient(httpURLConnectionClientWithProxy);
client.setHttpClient(adyenHttpClientWithProxy);
~~~~

### Example integrations
Expand Down
23 changes: 14 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<packaging>jar</packaging>
<version>15.1.0</version>
<version>16.0.0</version>
<name>Adyen Java API Library</name>
<description>Adyen API Client Library for Java</description>
<url>https://github.com/adyen/adyen-java-api-library</url>
Expand Down Expand Up @@ -182,14 +182,9 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -214,5 +209,15 @@
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Client {
public static final String MARKETPAY_NOTIFICATION_API_VERSION = "v6";
public static final String MARKETPAY_HOP_API_VERSION = "v6";
public static final String LIB_NAME = "adyen-java-api-library";
public static final String LIB_VERSION = "15.1.0";
public static final String LIB_VERSION = "16.0.0";
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com/checkout";
public static final String CHECKOUT_ENDPOINT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
public static final String CHECKOUT_ENDPOINT_CERT_LIVE = "https://checkoutcert-live-%s.adyen.com/checkout";
Expand Down
68 changes: 37 additions & 31 deletions src/main/java/com/adyen/httpclient/AdyenHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
import com.adyen.model.RequestOptions;
import com.adyen.terminal.security.TerminalCommonNameValidator;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPatch;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.net.URIBuilder;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManagerFactory;
Expand All @@ -52,10 +53,12 @@
import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.adyen.constants.ApiConstants.HttpMethod.POST;
import static com.adyen.constants.ApiConstants.RequestProperty.ACCEPT_CHARSET;
Expand Down Expand Up @@ -104,7 +107,7 @@ public String request(String endpoint, String requestBody, Config config, boolea
@Override
public String request(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions, ApiConstants.HttpMethod httpMethod, Map<String, String> params) throws IOException, HTTPClientException {
try (CloseableHttpClient httpclient = createCloseableHttpClient(config)) {
HttpRequestBase httpRequest = createRequest(endpoint, requestBody, config, isApiKeyRequired, requestOptions, httpMethod, params);
HttpUriRequestBase httpRequest = createRequest(endpoint, requestBody, config, isApiKeyRequired, requestOptions, httpMethod, params);

// Execute request with a custom response handler
AdyenResponse response = httpclient.execute(httpRequest, new AdyenResponseHandler());
Expand All @@ -116,15 +119,15 @@ public String request(String endpoint, String requestBody, Config config, boolea
}
}

private HttpRequestBase createRequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions, ApiConstants.HttpMethod httpMethod, Map<String, String> params) throws HTTPClientException {
HttpRequestBase httpRequest = createHttpRequestBase(createUri(endpoint, params), requestBody, httpMethod);
private HttpUriRequestBase createRequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions, ApiConstants.HttpMethod httpMethod, Map<String, String> params) throws HTTPClientException {
HttpUriRequestBase httpRequest = createHttpRequestBase(createUri(endpoint, params), requestBody, httpMethod);

RequestConfig.Builder builder = RequestConfig.custom();
if (config.getReadTimeoutMillis() > 0) {
builder.setSocketTimeout(config.getReadTimeoutMillis());
builder.setResponseTimeout(config.getReadTimeoutMillis(), TimeUnit.MILLISECONDS);
}
if (config.getConnectionTimeoutMillis() > 0) {
builder.setConnectTimeout(config.getConnectionTimeoutMillis());
builder.setConnectTimeout(config.getConnectionTimeoutMillis(), TimeUnit.MILLISECONDS);
}
if (proxy != null && proxy.address() instanceof InetSocketAddress) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) proxy.address();
Expand All @@ -138,7 +141,7 @@ private HttpRequestBase createRequest(String endpoint, String requestBody, Confi
return httpRequest;
}

private void setHeaders(Config config, RequestOptions requestOptions, HttpRequestBase httpUriRequest) {
private void setHeaders(Config config, RequestOptions requestOptions, HttpUriRequestBase httpUriRequest) {

setContentType(httpUriRequest, APPLICATION_JSON_TYPE);
httpUriRequest.addHeader(ACCEPT_CHARSET, CHARSET);
Expand All @@ -149,10 +152,10 @@ private void setHeaders(Config config, RequestOptions requestOptions, HttpReques
}
}

private HttpRequestBase createHttpRequestBase(URI endpoint, String requestBody, ApiConstants.HttpMethod httpMethod) {
private HttpUriRequestBase createHttpRequestBase(URI endpoint, String requestBody, ApiConstants.HttpMethod httpMethod) {
StringEntity requestEntity = null;
if (requestBody != null && !requestBody.isEmpty()) {
requestEntity = new StringEntity(requestBody, CHARSET);
requestEntity = new StringEntity(requestBody, Charset.forName(CHARSET));
}

switch (httpMethod) {
Expand Down Expand Up @@ -187,18 +190,21 @@ private URI createUri(String endpoint, Map<String, String> params) throws HTTPCl
}

private CloseableHttpClient createCloseableHttpClient(Config config) throws HTTPClientException {

if (config.getClientKeyStore() != null && config.getTrustKeyStore() != null) {
return HttpClients.custom()
.setSSLSocketFactory(getClientCertificateAuthSSLContext(config))
.build();
} else if (config.getTerminalCertificate() != null) {
return HttpClients.custom()
.setSSLSocketFactory(getTerminalCertificateSocketFactory(config))
.build();
} else {
return HttpClients.createDefault();
return createHttpClientWithSocketFactory(getClientCertificateAuthSSLContext(config));
}
if (config.getTerminalCertificate() != null) {
return createHttpClientWithSocketFactory(getTerminalCertificateSocketFactory(config));
}
return HttpClients.createDefault();
}

private CloseableHttpClient createHttpClientWithSocketFactory(SSLConnectionSocketFactory socketFactory) {
return HttpClients.custom()
.setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(socketFactory)
.build())
.build();
}

private SSLConnectionSocketFactory getTerminalCertificateSocketFactory(Config config) throws HTTPClientException {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/adyen/httpclient/AdyenResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@
*/
package com.adyen.httpclient;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdyenResponseHandler implements ResponseHandler<AdyenResponse> {
public class AdyenResponseHandler implements HttpClientResponseHandler<AdyenResponse> {

@Override
public AdyenResponse handleResponse(HttpResponse httpResponse) throws IOException {
public AdyenResponse handleResponse(ClassicHttpResponse httpResponse) throws IOException, ParseException {
AdyenResponse adyenResponse = new AdyenResponse();
adyenResponse.setStatus(httpResponse.getStatusLine().getStatusCode());
adyenResponse.setHeaders(getHeaders(httpResponse.getAllHeaders()));
adyenResponse.setStatus(httpResponse.getCode());
adyenResponse.setHeaders(getHeaders(httpResponse.getHeaders()));

HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

package com.adyen.model.checkout;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.adyen.util.MaskUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;

import java.util.Objects;
Expand Down Expand Up @@ -90,6 +90,8 @@ public class DefaultPaymentMethodDetails implements PaymentMethodDetails {
private String brand;
@SerializedName("networkPaymentReference")
private String networkPaymentReference;
@SerializedName("shopperNotificationReference")
private String shopperNotificationReference;

@Override
public String getType() {
Expand Down Expand Up @@ -427,6 +429,14 @@ public void setNetworkPaymentReference(String networkPaymentReference) {
this.networkPaymentReference = networkPaymentReference;
}

public String getShopperNotificationReference() {
return shopperNotificationReference;
}

public void setShopperNotificationReference(String shopperNotificationReference) {
this.shopperNotificationReference = shopperNotificationReference;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -460,15 +470,16 @@ public boolean equals(Object o) {
&& Objects.equals(separateDeliveryAddress, that.separateDeliveryAddress)
&& Objects.equals(brand, that.brand)
&& Objects.equals(networkPaymentReference, that.networkPaymentReference)
&& Objects.equals(securityCode, that.securityCode);
&& Objects.equals(securityCode, that.securityCode)
&& Objects.equals(shopperNotificationReference, that.shopperNotificationReference);
}

@Override
public int hashCode() {
return Objects.hash(type, number, expiryMonth, expiryYear, holderName, cvc, installmentConfigurationKey,
personalDetails, encryptedCardNumber, encryptedExpiryMonth, encryptedExpiryYear, encryptedSecurityCode,
recurringDetailReference, storedPaymentMethodId, storeDetails, idealIssuer, issuer, sepaOwnerName,
sepaIbanNumber, applepayToken, googlepayToken, separateDeliveryAddress, brand, networkPaymentReference, securityCode);
sepaIbanNumber, applepayToken, googlepayToken, separateDeliveryAddress, brand, networkPaymentReference, securityCode, shopperNotificationReference);
}

@Override
Expand Down Expand Up @@ -499,6 +510,7 @@ public String toString() {
", securityCode='" + MaskUtil.mask(securityCode) + '\'' +
", brand='" + brand + '\'' +
", networkPaymentReference='" + networkPaymentReference + '\'' +
", shopperNotificationReference='" + shopperNotificationReference + '\'' +
'}';
}
}
Expand Down
Loading

0 comments on commit 94e9415

Please sign in to comment.