Skip to content

Commit aa0c54f

Browse files
author
Kevin Hellemun
committed
Merge branch 'release/0.12.2'
2 parents 3ffdb9c + 8f576ef commit aa0c54f

13 files changed

+346
-25
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Steps to reproduce:
2+
1.
3+
4+
## What should happen:
5+
1.
6+
7+
## What happens:
8+
1.
9+
10+
## Logs
11+
- Logs
12+
13+
## Extra info:
14+
- Tested on
15+

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.bunq.sdk'
2-
version '0.12.0'
2+
version '0.12.2'
33

44
apply plugin: 'java'
55
apply plugin: 'maven'

src/main/java/com/bunq/sdk/context/ApiContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,14 @@ private void deleteSession() {
230230
* needed.
231231
*/
232232
public void ensureSessionActive() {
233-
if (sessionContext == null) {
234-
return;
235-
}
233+
if (!isSessionActive()){
234+
resetSession();
235+
}
236+
}
236237

237-
if (getTimeToSessionExpiryInSeconds() < TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS) {
238-
resetSession();
239-
}
238+
public boolean isSessionActive() {
239+
return sessionContext != null ||
240+
getTimeToSessionExpiryInSeconds() > TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS;
240241
}
241242

242243
private long getTimeToSessionExpiryInSeconds() {

src/main/java/com/bunq/sdk/http/ApiClient.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.security.KeyManagementException;
2121
import java.security.NoSuchAlgorithmException;
2222
import java.util.ArrayList;
23+
import java.util.Arrays;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
@@ -52,6 +53,18 @@
5253
*/
5354
public class ApiClient {
5455

56+
/**
57+
* Endpoints not requiring active session for the request to succeed.
58+
*/
59+
private static final String DEVICE_SERVER_URL = "device-server";
60+
private static final String INSTALLATION_URL = "installation";
61+
private static final String SESSION_SERVER_URL = "session-server";
62+
private static final List<String> URIS_NOT_REQUIRING_ACTIVE_SESSION = Arrays.asList(
63+
DEVICE_SERVER_URL,
64+
INSTALLATION_URL,
65+
SESSION_SERVER_URL
66+
);
67+
5568
/**
5669
* Header constants.
5770
*/
@@ -80,7 +93,7 @@ public class ApiClient {
8093
/**
8194
* Prefix for bunq's own headers.
8295
*/
83-
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.12.0";
96+
private static final String USER_AGENT_BUNQ = "bunq-sdk-java/0.12.2";
8497
private static final String LANGUAGE_EN_US = "en_US";
8598
private static final String REGION_NL_NL = "nl_NL";
8699
private static final String GEOLOCATION_ZERO = "0 0 0 0 000";
@@ -137,7 +150,7 @@ public BunqResponseRaw post(String uri, byte[] requestBodyBytes,
137150
try {
138151
HttpPost httpPost = new HttpPost(determineFullUri(uri));
139152
httpPost.setEntity(new ByteArrayEntity(requestBodyBytes, ContentType.APPLICATION_JSON));
140-
CloseableHttpResponse response = executeRequest(httpPost, customHeaders);
153+
CloseableHttpResponse response = executeRequest(httpPost, customHeaders, uri);
141154

142155
return createBunqResponseRaw(response);
143156
} catch (IOException | URISyntaxException exception) {
@@ -161,8 +174,11 @@ private URI determineFullUri(String uri, Map<String, String> params) throws URIS
161174
}
162175

163176
private CloseableHttpResponse executeRequest(HttpUriRequest request,
164-
Map<String, String> customHeaders) throws IOException {
165-
apiContext.ensureSessionActive();
177+
Map<String, String> customHeaders, String uri) throws IOException {
178+
if (!URIS_NOT_REQUIRING_ACTIVE_SESSION.contains(uri)) {
179+
apiContext.ensureSessionActive();
180+
}
181+
166182
setHeaders(request, customHeaders);
167183

168184
return httpClient.execute(request);
@@ -299,7 +315,7 @@ public BunqResponseRaw get(String uri, Map<String, String> params,
299315
Map<String, String> customHeaders) {
300316
try {
301317
HttpGet httpGet = new HttpGet(determineFullUri(uri, params));
302-
CloseableHttpResponse response = executeRequest(httpGet, customHeaders);
318+
CloseableHttpResponse response = executeRequest(httpGet, customHeaders, uri);
303319

304320
return createBunqResponseRaw(response);
305321
} catch (IOException | URISyntaxException exception) {
@@ -317,7 +333,7 @@ public BunqResponseRaw put(String uri, byte[] requestBodyBytes,
317333
try {
318334
HttpPut httpPut = new HttpPut(determineFullUri(uri));
319335
httpPut.setEntity(new ByteArrayEntity(requestBodyBytes, ContentType.APPLICATION_JSON));
320-
CloseableHttpResponse response = executeRequest(httpPut, customHeaders);
336+
CloseableHttpResponse response = executeRequest(httpPut, customHeaders, uri);
321337

322338
return createBunqResponseRaw(response);
323339
} catch (IOException | URISyntaxException exception) {
@@ -333,7 +349,7 @@ public BunqResponseRaw put(String uri, byte[] requestBodyBytes,
333349
public BunqResponseRaw delete(String uri, Map<String, String> customHeaders) {
334350
try {
335351
HttpDelete httpDelete = new HttpDelete(determineFullUri(uri));
336-
CloseableHttpResponse response = executeRequest(httpDelete, customHeaders);
352+
CloseableHttpResponse response = executeRequest(httpDelete, customHeaders, uri);
337353

338354
return createBunqResponseRaw(response);
339355
} catch (IOException | URISyntaxException exception) {

src/main/java/com/bunq/sdk/model/generated/endpoint/Card.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public class Card extends BunqModel {
7979
@SerializedName("public_uuid")
8080
private String publicUuid;
8181

82+
/**
83+
* The type of the card. Can be MAESTRO, MASTERCARD.
84+
*/
85+
@Expose
86+
@SerializedName("type")
87+
private String type;
88+
8289
/**
8390
* The second line of text on the card
8491
*/
@@ -275,6 +282,17 @@ public void setPublicUuid(String publicUuid) {
275282
this.publicUuid = publicUuid;
276283
}
277284

285+
/**
286+
* The type of the card. Can be MAESTRO, MASTERCARD.
287+
*/
288+
public String getType() {
289+
return this.type;
290+
}
291+
292+
public void setType(String type) {
293+
this.type = type;
294+
}
295+
278296
/**
279297
* The second line of text on the card
280298
*/

src/main/java/com/bunq/sdk/model/generated/endpoint/CardDebit.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public class CardDebit extends BunqModel {
7676
@SerializedName("public_uuid")
7777
private String publicUuid;
7878

79+
/**
80+
* The type of the card. Can be MAESTRO, MASTERCARD.
81+
*/
82+
@Expose
83+
@SerializedName("type")
84+
private String type;
85+
7986
/**
8087
* The second line of text on the card
8188
*/
@@ -228,6 +235,17 @@ public void setPublicUuid(String publicUuid) {
228235
this.publicUuid = publicUuid;
229236
}
230237

238+
/**
239+
* The type of the card. Can be MAESTRO, MASTERCARD.
240+
*/
241+
public String getType() {
242+
return this.type;
243+
}
244+
245+
public void setType(String type) {
246+
this.type = type;
247+
}
248+
231249
/**
232250
* The second line of text on the card
233251
*/
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package com.bunq.sdk.model.generated.endpoint;
2+
3+
import com.bunq.sdk.context.ApiContext;
4+
import com.bunq.sdk.http.ApiClient;
5+
import com.bunq.sdk.http.BunqResponse;
6+
import com.bunq.sdk.http.BunqResponseRaw;
7+
import com.bunq.sdk.model.core.BunqModel;
8+
import com.bunq.sdk.model.core.MonetaryAccountReference;
9+
import com.bunq.sdk.security.SecurityUtils;
10+
import com.google.gson.annotations.Expose;
11+
import com.google.gson.annotations.SerializedName;
12+
import java.math.BigDecimal;
13+
import java.util.ArrayList;
14+
import java.util.HashMap;
15+
import java.util.List;
16+
import java.util.Map;
17+
import javax.lang.model.type.NullType;
18+
19+
/**
20+
* Endpoint for generating and retrieving a new CVC2 code.
21+
*/
22+
public class CardGeneratedCvc2 extends BunqModel {
23+
24+
/**
25+
* Endpoint constants.
26+
*/
27+
private static final String ENDPOINT_URL_CREATE = "user/%s/card/%s/generated-cvc2";
28+
private static final String ENDPOINT_URL_READ = "user/%s/card/%s/generated-cvc2/%s";
29+
private static final String ENDPOINT_URL_LISTING = "user/%s/card/%s/generated-cvc2";
30+
31+
/**
32+
* Object type.
33+
*/
34+
private static final String OBJECT_TYPE = "CardGeneratedCvc2";
35+
36+
/**
37+
* The id of the cvc code.
38+
*/
39+
@Expose
40+
@SerializedName("id")
41+
private Integer id;
42+
43+
/**
44+
* The timestamp of the cvc code's creation.
45+
*/
46+
@Expose
47+
@SerializedName("created")
48+
private String created;
49+
50+
/**
51+
* The timestamp of the cvc code's last update.
52+
*/
53+
@Expose
54+
@SerializedName("updated")
55+
private String updated;
56+
57+
/**
58+
* The cvc2 code.
59+
*/
60+
@Expose
61+
@SerializedName("cvc2")
62+
private String cvc2;
63+
64+
/**
65+
* The status of the cvc2. Can be AVAILABLE, USED, EXPIRED, BLOCKED.
66+
*/
67+
@Expose
68+
@SerializedName("status")
69+
private String status;
70+
71+
/**
72+
* Expiry time of the cvc2.
73+
*/
74+
@Expose
75+
@SerializedName("expiry_time")
76+
private String expiryTime;
77+
78+
public static BunqResponse<CardGeneratedCvc2> create(ApiContext apiContext, Map<String, Object> requestMap, Integer userId, Integer cardId) {
79+
return create(apiContext, requestMap, userId, cardId, new HashMap<>());
80+
}
81+
82+
/**
83+
* Generate a new CVC2 code for a card.
84+
*/
85+
public static BunqResponse<CardGeneratedCvc2> create(ApiContext apiContext, Map<String, Object> requestMap, Integer userId, Integer cardId, Map<String, String> customHeaders) {
86+
ApiClient apiClient = new ApiClient(apiContext);
87+
byte[] requestBytes = gson.toJson(requestMap).getBytes();
88+
requestBytes = SecurityUtils.encrypt(apiContext, requestBytes, customHeaders);
89+
BunqResponseRaw responseRaw = apiClient.post(String.format(ENDPOINT_URL_CREATE, userId, cardId), requestBytes, customHeaders);
90+
91+
return fromJson(CardGeneratedCvc2.class, responseRaw, OBJECT_TYPE);
92+
}
93+
94+
public static BunqResponse<CardGeneratedCvc2> get(ApiContext apiContext, Integer userId, Integer cardId, Integer cardGeneratedCvc2Id) {
95+
return get(apiContext, userId, cardId, cardGeneratedCvc2Id, new HashMap<>());
96+
}
97+
98+
/**
99+
* Get the details for a specific generated CVC2 code.
100+
*/
101+
public static BunqResponse<CardGeneratedCvc2> get(ApiContext apiContext, Integer userId, Integer cardId, Integer cardGeneratedCvc2Id, Map<String, String> customHeaders) {
102+
ApiClient apiClient = new ApiClient(apiContext);
103+
BunqResponseRaw responseRaw = apiClient.get(String.format(ENDPOINT_URL_READ, userId, cardId, cardGeneratedCvc2Id), new HashMap<>(), customHeaders);
104+
105+
return fromJson(CardGeneratedCvc2.class, responseRaw, OBJECT_TYPE);
106+
}
107+
108+
public static BunqResponse<List<CardGeneratedCvc2>> list(ApiContext apiContext, Integer userId, Integer cardId) {
109+
return list(apiContext, userId, cardId, new HashMap<>());
110+
}
111+
112+
public static BunqResponse<List<CardGeneratedCvc2>> list(ApiContext apiContext, Integer userId, Integer cardId, Map<String, String> params) {
113+
return list(apiContext, userId, cardId, params, new HashMap<>());
114+
}
115+
116+
/**
117+
* Get all generated CVC2 codes for a card.
118+
*/
119+
public static BunqResponse<List<CardGeneratedCvc2>> list(ApiContext apiContext, Integer userId, Integer cardId, Map<String, String> params, Map<String, String> customHeaders) {
120+
ApiClient apiClient = new ApiClient(apiContext);
121+
BunqResponseRaw responseRaw = apiClient.get(String.format(ENDPOINT_URL_LISTING, userId, cardId), params, customHeaders);
122+
123+
return fromJsonList(CardGeneratedCvc2.class, responseRaw, OBJECT_TYPE);
124+
}
125+
126+
/**
127+
* The id of the cvc code.
128+
*/
129+
public Integer getId() {
130+
return this.id;
131+
}
132+
133+
public void setId(Integer id) {
134+
this.id = id;
135+
}
136+
137+
/**
138+
* The timestamp of the cvc code's creation.
139+
*/
140+
public String getCreated() {
141+
return this.created;
142+
}
143+
144+
public void setCreated(String created) {
145+
this.created = created;
146+
}
147+
148+
/**
149+
* The timestamp of the cvc code's last update.
150+
*/
151+
public String getUpdated() {
152+
return this.updated;
153+
}
154+
155+
public void setUpdated(String updated) {
156+
this.updated = updated;
157+
}
158+
159+
/**
160+
* The cvc2 code.
161+
*/
162+
public String getCvc2() {
163+
return this.cvc2;
164+
}
165+
166+
public void setCvc2(String cvc2) {
167+
this.cvc2 = cvc2;
168+
}
169+
170+
/**
171+
* The status of the cvc2. Can be AVAILABLE, USED, EXPIRED, BLOCKED.
172+
*/
173+
public String getStatus() {
174+
return this.status;
175+
}
176+
177+
public void setStatus(String status) {
178+
this.status = status;
179+
}
180+
181+
/**
182+
* Expiry time of the cvc2.
183+
*/
184+
public String getExpiryTime() {
185+
return this.expiryTime;
186+
}
187+
188+
public void setExpiryTime(String expiryTime) {
189+
this.expiryTime = expiryTime;
190+
}
191+
192+
}

0 commit comments

Comments
 (0)