Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bunq update 7 #84

Merged
merged 6 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions BunqSdk.Samples/AttachmentPublicSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class AttachmentPublicSample : ISample

public void Run()
{
var apiContext = ApiContext.Restore();
BunqContext.LoadApiContext(ApiContext.Restore());
var customHeaders =
new Dictionary<string, string>
{
{ApiClient.HEADER_CONTENT_TYPE, CONTENT_TYPE_IMAGE_JPEG},
{ApiClient.HEADER_ATTACHMENT_DESCRIPTION, DESCRIPTION_TEST_JPG_ATTACHMENT}
};
var requestBytes = File.ReadAllBytes(PATH_ATTACHMENT_IN);
var uuid = AttachmentPublic.Create(apiContext, requestBytes, customHeaders).Value;
var responseBytes = AttachmentPublicContent.List(apiContext, uuid).Value;
var uuid = AttachmentPublic.Create(requestBytes, customHeaders).Value;
var responseBytes = AttachmentPublicContent.List(uuid).Value;
var fileOut = new FileInfo(PATH_ATTACHMENT_OUT);
fileOut.Directory.Create();
File.WriteAllBytes(fileOut.FullName, responseBytes);
Expand Down
16 changes: 4 additions & 12 deletions BunqSdk.Samples/CardDebitSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ public class CardDebitSample : ISample

public void Run()
{
var apiContext = ApiContext.Restore();
BunqContext.LoadApiContext(ApiContext.Restore());
var cardPinAssignment = new CardPinAssignment(
CARD_PIN_ASSIGNMENT_TYPE_PRIMARY,
PIN_CODE,
MONETARY_ACCOUNT_ID
);
var allCardPinAssignments = new List<CardPinAssignment> {cardPinAssignment};
var requestMap = new Dictionary<string, object>
{
{CardDebit.FIELD_NAME_ON_CARD, NAME_YOUR_COMPANY},
{CardDebit.FIELD_SECOND_LINE, GenerateRandomSecondLine()},
{CardDebit.FIELD_PIN_CODE_ASSIGNMENT, allCardPinAssignments},
{
CardDebit.FIELD_ALIAS,
new Pointer(POINTER_TYPE_EMAIL, EMAIL_YOUR_COMPANY) {Name = POINTER_NAME_TEST}
},
};

Console.WriteLine(CardDebit.Create(apiContext, requestMap, USER_ITEM_ID));
Console.WriteLine(CardDebit.Create(GenerateRandomSecondLine(), NAME_YOUR_COMPANY,
new Pointer(POINTER_TYPE_EMAIL, EMAIL_YOUR_COMPANY) {Name = POINTER_NAME_TEST},
pinCodeAssignment: allCardPinAssignments));
}

private static string GenerateRandomSecondLine()
Expand Down
33 changes: 10 additions & 23 deletions BunqSdk.Samples/CustomerStatementExportSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CustomerStatementExportSample : ISample

public void Run()
{
var apiContext = ApiContext.Restore();
BunqContext.LoadApiContext(ApiContext.Restore());
var timeSpanWeek = new TimeSpan(
DAYS_IN_WEEK,
TIME_UNIT_COUNT_NONE,
Expand All @@ -45,31 +45,18 @@ public void Run()
var dateStart = DateTime.Now.Subtract(timeSpanWeek);
var dateEnd = DateTime.Now;

var customerStatementMap = new Dictionary<string, object>
{
{CustomerStatementExport.FIELD_STATEMENT_FORMAT, STATEMENT_FORMAT},
{CustomerStatementExport.FIELD_DATE_START, dateStart.ToString(FORMAT_DATE_STATEMENT)},
{CustomerStatementExport.FIELD_DATE_END, dateEnd.ToString(FORMAT_DATE_STATEMENT)},
};
var userId = BunqContext.UserContext.UserId;

var userId = User.List(apiContext).Value[INDEX_FIRST].UserCompany.Id;
var userIdInt = userId;
var monetaryAccountId = BunqContext.UserContext.PrimaryMonetaryAccountBank.Id.Value;

if (userId != null)
{
var userIdInt = (int) userId;
var monetaryAccountId = MonetaryAccountBank.List(apiContext, userIdInt).Value[INDEX_FIRST].Id;
var monetaryAccountIdInt = monetaryAccountId;
var customerStatementId = CustomerStatementExport.Create(STATEMENT_FORMAT,
dateStart.ToString(FORMAT_DATE_STATEMENT), dateEnd.ToString(FORMAT_DATE_STATEMENT)).Value;

if (monetaryAccountId != null)
{
var monetaryAccountIdInt = (int) monetaryAccountId;
var customerStatementId = CustomerStatementExport.Create(apiContext, customerStatementMap,
userIdInt, monetaryAccountIdInt).Value;
CustomerStatementExport.Delete(customerStatementId);

CustomerStatementExport.Delete(apiContext, userIdInt, monetaryAccountIdInt, customerStatementId);
}
}

apiContext.Save();
BunqContext.ApiContext.Save();
}
}
}
}
9 changes: 3 additions & 6 deletions BunqSdk.Samples/MonetaryAccountSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ namespace Bunq.Sdk.Samples
{
public class MonetaryAccountSample : ISample
{
private const int USER_ITEM_ID = 0; // Put your user ID here
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here

public void Run()
{
var apiContext = ApiContext.Restore();
var monetaryAccount = MonetaryAccount.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
Console.WriteLine(monetaryAccount.MonetaryAccountBank);
BunqContext.LoadApiContext(ApiContext.Restore());
var monetaryAccount = BunqContext.UserContext.PrimaryMonetaryAccountBank;
Console.WriteLine(monetaryAccount);
}
}
}
16 changes: 11 additions & 5 deletions BunqSdk.Samples/PaymentBatchSample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Bunq.Sdk.Context;
using Bunq.Sdk.Model.Core;
using Bunq.Sdk.Model.Generated.Endpoint;
using Bunq.Sdk.Model.Generated.Object;
using Bunq.Sdk.Samples.Utils;
Expand All @@ -14,8 +15,6 @@ public class PaymentBatchSample : ISample
private const string COUNTERPARTY_POINTER_TYPE = "EMAIL";
private const string COUNTERPARTY_EMAIL = "bravo@bunq.com";
private const string PAYMENT_DESCRIPTION = "This is a generated payment batch!";
private const int USER_ITEM_ID = 0; // Put your user ID here
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here

