Skip to content

Commit de76034

Browse files
authored
Merge pull request #84 from bunq/bunq_update_7_
Bunq update 7
2 parents f731c5d + 38af572 commit de76034

File tree

185 files changed

+7970
-4641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+7970
-4641
lines changed

BunqSdk.Samples/AttachmentPublicSample.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ public class AttachmentPublicSample : ISample
1616

1717
public void Run()
1818
{
19-
var apiContext = ApiContext.Restore();
19+
BunqContext.LoadApiContext(ApiContext.Restore());
2020
var customHeaders =
2121
new Dictionary<string, string>
2222
{
2323
{ApiClient.HEADER_CONTENT_TYPE, CONTENT_TYPE_IMAGE_JPEG},
2424
{ApiClient.HEADER_ATTACHMENT_DESCRIPTION, DESCRIPTION_TEST_JPG_ATTACHMENT}
2525
};
2626
var requestBytes = File.ReadAllBytes(PATH_ATTACHMENT_IN);
27-
var uuid = AttachmentPublic.Create(apiContext, requestBytes, customHeaders).Value;
28-
var responseBytes = AttachmentPublicContent.List(apiContext, uuid).Value;
27+
var uuid = AttachmentPublic.Create(requestBytes, customHeaders).Value;
28+
var responseBytes = AttachmentPublicContent.List(uuid).Value;
2929
var fileOut = new FileInfo(PATH_ATTACHMENT_OUT);
3030
fileOut.Directory.Create();
3131
File.WriteAllBytes(fileOut.FullName, responseBytes);

BunqSdk.Samples/CardDebitSample.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,17 @@ public class CardDebitSample : ISample
2020

2121
public void Run()
2222
{
23-
var apiContext = ApiContext.Restore();
23+
BunqContext.LoadApiContext(ApiContext.Restore());
2424
var cardPinAssignment = new CardPinAssignment(
2525
CARD_PIN_ASSIGNMENT_TYPE_PRIMARY,
2626
PIN_CODE,
2727
MONETARY_ACCOUNT_ID
2828
);
2929
var allCardPinAssignments = new List<CardPinAssignment> {cardPinAssignment};
30-
var requestMap = new Dictionary<string, object>
31-
{
32-
{CardDebit.FIELD_NAME_ON_CARD, NAME_YOUR_COMPANY},
33-
{CardDebit.FIELD_SECOND_LINE, GenerateRandomSecondLine()},
34-
{CardDebit.FIELD_PIN_CODE_ASSIGNMENT, allCardPinAssignments},
35-
{
36-
CardDebit.FIELD_ALIAS,
37-
new Pointer(POINTER_TYPE_EMAIL, EMAIL_YOUR_COMPANY) {Name = POINTER_NAME_TEST}
38-
},
39-
};
4030

41-
Console.WriteLine(CardDebit.Create(apiContext, requestMap, USER_ITEM_ID));
31+
Console.WriteLine(CardDebit.Create(GenerateRandomSecondLine(), NAME_YOUR_COMPANY,
32+
new Pointer(POINTER_TYPE_EMAIL, EMAIL_YOUR_COMPANY) {Name = POINTER_NAME_TEST},
33+
pinCodeAssignment: allCardPinAssignments));
4234
}
4335

4436
private static string GenerateRandomSecondLine()

BunqSdk.Samples/CustomerStatementExportSample.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class CustomerStatementExportSample : ISample
3535

3636
public void Run()
3737
{
38-
var apiContext = ApiContext.Restore();
38+
BunqContext.LoadApiContext(ApiContext.Restore());
3939
var timeSpanWeek = new TimeSpan(
4040
DAYS_IN_WEEK,
4141
TIME_UNIT_COUNT_NONE,
@@ -45,31 +45,18 @@ public void Run()
4545
var dateStart = DateTime.Now.Subtract(timeSpanWeek);
4646
var dateEnd = DateTime.Now;
4747

48-
var customerStatementMap = new Dictionary<string, object>
49-
{
50-
{CustomerStatementExport.FIELD_STATEMENT_FORMAT, STATEMENT_FORMAT},
51-
{CustomerStatementExport.FIELD_DATE_START, dateStart.ToString(FORMAT_DATE_STATEMENT)},
52-
{CustomerStatementExport.FIELD_DATE_END, dateEnd.ToString(FORMAT_DATE_STATEMENT)},
53-
};
48+
var userId = BunqContext.UserContext.UserId;
5449

55-
var userId = User.List(apiContext).Value[INDEX_FIRST].UserCompany.Id;
50+
var userIdInt = userId;
51+
var monetaryAccountId = BunqContext.UserContext.PrimaryMonetaryAccountBank.Id.Value;
5652

57-
if (userId != null)
58-
{
59-
var userIdInt = (int) userId;
60-
var monetaryAccountId = MonetaryAccountBank.List(apiContext, userIdInt).Value[INDEX_FIRST].Id;
53+
var monetaryAccountIdInt = monetaryAccountId;
54+
var customerStatementId = CustomerStatementExport.Create(STATEMENT_FORMAT,
55+
dateStart.ToString(FORMAT_DATE_STATEMENT), dateEnd.ToString(FORMAT_DATE_STATEMENT)).Value;
6156

62-
if (monetaryAccountId != null)
63-
{
64-
var monetaryAccountIdInt = (int) monetaryAccountId;
65-
var customerStatementId = CustomerStatementExport.Create(apiContext, customerStatementMap,
66-
userIdInt, monetaryAccountIdInt).Value;
57+
CustomerStatementExport.Delete(customerStatementId);
6758

68-
CustomerStatementExport.Delete(apiContext, userIdInt, monetaryAccountIdInt, customerStatementId);
69-
}
70-
}
71-
72-
apiContext.Save();
59+
BunqContext.ApiContext.Save();
7360
}
7461
}
75-
}
62+
}

