Skip to content

Commit

Permalink
Merge branch 'release/0.12.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Nov 8, 2017
2 parents 0b5b73e + c1a7b7a commit 0fe0a00
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 20 deletions.
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Steps to reproduce:
1.

## What should happen:
1.

## What happens:
1.

## Logs
- Logs

## Extra info:
- Tested on

2 changes: 1 addition & 1 deletion BunqSdk.Samples/BunqSdk.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Bunq.Sdk.Samples</RootNamespace>
<TargetFramework>netcoreapp1.1</TargetFramework>
<LangVersion>5</LangVersion>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BunqSdk\BunqSdk.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion BunqSdk.Tests/BunqSdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RootNamespace>Bunq.Sdk.Tests</RootNamespace>
<LangVersion>5</LangVersion>
<LangVersion>default</LangVersion>
<AssemblyName>BunqSdk.Tests.xunit.runner.json</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions BunqSdk/BunqSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
<TargetFramework>netcoreapp1.1</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>5</LangVersion>
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup>
<AssemblyName>Bunq.Sdk</AssemblyName>
<PackageId>Bunq.Sdk</PackageId>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>0.12.0.0</VersionPrefix>
<VersionPrefix>0.12.2.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
</PropertyGroup>
<PropertyGroup>
Expand Down
18 changes: 13 additions & 5 deletions BunqSdk/Context/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,27 @@ private void DeleteSession()
/// </summary>
public void EnsureSessionActive()
{
if (SessionContext == null) return;
if (!IsSessionActive())
{
ResetSession();
}
}

public bool IsSessionActive()
{
if (SessionContext == null)
{
return false;
}

var timeToExpiry = SessionContext.ExpiryTime.Subtract(DateTime.Now);
var timeToExpiryMinimum = new TimeSpan(
TIME_UNIT_COUNT_NONE,
TIME_UNIT_COUNT_NONE,
TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS
);

if (timeToExpiry < timeToExpiryMinimum)
{
ResetSession();
}
return timeToExpiry > timeToExpiryMinimum;
}