public void Run()
{
Expand All @@ -38,11 +37,18 @@ public void Run()
}
}
};
var allPayment = new List<Payment>();
var payment = new Payment
{
Amount = new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY),
CounterpartyAlias =
new MonetaryAccountReference(new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)),
Description = PAYMENT_DESCRIPTION
};

var paymentBatchId = PaymentBatch.Create(apiContext, paymentBatchMap, USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID).Value;
var paymentBatchId = PaymentBatch.Create(allPayment).Value;

Console.WriteLine(PaymentBatch.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, paymentBatchId));
Console.WriteLine(PaymentBatch.Get(paymentBatchId));
}
}
}
14 changes: 3 additions & 11 deletions BunqSdk.Samples/PaymentListSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@ public class PaymentListSample : ISample
/// </summary>
private const int PAGE_SIZE = 3;

/// <summary>
/// Constants to be changed to run the example.
/// </summary>
private const int USER_ITEM_ID = 0; // Put your user ID here
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here

public void Run()
{
var apiContext = ApiContext.Restore();
BunqContext.LoadApiContext(ApiContext.Restore());
var paginationCountOnly = new Pagination
{
Count = PAGE_SIZE,
};
Console.WriteLine(MESSAGE_LATEST_PAGE_IDS);
var paymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
paginationCountOnly.UrlParamsCountOnly);
var paymentResponse = Payment.List(urlParams: paginationCountOnly.UrlParamsCountOnly);
PrintPayments(paymentResponse.Value);
var pagination = paymentResponse.Pagination;

