diff --git a/src/main/java/nl/stil4m/mollie/Client.java b/src/main/java/nl/stil4m/mollie/Client.java index 541862e..3cb30ee 100644 --- a/src/main/java/nl/stil4m/mollie/Client.java +++ b/src/main/java/nl/stil4m/mollie/Client.java @@ -37,7 +37,7 @@ public Issuers issuers() { } public Refunds refunds(String paymentId) { - return dynamicClient.refunds(apiKey,paymentId); + return dynamicClient.refunds(apiKey, paymentId); } public Customers customers() { @@ -47,7 +47,7 @@ public Customers customers() { public CustomerPayments customerPayments(String customerId) { return dynamicClient.customerPayments(apiKey, customerId); } - + public Mandates mandates(String customerId) { return dynamicClient.mandates(apiKey, customerId); } diff --git a/src/main/java/nl/stil4m/mollie/DynamicClient.java b/src/main/java/nl/stil4m/mollie/DynamicClient.java index 6a9cd8c..4282bb6 100644 --- a/src/main/java/nl/stil4m/mollie/DynamicClient.java +++ b/src/main/java/nl/stil4m/mollie/DynamicClient.java @@ -46,7 +46,7 @@ public Customers customers(String apiKey) { public CustomerPayments customerPayments(String apiKey, String customerId) { return new CustomerPayments(apiKey, endpoint, requestExecutor, customerId); } - + public Mandates mandates(String apiKey, String customerId) { return new Mandates(apiKey, endpoint, requestExecutor, customerId); } diff --git a/src/main/java/nl/stil4m/mollie/ResponseOrError.java b/src/main/java/nl/stil4m/mollie/ResponseOrError.java index 0abea6f..08dba6c 100644 --- a/src/main/java/nl/stil4m/mollie/ResponseOrError.java +++ b/src/main/java/nl/stil4m/mollie/ResponseOrError.java @@ -10,6 +10,13 @@ public class ResponseOrError { private final Map error; private final Boolean success; + private ResponseOrError(int status, V data, Map error, Boolean success) { + this.status = status; + this.data = data; + this.error = error; + this.success = success; + } + public static ResponseOrError withError(int status, Map error) { return new ResponseOrError<>(status, null, error, false); } @@ -18,13 +25,6 @@ public static ResponseOrError withData(int status, V data) { return new ResponseOrError<>(status, data, null, true); } - private ResponseOrError(int status, V data, Map error, Boolean success) { - this.status = status; - this.data = data; - this.error = error; - this.success = success; - } - public void get(Consumer onSuccess, Consumer onError) { if (success) { onSuccess.accept(data); diff --git a/src/main/java/nl/stil4m/mollie/concepts/AbstractConcept.java b/src/main/java/nl/stil4m/mollie/concepts/AbstractConcept.java index a01b33e..48e7c6d 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/AbstractConcept.java +++ b/src/main/java/nl/stil4m/mollie/concepts/AbstractConcept.java @@ -1,6 +1,15 @@ package nl.stil4m.mollie.concepts; -import static java.util.Objects.requireNonNull; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import nl.stil4m.mollie.RequestExecutor; +import nl.stil4m.mollie.ResponseOrError; +import nl.stil4m.mollie.domain.Page; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; + import java.io.IOException; import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; @@ -8,70 +17,61 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; - -import nl.stil4m.mollie.RequestExecutor; -import nl.stil4m.mollie.ResponseOrError; -import nl.stil4m.mollie.domain.Page; +import static java.util.Objects.requireNonNull; public abstract class AbstractConcept implements Concept { private static final Collector URL_JOINER = Collectors.joining("/"); - private static final TypeReference VOID_TYPE_REFERENCE = new TypeReference(){}; - + private static final TypeReference VOID_TYPE_REFERENCE = new TypeReference() { + }; + private final TypeReference> pageTypeReference; private final TypeReference singleTypeReference; private final String apiKey; private final String endpoint; private final RequestExecutor requestExecutor; - protected AbstractConcept(String apiKey, RequestExecutor requestExecutor,TypeReference singleTypeReference,TypeReference> pageTypeReference, String... endPoint) { + protected AbstractConcept(String apiKey, RequestExecutor requestExecutor, TypeReference singleTypeReference, TypeReference> pageTypeReference, String... endPoint) { this.apiKey = apiKey; - this.endpoint = requireNonNull(joinUrl(endPoint),"endPoint cannot be null or empty"); + this.endpoint = requireNonNull(joinUrl(endPoint), "endPoint cannot be null or empty"); this.requestExecutor = requestExecutor; this.singleTypeReference = singleTypeReference; this.pageTypeReference = pageTypeReference; } - + private static String joinUrl(String... elements) { return trimToNull(Stream.of(elements) .map(AbstractConcept::trimToNull) - .map(s->requireNonNull(s,"URL cannot contain null or blank elements: "+Arrays.asList(elements))) + .map(s -> requireNonNull(s, "URL cannot contain null or blank elements: " + Arrays.asList(elements))) .collect(URL_JOINER)); } - + private static String trimToNull(String value) { - return value!=null && !value.trim().isEmpty()?value.trim():null; + return value != null && !value.trim().isEmpty() ? value.trim() : null; } - + @Override public String url(String... elements) { - if(elements==null || elements.length==0) { + if (elements == null || elements.length == 0) { return this.endpoint; } - return joinUrl(this.endpoint,joinUrl(elements)); + return joinUrl(this.endpoint, joinUrl(elements)); } - + @Override public ResponseOrError> requestPage(HttpUriRequest httpRequest) throws IOException { return requestExecutor.execute(apiKey, httpRequest, pageTypeReference); } - + @Override public ResponseOrError requestSingle(HttpUriRequest httpRequest) throws IOException { return requestExecutor.execute(apiKey, httpRequest, singleTypeReference); } - + @Override public ResponseOrError requestVoid(HttpUriRequest httpRequest) throws IOException { return requestExecutor.execute(apiKey, httpRequest, VOID_TYPE_REFERENCE); } - + @Override public HttpEntity buildHttpEntity(Object value) throws UnsupportedCharsetException, JsonProcessingException { return new StringEntity(requestExecutor.serialize(value), ContentType.APPLICATION_JSON); diff --git a/src/main/java/nl/stil4m/mollie/concepts/Concept.java b/src/main/java/nl/stil4m/mollie/concepts/Concept.java index 019b78c..0f6edff 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Concept.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Concept.java @@ -1,24 +1,22 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; -import java.nio.charset.UnsupportedCharsetException; - -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.HttpUriRequest; - import com.fasterxml.jackson.core.JsonProcessingException; - import nl.stil4m.mollie.ResponseOrError; import nl.stil4m.mollie.domain.Page; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.HttpUriRequest; + +import java.io.IOException; +import java.nio.charset.UnsupportedCharsetException; public interface Concept { String url(String... elements); - + ResponseOrError> requestPage(HttpUriRequest get) throws IOException; - + ResponseOrError requestSingle(HttpUriRequest get) throws IOException; - + ResponseOrError requestVoid(HttpUriRequest get) throws IOException; - + HttpEntity buildHttpEntity(Object value) throws UnsupportedCharsetException, JsonProcessingException; } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Create.java b/src/main/java/nl/stil4m/mollie/concepts/Create.java index 269dab6..a574cac 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Create.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Create.java @@ -1,13 +1,12 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; - +import nl.stil4m.mollie.ResponseOrError; import org.apache.http.client.methods.HttpPost; -import nl.stil4m.mollie.ResponseOrError; +import java.io.IOException; + +public interface Create extends Concept { -public interface Create extends Concept { - default ResponseOrError create(O create) throws IOException { HttpPost httpPost = new HttpPost(url()); httpPost.setEntity(buildHttpEntity(create)); diff --git a/src/main/java/nl/stil4m/mollie/concepts/CustomerPayments.java b/src/main/java/nl/stil4m/mollie/concepts/CustomerPayments.java index 481bd24..21ad4ff 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/CustomerPayments.java +++ b/src/main/java/nl/stil4m/mollie/concepts/CustomerPayments.java @@ -4,9 +4,9 @@ import nl.stil4m.mollie.domain.CustomerPayment; import nl.stil4m.mollie.domain.Payment; -public class CustomerPayments extends AbstractConcept implements ListAll,Create { - +public class CustomerPayments extends AbstractConcept implements ListAll, Create { + public CustomerPayments(String apiKey, String endpoint, RequestExecutor requestExecutor, String customerId) { - super(apiKey,requestExecutor,Payments.SINGLE_TYPE,Payments.PAGE_TYPE,endpoint,"customers",customerId,"payments"); + super(apiKey, requestExecutor, Payments.SINGLE_TYPE, Payments.PAGE_TYPE, endpoint, "customers", customerId, "payments"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Customers.java b/src/main/java/nl/stil4m/mollie/concepts/Customers.java index 99d2b96..ff115e0 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Customers.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Customers.java @@ -1,18 +1,19 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.CreateCustomer; import nl.stil4m.mollie.domain.Customer; import nl.stil4m.mollie.domain.Page; import nl.stil4m.mollie.domain.UpdateCustomer; -public class Customers extends AbstractConcept implements ListAll,GetById,Create,Update { - private static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - private static final TypeReference SINGLE_TYPE = new TypeReference() {}; +public class Customers extends AbstractConcept implements ListAll, GetById, Create, Update { + private static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + private static final TypeReference SINGLE_TYPE = new TypeReference() { + }; public Customers(String apiKey, String endpoint, RequestExecutor requestExecutor) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"customers"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "customers"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Delete.java b/src/main/java/nl/stil4m/mollie/concepts/Delete.java index 78f604a..9efb0a5 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Delete.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Delete.java @@ -1,10 +1,9 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; - +import nl.stil4m.mollie.ResponseOrError; import org.apache.http.client.methods.HttpDelete; -import nl.stil4m.mollie.ResponseOrError; +import java.io.IOException; public interface Delete extends Concept { diff --git a/src/main/java/nl/stil4m/mollie/concepts/GetById.java b/src/main/java/nl/stil4m/mollie/concepts/GetById.java index f75e6ed..7e13796 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/GetById.java +++ b/src/main/java/nl/stil4m/mollie/concepts/GetById.java @@ -1,13 +1,12 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; - +import nl.stil4m.mollie.ResponseOrError; import org.apache.http.client.methods.HttpGet; -import nl.stil4m.mollie.ResponseOrError; +import java.io.IOException; public interface GetById extends Concept { - + default ResponseOrError get(String id) throws IOException { HttpGet httpGet = new HttpGet(url(id)); return requestSingle(httpGet); diff --git a/src/main/java/nl/stil4m/mollie/concepts/Issuers.java b/src/main/java/nl/stil4m/mollie/concepts/Issuers.java index 013ca05..c4fa813 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Issuers.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Issuers.java @@ -1,16 +1,17 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.Issuer; import nl.stil4m.mollie.domain.Page; -public class Issuers extends AbstractConcept implements ListAll,GetById { - private static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - private static final TypeReference SINGLE_TYPE = new TypeReference() {}; - +public class Issuers extends AbstractConcept implements ListAll, GetById { + private static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + private static final TypeReference SINGLE_TYPE = new TypeReference() { + }; + public Issuers(String apiKey, String endpoint, RequestExecutor requestExecutor) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"issuers"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "issuers"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/ListAll.java b/src/main/java/nl/stil4m/mollie/concepts/ListAll.java index b74db4c..1ffa140 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/ListAll.java +++ b/src/main/java/nl/stil4m/mollie/concepts/ListAll.java @@ -1,20 +1,19 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Optional; - -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; - import nl.stil4m.mollie.ResponseOrError; import nl.stil4m.mollie.domain.Page; import nl.stil4m.mollie.domain.Payment; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.utils.URIBuilder; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Optional; public interface ListAll extends Concept { - + default ResponseOrError> all(Optional count, Optional offset) throws IOException, URISyntaxException { - return list(count,offset); + return list(count, offset); } default ResponseOrError> list(Optional count, Optional offset) throws IOException, URISyntaxException { @@ -25,7 +24,7 @@ default ResponseOrError> list(Optional count, Optional HttpGet httpGet = new HttpGet(builder.build()); return requestPage(httpGet); } - + default ResponseOrError> next(Page page) throws IOException { if (!page.getLinks().getNext().isPresent()) { throw new IllegalArgumentException("Page does not have next"); diff --git a/src/main/java/nl/stil4m/mollie/concepts/Mandates.java b/src/main/java/nl/stil4m/mollie/concepts/Mandates.java index 0c54df8..df0aa56 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Mandates.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Mandates.java @@ -1,17 +1,18 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.CreateMandate; import nl.stil4m.mollie.domain.Mandate; import nl.stil4m.mollie.domain.Page; -public class Mandates extends AbstractConcept implements ListAll,GetById,Create,Delete { - private static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - private static final TypeReference SINGLE_TYPE = new TypeReference() {}; +public class Mandates extends AbstractConcept implements ListAll, GetById, Create, Delete { + private static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + private static final TypeReference SINGLE_TYPE = new TypeReference() { + }; public Mandates(String apiKey, String endpoint, RequestExecutor requestExecutor, String customerId) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"customers",customerId,"mandates"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "customers", customerId, "mandates"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Methods.java b/src/main/java/nl/stil4m/mollie/concepts/Methods.java index 75315bf..c48a173 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Methods.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Methods.java @@ -1,16 +1,17 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.Method; import nl.stil4m.mollie.domain.Page; -public class Methods extends AbstractConcept implements ListAll,GetById { - private static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - private static final TypeReference SINGLE_TYPE = new TypeReference() {}; - +public class Methods extends AbstractConcept implements ListAll, GetById { + private static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + private static final TypeReference SINGLE_TYPE = new TypeReference() { + }; + public Methods(String apiKey, String endpoint, RequestExecutor requestExecutor) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"methods"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "methods"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Payments.java b/src/main/java/nl/stil4m/mollie/concepts/Payments.java index 73924d1..28cb3c4 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Payments.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Payments.java @@ -1,17 +1,18 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.CreatePayment; import nl.stil4m.mollie.domain.Page; import nl.stil4m.mollie.domain.Payment; -public class Payments extends AbstractConcept implements ListAll,GetById,Create { - protected static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - protected static final TypeReference SINGLE_TYPE = new TypeReference() {}; - +public class Payments extends AbstractConcept implements ListAll, GetById, Create { + protected static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + protected static final TypeReference SINGLE_TYPE = new TypeReference() { + }; + public Payments(String apiKey, String endpoint, RequestExecutor requestExecutor) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"payments"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "payments"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Refunds.java b/src/main/java/nl/stil4m/mollie/concepts/Refunds.java index b04996b..ea18cf6 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Refunds.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Refunds.java @@ -1,17 +1,18 @@ package nl.stil4m.mollie.concepts; import com.fasterxml.jackson.core.type.TypeReference; - import nl.stil4m.mollie.RequestExecutor; import nl.stil4m.mollie.domain.CreateRefund; import nl.stil4m.mollie.domain.Page; import nl.stil4m.mollie.domain.Refund; -public class Refunds extends AbstractConcept implements ListAll,GetById,Create,Delete { - private static final TypeReference> PAGE_TYPE = new TypeReference>() {}; - private static final TypeReference SINGLE_TYPE = new TypeReference() {}; - +public class Refunds extends AbstractConcept implements ListAll, GetById, Create, Delete { + private static final TypeReference> PAGE_TYPE = new TypeReference>() { + }; + private static final TypeReference SINGLE_TYPE = new TypeReference() { + }; + public Refunds(String apiKey, String endpoint, RequestExecutor requestExecutor, String paymentId) { - super(apiKey,requestExecutor,SINGLE_TYPE,PAGE_TYPE,endpoint,"payments",paymentId,"refunds"); + super(apiKey, requestExecutor, SINGLE_TYPE, PAGE_TYPE, endpoint, "payments", paymentId, "refunds"); } } \ No newline at end of file diff --git a/src/main/java/nl/stil4m/mollie/concepts/Update.java b/src/main/java/nl/stil4m/mollie/concepts/Update.java index 0104aa7..84e1362 100644 --- a/src/main/java/nl/stil4m/mollie/concepts/Update.java +++ b/src/main/java/nl/stil4m/mollie/concepts/Update.java @@ -1,13 +1,12 @@ package nl.stil4m.mollie.concepts; -import java.io.IOException; - +import nl.stil4m.mollie.ResponseOrError; import org.apache.http.client.methods.HttpPost; -import nl.stil4m.mollie.ResponseOrError; +import java.io.IOException; + +public interface Update extends Concept { -public interface Update extends Concept { - default ResponseOrError update(String id, O update) throws IOException { HttpPost httpPost = new HttpPost(url(id)); httpPost.setEntity(buildHttpEntity(update)); diff --git a/src/main/java/nl/stil4m/mollie/domain/CreateMandate.java b/src/main/java/nl/stil4m/mollie/domain/CreateMandate.java index 733a7ed..a043f51 100644 --- a/src/main/java/nl/stil4m/mollie/domain/CreateMandate.java +++ b/src/main/java/nl/stil4m/mollie/domain/CreateMandate.java @@ -1,10 +1,9 @@ package nl.stil4m.mollie.domain; -import java.util.Date; -import java.util.Optional; - import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Date; +import java.util.Optional; public class CreateMandate { private final String method; @@ -13,19 +12,19 @@ public class CreateMandate { private final Optional consumerBic; private final Optional signatureDate; private final Optional mandateReference; - - public CreateMandate(@Nonnull String method, - @Nonnull String consumerName, - @Nonnull String consumerAccount) { - this(method,consumerName,consumerAccount,null,null,null); - } - - public CreateMandate(@Nonnull String method, - @Nonnull String consumerName, - @Nonnull String consumerAccount, - @Nullable String consumerBic, - @Nullable Date signatureDate, - @Nullable String mandateReference) { + + public CreateMandate(@Nonnull String method, + @Nonnull String consumerName, + @Nonnull String consumerAccount) { + this(method, consumerName, consumerAccount, null, null, null); + } + + public CreateMandate(@Nonnull String method, + @Nonnull String consumerName, + @Nonnull String consumerAccount, + @Nullable String consumerBic, + @Nullable Date signatureDate, + @Nullable String mandateReference) { super(); this.method = method; this.consumerName = consumerName; diff --git a/src/main/java/nl/stil4m/mollie/domain/CreateRefund.java b/src/main/java/nl/stil4m/mollie/domain/CreateRefund.java index f9cda7b..550af2f 100644 --- a/src/main/java/nl/stil4m/mollie/domain/CreateRefund.java +++ b/src/main/java/nl/stil4m/mollie/domain/CreateRefund.java @@ -1,8 +1,7 @@ package nl.stil4m.mollie.domain; -import java.util.Optional; - import javax.annotation.Nullable; +import java.util.Optional; public class CreateRefund { private final Optional amount; diff --git a/src/main/java/nl/stil4m/mollie/domain/Mandate.java b/src/main/java/nl/stil4m/mollie/domain/Mandate.java index 7b204be..bb204c5 100644 --- a/src/main/java/nl/stil4m/mollie/domain/Mandate.java +++ b/src/main/java/nl/stil4m/mollie/domain/Mandate.java @@ -1,33 +1,33 @@ package nl.stil4m.mollie.domain; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Date; import java.util.Map; import java.util.Optional; -import com.fasterxml.jackson.annotation.JsonProperty; - public class Mandate { private final String resource; private final String id; private final String status; private final String method; private final String customerId; - private final Map details; + private final Map details; private final Optional mandateReference; private final Date createdDatetime; public Mandate(@JsonProperty("resource") String resource, - @JsonProperty("id") String id, - @JsonProperty("status") String status, - @JsonProperty("method") String method, - @JsonProperty("customerId") String customerId, - @JsonProperty("details") Map details, - @JsonProperty("mandateReference") Optional mandateReference, - @JsonProperty("createdDatetime") Date createdDatetime) { + @JsonProperty("id") String id, + @JsonProperty("status") String status, + @JsonProperty("method") String method, + @JsonProperty("customerId") String customerId, + @JsonProperty("details") Map details, + @JsonProperty("mandateReference") Optional mandateReference, + @JsonProperty("createdDatetime") Date createdDatetime) { this.resource = resource; this.id = id; this.status = status; - this.method= method; + this.method = method; this.customerId = customerId; this.details = details; this.mandateReference = mandateReference; diff --git a/src/test/java/nl/stil4m/mollie/concepts/AbstractConceptTest.java b/src/test/java/nl/stil4m/mollie/concepts/AbstractConceptTest.java index d3145ff..0ec178a 100644 --- a/src/test/java/nl/stil4m/mollie/concepts/AbstractConceptTest.java +++ b/src/test/java/nl/stil4m/mollie/concepts/AbstractConceptTest.java @@ -1,63 +1,63 @@ package nl.stil4m.mollie.concepts; -import static org.junit.Assert.*; - import org.junit.Test; +import static org.junit.Assert.assertEquals; + public class AbstractConceptTest { @Test public void testConstructor() { - assertEquals("https://api.mollie.com/v1",new ConceptStub("https://api.mollie.com/v1").url()); - assertEquals("https://api.mollie.com/v1/api",new ConceptStub("https://api.mollie.com/v1","api").url()); + assertEquals("https://api.mollie.com/v1", new ConceptStub("https://api.mollie.com/v1").url()); + assertEquals("https://api.mollie.com/v1/api", new ConceptStub("https://api.mollie.com/v1", "api").url()); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testConstructorNullUrl() { - new ConceptStub((String)null); + new ConceptStub((String) null); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testConstructorNullArrayUrl() { - new ConceptStub((String[])null); + new ConceptStub((String[]) null); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testConstructorEmptyUrl() { new ConceptStub(""); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testConstructorBlankUrl() { new ConceptStub(" "); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testConstructorEmptyArray() { new ConceptStub(new String[]{}); } - + @Test public void testUrl() { - AbstractConcept sut = new ConceptStub("https://api.mollie.com/v1/api","customers"); - assertEquals("https://api.mollie.com/v1/api/customers",sut.url()); - assertEquals("https://api.mollie.com/v1/api/customers/someId",sut.url("someId")); + AbstractConcept sut = new ConceptStub("https://api.mollie.com/v1/api", "customers"); + assertEquals("https://api.mollie.com/v1/api/customers", sut.url()); + assertEquals("https://api.mollie.com/v1/api/customers/someId", sut.url("someId")); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testUrlBlankElement() { new ConceptStub("https://api.mollie.com/v1").url(" "); } - - @Test(expected=NullPointerException.class) + + @Test(expected = NullPointerException.class) public void testUrlNullElement() { - new ConceptStub("https://api.mollie.com/v1").url((String)null); + new ConceptStub("https://api.mollie.com/v1").url((String) null); } - + private class ConceptStub extends AbstractConcept { protected ConceptStub(String... url) { - super(null, null,null,null,url); + super(null, null, null, null, url); } } } \ No newline at end of file diff --git a/src/test/java/nl/stil4m/mollie/concepts/MandatesIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/MandatesIntegrationTest.java index 41a58e1..b7621d2 100644 --- a/src/test/java/nl/stil4m/mollie/concepts/MandatesIntegrationTest.java +++ b/src/test/java/nl/stil4m/mollie/concepts/MandatesIntegrationTest.java @@ -1,10 +1,14 @@ package nl.stil4m.mollie.concepts; -import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT; -import static nl.stil4m.mollie.TestUtil.VALID_API_KEY; -import static nl.stil4m.mollie.TestUtil.strictClientWithApiKey; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import nl.stil4m.mollie.Client; +import nl.stil4m.mollie.ResponseOrError; +import nl.stil4m.mollie.domain.CreateCustomer; +import nl.stil4m.mollie.domain.CreateMandate; +import nl.stil4m.mollie.domain.Customer; +import nl.stil4m.mollie.domain.Mandate; +import nl.stil4m.mollie.domain.Page; +import org.junit.Before; +import org.junit.Test; import java.io.IOException; import java.net.URISyntaxException; @@ -13,16 +17,11 @@ import java.util.Optional; import java.util.UUID; -import org.junit.Before; -import org.junit.Test; - -import nl.stil4m.mollie.Client; -import nl.stil4m.mollie.ResponseOrError; -import nl.stil4m.mollie.domain.CreateCustomer; -import nl.stil4m.mollie.domain.CreateMandate; -import nl.stil4m.mollie.domain.Customer; -import nl.stil4m.mollie.domain.Mandate; -import nl.stil4m.mollie.domain.Page; +import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT; +import static nl.stil4m.mollie.TestUtil.VALID_API_KEY; +import static nl.stil4m.mollie.TestUtil.strictClientWithApiKey; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; public class MandatesIntegrationTest { @@ -32,35 +31,35 @@ public class MandatesIntegrationTest { public void before() throws InterruptedException, IOException { Thread.sleep(TEST_TIMEOUT); Client client = strictClientWithApiKey(VALID_API_KEY); - + String uuid = UUID.randomUUID().toString(); Map defaultMetadata = new HashMap<>(); defaultMetadata.put("foo", "bar"); defaultMetadata.put("id", uuid); - + String name = "Test Customer " + uuid; - Customer customer = client.customers().create(new CreateCustomer(name, uuid+"@foobar.com", Optional.empty(), defaultMetadata)).getData(); - + Customer customer = client.customers().create(new CreateCustomer(name, uuid + "@foobar.com", Optional.empty(), defaultMetadata)).getData(); + mandates = client.mandates(customer.getId()); } @Test public void testList() throws IOException, URISyntaxException { ResponseOrError> list = mandates.list(Optional.empty(), Optional.empty()); - + assertThat(list.getSuccess(), is(true)); } @Test public void testCreate() throws IOException, URISyntaxException { - // https://www.mollie.com/nl/docs/reference/mandates/create - String method = "directdebit"; - String name = "Test geit"; - String account = "NL91ABNA0417164300"; - CreateMandate createMandate = new CreateMandate(method, name, account); - + // https://www.mollie.com/nl/docs/reference/mandates/create + String method = "directdebit"; + String name = "Test geit"; + String account = "NL91ABNA0417164300"; + CreateMandate createMandate = new CreateMandate(method, name, account); + ResponseOrError result = mandates.create(createMandate); - + // Mandates need to be enabled with your Mollie account (identifier with API key) in order to test this assertThat(result.getSuccess(), is(false)); //assertThat(result.getData().getId(),notNullValue()); diff --git a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java index 92f231b..8082f10 100644 --- a/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java +++ b/src/test/java/nl/stil4m/mollie/concepts/PaymentsIntegrationTest.java @@ -68,7 +68,8 @@ public void testGetPayment() throws IOException, InterruptedException { public void testGetPaymentWithRefunds() throws IOException, InterruptedException { ResponseOrError getResponse = payments.get("tr_3AdTKpQGii"); - getResponse.get(payment -> assertThat(payment.getLinks().getRefunds().isPresent(), is(true)), errorData -> {}); + getResponse.get(payment -> assertThat(payment.getLinks().getRefunds().isPresent(), is(true)), errorData -> { + }); } diff --git a/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java index 80506be..23145db 100644 --- a/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java +++ b/src/test/java/nl/stil4m/mollie/concepts/RefundsIntegrationTest.java @@ -1,28 +1,27 @@ package nl.stil4m.mollie.concepts; -import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT; -import static nl.stil4m.mollie.TestUtil.VALID_API_KEY; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; - import nl.stil4m.mollie.Client; import nl.stil4m.mollie.ClientBuilder; import nl.stil4m.mollie.ResponseOrError; import nl.stil4m.mollie.domain.CreatePayment; import nl.stil4m.mollie.domain.CreateRefund; -import nl.stil4m.mollie.domain.Payment; import nl.stil4m.mollie.domain.Page; +import nl.stil4m.mollie.domain.Payment; import nl.stil4m.mollie.domain.Refund; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static nl.stil4m.mollie.TestUtil.TEST_TIMEOUT; +import static nl.stil4m.mollie.TestUtil.VALID_API_KEY; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; public class RefundsIntegrationTest { @@ -41,9 +40,9 @@ public void testGetRefunds() throws IOException, URISyntaxException, Interrupted ResponseOrError payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)); String id = payment.getData().getId(); Refunds refunds = client.refunds(id); - + ResponseOrError> all = refunds.all(Optional.empty(), Optional.empty()); - + assertThat(all.getSuccess(), is(true)); Page refundPage = all.getData(); assertThat(refundPage.getCount(), is(0)); @@ -55,7 +54,7 @@ public void testGetRefunds() throws IOException, URISyntaxException, Interrupted public void testListRefundsForExistingPayment() throws IOException, URISyntaxException, InterruptedException { Payment payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)).getData(); Refunds refunds = client.refunds(payment.getId()); - + ResponseOrError> all = refunds.all(Optional.empty(), Optional.empty()); assertThat(all.getSuccess(), is(true)); @@ -72,9 +71,9 @@ public void testCancelNonExistingRefund() throws IOException { ResponseOrError payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)); assertThat(payment.getSuccess(), is(true)); Refunds refunds = client.refunds(payment.getData().getId()); - + ResponseOrError cancel = refunds.delete("foo_bar"); - + assertThat(cancel.getSuccess(), is(false)); assertThat(cancel.getError().get("error"), is(errorData)); } @@ -88,7 +87,7 @@ public void testGetNonExistingRefund() throws IOException { Refunds refunds = client.refunds(payment.getData().getId()); ResponseOrError get = refunds.get("foo_bar"); - + assertThat(get.getSuccess(), is(false)); assertThat(get.getError().get("error"), is(errorData)); } @@ -100,10 +99,10 @@ public void testCreateRefund() throws IOException, URISyntaxException { errorData.put("message", "The payment is already refunded or has not been paid for yet"); ResponseOrError payment = payments.create(new CreatePayment(Optional.empty(), 1.00, "Some description", "http://example.com", Optional.empty(), null)); Refunds refunds = client.refunds(payment.getData().getId()); - + CreateRefund createRefund = new CreateRefund(1.00); ResponseOrError create = refunds.create(createRefund); - + assertThat(create.getSuccess(), is(false)); assertThat(create.getError().get("error"), is(errorData)); }