-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportingGateway.cs
160 lines (147 loc) · 5.18 KB
/
ReportingGateway.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
150
151
152
153
154
155
156
157
158
159
160
using AuthorizeNet.APICore;
using System;
using System.Collections.Generic;
namespace AuthorizeNet
{
/// <summary>
/// The gateway for requesting Reports from Authorize.Net
/// </summary>
public class ReportingGateway : IReportingGateway
{
private HttpXmlUtility _gateway;
/// <summary>
/// Initializes a new instance of the <see cref="T:AuthorizeNet.CustomerGateway" /> class.
/// </summary>
/// <param name="apiLogin">The API login.</param>
/// <param name="transactionKey">The transaction key.</param>
/// <param name="mode">Test or Live.</param>
public ReportingGateway(string apiLogin, string transactionKey, ServiceMode mode)
{
if (mode == ServiceMode.Live)
{
this._gateway = new HttpXmlUtility(ServiceMode.Live, apiLogin, transactionKey);
return;
}
this._gateway = new HttpXmlUtility(ServiceMode.Test, apiLogin, transactionKey);
}
/// <summary>
/// Initializes a new instance of the <see cref="T:AuthorizeNet.CustomerGateway" /> class.
/// </summary>
/// <param name="apiLogin">The API login.</param>
/// <param name="transactionKey">The transaction key.</param>
public ReportingGateway(string apiLogin, string transactionKey) : this(apiLogin, transactionKey, ServiceMode.Test)
{
}
/// <summary>
/// Returns charges and statistics for a given batch
/// </summary>
/// <param name="batchId">the batch id</param>
/// <returns>a batch with statistics</returns>
public Batch GetBatchStatistics(string batchId)
{
getBatchStatisticsRequest req = new getBatchStatisticsRequest()
{
batchId = batchId
};
return Batch.NewFromResponse((getBatchStatisticsResponse)this._gateway.Send(req));
}
/// <summary>
/// Returns all Settled Batches for the last 30 days
/// </summary>
public List<Batch> GetSettledBatchList(bool includeStats)
{
DateTime from = DateTime.Today.AddDays(-30);
return this.GetSettledBatchList(from, DateTime.Today, includeStats);
}
/// <summary>
/// Returns all Settled Batches for the last 30 days
/// </summary>
public List<Batch> GetSettledBatchList()
{
DateTime from = DateTime.Today.AddDays(-30);
return this.GetSettledBatchList(from, DateTime.Today, false);
}
/// <summary>
/// Returns batch settlements for the specified date range
/// </summary>
public List<Batch> GetSettledBatchList(DateTime from, DateTime to)
{
return this.GetSettledBatchList(from, to, false);
}
/// <summary>
/// Returns batch settlements for the specified date range
/// </summary>
public List<Batch> GetSettledBatchList(DateTime from, DateTime to, bool includeStats)
{
getSettledBatchListRequest req = new getSettledBatchListRequest()
{
firstSettlementDate = from.ToUniversalTime(),
lastSettlementDate = to.ToUniversalTime(),
firstSettlementDateSpecified = true,
lastSettlementDateSpecified = true
};
if (includeStats)
{
req.includeStatistics = true;
req.includeStatisticsSpecified = true;
}
return Batch.NewFromResponse((getSettledBatchListResponse)this._gateway.Send(req));
}
/// <summary>
/// Returns Transaction details for a given transaction ID (transid)
/// </summary>
/// <param name="transactionID"></param>
public Transaction GetTransactionDetails(string transactionID)
{
getTransactionDetailsRequest req = new getTransactionDetailsRequest()
{
transId = transactionID
};
getTransactionDetailsResponse response = (getTransactionDetailsResponse)this._gateway.Send(req);
return Transaction.NewFromResponse(response.transaction);
}
/// <summary>
/// Returns all transaction within a particular batch
/// </summary>
public List<Transaction> GetTransactionList(string batchId)
{
getTransactionListRequest req = new getTransactionListRequest()
{
batchId = batchId
};
getTransactionListResponse response = (getTransactionListResponse)this._gateway.Send(req);
return Transaction.NewListFromResponse(response.transactions);
}
/// <summary>
/// Returns all transactions for the last 30 days
/// </summary>
/// <returns></returns>
public List<Transaction> GetTransactionList()
{
DateTime today = DateTime.Today;
return this.GetTransactionList(today.AddDays(-30), DateTime.Today);
}
/// <summary>
/// Returns all transactions for a given time period. This can result in a number of calls to the API
/// </summary>
public List<Transaction> GetTransactionList(DateTime from, DateTime to)
{
List<Batch> batches = this.GetSettledBatchList(from, to);
List<Transaction> result = new List<Transaction>();
foreach (Batch batch in batches)
{
result.AddRange(this.GetTransactionList(batch.ID.ToString()));
}
return result;
}
/// <summary>
/// returns the most recent 1000 transactions that are unsettled
/// </summary>
/// <returns></returns>
public List<Transaction> GetUnsettledTransactionList()
{
getUnsettledTransactionListResponse response = (getUnsettledTransactionListResponse)this._gateway.Send(new getUnsettledTransactionListRequest());
return Transaction.NewListFromResponse(response.transactions);
}
}
}