if (pagination.HasPreviousPage())
{
Console.WriteLine(MESSAGE_SECOND_LATEST_PAGE_IDS);
var previousPaymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
pagination.UrlParamsPreviousPage);
var previousPaymentResponse = Payment.List(urlParams: pagination.UrlParamsPreviousPage);
PrintPayments(previousPaymentResponse.Value);
}
else
Expand Down
21 changes: 6 additions & 15 deletions BunqSdk.Samples/PaymentSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,15 @@ public class PaymentSample : ISample

public void Run()
{
var apiContext = ApiContext.Restore();
var paymentMap = new Dictionary<string, object>
{
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY)},
{
Payment.FIELD_COUNTERPARTY_ALIAS,
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)
},
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION}
};
BunqContext.LoadApiContext(ApiContext.Restore());
var paymentId = Payment.Create(new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY),
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL), PAYMENT_DESCRIPTION).Value;

var paymentId = Payment.Create(apiContext, paymentMap, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
Console.WriteLine(Payment.Get(paymentId));

Console.WriteLine(Payment.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, paymentId));

// Save the API context to account for all the changes that might have occurred to it
// during the sample execution
apiContext.Save();
BunqContext.ApiContext.Save();
}
}
}
}
20 changes: 6 additions & 14 deletions BunqSdk.Samples/RequestSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@ public class RequestSample : ISample
private const string COUNTERPARTY_POINTER_TYPE = "EMAIL";
private const string COUNTERPARTY_EMAIL = "bravo@bunq.com";
private const string REQUEST_DESCRIPTION = "This is a generated request!";
private const int USER_ITEM_ID = 0; // Put your user ID here
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
private const string STATUS_REVOKED = "REVOKED";

public void Run()
{
var apiContext = ApiContext.Restore();
var requestMap = new Dictionary<string, object>
{
{RequestInquiry.FIELD_AMOUNT_INQUIRED, new Amount(REQUEST_AMOUNT, REQUEST_CURRENCY)},
{RequestInquiry.FIELD_COUNTERPARTY_ALIAS, new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)},
{RequestInquiry.FIELD_DESCRIPTION, REQUEST_DESCRIPTION},
{RequestInquiry.FIELD_ALLOW_BUNQME, true}
};
var requestId = RequestInquiry.Create(apiContext, requestMap, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
Console.WriteLine(RequestInquiry.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID, requestId));
var requestId = RequestInquiry.Create(new Amount(REQUEST_AMOUNT, REQUEST_CURRENCY),
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL), REQUEST_DESCRIPTION, false).Value;

Console.WriteLine(RequestInquiry.Get(requestId));

var requestUpdateMap = new Dictionary<string, object> {{RequestInquiry.FIELD_STATUS, STATUS_REVOKED}};
var requestUpdated = RequestInquiry.Update(apiContext, requestUpdateMap, USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID, requestId);
var requestUpdated = RequestInquiry.Update(requestId, status: STATUS_REVOKED);
Console.WriteLine(requestUpdated);
}
}
}
}
11 changes: 8 additions & 3 deletions BunqSdk.Samples/UserListSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ public class UserListSample : ISample
{
public void Run()
{
var apiContext = ApiContext.Restore();
var users = User.List(apiContext).Value;
BunqContext.LoadApiContext(ApiContext.Restore());
var users = User.List().Value;

apiContext.Save();
BunqContext.ApiContext.Save();

foreach (var oneUser in users)
{
Console.WriteLine(oneUser.UserCompany);
}

// or

Console.WriteLine(BunqContext.UserContext.UserCompany);
Console.WriteLine(BunqContext.UserContext.UserPerson);
}
}
}
4 changes: 3 additions & 1 deletion BunqSdk.Tests/BunqSdkTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class BunqSdkTestBase
/// <summary>
/// Gets an Api Context, re-creates if needed and returns it.
/// </summary>
protected static ApiContext GetApiContext()
protected static ApiContext SetUpApiContext()
{
ApiContext apiContext;

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

apiContext.EnsureSessionActive();
apiContext.Save(FILENAME_CONTEXT_CONF);

BunqContext.LoadApiContext(apiContext);

return apiContext;
}
Expand Down
4 changes: 2 additions & 2 deletions BunqSdk.Tests/Context/ApiContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ApiContextTest : BunqSdkTestBase, IClassFixture<ApiContextTest>

