diff --git a/src/main/java/com/gocardless/GoCardlessClient.java b/src/main/java/com/gocardless/GoCardlessClient.java index 4d87f53f..ceb32ea1 100644 --- a/src/main/java/com/gocardless/GoCardlessClient.java +++ b/src/main/java/com/gocardless/GoCardlessClient.java @@ -32,6 +32,7 @@ public class GoCardlessClient { private final CustomerNotificationService customerNotifications; private final EventService events; private final ExportService exports; + private final FundsAvailabilityService fundsAvailabilities; private final InstalmentScheduleService instalmentSchedules; private final InstitutionService institutions; private final LogoService logos; @@ -196,6 +197,7 @@ private GoCardlessClient(HttpClient httpClient) { this.customerNotifications = new CustomerNotificationService(httpClient); this.events = new EventService(httpClient); this.exports = new ExportService(httpClient); + this.fundsAvailabilities = new FundsAvailabilityService(httpClient); this.instalmentSchedules = new InstalmentScheduleService(httpClient); this.institutions = new InstitutionService(httpClient); this.logos = new LogoService(httpClient); @@ -349,6 +351,13 @@ public ExportService exports() { return exports; } + /** + * A service class for working with funds availability resources. + */ + public FundsAvailabilityService fundsAvailabilities() { + return fundsAvailabilities; + } + /** * A service class for working with instalment schedule resources. */ diff --git a/src/main/java/com/gocardless/resources/BillingRequestFlow.java b/src/main/java/com/gocardless/resources/BillingRequestFlow.java index 05df7caf..63e01714 100644 --- a/src/main/java/com/gocardless/resources/BillingRequestFlow.java +++ b/src/main/java/com/gocardless/resources/BillingRequestFlow.java @@ -63,7 +63,9 @@ public Boolean getCustomerDetailsCaptured() { } /** - * URL that the payer can be taken to if there isn't a way to progress ahead in flow. + * URL that the payer can be taken to if there isn't a way to progress ahead in flow, for + * example if the customer searches for a bank that doesn't exist or isn't supported on the + * scheme. */ public String getExitUri() { return exitUri; diff --git a/src/main/java/com/gocardless/resources/FundsAvailability.java b/src/main/java/com/gocardless/resources/FundsAvailability.java new file mode 100644 index 00000000..d3023011 --- /dev/null +++ b/src/main/java/com/gocardless/resources/FundsAvailability.java @@ -0,0 +1,22 @@ +package com.gocardless.resources; + +/** + * Represents a funds availability resource returned from the API. + * + * Checks if the payer's current balance is sufficient to cover the amount the merchant wants to + * charge within the consent parameters defined on the mandate. + */ +public class FundsAvailability { + private FundsAvailability() { + // blank to prevent instantiation + } + + private Boolean available; + + /** + * Indicates if the amount is available + */ + public Boolean getAvailable() { + return available; + } +} diff --git a/src/main/java/com/gocardless/services/BillingRequestFlowService.java b/src/main/java/com/gocardless/services/BillingRequestFlowService.java index 4eeddcec..92ecd394 100644 --- a/src/main/java/com/gocardless/services/BillingRequestFlowService.java +++ b/src/main/java/com/gocardless/services/BillingRequestFlowService.java @@ -80,7 +80,9 @@ public BillingRequestFlowCreateRequest withCustomerDetailsCaptured( } /** - * URL that the payer can be taken to if there isn't a way to progress ahead in flow. + * URL that the payer can be taken to if there isn't a way to progress ahead in flow, for + * example if the customer searches for a bank that doesn't exist or isn't supported on the + * scheme. */ public BillingRequestFlowCreateRequest withExitUri(String exitUri) { this.exitUri = exitUri; diff --git a/src/main/java/com/gocardless/services/FundsAvailabilityService.java b/src/main/java/com/gocardless/services/FundsAvailabilityService.java new file mode 100644 index 00000000..7aaa29e1 --- /dev/null +++ b/src/main/java/com/gocardless/services/FundsAvailabilityService.java @@ -0,0 +1,95 @@ +package com.gocardless.services; + +import com.gocardless.http.*; +import com.gocardless.resources.FundsAvailability; +import com.google.common.collect.ImmutableMap; +import java.util.Map; + +/** + * Service class for working with funds availability resources. + * + * Checks if the payer's current balance is sufficient to cover the amount the merchant wants to + * charge within the consent parameters defined on the mandate. + */ +public class FundsAvailabilityService { + private final HttpClient httpClient; + + /** + * Constructor. Users of this library should have no need to call this - an instance of this + * class can be obtained by calling + * {@link com.gocardless.GoCardlessClient#fundsAvailabilities() }. + */ + public FundsAvailabilityService(HttpClient httpClient) { + this.httpClient = httpClient; + } + + /** + * Checks if the payer's current balance is sufficient to cover the amount the merchant wants to + * charge within the consent parameters defined on the mandate. + */ + public FundsAvailabilityCheckRequest check(String identity) { + return new FundsAvailabilityCheckRequest(httpClient, identity); + } + + /** + * Request class for {@link FundsAvailabilityService#check }. + * + * Checks if the payer's current balance is sufficient to cover the amount the merchant wants to + * charge within the consent parameters defined on the mandate. + */ + public static final class FundsAvailabilityCheckRequest extends GetRequest { + @PathParam + private final String identity; + private String amount; + + /** + * The amount of the payment + */ + public FundsAvailabilityCheckRequest withAmount(String amount) { + this.amount = amount; + return this; + } + + private FundsAvailabilityCheckRequest(HttpClient httpClient, String identity) { + super(httpClient); + this.identity = identity; + } + + public FundsAvailabilityCheckRequest withHeader(String headerName, String headerValue) { + this.addHeader(headerName, headerValue); + return this; + } + + @Override + protected Map getPathParams() { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("identity", identity); + return params.build(); + } + + @Override + protected Map getQueryParams() { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.putAll(super.getQueryParams()); + if (amount != null) { + params.put("amount", amount); + } + return params.build(); + } + + @Override + protected String getPathTemplate() { + return "funds_availability/:identity"; + } + + @Override + protected String getEnvelope() { + return "funds_availability"; + } + + @Override + protected Class getResponseClass() { + return FundsAvailability.class; + } + } +}