BunqSdk.Samples/MonetaryAccountSample.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ namespace Bunq.Sdk.Samples
77
{
88
public class MonetaryAccountSample : ISample
99
{
10-
private const int USER_ITEM_ID = 0; // Put your user ID here
11-
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
12-
1310
public void Run()
1411
{
15-
var apiContext = ApiContext.Restore();
16-
var monetaryAccount = MonetaryAccount.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
17-
Console.WriteLine(monetaryAccount.MonetaryAccountBank);
12+
BunqContext.LoadApiContext(ApiContext.Restore());
13+
var monetaryAccount = BunqContext.UserContext.PrimaryMonetaryAccountBank;
14+
Console.WriteLine(monetaryAccount);
1815
}
1916
}
2017
}

BunqSdk.Samples/PaymentBatchSample.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Bunq.Sdk.Context;
4+
using Bunq.Sdk.Model.Core;
45
using Bunq.Sdk.Model.Generated.Endpoint;
56
using Bunq.Sdk.Model.Generated.Object;
67
using Bunq.Sdk.Samples.Utils;
@@ -14,8 +15,6 @@ public class PaymentBatchSample : ISample
1415
private const string COUNTERPARTY_POINTER_TYPE = "EMAIL";
1516
private const string COUNTERPARTY_EMAIL = "bravo@bunq.com";
1617
private const string PAYMENT_DESCRIPTION = "This is a generated payment batch!";
17-
private const int USER_ITEM_ID = 0; // Put your user ID here
18-
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
1918

2019
public void Run()
2120
{
@@ -38,11 +37,18 @@ public void Run()
3837
}
3938
}
4039
};
40+
var allPayment = new List<Payment>();
41+
var payment = new Payment
42+
{
43+
Amount = new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY),
44+
CounterpartyAlias =
45+
new MonetaryAccountReference(new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)),
46+
Description = PAYMENT_DESCRIPTION
47+
};
4148

42-
var paymentBatchId = PaymentBatch.Create(apiContext, paymentBatchMap, USER_ITEM_ID,
43-
MONETARY_ACCOUNT_ITEM_ID).Value;
49+
var paymentBatchId = PaymentBatch.Create(allPayment).Value;
4450

45-
Console.WriteLine(PaymentBatch.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, paymentBatchId));
51+
Console.WriteLine(PaymentBatch.Get(paymentBatchId));
4652
}
4753
}
4854
}

BunqSdk.Samples/PaymentListSample.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,22 @@ public class PaymentListSample : ISample
2121
/// </summary>
2222
private const int PAGE_SIZE = 3;
2323

24-
/// <summary>
25-
/// Constants to be changed to run the example.
26-
/// </summary>
27-
private const int USER_ITEM_ID = 0; // Put your user ID here
28-
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
29-
3024
public void Run()
3125
{
32-
var apiContext = ApiContext.Restore();
26+
BunqContext.LoadApiContext(ApiContext.Restore());
3327
var paginationCountOnly = new Pagination
3428
{
3529
Count = PAGE_SIZE,
3630
};
3731
Console.WriteLine(MESSAGE_LATEST_PAGE_IDS);
38-
var paymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
39-
paginationCountOnly.UrlParamsCountOnly);
32+
var paymentResponse = Payment.List(urlParams: paginationCountOnly.UrlParamsCountOnly);
4033
PrintPayments(paymentResponse.Value);
4134
var pagination = paymentResponse.Pagination;
4235