public ApiContextTest()
{
if (apiContext == null) apiContext = GetApiContext();
if (apiContext == null) apiContext = SetUpApiContext();
}

/// <summary>
Expand All @@ -27,7 +27,7 @@ public ApiContextTest()
[Fact]
public void TestApiContextSerializeDeserialize()
{
var apiContextJson = apiContext.ToJson();
var apiContextJson = BunqContext.ApiContext.ToJson();
var apiContextDeSerialised = ApiContext.FromJson(apiContextJson);

Assert.Equal(apiContextJson, apiContextDeSerialised.ToJson());
Expand Down
13 changes: 3 additions & 10 deletions BunqSdk.Tests/Http/PaginationScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PaginationScenarioTest : BunqSdkTestBase
/// <summary>
/// API context to use for the test API calls.
/// </summary>
private static readonly ApiContext API_CONTEXT = GetApiContext();
private static readonly ApiContext API_CONTEXT = SetUpApiContext();

[Fact]
public void TestApiScenarioPaymentListingWithPagination()
Expand Down Expand Up @@ -90,19 +90,12 @@ private static IList<Payment> GetPaymentsRequired()

private static BunqResponse<List<Payment>> ListPayments(IDictionary<string, string> urlParams)
{
return Payment.List(API_CONTEXT, USER_ID, MONETARY_ACCOUNT_ID, urlParams);
return Payment.List(urlParams: urlParams);
}

private static void CreatePayment()
{
var requestMap = new Dictionary<string, object>
{
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY)},
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION},
{Payment.FIELD_COUNTERPARTY_ALIAS, COUNTER_PARTY_OTHER}
};

Payment.Create(API_CONTEXT, requestMap, USER_ID, MONETARY_ACCOUNT_ID);
Payment.Create(new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY), COUNTER_PARTY_OTHER, PAYMENT_DESCRIPTION);
}
}
}
4 changes: 2 additions & 2 deletions BunqSdk.Tests/Http/ResponseIdOnBadRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
/// <summary>
/// API context to use for the test API calls.
/// </summary>
private static readonly ApiContext API_CONTEXT = GetApiContext();
private static readonly ApiContext API_CONTEXT = SetUpApiContext();

/// <summary>
/// Invalid user id to trigger BadRequestException
Expand All @@ -22,7 +22,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
public void TestBadRequestWithResponseId()
{
var caughtException = Assert.Throws<BadRequestException>(
() => UserPerson.Get(API_CONTEXT, INVALID_USER_PERSON_ID)
() => UserPerson.Get()
);

Assert.NotNull(caughtException.ResponseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AttachmentPublicTest : BunqSdkTestBase
/// <summary>
/// API context to use for the test API calls.
/// </summary>
private static readonly ApiContext API_CONTEXT = GetApiContext();
private static readonly ApiContext API_CONTEXT = SetUpApiContext();

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

var attachmentUuid = AttachmentPublic.Create(API_CONTEXT, fileContentBytes, customHeaders).Value;
var responseBytes = AttachmentPublicContent.List(API_CONTEXT, attachmentUuid).Value;
var attachmentUuid = AttachmentPublic.Create(fileContentBytes, customHeaders).Value;
var responseBytes = AttachmentPublicContent.List(attachmentUuid).Value;

Assert.Equal(fileContentBytes, responseBytes);
}
Expand Down
Loading