Skip to content

Commit d84a052

Browse files
committed
Add support for WWW-Authenticate header
1 parent 612ee74 commit d84a052

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/main/java/com/adyen/constants/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ interface RequestProperty {
109109
String API_KEY = "x-api-key";
110110
String APPLICATION_JSON_TYPE = "application/json";
111111
String REQUESTED_VERIFICATION_CODE_HEADER = "x-requested-verification-code";
112+
String WWW_AUTHENTICATE_HEADER = "WWW-Authenticate";
112113
}
113114

114115
interface ThreeDS2Property {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static com.adyen.constants.ApiConstants.RequestProperty.IDEMPOTENCY_KEY;
3131
import static com.adyen.constants.ApiConstants.RequestProperty.REQUESTED_VERIFICATION_CODE_HEADER;
3232
import static com.adyen.constants.ApiConstants.RequestProperty.USER_AGENT;
33+
import static com.adyen.constants.ApiConstants.RequestProperty.WWW_AUTHENTICATE_HEADER;
3334

3435
import com.adyen.Client;
3536
import com.adyen.Config;
@@ -199,6 +200,10 @@ private void setHeaders(
199200
REQUESTED_VERIFICATION_CODE_HEADER,
200201
requestOptions.getRequestedVerificationCodeHeader());
201202
}
203+
if (requestOptions.getWwwAuthenticateHeader() != null) {
204+
httpUriRequest.addHeader(
205+
WWW_AUTHENTICATE_HEADER, requestOptions.getWwwAuthenticateHeader());
206+
}
202207

203208
if (requestOptions.getAdditionalServiceHeaders() != null) {
204209
requestOptions.getAdditionalServiceHeaders().forEach(httpUriRequest::addHeader);

src/main/java/com/adyen/model/RequestOptions.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public class RequestOptions {
66
private String idempotencyKey;
77
private String requestedVerificationCodeHeader;
8+
private String wwwAuthenticateHeader;
89
private HashMap<String, String> additionalServiceHeaders;
910

1011
public RequestOptions idempotencyKey(String idempotencyKey) {
@@ -17,11 +18,24 @@ public RequestOptions requestedVerificationCodeHeader(String requestedVerificati
1718
return this;
1819
}
1920

21+
public RequestOptions wwwAuthenticateHeader(String wwwAuthenticateHeader) {
22+
this.wwwAuthenticateHeader = wwwAuthenticateHeader;
23+
return this;
24+
}
25+
2026
public RequestOptions additionalServiceHeaders(HashMap<String, String> additionalServiceHeaders) {
2127
this.additionalServiceHeaders = additionalServiceHeaders;
2228
return this;
2329
}
2430

31+
public RequestOptions addAdditionalServiceHeader(String key, String value) {
32+
if (this.additionalServiceHeaders == null) {
33+
this.additionalServiceHeaders = new HashMap<>();
34+
}
35+
this.additionalServiceHeaders.put(key, value);
36+
return this;
37+
}
38+
2539
public String getIdempotencyKey() {
2640
return idempotencyKey;
2741
}
@@ -46,6 +60,14 @@ public void setAdditionalServiceHeaders(HashMap<String, String> additionalServic
4660
this.additionalServiceHeaders = additionalServiceHeaders;
4761
}
4862

63+
public String getWwwAuthenticateHeader() {
64+
return wwwAuthenticateHeader;
65+
}
66+
67+
public void setWwwAuthenticateHeader(String wwwAuthenticateHeader) {
68+
this.wwwAuthenticateHeader = wwwAuthenticateHeader;
69+
}
70+
4971
@Override
5072
public String toString() {
5173
return "RequestOptions{"
@@ -55,6 +77,9 @@ public String toString() {
5577
+ ", requestedVerificationCodeHeader='"
5678
+ requestedVerificationCodeHeader
5779
+ '\''
80+
+ ", wwwAuthenticateHeader='"
81+
+ wwwAuthenticateHeader
82+
+ '\''
5883
+ ", additionalServiceHeaders="
5984
+ additionalServiceHeaders
6085
+ '}';

src/test/java/com/adyen/httpclient/ClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public void testRequestOptionsBuilderPattern() {
139139
assertEquals(requestOptions.getAdditionalServiceHeaders(), map);
140140
}
141141

142+
@Test
143+
public void testRequestOptionsAddAdditionalServiceHeader() {
144+
RequestOptions requestOptions =
145+
new RequestOptions()
146+
.addAdditionalServiceHeader("key1", "value1")
147+
.addAdditionalServiceHeader("key2", "value2")
148+
.addAdditionalServiceHeader("key3", "value3");
149+
assertNotNull(requestOptions.getAdditionalServiceHeaders());
150+
assertEquals(3, requestOptions.getAdditionalServiceHeaders().size());
151+
}
152+
142153
@Test
143154
public void testUserAgentWithApplicationName() throws Exception {
144155

@@ -186,6 +197,7 @@ public void testRequestWithHttpHeaders() throws Exception {
186197
RequestOptions requestOptions =
187198
new RequestOptions()
188199
.idempotencyKey("test-idempotency-key")
200+
.wwwAuthenticateHeader("www-authenticate-header")
189201
.additionalServiceHeaders(additionalHeaders);
190202

191203
HttpUriRequestBase request =
@@ -205,5 +217,9 @@ public void testRequestWithHttpHeaders() throws Exception {
205217
Header customHeader = request.getFirstHeader("X-Custom-Header");
206218
assertNotNull(customHeader);
207219
assertEquals("custom-value", customHeader.getValue());
220+
221+
Header wwwAuthenticate = request.getFirstHeader("WWW-Authenticate");
222+
assertNotNull(wwwAuthenticate);
223+
assertEquals("www-authenticate-header", wwwAuthenticate.getValue());
208224
}
209225
}

0 commit comments

Comments
 (0)