-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTransaction.cs
149 lines (127 loc) · 7.99 KB
/
Transaction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using CorePro.SDK.Models;
using CorePro.SDK.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CorePro.SDK
{
public class Transaction : ModelBase
{
public Transaction()
{
}
public Transaction(int? customerId)
{
this.CustomerId = customerId;
}
public int? TransactionCount { get; set; }
public int? CustomerId { get; set; }
public long? TransactionId { get; set; }
public string Tag { get; set; }
public DateTimeOffset? CreatedDate { get; set; }
public string Type { get; set; }
public string TypeCode { get; set; }
public string Status { get; set; }
public decimal? Amount { get; set; }
public bool? IsAvailable { get; set; }
public DateTimeOffset? SettledDate { get; set; }
public DateTimeOffset? VoidedDate { get; set; }
public string NachaDescription { get; set; }
public string FriendlyDescription { get; set; }
public DateTimeOffset? AvailableDate { get; set; }
public string ReturnCode { get; set; }
public bool? IsCredit { get; set; }
public string FeeCode { get; set; }
public string FeeDescription { get; set; }
public string InstitutionName { get; set; }
public string CustomField1 { get; set; }
#region Synchronous
/// <summary>
/// Lists all transactions for given user for all accounts for all time. Optionally can restrict to a given account or a given range of dates.
/// </summary>
/// <param name="customerId"></param>
/// <param name="accountId"></param>
/// <param name="beginDate">Null or empty string means beginning of time.</param>
/// <param name="endDate">Null or empty string means end of time</param>
/// <param name="connection"></param>
/// <returns></returns>
public static List<Transaction> List(int? customerId, int? accountId, string status = null, DateTimeOffset? beginDate = null, DateTimeOffset? endDate = null, int pageNumber = 0, int pageSize = 200, Connection connection = null, object userDefinedObjectForLogging = null)
{
return new Transaction(customerId).List(accountId, status, beginDate, endDate, pageNumber, pageSize, connection, userDefinedObjectForLogging);
}
public virtual List<Transaction> List(int? accountId, string status = null, DateTimeOffset? beginDate = null, DateTimeOffset? endDate = null, int pageNumber = 0, int pageSize = 200, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
var begin = beginDate == null ? "" : beginDate.Value.ToString("yyyy-MM-dd");
var end = endDate == null ? "" : endDate.Value.ToString("yyyy-MM-dd");
if (!String.IsNullOrWhiteSpace(end) && String.IsNullOrWhiteSpace(begin))
{
// if we want to specify an end date, we must also specify a begin date.
// api assumes if only 1 date is specified, it is the begin date (not the end date).
// by forcing a begin date here, we make sure the end date is respected as expected.
begin = "1900-01-01";
}
var rv = Requestor.Get<List<Transaction>>(String.Format("transaction/list/{0}/{1}/{2}/{3}/{4}?pageNumber={5}&pageSize={6}", this.CustomerId, accountId, status, begin, end, pageNumber, pageSize), connection, userDefinedObjectForLogging);
return rv;
}
public static List<Transaction> GetByTag(int? customerId, string tag, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
return Requestor.Get<List<Transaction>>(String.Format("transaction/getbytag/{0}/{1}", customerId, tag), connection, userDefinedObjectForLogging);
}
public static List<Transaction> Get(int? customerId, long? transactionId, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
return Requestor.Get<List<Transaction>>(String.Format("transaction/get/{0}/{1}", customerId, transactionId), connection, userDefinedObjectForLogging);
}
#endregion Synchronous
#region Async
/// <summary>
/// Lists all transactions for given user for all accounts for all time. Optionally can restrict to a given account or a given range of dates.
/// </summary>
/// <param name="customerId"></param>
/// <param name="accountId"></param>
/// <param name="beginDate">Null or empty string means beginning of time.</param>
/// <param name="endDate">Null or empty string means end of time</param>
/// <param name="connection"></param>
/// <returns></returns>
public async static Task<List<Transaction>> ListAsync(CancellationToken cancellationToken, int? customerId, int? accountId, string status = null, DateTimeOffset? beginDate = null, DateTimeOffset? endDate = null, int pageNumber = 0, int pageSize = 200, Connection connection = null, object userDefinedObjectForLogging = null)
{
return await new Transaction(customerId).ListAsync(cancellationToken, accountId, status, beginDate, endDate, pageNumber, pageSize, connection, userDefinedObjectForLogging);
}
public async virtual Task<List<Transaction>> ListAsync(CancellationToken cancellationToken, int? accountId, string status = null, DateTimeOffset? beginDate = null, DateTimeOffset? endDate = null, int pageNumber = 0, int pageSize = 200, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
var begin = beginDate == null ? "" : beginDate.Value.ToString("yyyy-MM-dd");
var end = endDate == null ? "" : endDate.Value.ToString("yyyy-MM-dd");
if (!String.IsNullOrEmpty(status)){
status = Uri.EscapeUriString(status);
}
if (!String.IsNullOrWhiteSpace(end) && String.IsNullOrWhiteSpace(begin))
{
// if we want to specify an end date, we must also specify a begin date.
// api assumes if only 1 date is specified, it is the begin date (not the end date).
// by forcing a begin date here, we make sure the end date is respected as expected.
begin = "1900-01-01";
}
var rv = await Requestor.GetAsync<List<Transaction>>(cancellationToken, String.Format("transaction/list/{0}/{1}/{2}/{3}/{4}?pageNumber={5}&pageSize={6}", this.CustomerId, accountId, status, begin, end, pageNumber, pageSize), connection, userDefinedObjectForLogging);
return rv.Data;
}
public async static Task<List<Transaction>> GetByTagAsync(CancellationToken cancellationToken, int? customerId, string tag, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
var rv = await Requestor.GetAsync<List<Transaction>>(cancellationToken, String.Format("transaction/getbytag/{0}/{1}", customerId, tag), connection, userDefinedObjectForLogging);
return rv.Data;
}
public async static Task<List<Transaction>> GetAsync(CancellationToken cancellationToken, int? customerId, long? transactionId, Connection connection = null, object userDefinedObjectForLogging = null)
{
connection = connection ?? Connection.CreateFromConfig();
var rv = await Requestor.GetAsync<List<Transaction>>(cancellationToken, String.Format("transaction/get/{0}/{1}", customerId, transactionId), connection, userDefinedObjectForLogging);
return rv.Data;
}
#endregion Async
}
}