/// <summary>
Expand Down
26 changes: 22 additions & 4 deletions BunqSdk/Http/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ namespace Bunq.Sdk.Http
{
public class ApiClient
{

/// <summary>
/// Endpoints not requiring active session for the request to succeed.
/// </summary>
private const string DEVICE_SERVER_URL = "device-server";
private const string INSTALLATION_URL = "installation";
private const string SESSION_SERVER_URL = "session-server";
private static readonly string[] URIS_NOT_REQUIRING_ACTIVE_SESSION = new string[]
{
DEVICE_SERVER_URL,
INSTALLATION_URL,
SESSION_SERVER_URL
};

/// <summary>
/// Header constants.
/// </summary>
Expand Down Expand Up @@ -115,21 +129,25 @@ private BunqResponseRaw SendRequest(HttpMethod method, string uriRelative, byte[
{
var requestMessage = CreateHttpRequestMessage(method, uriRelative, uriParams, requestBodyBytes);

return SendRequest(requestMessage, customHeaders);
return SendRequest(requestMessage, customHeaders, uriRelative);
}

private BunqResponseRaw SendRequest(HttpMethod method, string uriRelative,
IDictionary<string, string> uriParams, IDictionary<string, string> customHeaders)
{
var requestMessage = CreateHttpRequestMessage(method, uriRelative, uriParams);

return SendRequest(requestMessage, customHeaders);
return SendRequest(requestMessage, customHeaders, uriRelative);
}

private BunqResponseRaw SendRequest(HttpRequestMessage requestMessage,
IDictionary<string, string> customHeaders)
IDictionary<string, string> customHeaders, string uriRelative)
{
apiContext.EnsureSessionActive();
if (!URIS_NOT_REQUIRING_ACTIVE_SESSION.Contains(uriRelative))
{
apiContext.EnsureSessionActive();
}

SetDefaultHeaders(requestMessage);
SetHeaders(requestMessage, customHeaders);
SetSessionHeaders(requestMessage);
Expand Down
6 changes: 6 additions & 0 deletions BunqSdk/Model/Generated/Endpoint/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public class Card : BunqModel
[JsonProperty(PropertyName = "public_uuid")]
public string PublicUuid { get; private set; }

/// <summary>
/// The type of the card. Can be MAESTRO, MASTERCARD.
/// </summary>
[JsonProperty(PropertyName = "type")]
public string Type { get; private set; }

/// <summary>
/// The second line of text on the card
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions BunqSdk/Model/Generated/Endpoint/CardDebit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public class CardDebit : BunqModel
[JsonProperty(PropertyName = "public_uuid")]
public string PublicUuid { get; private set; }

/// <summary>
/// The type of the card. Can be MAESTRO, MASTERCARD.
/// </summary>
[JsonProperty(PropertyName = "type")]
public string Type { get; private set; }

/// <summary>
/// The second line of text on the card
/// </summary>
Expand Down
108 changes: 108 additions & 0 deletions BunqSdk/Model/Generated/Endpoint/CardGeneratedCvc2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Bunq.Sdk.Context;
using Bunq.Sdk.Http;
using Bunq.Sdk.Json;
using Bunq.Sdk.Model.Core;
using Bunq.Sdk.Security;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text;
using System;

namespace Bunq.Sdk.Model.Generated.Endpoint
{
/// <summary>
/// Endpoint for generating and retrieving a new CVC2 code.
/// </summary>
public class CardGeneratedCvc2 : BunqModel
{
/// <summary>
/// Endpoint constants.
/// </summary>
private const string ENDPOINT_URL_CREATE = "user/{0}/card/{1}/generated-cvc2";
private const string ENDPOINT_URL_READ = "user/{0}/card/{1}/generated-cvc2/{2}";
private const string ENDPOINT_URL_LISTING = "user/{0}/card/{1}/generated-cvc2";

/// <summary>
/// Object type.
/// </summary>
private const string OBJECT_TYPE = "CardGeneratedCvc2";

/// <summary>
/// The id of the cvc code.
/// </summary>
[JsonProperty(PropertyName = "id")]
public int? Id { get; private set; }

/// <summary>
/// The timestamp of the cvc code's creation.
/// </summary>
[JsonProperty(PropertyName = "created")]
public string Created { get; private set; }

/// <summary>
/// The timestamp of the cvc code's last update.
/// </summary>
[JsonProperty(PropertyName = "updated")]
public string Updated { get; private set; }

/// <summary>
/// The cvc2 code.
/// </summary>
[JsonProperty(PropertyName = "cvc2")]
public string Cvc2 { get; private set; }

/// <summary>
/// The status of the cvc2. Can be AVAILABLE, USED, EXPIRED, BLOCKED.
/// </summary>
[JsonProperty(PropertyName = "status")]
public string Status { get; private set; }

/// <summary>
/// Expiry time of the cvc2.
/// </summary>
[JsonProperty(PropertyName = "expiry_time")]
public string ExpiryTime { get; private set; }

/// <summary>
/// Generate a new CVC2 code for a card.
/// </summary>
public static BunqResponse<CardGeneratedCvc2> Create(ApiContext apiContext, IDictionary<string, object> requestMap, int userId, int cardId, IDictionary<string, string> customHeaders = null)
{
if (customHeaders == null) customHeaders = new Dictionary<string, string>();

var apiClient = new ApiClient(apiContext);
var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
requestBytes = SecurityUtils.Encrypt(apiContext, requestBytes, customHeaders);
var responseRaw = apiClient.Post(string.Format(ENDPOINT_URL_CREATE, userId, cardId), requestBytes, customHeaders);

return FromJson<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE);
}

/// <summary>
/// Get the details for a specific generated CVC2 code.
/// </summary>
public static BunqResponse<CardGeneratedCvc2> Get(ApiContext apiContext, int userId, int cardId, int cardGeneratedCvc2Id, IDictionary<string, string> customHeaders = null)
{
if (customHeaders == null) customHeaders = new Dictionary<string, string>();

var apiClient = new ApiClient(apiContext);
var responseRaw = apiClient.Get(string.Format(ENDPOINT_URL_READ, userId, cardId, cardGeneratedCvc2Id), new Dictionary<string, string>(), customHeaders);

return FromJson<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE);
}

/// <summary>
/// Get all generated CVC2 codes for a card.
/// </summary>
public static BunqResponse<List<CardGeneratedCvc2>> List(ApiContext apiContext, int userId, int cardId, IDictionary<string, string> urlParams = null, IDictionary<string, string> customHeaders = null)
{
if (urlParams == null) urlParams = new Dictionary<string, string>();
if (customHeaders == null) customHeaders = new Dictionary<string, string>();

var apiClient = new ApiClient(apiContext);
var responseRaw = apiClient.Get(string.Format(ENDPOINT_URL_LISTING, userId, cardId), urlParams, customHeaders);

return FromJsonList<CardGeneratedCvc2>(responseRaw, OBJECT_TYPE);
}
}
}
7 changes: 5 additions & 2 deletions BunqSdk/Model/Generated/Endpoint/CashRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
namespace Bunq.Sdk.Model.Generated.Endpoint
{
/// <summary>
/// CashRegisters act as an point of sale. They have a specific name and avatar, and optionally a location. A
/// CashRegister is used to create Tabs. A CashRegister can have an QR code that links to one of its Tabs.
/// CashRegisters are virtual points of sale. They have a specific name and avatar, and optionally, a
/// location.<br/>With a CashRegister you can create a Tab and then use a QR code to receive payments.<br/>Check out
/// our Quickstart example to learn how you can easily <a href="/api/1/page/usecase-tab-payment">create Tab
/// payments</a>.<br/><br/>Notification filters can be set on a CashRegister to receive callbacks. For more
/// information check the <a href="/api/1/page/callbacks">dedicated callbacks page</a>.
/// </summary>
public class CashRegister : BunqModel
{
Expand Down
4 changes: 2 additions & 2 deletions BunqSdk/Model/Generated/Endpoint/DraftPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DraftPayment : BunqModel
private const string OBJECT_TYPE = "DraftPayment";

/// <summary>
/// The id of the DraftPayment.
/// The id of the created DrafPayment.
/// </summary>
[JsonProperty(PropertyName = "id")]
public int? Id { get; private set; }
Expand Down Expand Up @@ -83,7 +83,7 @@ public class DraftPayment : BunqModel
/// The Payment or PaymentBatch. This will only be present after the DraftPayment has been accepted.
/// </summary>
[JsonProperty(PropertyName = "object")]
public BunqModel Object { get; private set; }
public DraftPaymentAnchorObject Object { get; private set; }

/// <summary>
/// Create a new DraftPayment.
Expand Down
2 changes: 1 addition & 1 deletion BunqSdk/Model/Generated/Endpoint/MonetaryAccountBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Bunq.Sdk.Model.Generated.Endpoint
/// MonetaryAccountBanks and update specific fields of an existing MonetaryAccountBank. Examples of fields that can
/// be updated are the description, the daily limit and the avatar of the account.<br/><br/>Notification filters can
/// be set on a monetary account level to receive callbacks. For more information check the <a
/// href="/api/2/page/callbacks">dedicated callbacks page</a>.
/// href="/api/1/page/callbacks">dedicated callbacks page</a>.
/// </summary>
public class MonetaryAccountBank : BunqModel
{
Expand Down
4 changes: 3 additions & 1 deletion BunqSdk/Model/Generated/Endpoint/UserCompany.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
namespace Bunq.Sdk.Model.Generated.Endpoint
{
/// <summary>
/// Show the authenticated user, if it is a company.
/// With UserCompany you can retrieve information regarding the authenticated UserCompany and update specific
/// fields.<br/><br/>Notification filters can be set on a UserCompany level to receive callbacks. For more
/// information check the <a href="/api/1/page/callbacks">dedicated callbacks page</a>.
/// </summary>
public class UserCompany : BunqModel
{
Expand Down
4 changes: 3 additions & 1 deletion BunqSdk/Model/Generated/Endpoint/UserPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
namespace Bunq.Sdk.Model.Generated.Endpoint
{
/// <summary>
/// Show the authenticated user, if it is a person.
/// With UserPerson you can retrieve information regarding the authenticated UserPerson and update specific
/// fields.<br/><br/>Notification filters can be set on a UserPerson level to receive callbacks. For more
/// information check the <a href="/api/1/page/callbacks">dedicated callbacks page</a>.
/// </summary>
public class UserPerson : BunqModel
{
Expand Down
22 changes: 22 additions & 0 deletions BunqSdk/Model/Generated/Object/DraftPaymentAnchorObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Bunq.Sdk.Model.Core;
using Bunq.Sdk.Model.Generated.Endpoint;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Bunq.Sdk.Model.Generated.Object
{
/// <summary>
/// </summary>
public class DraftPaymentAnchorObject : BunqModel
{
/// <summary>
/// </summary>
[JsonProperty(PropertyName = "Payment")]
public Payment Payment { get; set; }

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "PaymentBatch")]
public PaymentBatch PaymentBatch { get; set; }
}
}

0 comments on commit 0fe0a00

Please sign in to comment.