4336
if (pagination.HasPreviousPage())
4437
{
4538
Console.WriteLine(MESSAGE_SECOND_LATEST_PAGE_IDS);
46-
var previousPaymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
47-
pagination.UrlParamsPreviousPage);
39+
var previousPaymentResponse = Payment.List(urlParams: pagination.UrlParamsPreviousPage);
4840
PrintPayments(previousPaymentResponse.Value);
4941
}
5042
else

BunqSdk.Samples/PaymentSample.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,15 @@ public class PaymentSample : ISample
1919

2020
public void Run()
2121
{
22-
var apiContext = ApiContext.Restore();
23-
var paymentMap = new Dictionary<string, object>
24-
{
25-
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY)},
26-
{
27-
Payment.FIELD_COUNTERPARTY_ALIAS,
28-
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)
29-
},
30-
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION}
31-
};
22+
BunqContext.LoadApiContext(ApiContext.Restore());
23+
var paymentId = Payment.Create(new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY),
24+
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL), PAYMENT_DESCRIPTION).Value;
3225

33-
var paymentId = Payment.Create(apiContext, paymentMap, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
26+
Console.WriteLine(Payment.Get(paymentId));
3427

35-
Console.WriteLine(Payment.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, paymentId));
36-
3728
// Save the API context to account for all the changes that might have occurred to it
3829
// during the sample execution
39-
apiContext.Save();
30+
BunqContext.ApiContext.Save();
4031
}
4132
}
42-
}
33+
}

BunqSdk.Samples/RequestSample.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,19 @@ public class RequestSample : ISample
1414
private const string COUNTERPARTY_POINTER_TYPE = "EMAIL";
1515
private const string COUNTERPARTY_EMAIL = "bravo@bunq.com";
1616
private const string REQUEST_DESCRIPTION = "This is a generated request!";
17-
private const int USER_ITEM_ID = 0; // Put your user ID here
18-
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
1917
private const string STATUS_REVOKED = "REVOKED";
2018

2119
public void Run()
2220
{
2321
var apiContext = ApiContext.Restore();
24-
var requestMap = new Dictionary<string, object>
25-
{
26-
{RequestInquiry.FIELD_AMOUNT_INQUIRED, new Amount(REQUEST_AMOUNT, REQUEST_CURRENCY)},
27-
{RequestInquiry.FIELD_COUNTERPARTY_ALIAS, new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)},
28-
{RequestInquiry.FIELD_DESCRIPTION, REQUEST_DESCRIPTION},
29-
{RequestInquiry.FIELD_ALLOW_BUNQME, true}
30-
};
31-
var requestId = RequestInquiry.Create(apiContext, requestMap, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
32-
Console.WriteLine(RequestInquiry.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, requestId));
22+
var requestId = RequestInquiry.Create(new Amount(REQUEST_AMOUNT, REQUEST_CURRENCY),
23+
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL), REQUEST_DESCRIPTION, false).Value;
24+
25+
Console.WriteLine(RequestInquiry.Get(requestId));
3326

3427
var requestUpdateMap = new Dictionary<string, object> {{RequestInquiry.FIELD_STATUS, STATUS_REVOKED}};
35-
var requestUpdated = RequestInquiry.Update(apiContext, requestUpdateMap, USER_ITEM_ID,
36-
MONETARY_ACCOUNT_ITEM_ID, requestId);
28+
var requestUpdated = RequestInquiry.Update(requestId, status: STATUS_REVOKED);
3729
Console.WriteLine(requestUpdated);
3830
}
3931
}
40-
}
32+
}

BunqSdk.Samples/UserListSample.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ public class UserListSample : ISample
99
{
1010
public void Run()
1111
{
12-
var apiContext = ApiContext.Restore();
13-
var users = User.List(apiContext).Value;
12+
BunqContext.LoadApiContext(ApiContext.Restore());
13+
var users = User.List().Value;
1414

15-
apiContext.Save();
15+
BunqContext.ApiContext.Save();
1616

1717
foreach (var oneUser in users)
1818
{
1919
Console.WriteLine(oneUser.UserCompany);
2020
}
21+
22+
// or
23+
24+
Console.WriteLine(BunqContext.UserContext.UserCompany);
25+
Console.WriteLine(BunqContext.UserContext.UserPerson);
2126
}
2227
}
2328
}

