Skip to content

Commit 6df69d4

Browse files
author
dexter-onboard
committed
feat/ACH-get
1 parent 50d73e4 commit 6df69d4

4 files changed

Lines changed: 137 additions & 6 deletions

File tree

src/Dapi/DapiApp.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ public class DapiApp {
1717
private readonly Data d;
1818
private readonly Payment p;
1919
private readonly Metadata m;
20+
private readonly ACH c;
2021

2122
public DapiApp(string appSecret) {
2223
this.appSecret = appSecret;
2324
this.a = new Auth(appSecret);
2425
this.d = new Data(appSecret);
2526
this.p = new Payment(appSecret);
27+
this.c = new ACH(appSecret);
2628
this.m = new Metadata(appSecret);
2729
}
2830

@@ -406,7 +408,7 @@ public CreateTransferResponse createTransfer(Payment.Transfer transfer, string a
406408
}
407409

408410
/// <summary>
409-
/// createACHTransfer talks to the CreateACHTransfer endpoint of Dapi, with this DapiApp's appSecret.
411+
/// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret.
410412
/// </summary>
411413
///
412414
/// <param name="transfer">
@@ -418,8 +420,18 @@ public CreateTransferResponse createTransfer(Payment.Transfer transfer, string a
418420
/// <param name="userSecret">
419421
/// retrieved from the user login.
420422
/// </param>
421-
public CreateACHTransferResponse createACHTransfer(Payment.ACHTransfer transfer, string accessToken, string userSecret) {
422-
return this.p.createACHTransfer(transfer, accessToken, userSecret, "", null);
423+
public CreateACHPullResponse createACHPull(ACH.ACHPull transfer, string accessToken, string userSecret) {
424+
return this.c.createACHPull(transfer, accessToken, userSecret, "", null);
425+
}
426+
427+
/// <summary>
428+
/// createACHPull talks to the CreateACHPull endpoint of Dapi, with this DapiApp's appSecret.
429+
/// </summary>
430+
/// <param name="userSecret">
431+
/// retrieved from the user login.
432+
/// </param>
433+
public GetACHPullResponse getACHPull(string accessToken, string userSecret) {
434+
return this.c.getACHPull(accessToken, userSecret, "", null);
423435
}
424436

425437
/// <summary>

src/Dapi/Products/ACH.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System.Collections.Generic;
2+
using Dapi.Response;
3+
using Dapi.Types;
4+
5+
namespace Dapi.Products {
6+
7+
public class ACH {
8+
private string appSecret { get; }
9+
10+
public ACH(string appSecret) {
11+
this.appSecret = appSecret;
12+
}
13+
14+
15+
public CreateACHPullResponse createACHPull(ACHPull transfer, string accessToken, string userSecret, string operationID, UserInput[] userInputs) {
16+
// Create the request body of this call
17+
var reqBody = new CreateACHPullRequest(transfer, appSecret, userSecret, operationID, userInputs);
18+
19+
// Construct the headers needed for this request
20+
var headers = new List<KeyValuePair<string, string>>();
21+
headers.Add(new KeyValuePair<string, string>("Authorization", "Bearer " + accessToken));
22+
23+
// Make the request and get the response
24+
var respBody = DapiRequest.Do<CreateACHPullRequest, CreateACHPullResponse>(reqBody, reqBody.action, headers);
25+
26+
// return the data if it's valid, otherwise return an error response
27+
return respBody ?? new CreateACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body");
28+
}
29+
30+
public getACHPullResponse getACHPull(string accessToken, string userSecret, string operationID, UserInput[] userInputs) {
31+
// Create the request body of this call
32+
var reqBody = new getACHPullRequest(appSecret, userSecret, operationID, userInputs);
33+
34+
// Construct the headers needed for this request
35+
var headers = new List<KeyValuePair<string, string>>();
36+
headers.Add(new KeyValuePair<string, string>("Authorization", "Bearer " + accessToken));
37+
38+
// Make the request and get the response
39+
var respBody = DapiRequest.Do<getACHPullRequest, getACHPullResponse>(reqBody, reqBody.action, headers);
40+
41+
// return the data if it's valid, otherwise return an error response
42+
return respBody ?? new getACHPullResponse("UNEXPECTED_RESPONSE", "Unexpected response body");
43+
}
44+
45+
public class ACHPull {
46+
public string senderID { get; }
47+
public float amount { get; }
48+
public string description { get; }
49+
50+
/// <summary>
51+
/// Create an object that holds the info for a transfer from a bank that requires the receiver to be already
52+
/// registered as a beneficiary to perform a transaction.
53+
/// </summary>
54+
///
55+
/// <param name="senderID">
56+
/// the id of the account which the money should be sent from.
57+
/// retrieved from one of the accounts array returned from the getAccounts method.
58+
/// </param>
59+
/// <param name="amount">
60+
/// the amount of money which should be sent.
61+
/// </param>
62+
/// <param name="description">
63+
/// the id of the beneficiary which the money should be sent to.
64+
/// retrieved from one of the beneficiaries array returned from the getBeneficiaries method.
65+
/// </param>
66+
public ACHPull(string senderID, float amount, string description) {
67+
this.senderID = senderID;
68+
this.amount = amount;
69+
this.description = description;
70+
}
71+
}
72+
73+
private class CreateACHPullRequest : DapiRequest.BaseRequest {
74+
internal string action => "/ach/pull/create";
75+
76+
public string senderID { get; }
77+
public float amount { get; }
78+
public string description { get; }
79+
80+
public CreateACHPullRequest(ACHPull transfer, string appSecret, string userSecret, string operationID, UserInput[] userInputs) :
81+
base(appSecret, userSecret, operationID, userInputs) {
82+
this.senderID = transfer.senderID;
83+
this.amount = transfer.amount;
84+
this.description = transfer.description;
85+
}
86+
}
87+
88+
private class GetACHPullRequest : DapiRequest.BaseRequest {
89+
internal string action => "/ach/pull/get";
90+
91+
public GetACHPullRequest(string appSecret, string userSecret, string operationID, UserInput[] userInputs) :
92+
base(appSecret, userSecret, operationID, userInputs) {
93+
}
94+
}
95+
}
96+
}

src/Dapi/Response/CreateACHTransferResponse.cs renamed to src/Dapi/Response/CreateACHPullResponse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
using Newtonsoft.Json;
33

44
namespace Dapi.Response {
5-
public class CreateACHTransferResponse : BaseResponse {
5+
public class CreateACHPullResponse : BaseResponse {
66

77
/// <summary>
88
/// This is used only to automate the deserialization of the get response.
99
/// This is a private constructor to this lib.
1010
/// </summary>
1111
[JsonConstructor]
12-
internal CreateACHTransferResponse(string reference, APIStatus status, bool success, string operationID) :
12+
internal CreateACHPullResponse(string reference, APIStatus status, bool success, string operationID) :
1313
base(status, success, operationID, null, "", "") {
1414
}
1515

1616
/// <summary>
1717
/// This is used to construct an error response from the reading of the got response.
1818
/// This is a private constructor to this lib.
1919
/// </summary>
20-
internal CreateACHTransferResponse(string errType, string errMsg) : base(errType, errMsg) {
20+
internal CreateACHPullResponse(string errType, string errMsg) : base(errType, errMsg) {
2121
}
2222
}
2323
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Dapi.Types;
2+
using Newtonsoft.Json;
3+
4+
namespace Dapi.Response {
5+
public class GetACHPullResponse : BaseResponse {
6+
7+
/// <summary>
8+
/// This is used only to automate the deserialization of the get response.
9+
/// This is a private constructor to this lib.
10+
/// </summary>
11+
[JsonConstructor]
12+
internal GetACHPullResponse(string reference, APIStatus status, bool success, string operationID) :
13+
base(status, success, operationID, null, "", "") {
14+
}
15+
16+
/// <summary>
17+
/// This is used to construct an error response from the reading of the got response.
18+
/// This is a private constructor to this lib.
19+
/// </summary>
20+
internal GetACHPullResponse(string errType, string errMsg) : base(errType, errMsg) {
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)