From f5d218f1d4be134929222c3e2ff5623dd5b4f237 Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Tue, 10 Jan 2023 18:08:22 +0545 Subject: [PATCH 1/8] CS-1982: Added ACH pull --- src/main/java/co/dapi/ACH.java | 104 ++++++++++++++++++ src/main/java/co/dapi/DapiApp.java | 22 +++- .../co/dapi/response/CreatePullResponse.java | 11 ++ 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/dapi/ACH.java create mode 100644 src/main/java/co/dapi/response/CreatePullResponse.java diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java new file mode 100644 index 0000000..95b62fe --- /dev/null +++ b/src/main/java/co/dapi/ACH.java @@ -0,0 +1,104 @@ +package co.dapi; + +import co.dapi.response.CreatePullResponse; +import co.dapi.types.UserInput; +import com.google.gson.JsonSyntaxException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Optional; + + +public class ACH { + private final Config config; + + public ACH(Config config) { + this.config = config; + } + + public CreatePullResponse createPull(CreatePull transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + + // Create the request body of this call + CreatePullRequest bodyObj = new CreatePullRequest(transfer, this.config.getAppSecret(), userSecret, + operationID, userInputs); + + // Convert the request body to a JSON string + String bodyJson = DapiRequest.jsonAgent.toJson(bodyObj, CreatePullRequest.class); + + // Construct the headers needed for this request + HashMap headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + accessToken); + + // Make the request and get the response + String respJson = DapiRequest.Do(bodyJson, DapiRequest.Dapi_URL + "/v2" + bodyObj.action, headers); + + + // Convert the got response to the wanted response type + CreatePullResponse resp = null; + try { + resp = DapiRequest.jsonAgent.fromJson(respJson, CreatePullResponse.class); + } catch (JsonSyntaxException e) { + // Empty catch, cause the handling code is below + } + + // Check if the got response was of unexpected format, and return a suitable response + if (resp == null || (resp.getStatus() == null && !resp.getType().isPresent())) { + // If the got response wasn't a JSON string, resp will be null, and if + // it didn't have the 'status' field, getStatus() will return null. + return new CreatePullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + } + + return resp; + } + + + public static class CreatePull { + private final String senderID; + private final float amount; + private final String description; + + /** + * Create an object that holds the info for an ACH create pull + * + * @param senderID the id of the account which the money should be pulled from. + * retrieved from one of the accounts array returned from the getAccounts method. + * @param amount the amount of money which should be pulled. + * @param description description for the ACH pull. + */ + public CreatePull(String senderID, float amount, String description) { + this.senderID = senderID; + this.amount = amount; + this.description = description; + } + + public String getSenderID() { + return senderID; + } + + public float getAmount() { + return amount; + } + + public Optional getDescription() { + return Optional.ofNullable(description); + } + } + + private static class CreatePullRequest extends DapiRequest.BaseRequest { + private final String action = "/ach/pull/create"; + private final String senderID; + private final float amount; + private final String description; + + public CreatePullRequest(CreatePull transfer, + String appSecret, + String userSecret, + String operationID, + UserInput[] userInputs) { + super(appSecret, userSecret, operationID, userInputs); + this.senderID = transfer.senderID; + this.amount = transfer.amount; + this.description = transfer.description; + } + } + +} diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index eb8880e..a9c4698 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -4,12 +4,12 @@ import co.dapi.types.UserInput; import com.google.gson.JsonSyntaxException; import okhttp3.Response; - import java.io.IOException; import java.time.LocalDate; import java.util.HashMap; + /** * {@link DapiApp} represents a client app that's using one or more of the Dapi products. */ @@ -19,6 +19,7 @@ public class DapiApp { private final Auth a; private final Data d; private final Payment p; + private final ACH ach; private final Metadata m; public DapiApp(Config config) { @@ -27,6 +28,7 @@ public DapiApp(Config config) { this.d = new Data(config); this.p = new Payment(config); this.m = new Metadata(config); + this.ach = new ACH(config); } /** @@ -297,6 +299,24 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin return this.m.getAccountsMetadata(accessToken, userSecret, operationID, userInputs); } + + /** + * createPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * to continue a previous operation that required to provide some userInputs. + * + * @param transfer the transfer details that we want to initiate. + * @param accessToken retrieved from the ExchangeToken process. + * @param userSecret retrieved from the user login. + * @param operationID retrieved from the previous call's response. + * @param userInputs built from the previous call's response, and the required user input. + * @return an {@link CreateTransferResponse}. + * @throws IOException in case of trouble happened while executing the request or reading the response. + */ + public CreatePullResponse createPull(ACH.CreatePull transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); + } + + /** * handleSDKRequest injects this {@link DapiApp}'s appSecret in the provided request body, bodyJson, and then * forwards the request to Dapi, with the passed headers, headersMap, and returns the RAW response got. diff --git a/src/main/java/co/dapi/response/CreatePullResponse.java b/src/main/java/co/dapi/response/CreatePullResponse.java new file mode 100644 index 0000000..e4a212e --- /dev/null +++ b/src/main/java/co/dapi/response/CreatePullResponse.java @@ -0,0 +1,11 @@ +package co.dapi.response; + +public class CreatePullResponse extends BaseResponse { + CreatePullResponse() { + super(); + } + + public CreatePullResponse(String errType, String errMsg) { + super(errType, errMsg); + } +} From a07c51eaa3b526583f181c54a21d00c385021f1f Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Wed, 25 Jan 2023 13:57:22 +0545 Subject: [PATCH 2/8] CS-1982: Fixed create pull request class --- src/main/java/co/dapi/ACH.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java index 95b62fe..aa26b38 100644 --- a/src/main/java/co/dapi/ACH.java +++ b/src/main/java/co/dapi/ACH.java @@ -85,9 +85,8 @@ public Optional getDescription() { private static class CreatePullRequest extends DapiRequest.BaseRequest { private final String action = "/ach/pull/create"; - private final String senderID; - private final float amount; - private final String description; + + private final CreatePull transfer; public CreatePullRequest(CreatePull transfer, String appSecret, @@ -95,9 +94,7 @@ public CreatePullRequest(CreatePull transfer, String operationID, UserInput[] userInputs) { super(appSecret, userSecret, operationID, userInputs); - this.senderID = transfer.senderID; - this.amount = transfer.amount; - this.description = transfer.description; + this.transfer = transfer; } } From c69f6304718b3c805a565a5601f16bf7c216c898 Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Wed, 25 Jan 2023 18:08:31 +0545 Subject: [PATCH 3/8] CS-2170: Added ACH getPull --- src/main/java/co/dapi/ACH.java | 45 +++++++++++++++++++ src/main/java/co/dapi/DapiApp.java | 18 +++++++- .../co/dapi/response/GetPullResponse.java | 21 +++++++++ src/main/java/co/dapi/types/PullTransfer.java | 26 +++++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/dapi/response/GetPullResponse.java create mode 100644 src/main/java/co/dapi/types/PullTransfer.java diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java index aa26b38..14b8672 100644 --- a/src/main/java/co/dapi/ACH.java +++ b/src/main/java/co/dapi/ACH.java @@ -1,6 +1,7 @@ package co.dapi; import co.dapi.response.CreatePullResponse; +import co.dapi.response.GetPullResponse; import co.dapi.types.UserInput; import com.google.gson.JsonSyntaxException; import java.io.IOException; @@ -50,6 +51,38 @@ public CreatePullResponse createPull(CreatePull transfer, String accessToken, St return resp; } + public GetPullResponse getPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + + // Create the request body of this call + GetPullRequest bodyObj = new GetPullRequest(this.config.getAppSecret(), userSecret, operationID, userInputs); + + // Convert the request body to a JSON string + String bodyJson = DapiRequest.jsonAgent.toJson(bodyObj, GetPullRequest.class); + + // Construct the headers needed for this request + HashMap headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + accessToken); + + // Make the request and get the response + String respJson = DapiRequest.Do(bodyJson, DapiRequest.Dapi_URL + "/v2" + bodyObj.action, headers); + + // Convert the got response to the wanted response type + GetPullResponse resp = null; + try { + resp = DapiRequest.jsonAgent.fromJson(respJson, GetPullResponse.class); + } catch (JsonSyntaxException e) { + // Empty catch, cause the handling code is below + } + + // Check if the got response was of unexpected format, and return a suitable response + if (resp == null || (resp.getStatus() == null && !resp.getType().isPresent())) { + // If the got response wasn't a JSON string, resp will be null, and if + // it didn't have the 'status' field, getStatus() will return null. + return new GetPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + } + + return resp; + } public static class CreatePull { private final String senderID; @@ -98,4 +131,16 @@ public CreatePullRequest(CreatePull transfer, } } + + private static class GetPullRequest extends DapiRequest.BaseRequest{ + private final String action = "/ach/pull/get"; + + public GetPullRequest(String appSecret, + String userSecret, + String operationID, + UserInput[] userInputs) { + super(appSecret, userSecret, operationID, userInputs); + } + } + } diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index a9c4698..70de38f 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -309,7 +309,7 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin * @param userSecret retrieved from the user login. * @param operationID retrieved from the previous call's response. * @param userInputs built from the previous call's response, and the required user input. - * @return an {@link CreateTransferResponse}. + * @return an {@link CreatePullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ public CreatePullResponse createPull(ACH.CreatePull transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { @@ -317,6 +317,22 @@ public CreatePullResponse createPull(ACH.CreatePull transfer, String accessToken } + /** + * getPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * to continue a previous operation that required to provide some userInputs. + * + * @param accessToken retrieved from the ExchangeToken process. + * @param userSecret retrieved from the user login. + * @param operationID OperationID of the createPull request + * @param userInputs built from the previous call's response, and the required user input. + * @return an {@link GetPullResponse}. + * @throws IOException in case of trouble happened while executing the request or reading the response. + */ + public GetPullResponse getPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + return this.ach.getPull(accessToken, userSecret, operationID, userInputs); + } + + /** * handleSDKRequest injects this {@link DapiApp}'s appSecret in the provided request body, bodyJson, and then * forwards the request to Dapi, with the passed headers, headersMap, and returns the RAW response got. diff --git a/src/main/java/co/dapi/response/GetPullResponse.java b/src/main/java/co/dapi/response/GetPullResponse.java new file mode 100644 index 0000000..74798ab --- /dev/null +++ b/src/main/java/co/dapi/response/GetPullResponse.java @@ -0,0 +1,21 @@ +package co.dapi.response; + +import co.dapi.types.PullTransfer; + +import java.util.Optional; + +public class GetPullResponse extends BaseResponse { + GetPullResponse() { + super(); + } + + private PullTransfer transfer; + + public GetPullResponse(String errType, String errMsg) { + super(errType, errMsg); + } + + public Optional getTransfer() { + return Optional.ofNullable(transfer); + } +} diff --git a/src/main/java/co/dapi/types/PullTransfer.java b/src/main/java/co/dapi/types/PullTransfer.java new file mode 100644 index 0000000..76c4104 --- /dev/null +++ b/src/main/java/co/dapi/types/PullTransfer.java @@ -0,0 +1,26 @@ +package co.dapi.types; + +public class PullTransfer { + private final Float amount; + private final String status; + private final Currency currency; + + public PullTransfer(Float amount, String status, Currency currency) { + this.amount = amount; + this.status = status; + this.currency = currency; + } + + public Float getAmount() { + return amount; + } + + public String getStatus() { + return status; + } + + public Currency getCurrency() { + return currency; + } + +} From d34e467ee490e4794fc780416e1e1bdfba86e2a6 Mon Sep 17 00:00:00 2001 From: Ahmad Sameh <8120013+asmsh@users.noreply.github.com> Date: Fri, 10 Feb 2023 13:00:54 +0400 Subject: [PATCH 4/8] CS-2170: formatting --- src/main/java/co/dapi/ACH.java | 19 +++++++++---------- src/main/java/co/dapi/DapiApp.java | 5 +---- .../co/dapi/response/GetPullResponse.java | 4 ++-- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java index 14b8672..304677a 100644 --- a/src/main/java/co/dapi/ACH.java +++ b/src/main/java/co/dapi/ACH.java @@ -4,6 +4,7 @@ import co.dapi.response.GetPullResponse; import co.dapi.types.UserInput; import com.google.gson.JsonSyntaxException; + import java.io.IOException; import java.util.HashMap; import java.util.Optional; @@ -122,25 +123,23 @@ private static class CreatePullRequest extends DapiRequest.BaseRequest { private final CreatePull transfer; public CreatePullRequest(CreatePull transfer, - String appSecret, - String userSecret, - String operationID, - UserInput[] userInputs) { + String appSecret, + String userSecret, + String operationID, + UserInput[] userInputs) { super(appSecret, userSecret, operationID, userInputs); this.transfer = transfer; } } - - private static class GetPullRequest extends DapiRequest.BaseRequest{ + private static class GetPullRequest extends DapiRequest.BaseRequest { private final String action = "/ach/pull/get"; public GetPullRequest(String appSecret, - String userSecret, - String operationID, - UserInput[] userInputs) { + String userSecret, + String operationID, + UserInput[] userInputs) { super(appSecret, userSecret, operationID, userInputs); } } - } diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index 70de38f..01d0220 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -4,12 +4,12 @@ import co.dapi.types.UserInput; import com.google.gson.JsonSyntaxException; import okhttp3.Response; + import java.io.IOException; import java.time.LocalDate; import java.util.HashMap; - /** * {@link DapiApp} represents a client app that's using one or more of the Dapi products. */ @@ -299,7 +299,6 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin return this.m.getAccountsMetadata(accessToken, userSecret, operationID, userInputs); } - /** * createPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs. @@ -316,7 +315,6 @@ public CreatePullResponse createPull(ACH.CreatePull transfer, String accessToken return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); } - /** * getPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs. @@ -332,7 +330,6 @@ public GetPullResponse getPull(String accessToken, String userSecret, String ope return this.ach.getPull(accessToken, userSecret, operationID, userInputs); } - /** * handleSDKRequest injects this {@link DapiApp}'s appSecret in the provided request body, bodyJson, and then * forwards the request to Dapi, with the passed headers, headersMap, and returns the RAW response got. diff --git a/src/main/java/co/dapi/response/GetPullResponse.java b/src/main/java/co/dapi/response/GetPullResponse.java index 74798ab..4c7d632 100644 --- a/src/main/java/co/dapi/response/GetPullResponse.java +++ b/src/main/java/co/dapi/response/GetPullResponse.java @@ -5,12 +5,12 @@ import java.util.Optional; public class GetPullResponse extends BaseResponse { + private PullTransfer transfer; + GetPullResponse() { super(); } - private PullTransfer transfer; - public GetPullResponse(String errType, String errMsg) { super(errType, errMsg); } From b38f593f0bf4ea3315554b5cffa42bca0603dfb6 Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Sat, 11 Feb 2023 17:12:53 +0545 Subject: [PATCH 5/8] CS-2170: Renamed class to pullTransfer --- src/main/java/co/dapi/ACH.java | 10 +++++----- src/main/java/co/dapi/DapiApp.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java index 304677a..d4cc65c 100644 --- a/src/main/java/co/dapi/ACH.java +++ b/src/main/java/co/dapi/ACH.java @@ -17,7 +17,7 @@ public ACH(Config config) { this.config = config; } - public CreatePullResponse createPull(CreatePull transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public CreatePullResponse createPull(PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { // Create the request body of this call CreatePullRequest bodyObj = new CreatePullRequest(transfer, this.config.getAppSecret(), userSecret, @@ -85,7 +85,7 @@ public GetPullResponse getPull(String accessToken, String userSecret, String ope return resp; } - public static class CreatePull { + public static class PullTransfer { private final String senderID; private final float amount; private final String description; @@ -98,7 +98,7 @@ public static class CreatePull { * @param amount the amount of money which should be pulled. * @param description description for the ACH pull. */ - public CreatePull(String senderID, float amount, String description) { + public PullTransfer(String senderID, float amount, String description) { this.senderID = senderID; this.amount = amount; this.description = description; @@ -120,9 +120,9 @@ public Optional getDescription() { private static class CreatePullRequest extends DapiRequest.BaseRequest { private final String action = "/ach/pull/create"; - private final CreatePull transfer; + private final PullTransfer transfer; - public CreatePullRequest(CreatePull transfer, + public CreatePullRequest(PullTransfer transfer, String appSecret, String userSecret, String operationID, diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index 01d0220..6451ffe 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -311,7 +311,7 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin * @return an {@link CreatePullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ - public CreatePullResponse createPull(ACH.CreatePull transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public CreatePullResponse createPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); } From b06d400dd7b832a87c000dc14cc3cc5990b1da32 Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Sat, 11 Feb 2023 17:18:04 +0545 Subject: [PATCH 6/8] CS-2170: Renamed ACH method names in DapiApp --- src/main/java/co/dapi/DapiApp.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index 6451ffe..4a13072 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -300,7 +300,7 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin } /** - * createPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * createACHPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs. * * @param transfer the transfer details that we want to initiate. @@ -311,22 +311,22 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin * @return an {@link CreatePullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ - public CreatePullResponse createPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public CreatePullResponse createACHPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); } /** - * getPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * getACHPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs. * * @param accessToken retrieved from the ExchangeToken process. * @param userSecret retrieved from the user login. - * @param operationID OperationID of the createPull request + * @param operationID OperationID of the createACHPull request * @param userInputs built from the previous call's response, and the required user input. * @return an {@link GetPullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ - public GetPullResponse getPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public GetPullResponse getACHPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.getPull(accessToken, userSecret, operationID, userInputs); } From e37786836f685247d73f9919beb62e0f8428bd02 Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Sat, 11 Feb 2023 18:00:16 +0545 Subject: [PATCH 7/8] CS-2170: Renamed response and types --- src/main/java/co/dapi/ACH.java | 20 +++++++++--------- src/main/java/co/dapi/DapiApp.java | 8 +++---- .../dapi/response/CreateACHPullResponse.java | 11 ++++++++++ .../co/dapi/response/CreatePullResponse.java | 11 ---------- .../co/dapi/response/GetACHPullResponse.java | 21 +++++++++++++++++++ .../co/dapi/response/GetPullResponse.java | 21 ------------------- ...Transfer.java => ACHPullTransferInfo.java} | 4 ++-- 7 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 src/main/java/co/dapi/response/CreateACHPullResponse.java delete mode 100644 src/main/java/co/dapi/response/CreatePullResponse.java create mode 100644 src/main/java/co/dapi/response/GetACHPullResponse.java delete mode 100644 src/main/java/co/dapi/response/GetPullResponse.java rename src/main/java/co/dapi/types/{PullTransfer.java => ACHPullTransferInfo.java} (78%) diff --git a/src/main/java/co/dapi/ACH.java b/src/main/java/co/dapi/ACH.java index d4cc65c..98ae917 100644 --- a/src/main/java/co/dapi/ACH.java +++ b/src/main/java/co/dapi/ACH.java @@ -1,7 +1,7 @@ package co.dapi; -import co.dapi.response.CreatePullResponse; -import co.dapi.response.GetPullResponse; +import co.dapi.response.CreateACHPullResponse; +import co.dapi.response.GetACHPullResponse; import co.dapi.types.UserInput; import com.google.gson.JsonSyntaxException; @@ -17,7 +17,7 @@ public ACH(Config config) { this.config = config; } - public CreatePullResponse createPull(PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public CreateACHPullResponse createPull(PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { // Create the request body of this call CreatePullRequest bodyObj = new CreatePullRequest(transfer, this.config.getAppSecret(), userSecret, @@ -35,9 +35,9 @@ public CreatePullResponse createPull(PullTransfer transfer, String accessToken, // Convert the got response to the wanted response type - CreatePullResponse resp = null; + CreateACHPullResponse resp = null; try { - resp = DapiRequest.jsonAgent.fromJson(respJson, CreatePullResponse.class); + resp = DapiRequest.jsonAgent.fromJson(respJson, CreateACHPullResponse.class); } catch (JsonSyntaxException e) { // Empty catch, cause the handling code is below } @@ -46,13 +46,13 @@ public CreatePullResponse createPull(PullTransfer transfer, String accessToken, if (resp == null || (resp.getStatus() == null && !resp.getType().isPresent())) { // If the got response wasn't a JSON string, resp will be null, and if // it didn't have the 'status' field, getStatus() will return null. - return new CreatePullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + return new CreateACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); } return resp; } - public GetPullResponse getPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public GetACHPullResponse getPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { // Create the request body of this call GetPullRequest bodyObj = new GetPullRequest(this.config.getAppSecret(), userSecret, operationID, userInputs); @@ -68,9 +68,9 @@ public GetPullResponse getPull(String accessToken, String userSecret, String ope String respJson = DapiRequest.Do(bodyJson, DapiRequest.Dapi_URL + "/v2" + bodyObj.action, headers); // Convert the got response to the wanted response type - GetPullResponse resp = null; + GetACHPullResponse resp = null; try { - resp = DapiRequest.jsonAgent.fromJson(respJson, GetPullResponse.class); + resp = DapiRequest.jsonAgent.fromJson(respJson, GetACHPullResponse.class); } catch (JsonSyntaxException e) { // Empty catch, cause the handling code is below } @@ -79,7 +79,7 @@ public GetPullResponse getPull(String accessToken, String userSecret, String ope if (resp == null || (resp.getStatus() == null && !resp.getType().isPresent())) { // If the got response wasn't a JSON string, resp will be null, and if // it didn't have the 'status' field, getStatus() will return null. - return new GetPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + return new GetACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); } return resp; diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index 4a13072..b592174 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -308,10 +308,10 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin * @param userSecret retrieved from the user login. * @param operationID retrieved from the previous call's response. * @param userInputs built from the previous call's response, and the required user input. - * @return an {@link CreatePullResponse}. + * @return an {@link CreateACHPullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ - public CreatePullResponse createACHPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public CreateACHPullResponse createACHPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); } @@ -323,10 +323,10 @@ public CreatePullResponse createACHPull(ACH.PullTransfer transfer, String access * @param userSecret retrieved from the user login. * @param operationID OperationID of the createACHPull request * @param userInputs built from the previous call's response, and the required user input. - * @return an {@link GetPullResponse}. + * @return an {@link GetACHPullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ - public GetPullResponse getACHPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { + public GetACHPullResponse getACHPull(String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.getPull(accessToken, userSecret, operationID, userInputs); } diff --git a/src/main/java/co/dapi/response/CreateACHPullResponse.java b/src/main/java/co/dapi/response/CreateACHPullResponse.java new file mode 100644 index 0000000..00bbd9b --- /dev/null +++ b/src/main/java/co/dapi/response/CreateACHPullResponse.java @@ -0,0 +1,11 @@ +package co.dapi.response; + +public class CreateACHPullResponse extends BaseResponse { + CreateACHPullResponse() { + super(); + } + + public CreateACHPullResponse(String errType, String errMsg) { + super(errType, errMsg); + } +} diff --git a/src/main/java/co/dapi/response/CreatePullResponse.java b/src/main/java/co/dapi/response/CreatePullResponse.java deleted file mode 100644 index e4a212e..0000000 --- a/src/main/java/co/dapi/response/CreatePullResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.dapi.response; - -public class CreatePullResponse extends BaseResponse { - CreatePullResponse() { - super(); - } - - public CreatePullResponse(String errType, String errMsg) { - super(errType, errMsg); - } -} diff --git a/src/main/java/co/dapi/response/GetACHPullResponse.java b/src/main/java/co/dapi/response/GetACHPullResponse.java new file mode 100644 index 0000000..135d576 --- /dev/null +++ b/src/main/java/co/dapi/response/GetACHPullResponse.java @@ -0,0 +1,21 @@ +package co.dapi.response; + +import co.dapi.types.ACHPullTransferInfo; + +import java.util.Optional; + +public class GetACHPullResponse extends BaseResponse { + private ACHPullTransferInfo transfer; + + GetACHPullResponse() { + super(); + } + + public GetACHPullResponse(String errType, String errMsg) { + super(errType, errMsg); + } + + public Optional getTransfer() { + return Optional.ofNullable(transfer); + } +} diff --git a/src/main/java/co/dapi/response/GetPullResponse.java b/src/main/java/co/dapi/response/GetPullResponse.java deleted file mode 100644 index 4c7d632..0000000 --- a/src/main/java/co/dapi/response/GetPullResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -package co.dapi.response; - -import co.dapi.types.PullTransfer; - -import java.util.Optional; - -public class GetPullResponse extends BaseResponse { - private PullTransfer transfer; - - GetPullResponse() { - super(); - } - - public GetPullResponse(String errType, String errMsg) { - super(errType, errMsg); - } - - public Optional getTransfer() { - return Optional.ofNullable(transfer); - } -} diff --git a/src/main/java/co/dapi/types/PullTransfer.java b/src/main/java/co/dapi/types/ACHPullTransferInfo.java similarity index 78% rename from src/main/java/co/dapi/types/PullTransfer.java rename to src/main/java/co/dapi/types/ACHPullTransferInfo.java index 76c4104..b5006d1 100644 --- a/src/main/java/co/dapi/types/PullTransfer.java +++ b/src/main/java/co/dapi/types/ACHPullTransferInfo.java @@ -1,11 +1,11 @@ package co.dapi.types; -public class PullTransfer { +public class ACHPullTransferInfo { private final Float amount; private final String status; private final Currency currency; - public PullTransfer(Float amount, String status, Currency currency) { + public ACHPullTransferInfo(Float amount, String status, Currency currency) { this.amount = amount; this.status = status; this.currency = currency; From c78847c55846319e25198152a648e275c6e0a47c Mon Sep 17 00:00:00 2001 From: kc-sabal Date: Sat, 11 Feb 2023 18:16:40 +0545 Subject: [PATCH 8/8] CS-2170: Added overloaded ach methods --- src/main/java/co/dapi/DapiApp.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/co/dapi/DapiApp.java b/src/main/java/co/dapi/DapiApp.java index b592174..feec40d 100644 --- a/src/main/java/co/dapi/DapiApp.java +++ b/src/main/java/co/dapi/DapiApp.java @@ -299,6 +299,19 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin return this.m.getAccountsMetadata(accessToken, userSecret, operationID, userInputs); } + /** + * createACHPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * + * @param transfer the transfer details that we want to initiate. + * @param accessToken retrieved from the ExchangeToken process. + * @param userSecret retrieved from the user login. + * @return an {@link CreateACHPullResponse}. + * @throws IOException in case of trouble happened while executing the request or reading the response. + */ + public CreateACHPullResponse createACHPull(ACH.PullTransfer transfer, String accessToken, String userSecret) throws IOException { + return this.ach.createPull(transfer, accessToken, userSecret, "", null); + } + /** * createACHPull talks to the CreatePull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs. @@ -311,10 +324,25 @@ public GetAccountsMetadataResponse getAccountsMetadata(String accessToken, Strin * @return an {@link CreateACHPullResponse}. * @throws IOException in case of trouble happened while executing the request or reading the response. */ + public CreateACHPullResponse createACHPull(ACH.PullTransfer transfer, String accessToken, String userSecret, String operationID, UserInput[] userInputs) throws IOException { return this.ach.createPull(transfer, accessToken, userSecret, operationID, userInputs); } + /** + * getACHPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, + * + * @param accessToken retrieved from the ExchangeToken process. + * @param userSecret retrieved from the user login. + * @param operationID OperationID of the createACHPull request + * @param userInputs built from the previous call's response, and the required user input. + * @return an {@link GetACHPullResponse}. + * @throws IOException in case of trouble happened while executing the request or reading the response. + */ + public GetACHPullResponse getACHPull(String accessToken, String userSecret, String operationID) throws IOException { + return this.ach.getPull(accessToken, userSecret, operationID, null); + } + /** * getACHPull talks to the GetPull endpoint of Dapi, with this {@link DapiApp}'s appSecret, * to continue a previous operation that required to provide some userInputs.