BunqSdk.Tests/BunqSdkTestBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class BunqSdkTestBase
2929
/// <summary>
3030
/// Gets an Api Context, re-creates if needed and returns it.
3131
/// </summary>
32-
protected static ApiContext GetApiContext()
32+
protected static ApiContext SetUpApiContext()
3333
{
3434
ApiContext apiContext;
3535

@@ -44,6 +44,8 @@ protected static ApiContext GetApiContext()
4444

4545
apiContext.EnsureSessionActive();
4646
apiContext.Save(FILENAME_CONTEXT_CONF);
47+
48+
BunqContext.LoadApiContext(apiContext);
4749

4850
return apiContext;
4951
}

BunqSdk.Tests/Context/ApiContextTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ApiContextTest : BunqSdkTestBase, IClassFixture<ApiContextTest>
1818

1919
public ApiContextTest()
2020
{
21-
if (apiContext == null) apiContext = GetApiContext();
21+
if (apiContext == null) apiContext = SetUpApiContext();
2222
}
2323

2424
/// <summary>
@@ -27,7 +27,7 @@ public ApiContextTest()
2727
[Fact]
2828
public void TestApiContextSerializeDeserialize()
2929
{
30-
var apiContextJson = apiContext.ToJson();
30+
var apiContextJson = BunqContext.ApiContext.ToJson();
3131
var apiContextDeSerialised = ApiContext.FromJson(apiContextJson);
3232

3333
Assert.Equal(apiContextJson, apiContextDeSerialised.ToJson());

BunqSdk.Tests/Http/PaginationScenarioTest.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PaginationScenarioTest : BunqSdkTestBase
3838
/// <summary>
3939
/// API context to use for the test API calls.
4040
/// </summary>
41-
private static readonly ApiContext API_CONTEXT = GetApiContext();
41+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
4242

4343
[Fact]
4444
public void TestApiScenarioPaymentListingWithPagination()
@@ -90,19 +90,12 @@ private static IList<Payment> GetPaymentsRequired()
9090

9191
private static BunqResponse<List<Payment>> ListPayments(IDictionary<string, string> urlParams)
9292
{
93-
return Payment.List(API_CONTEXT, USER_ID, MONETARY_ACCOUNT_ID, urlParams);
93+
return Payment.List(urlParams: urlParams);
9494
}
9595

9696
private static void CreatePayment()
9797
{
98-
var requestMap = new Dictionary<string, object>
99-
{
100-
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY)},
101-
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION},
102-
{Payment.FIELD_COUNTERPARTY_ALIAS, COUNTER_PARTY_OTHER}
103-
};
104-
105-
Payment.Create(API_CONTEXT, requestMap, USER_ID, MONETARY_ACCOUNT_ID);
98+
Payment.Create(new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY), COUNTER_PARTY_OTHER, PAYMENT_DESCRIPTION);
10699
}
107100
}
108101
}

BunqSdk.Tests/Http/ResponseIdOnBadRequestTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
1111
/// <summary>
1212
/// API context to use for the test API calls.
1313
/// </summary>
14-
private static readonly ApiContext API_CONTEXT = GetApiContext();
14+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
1515

1616
/// <summary>
1717
/// Invalid user id to trigger BadRequestException
@@ -22,7 +22,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
2222
public void TestBadRequestWithResponseId()
2323
{
2424
var caughtException = Assert.Throws<BadRequestException>(
25-
() => UserPerson.Get(API_CONTEXT, INVALID_USER_PERSON_ID)
25+
() => UserPerson.Get()
2626
);
2727

2828
Assert.NotNull(caughtException.ResponseId);

BunqSdk.Tests/Model/Generated/Endpoint/AttachmentPublicTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AttachmentPublicTest : BunqSdkTestBase
2626
/// <summary>
2727
/// API context to use for the test API calls.
2828
/// </summary>
29-
private static readonly ApiContext API_CONTEXT = GetApiContext();
29+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3030

3131
/// <summary>
3232
/// Tests if the file we upload is the file we are getting back once successfully uploaded does.
@@ -42,8 +42,8 @@ public void TestAttachmentUploadAndRetrieval()
4242
{ApiClient.HEADER_ATTACHMENT_DESCRIPTION, ATTACHMENT_DESCRIPTION}
4343
};
4444

45-
var attachmentUuid = AttachmentPublic.Create(API_CONTEXT, fileContentBytes, customHeaders).Value;
46-
var responseBytes = AttachmentPublicContent.List(API_CONTEXT, attachmentUuid).Value;
45+
var attachmentUuid = AttachmentPublic.Create(fileContentBytes, customHeaders).Value;
46+
var responseBytes = AttachmentPublicContent.List(attachmentUuid).Value;
4747

4848
Assert.Equal(fileContentBytes, responseBytes);
4949
}

0 commit comments

Comments
 (0)