-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCustomerStatementExportSample.cs
75 lines (63 loc) · 2.53 KB
/
CustomerStatementExportSample.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
using System;
using System.Collections.Generic;
using Bunq.Sdk.Context;
using Bunq.Sdk.Model.Generated.Endpoint;
using Bunq.Sdk.Samples.Utils;
namespace Bunq.Sdk.Samples
{
public class CustomerStatementExportSample : ISample
{
/// <summary>
/// Constant to translate weeks to milliseconds.
/// </summary>
private const int IndexFirst = 0;
/// <summary>
/// Date format for Customer Statement Export endpoint.
/// </summary>
private const string FormatDateStatement = "yyyy-MM-dd";
/// <summary>
/// Format of the statement file requested.
/// </summary>
private const string StatementFormat = "PDF";
/// <summary>
/// Measure of any time unit when none of it is needed.
/// </summary>
private const int TimeUnitCountNone = 0;
/// <summary>
/// Measure of any time unit when none of it is needed.
/// </summary>
private const int DaysInWeek = 7;
public void Run()
{
var apiContext = ApiContext.Restore();
var timeSpanWeek = new TimeSpan(
DaysInWeek,
TimeUnitCountNone,
TimeUnitCountNone,
TimeUnitCountNone
);
var dateStart = DateTime.Now.Subtract(timeSpanWeek);
var dateEnd = DateTime.Now;
var customerStatementMap = new Dictionary<string, object>
{
{CustomerStatementExport.FIELD_STATEMENT_FORMAT, StatementFormat},
{CustomerStatementExport.FIELD_DATE_START, dateStart.ToString(FormatDateStatement)},
{CustomerStatementExport.FIELD_DATE_END, dateEnd.ToString(FormatDateStatement)},
};
var userId = User.List(apiContext).Value[IndexFirst].UserCompany.Id;
if (userId != null)
{
var userIdInt = (int) userId;
var monetaryAccountId = MonetaryAccountBank.List(apiContext, userIdInt).Value[IndexFirst].Id;
if (monetaryAccountId != null)
{
var monetaryAccountIdInt = (int) monetaryAccountId;
var customerStatementId = CustomerStatementExport.Create(apiContext, customerStatementMap,
userIdInt, monetaryAccountIdInt).Value;
CustomerStatementExport.Delete(apiContext, userIdInt, monetaryAccountIdInt, customerStatementId);
}
}
apiContext.Save();
}
}
}