Skip to content

Commit 1f248f2

Browse files
authored
Merge pull request #69 from unzerdev/develop
Releas 1.1.2.6
2 parents 7522828 + d4add6f commit 1f248f2

File tree

7 files changed

+199
-60
lines changed

7 files changed

+199
-60
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres
66
to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.2.6][1.1.2.6]
9+
10+
### Added
11+
* Added Unzer-Logo and updated the reference in Readme-File.
12+
* Added Json-Validation to JsonParser-Class before real Json-Deserialization happens.
13+
* Added Twitter-Handle to Readme-File.
14+
15+
### Changed
16+
* Documentation-Link in Readme-File has been changed.
17+
* Several minor improvements.
18+
819
## [1.1.2.5][1.1.2.5]
920

1021
### Changed
@@ -122,6 +133,8 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
122133
* Remove deprecated classes
123134
* RestCommunication
124135

136+
[1.1.2.6]: http://github.com/unzerdev/java-sdk/compare/1.1.2.5..1.1.2.6
137+
125138
[1.1.2.5]: http://github.com/unzerdev/java-sdk/compare/1.1.2.4..1.1.2.5
126139

127140
[1.1.2.4]: http://github.com/unzerdev/java-sdk/compare/1.1.2.3..1.1.2.4

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Logo](https://dev.unzer.com/wp-content/uploads/2020/09/Unzer__PrimaryLogo_Raspberry_RGB.png)
1+
![Logo](unzer_logo.svg)
22

33
# Unzer Java Payment SDK
44
This SDK provides for an easy way to connect to the Unzer Rest API.
@@ -12,12 +12,12 @@ Java 1.8 or later.
1212
<dependency>
1313
<groupId>com.unzer.payment</groupId>
1414
<artifactId>java-sdk</artifactId>
15-
<version>1.1.2.5</version>
15+
<version>1.1.2.6</version>
1616
</dependency>
1717
```
1818

1919
## Documentation
20-
Documentation is available at https://docs.unzer.com/integrate/java-sdk/.
20+
Documentation is available at https://docs.unzer.com/server-side-integration/java-sdk-integration/.
2121

2222
## SDK Overview
2323
### Unzer class
@@ -140,4 +140,7 @@ For any issues or questions please get in touch with our support team.
140140

141141
### Phone
142142
* DE: [+49 6221 43101-00](tel:+4962214310100)
143-
* AT: [+43 1 513 66 33 669](tel:+4315136633669)
143+
* AT: [+43 1 513 66 33 669](tel:+4315136633669)
144+
145+
### Twitter
146+
[@UnzerTech](https://twitter.com/UnzerTech)

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.unzer.payment</groupId>
88
<artifactId>java-sdk</artifactId>
9-
<version>1.1.2.5</version>
9+
<version>1.1.2.6</version>
1010
<name>Unzer Java SDK</name>
1111
<description>Unzer Java SDK</description>
1212
<url>https://docs.unzer.com/</url>
@@ -248,13 +248,13 @@
248248
<dependency>
249249
<groupId>org.apache.logging.log4j</groupId>
250250
<artifactId>log4j-api</artifactId>
251-
<version>2.17.0</version>
251+
<version>2.17.1</version>
252252
</dependency>
253253

254254
<dependency>
255255
<groupId>org.apache.logging.log4j</groupId>
256256
<artifactId>log4j-core</artifactId>
257-
<version>2.17.0</version>
257+
<version>2.17.1</version>
258258
</dependency>
259259

260260

src/main/java/com/unzer/payment/communication/JsonParser.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* Licensed under the Apache License, Version 2.0 (the "License");
2121
* you may not use this file except in compliance with the License.
2222
* You may obtain a copy of the License at
23-
*
23+
*
2424
* http://www.apache.org/licenses/LICENSE-2.0
25-
*
25+
*
2626
* Unless required by applicable law or agreed to in writing, software
2727
* distributed under the License is distributed on an "AS IS" BASIS,
2828
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,11 +31,13 @@
3131
* #L%
3232
*/
3333

34+
import com.fasterxml.jackson.databind.ObjectMapper;
3435
import com.google.gson.Gson;
3536
import com.google.gson.GsonBuilder;
3637
import com.unzer.payment.PaymentException;
3738
import com.unzer.payment.communication.json.JsonErrorObject;
3839

40+
import java.io.IOException;
3941
import java.math.BigDecimal;
4042
import java.net.URL;
4143
import java.util.Currency;
@@ -64,7 +66,7 @@ public JsonParser() {
6466

6567
/**
6668
* Provides a function which simple parse object to json
67-
*
69+
*
6870
* @param model refers to object to be parsed
6971
* @return json method
7072
* @throws IllegalArgumentException if the model is null
@@ -85,10 +87,13 @@ public String toJson(Object model) {
8587
* @return an object of type T
8688
*/
8789
@SuppressWarnings("hiding")
88-
public <T> T fromJson(String json, Class<T> clazz) {
90+
public <T> T fromJson(String json, Class<T> clazz) throws IllegalArgumentException, PaymentException {
8991
if (Objects.isNull(json) || Objects.isNull(clazz)) {
9092
throw new IllegalArgumentException("Null object cannot be parsed!");
9193
}
94+
if(!isJsonValid(json)) {
95+
throw new IllegalArgumentException(String.format("The provided JSON String is not valid! The provided Json was: %s", json));
96+
}
9297
if (isError(json) && !clazz.isAssignableFrom(JsonErrorObject.class)) {
9398
throw toPaymentException(json);
9499
}
@@ -105,4 +110,14 @@ private boolean isError(String json) {
105110
return json.contains(ERRORS) && json.contains(ERROR_CODE);
106111
}
107112

113+
public boolean isJsonValid(String jsonInString) {
114+
try {
115+
final ObjectMapper mapper = new ObjectMapper();
116+
mapper.readTree(jsonInString);
117+
return true;
118+
} catch (IOException | IllegalArgumentException e) {
119+
return false;
120+
}
121+
}
122+
108123
}

src/test/java/com/unzer/payment/business/AbstractSeleniumTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ protected Paypage getMaximumPaypage() throws MalformedURLException {
243243
paypage.setPrivacyPolicyUrl(new URL("https://www.unzer.com/en/privacy-statement/"));
244244
paypage.setCss(getCssMap());
245245

246-
paypage.setLogoImage("https://dev.unzer.de/wp-content/uploads/2020/09/Unzer__PrimaryLogo_Raspberry_RGB-595x272.png");
246+
paypage.setLogoImage("https://docs.unzer.com/payment-nutshell/payment-in-nutshell.png");
247247
paypage.setFullPageImage("https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/iphone-12-pro-family-hero");
248248

249249
paypage.setContactUrl(new URL("mailto:[email protected]"));
@@ -271,7 +271,7 @@ protected Linkpay getMaximumLinkpay() throws MalformedURLException {
271271
linkpay.setPrivacyPolicyUrl(new URL("https://www.unzer.com/en/datenschutz/"));
272272
linkpay.setCss(getCssMap());
273273

274-
linkpay.setLogoImage("https://dev.unzer.de/wp-content/uploads/2020/09/Unzer__PrimaryLogo_Raspberry_RGB-595x272.png");
274+
linkpay.setLogoImage("https://docs.unzer.com/payment-nutshell/payment-in-nutshell.png");
275275
linkpay.setFullPageImage("https://store.storeimages.cdn-apple.com/4668/as-images.apple.com/is/iphone-12-pro-family-hero");
276276

277277
linkpay.setContactUrl(new URL("mailto:[email protected]"));

src/test/java/com/unzer/payment/communication/JsonParserTest.java

+75-47
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,53 +21,81 @@
2121
*/
2222

2323

24-
import com.unzer.payment.PaymentError;
25-
import com.unzer.payment.PaymentException;
26-
import com.unzer.payment.TestData;
24+
import com.unzer.payment.*;
25+
import com.unzer.payment.business.AbstractPaymentTest;
2726
import com.unzer.payment.communication.json.JsonCharge;
2827
import com.unzer.payment.communication.json.JsonErrorObject;
2928
import org.junit.Test;
3029

31-
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assert.fail;
33-
34-
public class JsonParserTest {
35-
36-
@Test
37-
public void given_an_error_message_then_payment_exception_is_thrown() {
38-
try {
39-
JsonParser parser = new JsonParser();
40-
parser.fromJson(TestData.errorJson(), JsonCharge.class);
41-
42-
fail("Expected PaymentException");
43-
} catch (PaymentException exception) {
44-
assertBasicErrorAttributes(exception.getId(), exception.getUrl(), exception.getTimestamp());
45-
assertPaymentError(exception.getPaymentErrorList().get(0));
46-
}
47-
}
48-
49-
@Test
50-
public void given_an_error_json_then_fromJson_returnes_jsonerrorobject() {
51-
assertJsonError(new JsonParser().fromJson(TestData.errorJson(), JsonErrorObject.class));
52-
}
53-
54-
private void assertJsonError(JsonErrorObject expectedError) {
55-
assertBasicErrorAttributes(expectedError.getId(), expectedError.getUrl(), expectedError.getTimestamp());
56-
assertEquals(1, expectedError.getErrors().size());
57-
assertPaymentError(expectedError.getErrors().get(0));
58-
}
59-
60-
private void assertBasicErrorAttributes(String id, String url, String timestamp) {
61-
assertEquals("s-err-f2ea241e5e8e4eb3b1513fab12c", id);
62-
assertEquals("https://api.unzer.com/v1/payments/charges", url);
63-
assertEquals("2019-01-09 15:42:24", timestamp);
64-
65-
}
66-
67-
private void assertPaymentError(PaymentError error) {
68-
assertEquals("COR.400.100.101", error.getCode());
69-
assertEquals("Address untraceable", error.getMerchantMessage());
70-
assertEquals("The provided address is invalid. Please check your input and try agian.",
71-
error.getCustomerMessage());
72-
}
30+
import static org.junit.Assert.*;
31+
32+
public class JsonParserTest extends AbstractPaymentTest {
33+
34+
@Test
35+
public void given_an_error_message_then_payment_exception_is_thrown() {
36+
try {
37+
JsonParser parser = new JsonParser();
38+
parser.fromJson(TestData.errorJson(), JsonCharge.class);
39+
40+
fail("Expected PaymentException");
41+
} catch (PaymentException exception) {
42+
assertBasicErrorAttributes(exception.getId(), exception.getUrl(), exception.getTimestamp());
43+
assertPaymentError(exception.getPaymentErrorList().get(0));
44+
}
45+
}
46+
47+
@Test
48+
public void given_an_error_json_then_fromJson_returnes_jsonerrorobject() {
49+
assertJsonError(new JsonParser().fromJson(TestData.errorJson(), JsonErrorObject.class));
50+
}
51+
52+
@Test
53+
public void testValidJson() {
54+
assertTrue(new JsonParser().isJsonValid("{\"name\": \"value\"}"));
55+
}
56+
57+
@Test
58+
public void testInvalidJson() {
59+
assertFalse(new JsonParser().isJsonValid("This is an error message!"));
60+
}
61+
62+
@Test(expected = IllegalArgumentException.class)
63+
public void testNullJson() {
64+
new JsonParser().fromJson(null, Payment.class);
65+
}
66+
67+
@Test(expected = IllegalArgumentException.class)
68+
public void testNullClass() {
69+
new JsonParser().fromJson("{\"name\": \"value\"}", null);
70+
}
71+
72+
@Test
73+
public void testNullValidJson() {
74+
assertFalse(new JsonParser().isJsonValid(null));
75+
}
76+
77+
@Test(expected = IllegalArgumentException.class)
78+
public void testFromInvalidJson() {
79+
new JsonParser().fromJson("This is an error message!", Payment.class);
80+
}
81+
82+
private void assertJsonError(JsonErrorObject expectedError) {
83+
assertBasicErrorAttributes(expectedError.getId(), expectedError.getUrl(), expectedError.getTimestamp());
84+
assertEquals(1, expectedError.getErrors().size());
85+
assertPaymentError(expectedError.getErrors().get(0));
86+
}
87+
88+
private void assertBasicErrorAttributes(String id, String url, String timestamp) {
89+
assertEquals("s-err-f2ea241e5e8e4eb3b1513fab12c", id);
90+
assertEquals("https://api.unzer.com/v1/payments/charges", url);
91+
assertEquals("2019-01-09 15:42:24", timestamp);
92+
93+
}
94+
95+
private void assertPaymentError(PaymentError error) {
96+
assertEquals("COR.400.100.101", error.getCode());
97+
assertEquals("Address untraceable", error.getMerchantMessage());
98+
assertEquals("The provided address is invalid. Please check your input and try agian.",
99+
error.getCustomerMessage());
100+
}
73101
}

unzer_logo.svg

+80
Loading

0 commit comments

Comments
 (0)