Skip to content

Commit 2e2eebf

Browse files
authored
Merge pull request #99 from Adyen/feature/CheckoutAPI_PW_422
Feature/checkout api pw 422
2 parents 650171e + 874d99b commit 2e2eebf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+8914
-80
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea
22
*.iml
3+
/target/**
4+
.DS_Store
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
*
15+
* Adyen Java API Library
16+
*
17+
* Copyright (c) 2018 Adyen B.V.
18+
* This file is open source and available under the MIT license.
19+
* See the LICENSE file for more info.
20+
*/
21+
package com.adyen;
22+
23+
/**
24+
* <h1>ApiKeyAuthenticatedService</h1>
25+
* The ApiKeyAuthenticatedService is an interface to enable a child service to support API key authentication feature.
26+
*/
27+
public class ApiKeyAuthenticatedService extends Service {
28+
29+
protected ApiKeyAuthenticatedService(Client client) {
30+
super(client);
31+
setApiKeyRequired(true);
32+
}
33+
}

src/main/java/com/adyen/Client.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public class Client {
4141
public static final String MARKETPAY_NOTIFICATION_API_VERSION = "v1";
4242
public static final String USER_AGENT_SUFFIX = "adyen-java-api-library/";
4343
public static final String LIB_VERSION = "1.4.1";
44+
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com";
45+
public static final String CHECKOUT_ENDPOINT_LIVE = "https://checkout-live.adyen.com";
46+
public static final String CHECKOUT_API_VERSION = "v32";
47+
public static final String CHECKOUT_UTILITY_API_VERSION = "v1";
4448

4549
public Client() {
4650
this.config = new Config();
@@ -66,11 +70,14 @@ public void setEnvironment(Environment environment) {
6670
this.config.setEndpoint(ENDPOINT_TEST);
6771
this.config.setMarketPayEndpoint(MARKETPAY_ENDPOINT_TEST);
6872
this.config.setHppEndpoint(HPP_TEST);
73+
this.config.setCheckoutEndpoint(CHECKOUT_ENDPOINT_TEST);
74+
6975
} else if (environment.equals(Environment.LIVE)) {
7076
this.config.setEnvironment(environment);
7177
this.config.setEndpoint(ENDPOINT_LIVE);
7278
this.config.setMarketPayEndpoint(MARKETPAY_ENDPOINT_LIVE);
7379
this.config.setHppEndpoint(HPP_LIVE);
80+
this.config.setCheckoutEndpoint(CHECKOUT_ENDPOINT_LIVE);
7481
} else {
7582
// throw exception
7683
}

src/main/java/com/adyen/Config.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* Adyen Java API Library
1616
*
17-
* Copyright (c) 2017 Adyen B.V.
17+
* Copyright (c) 2018 Adyen B.V.
1818
* This file is open source and available under the MIT license.
1919
* See the LICENSE file for more info.
2020
*/
@@ -30,12 +30,17 @@ public class Config {
3030
protected String endpoint;
3131
protected String marketPayEndpoint;
3232
protected String applicationName;
33+
protected String apiKey;
3334

3435
//HPP specific
3536
protected String hppEndpoint;
3637
protected String skinCode;
3738
protected String hmacKey;
3839

40+
//Checkout Specific
41+
protected String checkoutEndpoint;
42+
43+
3944
public Config() {
4045
// do nothing
4146
}
@@ -96,6 +101,14 @@ public void setApplicationName(String applicationName) {
96101
this.applicationName = applicationName;
97102
}
98103

104+
public String getApiKey() {
105+
return apiKey;
106+
}
107+
108+
public void setApiKey(String apiKey) {
109+
this.apiKey = apiKey;
110+
}
111+
99112
public String getHppEndpoint() {
100113
return hppEndpoint;
101114
}
@@ -119,4 +132,14 @@ public String getHmacKey() {
119132
public void setHmacKey(String hmacKey) {
120133
this.hmacKey = hmacKey;
121134
}
135+
136+
public String getCheckoutEndpoint() {
137+
return checkoutEndpoint;
138+
}
139+
140+
public void setCheckoutEndpoint(String checkoutEndpoint) {
141+
this.checkoutEndpoint = checkoutEndpoint;
142+
}
143+
144+
122145
}
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* ######
33
* ######
44
* ############ ####( ###### #####. ###### ############ ############
@@ -14,30 +14,38 @@
1414
*
1515
* Adyen Java API Library
1616
*
17-
* Copyright (c) 2017 Adyen B.V.
17+
* Copyright (c) 2018 Adyen B.V.
1818
* This file is open source and available under the MIT license.
1919
* See the LICENSE file for more info.
2020
*/
2121
package com.adyen;
2222

2323
import com.google.gson.Gson;
2424

25-
public class Service{
26-
27-
protected static final Gson GSON = new Gson();
28-
29-
private Client client;
30-
31-
protected Service(Client client){
32-
this.client = client;
33-
}
34-
35-
public Client getClient() {
36-
return client;
37-
}
38-
39-
public void setClient(Client client) {
40-
this.client = client;
41-
}
42-
25+
public class Service {
26+
27+
protected static final Gson GSON = new Gson();
28+
protected boolean isApiKeyRequired = false;
29+
private Client client;
30+
31+
protected Service(Client client) {
32+
this.client = client;
33+
}
34+
35+
public Client getClient() {
36+
return client;
37+
}
38+
39+
public void setClient(Client client) {
40+
this.client = client;
41+
}
42+
43+
public boolean isApiKeyRequired() {
44+
return isApiKeyRequired;
45+
}
46+
47+
public void setApiKeyRequired(boolean apiKeyRequired) {
48+
isApiKeyRequired = apiKeyRequired;
49+
}
50+
4351
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* ######
33
* ######
44
* ############ ####( ###### #####. ###### ############ ############
@@ -14,19 +14,20 @@
1414
*
1515
* Adyen Java API Library
1616
*
17-
* Copyright (c) 2017 Adyen B.V.
17+
* Copyright (c) 2018 Adyen B.V.
1818
* This file is open source and available under the MIT license.
1919
* See the LICENSE file for more info.
2020
*/
2121
package com.adyen.httpclient;
2222

23+
import com.adyen.Config;
24+
2325
import java.io.IOException;
2426
import java.util.Map;
25-
import com.adyen.Config;
2627

2728
public interface ClientInterface {
2829

29-
String request(String endpoint, String json, Config config) throws IOException, HTTPClientException;
30-
31-
String post(String endpoint, Map<String, String> postParameters, Config config) throws IOException, HTTPClientException;
30+
String request(String endpoint, String json, Config config) throws IOException, HTTPClientException;
31+
String request(String endpoint, String json, Config config, boolean isApiKeyRequired) throws IOException, HTTPClientException;
32+
String post(String endpoint, Map<String, String> postParameters, Config config) throws IOException, HTTPClientException;
3233
}

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
*/
2121
package com.adyen.httpclient;
2222

23+
import com.adyen.Client;
24+
import com.adyen.Config;
25+
import org.apache.commons.codec.binary.Base64;
26+
2327
import java.io.IOException;
2428
import java.io.InputStream;
2529
import java.io.OutputStream;
@@ -30,24 +34,33 @@
3034
import java.net.URLEncoder;
3135
import java.util.Map;
3236
import java.util.Scanner;
33-
import org.apache.commons.codec.binary.Base64;
34-
import com.adyen.Client;
35-
import com.adyen.Config;
3637

3738
public class HttpURLConnectionClient implements ClientInterface {
3839
private static final String CHARSET = "UTF-8";
3940
private Proxy proxy;
4041

42+
/**
43+
* Does a POST request.
44+
* config is used to obtain basic auth username, password and User-Agent
45+
*/
4146
/**
4247
* Does a POST request.
4348
* config is used to obtain basic auth username, password and User-Agent
4449
*/
4550
@Override
4651
public String request(String requestUrl, String requestBody, Config config) throws IOException, HTTPClientException {
52+
return request(requestUrl, requestBody, config, false);
53+
}
54+
55+
@Override
56+
public String request(String requestUrl, String requestBody, Config config, boolean isApiKeyRequired) throws IOException, HTTPClientException {
4757
HttpURLConnection httpConnection = createRequest(requestUrl, config.getApplicationName());
48-
setBasicAuthentication(httpConnection, config.getUsername(), config.getPassword());
58+
if (isApiKeyRequired) {
59+
setApiKey(httpConnection, config.getApiKey());
60+
} else {
61+
setBasicAuthentication(httpConnection, config.getUsername(), config.getPassword());
62+
}
4963
setContentType(httpConnection, "application/json");
50-
5164
String response = doPostRequest(httpConnection, requestBody);
5265

5366
return response;
@@ -140,6 +153,16 @@ private HttpURLConnection setContentType(HttpURLConnection httpConnection, Strin
140153
return httpConnection;
141154
}
142155

156+
/**
157+
* Sets api key
158+
*/
159+
private HttpURLConnection setApiKey(HttpURLConnection httpConnection, String apiKey) {
160+
if (apiKey != null && !apiKey.isEmpty()) {
161+
httpConnection.setRequestProperty("x-api-key", apiKey);
162+
}
163+
return httpConnection;
164+
}
165+
143166
/**
144167
* Does a POST request with raw body
145168
*/

0 commit comments

Comments
 (0)