diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 991db1b..7b59bde --- a/README.md +++ b/README.md @@ -480,3 +480,61 @@ In addition to the fields described in the BaseResponse, it has the following fi --- + +#### DapiApp.createACHPull + +Method is used to initiate a new ACH pull create. + +##### Method Description + +```c# +public CreateACHPullResponse createACHPull(ACHPull transfer, string accessToken, string userSecret, string operationID, UserInput[] userInputs) + +``` + +##### Input Parameters + +| Parameter | Type | Description | +|---|---|---| +| **transfer**
_REQUIRED_ | `ACH.ACHPull` | An object that contains info about the transfer that should be initiated. | +| **accessToken**
_REQUIRED_ | `string` | Access Token obtained using the `exchangeToken` method. | +| **userSecret**
_REQUIRED_ | `string` | The `userSecret` from a user’s successful log in to **Connect**. | +| **operationID**
_OPTIONAL_ | `string` | The `operationID` from a previous call's response.
Required only when resuming a previous call that responded with `user_input_required` status, to provided user inputs. | +| **userInputs**
_OPTIONAL_ | `UserInput[]` | Array of `UserInput` object, that are needed to complete this operation.
Required only if a previous call responded with `user_input_required` status.

You can read more about user inputs specification on [Specify User Input](https://dapi-api.readme.io/docs/specify-user-input) | + +##### Response + +Method returns only the fields defined in the BaseResponse. + +--- + + +#### DapiApp.getACHPull + +Method is used to initiate a new get ACH pull. + +##### Method Description + +```c# +public GetACHPullResponse getACHPull(string accessToken, string userSecret, string operationID, UserInput[] userInputs) + +``` + +##### Input Parameters + +| Parameter | Type | Description | +|---|---|---| +| **accessToken**
_REQUIRED_ | `string` | Access Token obtained using the `exchangeToken` method. | +| **userSecret**
_REQUIRED_ | `string` | The `userSecret` from a user’s successful log in to **Connect**. | +| **operationID**
_OPTIONAL_ | `string` | The `operationID` from a previous call's response.
Required only when resuming a previous call that responded with `user_input_required` status, to provided user inputs. | +| **userInputs**
_OPTIONAL_ | `UserInput[]` | Array of `UserInput` object, that are needed to complete this operation.
Required only if a previous call responded with `user_input_required` status.

You can read more about user inputs specification on [Specify User Input](https://dapi-api.readme.io/docs/specify-user-input) | + +##### Response + +In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is `done`: + +| Parameter | Type | Description | +|---|---|---| +| transfer | `ACHPullTransferInfo` | ACH transfer details returned by the bank. | + +--- diff --git a/src/Dapi/DapiApp.cs b/src/Dapi/DapiApp.cs old mode 100644 new mode 100755 index 12bd6b6..3b87160 --- a/src/Dapi/DapiApp.cs +++ b/src/Dapi/DapiApp.cs @@ -17,12 +17,14 @@ public class DapiApp { private readonly Data d; private readonly Payment p; private readonly Metadata m; + private readonly ACH c; public DapiApp(string appSecret) { this.appSecret = appSecret; this.a = new Auth(appSecret); this.d = new Data(appSecret); this.p = new Payment(appSecret); + this.c = new ACH(appSecret); this.m = new Metadata(appSecret); } @@ -504,6 +506,81 @@ public GetAccountsMetadataResponse getAccountsMetadata(string accessToken, strin return this.m.getAccountsMetadata(accessToken, userSecret, operationID, userInputs); } + /// + /// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret. + /// + /// + /// + /// the details of the transfer that should be initiate. + /// + /// + /// retrieved from the ExchangeToken process. + /// + /// + /// retrieved from the user login. + /// + /// + /// retrieved from the previous call's response. + /// + /// + /// built from the previous call's response, and the required user input. + /// + public CreateACHPullResponse createACHPull(ACH.PullTransfer transfer, string accessToken, string userSecret, string operationID, UserInput[] userInputs) { + return this.c.createACHPull(transfer, accessToken, userSecret, operationID, userInputs); + } + + /// + /// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret. + /// + /// + /// retrieved from the ExchangeToken process. + /// + /// + /// retrieved from the user login. + /// + /// + /// retrieved from the previous call's response. + /// + /// + /// built from the previous call's response, and the required user input. + /// + public GetACHPullResponse getACHPull(string accessToken, string userSecret, string operationID, UserInput[] userInputs) { + return this.c.getACHPull(accessToken, userSecret, operationID, userInputs); + } + + /// + /// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret. + /// + /// + /// + /// the details of the transfer that should be initiate. + /// + /// + /// retrieved from the ExchangeToken process. + /// + /// + /// retrieved from the user login. + /// + public CreateACHPullResponse createACHPull(ACH.PullTransfer transfer, string accessToken, string userSecret) { + return this.c.createACHPull(transfer, accessToken, userSecret, "", null); + } + + /// + /// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret. + /// + /// + /// retrieved from the ExchangeToken process. + /// + /// + /// retrieved from the user login. + /// + /// + /// retrieved from the previous call's response. + /// + public GetACHPullResponse getACHPull(string accessToken, string userSecret, string operationID) { + return this.c.getACHPull(accessToken, userSecret, operationID, null); + } + /// /// handleSDKRequest injects this {@link DapiApp}'s appSecret in the passed 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/Dapi/Products/ACH.cs b/src/Dapi/Products/ACH.cs new file mode 100755 index 0000000..a3aeab1 --- /dev/null +++ b/src/Dapi/Products/ACH.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; +using Dapi.Response; +using Dapi.Types; + +namespace Dapi.Products { + public class ACH { + private string appSecret { get; } + + public ACH(string appSecret) { + this.appSecret = appSecret; + } + + public CreateACHPullResponse createACHPull(PullTransfer transfer, string accessToken, string userSecret, string operationID, UserInput[] userInputs) { + // Create the request body of this call + var reqBody = new CreateACHPullRequest(transfer, appSecret, userSecret, operationID, userInputs); + + // Construct the headers needed for this request + var headers = new List>(); + headers.Add(new KeyValuePair("Authorization", "Bearer " + accessToken)); + + // Make the request and get the response + var respBody = DapiRequest.Do(reqBody, reqBody.action, headers); + + // return the data if it's valid, otherwise return an error response + return respBody ?? new CreateACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + } + + public GetACHPullResponse getACHPull(string accessToken, string userSecret, string operationID, UserInput[] userInputs) { + // Create the request body of this call + var reqBody = new GetACHPullRequest(appSecret, userSecret, operationID, userInputs); + + // Construct the headers needed for this request + var headers = new List>(); + headers.Add(new KeyValuePair("Authorization", "Bearer " + accessToken)); + + // Make the request and get the response + var respBody = DapiRequest.Do(reqBody, reqBody.action, headers); + + // return the data if it's valid, otherwise return an error response + return respBody ?? new GetACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body"); + } + + public class PullTransfer { + public string senderID { get; } + public float amount { get; } + public string description { get; } + + /// + /// Create an object that holds the info for a transfer from a bank that requires the receiver to be already + /// registered as a beneficiary to perform a transaction. + /// + /// + /// the id of the account which the money should be sent from. + /// retrieved from one of the accounts array returned from the getAccounts method. + /// + /// + /// the amount of money which should be sent. + /// + /// + /// the id of the beneficiary which the money should be sent to. + /// retrieved from one of the beneficiaries array returned from the getBeneficiaries method. + /// + public PullTransfer(string senderID, float amount, string description) { + this.senderID = senderID; + this.amount = amount; + this.description = description; + } + } + + private class CreateACHPullRequest : DapiRequest.BaseRequest { + internal string action => "/ach/pull/create"; + + public PullTransfer transfer { get; } + + public CreateACHPullRequest(PullTransfer transfer, string appSecret, string userSecret, string operationID, UserInput[] userInputs) : + base(appSecret, userSecret, operationID, userInputs) { + this.transfer = transfer; + } + } + + private class GetACHPullRequest : DapiRequest.BaseRequest { + internal string action => "/ach/pull/get"; + + public GetACHPullRequest(string appSecret, string userSecret, string operationID, UserInput[] userInputs) : + base(appSecret, userSecret, operationID, userInputs) { + } + } + } +} diff --git a/src/Dapi/Products/Payment.cs b/src/Dapi/Products/Payment.cs old mode 100644 new mode 100755 diff --git a/src/Dapi/Response/CreateACHPullResponse.cs b/src/Dapi/Response/CreateACHPullResponse.cs new file mode 100755 index 0000000..7674e06 --- /dev/null +++ b/src/Dapi/Response/CreateACHPullResponse.cs @@ -0,0 +1,23 @@ +using Dapi.Types; +using Newtonsoft.Json; + +namespace Dapi.Response { + public class CreateACHPullResponse : BaseResponse { + + /// + /// This is used only to automate the deserialization of the get response. + /// This is a private constructor to this lib. + /// + [JsonConstructor] + internal CreateACHPullResponse(APIStatus status, bool success, string operationID, UserInput[] userInputs, string type, string msg) : + base(status, success, operationID, userInputs, type, msg) { + } + + /// + /// This is used to construct an error response from the reading of the got response. + /// This is a private constructor to this lib. + /// + internal CreateACHPullResponse(string errType, string errMsg) : base(errType, errMsg) { + } + } +} diff --git a/src/Dapi/Response/GetACHPullResponse.cs b/src/Dapi/Response/GetACHPullResponse.cs new file mode 100755 index 0000000..c5bcfa7 --- /dev/null +++ b/src/Dapi/Response/GetACHPullResponse.cs @@ -0,0 +1,25 @@ +using Dapi.Types; +using Newtonsoft.Json; + +namespace Dapi.Response { + public class GetACHPullResponse : BaseResponse { + public ACHPullTransferInfo transfer { get; } + + /// + /// This is used only to automate the deserialization of the get response. + /// This is a private constructor to this lib. + /// + [JsonConstructor] + internal GetACHPullResponse(ACHPullTransferInfo transfer, string reference, APIStatus status, bool success, string operationID, UserInput[] userInputs, string type, string msg) : + base(status, success, operationID, userInputs, type, msg) { + this.transfer = transfer; + } + + /// + /// This is used to construct an error response from the reading of the got response. + /// This is a private constructor to this lib. + /// + internal GetACHPullResponse(string errType, string errMsg) : base(errType, errMsg) { + } + } +} diff --git a/src/Dapi/Types/ACHGetTransfer.cs b/src/Dapi/Types/ACHGetTransfer.cs new file mode 100644 index 0000000..495fb10 --- /dev/null +++ b/src/Dapi/Types/ACHGetTransfer.cs @@ -0,0 +1,13 @@ +namespace Dapi.Types { + public class ACHPullTransferInfo { + public float amount { get; } + public Currency currency { get; } + public string status { get; } + + public ACHPullTransferInfo(float amount, Currency currency, string status) { + this.amount = amount; + this.currency = currency; + this.status = status; + } + } +}