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

PS2-148 - Custom and Additional fields lists uninstantiated in datare… #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
102 changes: 51 additions & 51 deletions BuckarooSdk.Tests/Services/IdealQr/IdealQrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,55 @@

namespace BuckarooSdk.Tests.Services.IdealQr
{
[TestClass]
public class IdealQrTests
{
public SdkClient BuckarooClient { get; private set; }

[TestInitialize]
public void Setup()
{
this.BuckarooClient = new SdkClient(TestSettings.Logger);
}

[TestMethod]
public void GenerateTest()
{
var request = this.BuckarooClient.CreateRequest()
.Authenticate(TestSettings.WebsiteKey, TestSettings.SecretKey, false, new CultureInfo("nl-NL"))
.DataRequest()
.SetBasicFields(new DataBase())
.IdealQr()
.Generate(new IdealQrGenerateRequest()
{
Amount = 0.02m,
Description = "Dit is de description.",
Expiration = DateTime.Now.AddDays(4),
AmountIsChangeable = true,
MinAmount = 0.02m,
MaxAmount = 0.05m,
ImageSize = 250,
PurchaseId = "purchaseId",
IsOneOff = true,
IsProcessing = false,
});

var response = request.Execute();

var rawRequest = response.BuckarooSdkLogger.GetRawRequest();

var actionResponse = response.GetActionResponse<IdealQrGenerateResponse>();

var qrImageUrl = actionResponse.QrImageUrl;

//From this point on a Merchant can do anything he wants with a qr. He can save the link if it is later on used in an email
//or printed on a sticker or poster. He can also return it and place it in a <img> tag on a website. In this example I run
//just the image url to confirm that is returns a legit image of an iDEAL QR image.

if (response.Status.Code.Code == BuckarooSdk.Constants.Status.Success)
{
Process.Start(actionResponse.QrImageUrl);
}
}
}
[TestClass]
public class IdealQrTests
{
public SdkClient BuckarooClient { get; private set; }

[TestInitialize]
public void Setup()
{
this.BuckarooClient = new SdkClient(TestSettings.Logger);
}

[TestMethod]
public void GenerateTest()
{
var request = this.BuckarooClient.CreateRequest()
.Authenticate(TestSettings.WebsiteKey, TestSettings.SecretKey, false, new CultureInfo("nl-NL"))
.DataRequest()
.SetBasicFields(new DataBase())
.IdealQr()
.Generate(new IdealQrGenerateRequest()
{
Amount = 0.02m,
Description = "Dit is de description.",
Expiration = DateTime.Now.AddDays(4),
AmountIsChangeable = true,
MinAmount = 0.02m,
MaxAmount = 0.05m,
ImageSize = 250,
PurchaseId = "purchaseId",
IsOneOff = true,
IsProcessing = false,
});

var response = request.Execute();

var rawRequest = response.BuckarooSdkLogger.GetRawRequest();

var actionResponse = response.GetActionResponse<IdealQrGenerateResponse>();

var qrImageUrl = actionResponse.QrImageUrl;

//From this point on a Merchant can do anything he wants with a qr. He can save the link if it is later on used in an email
//or printed on a sticker or poster. He can also return it and place it in a <img> tag on a website. In this example I run
//just the image url to confirm that is returns a legit image of an iDEAL QR image.

if (response.Status.Code.Code == BuckarooSdk.Constants.Status.Success)
{
Process.Start(actionResponse.QrImageUrl);
}
}
}
}
14 changes: 6 additions & 8 deletions BuckarooSdk/Connection/BuckarooDelegatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace BuckarooSdk.Connection
{
internal class BuckarooDelegatingHandler : DelegatingHandler
internal class BuckarooDelegatingHandler : DelegatingHandler
{
private SignatureCalculationService SignatureCalculationService { get; }

Expand All @@ -35,12 +35,9 @@ internal BuckarooDelegatingHandler(string websiteKey, string apiKey, string chan
private readonly string _channel;
private readonly string _culture;
private readonly string _software;

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = null;

var requestUri = WebUtility.UrlEncode(request.RequestUri.Authority + request.RequestUri.PathAndQuery).ToLower();
var requestUri = WebUtility.UrlEncode(request.RequestUri.Authority + request.RequestUri.PathAndQuery).ToLower();

var requestHttpMethod = request.Method.Method;

Expand All @@ -60,17 +57,18 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}

var authorizationHeaderString = this.SignatureCalculationService.CalculateSignature(content, requestHttpMethod, requestTimeStamp, nonce, requestUri, this._websiteKey, this._apiKey);
var authorizationHeaderString = this.SignatureCalculationService.CalculateSignature(content, requestHttpMethod, requestTimeStamp, nonce,
requestUri, this._websiteKey, this._apiKey);

request.Headers.Authorization = new AuthenticationHeaderValue("hmac", authorizationHeaderString);
// set other headers
request.Headers.Add("culture", this._culture);
request.Headers.Add("channel", this._channel);
request.Headers.Add("software", this._software);

response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
HttpResponseMessage response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

if (!await this.ValidateResponse(response, request.Method.ToString(), requestUri).ConfigureAwait(false))
if (!await this.ValidateResponse(response, request.Method.ToString(), requestUri).ConfigureAwait(false))
{
throw new AuthenticationException();
}
Expand Down
122 changes: 61 additions & 61 deletions BuckarooSdk/DataTypes/RequestBases/DataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,70 @@

namespace BuckarooSdk.DataTypes.RequestBases
{
public class DataBase : IRequestBase
{
public IpAddress ClientIp { get; set; }
public string ReturnUrl { get; set; }
public string ReturnUrlCancel { get; set; }
public string ReturnUrlError { get; set; }
public string ReturnUrlReject { get; set; }
public string Invoice { get; set; }
public string Description { get; set; }
public string Currency { get; set; }
public decimal Amount { get; set; }
public decimal AmountCredit { get; set; }
public string OriginalTransactionKey { get; set; }
public TransactionReference OriginalTransactionReference { get; set; }
public ContinueOnIncomplete ContinueOnIncomplete { get; set; }
public string ClientUserAgent { get; set; }
[JsonProperty()]
internal Services.DataRequestServices Services { get; set; }
[JsonProperty()]
internal CustomParameters CustomParameters { get; set; }
[JsonProperty()]
internal AdditionalParameters AdditionalParameters { get; set; }
public class DataBase : IRequestBase
{
public IpAddress ClientIp { get; set; }
public string ReturnUrl { get; set; }
public string ReturnUrlCancel { get; set; }
public string ReturnUrlError { get; set; }
public string ReturnUrlReject { get; set; }
public string Invoice { get; set; }
public string Description { get; set; }
public string Currency { get; set; }
public decimal Amount { get; set; }
public decimal AmountCredit { get; set; }
public string OriginalTransactionKey { get; set; }
public TransactionReference OriginalTransactionReference { get; set; }
public ContinueOnIncomplete ContinueOnIncomplete { get; set; }
public string ClientUserAgent { get; set; }
[JsonProperty()]
internal Services.DataRequestServices Services { get; set; }
[JsonProperty()]
internal CustomParameters CustomParameters { get; set; }
[JsonProperty()]
internal AdditionalParameters AdditionalParameters { get; set; }

public DataBase()
{
//this.CustomParameters = new CustomParameters();
//this.AdditionalParameters = new AdditionalParameters();
this.Services = new Services.DataRequestServices();
this.OriginalTransactionReference = new TransactionReference();
this.ClientIp = new IpAddress();
}
public DataBase()
{
this.CustomParameters = new CustomParameters();
this.AdditionalParameters = new AdditionalParameters();
this.Services = new Services.DataRequestServices();
this.OriginalTransactionReference = new TransactionReference();
this.ClientIp = new IpAddress();
}

/// <summary>
/// Adds a custom parameter to the transactionbase. requires a parameter key and a parameter value.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public DataBase AddCustomParameter(string key, string value)
{
this.CustomParameters.List.Add(new CustomParameter()
{
Name = key,
Value = value
});
/// <summary>
/// Adds a custom parameter to the transactionbase. requires a parameter key and a parameter value.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public DataBase AddCustomParameter(string key, string value)
{
this.CustomParameters.List.Add(new CustomParameter()
{
Name = key,
Value = value
});

return this;
}
return this;
}

/// <summary>
/// Adds an additional parameter to the transactionbase. requires a parameter key and a parameter value.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public DataBase AddAdditionalParameter(string key, string value)
{
this.AdditionalParameters.AdditionalParameter.Add(new AdditionalParameter()
{
Name = key,
Value = value
});
/// <summary>
/// Adds an additional parameter to the transactionbase. requires a parameter key and a parameter value.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public DataBase AddAdditionalParameter(string key, string value)
{
this.AdditionalParameters.AdditionalParameter.Add(new AdditionalParameter()
{
Name = key,
Value = value
});

return this;
}
}
return this;
}
}
}