Skip to content
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
12 changes: 11 additions & 1 deletion src/Client/NotificationArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Trustly.Api.Client

public delegate Task NotificationFailResponseDelegate(string method, string uuid, string message);

public delegate Task NotificationCustomResponseDelegate(string method, string uuid, string status, string message);

public class NotificationArgs<TData>
where TData : IRequestParamsData
{
Expand All @@ -18,8 +20,10 @@ public class NotificationArgs<TData>

private readonly NotificationResponseDelegate _onOK;
private readonly NotificationFailResponseDelegate _onFailed;
private readonly NotificationCustomResponseDelegate _onCustomStatus;

public NotificationArgs(TData data, string method, string uuid, NotificationResponseDelegate onOK, NotificationFailResponseDelegate onFailed)
public NotificationArgs(TData data, string method, string uuid, NotificationResponseDelegate onOK, NotificationFailResponseDelegate onFailed,
NotificationCustomResponseDelegate onCustomStatus)
{
this.Data = data;

Expand All @@ -28,6 +32,7 @@ public NotificationArgs(TData data, string method, string uuid, NotificationResp

this._onOK = onOK;
this._onFailed = onFailed;
this._onCustomStatus = onCustomStatus;
}

public void RespondWithOK()
Expand All @@ -39,5 +44,10 @@ public void RespondWithFailed(string message)
{
this._onFailed(this._method, this._uuid, message);
}

public void RespondWithCustomStatus(string status, string message)
{
this._onCustomStatus(this._method, this._uuid, status, message);
}
}
}
34 changes: 19 additions & 15 deletions src/Client/TrustlyApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ public class TrustlyApiClient : IDisposable
public event EventHandler<NotificationArgs<DebitNotificationData>> OnDebit;
public event EventHandler<NotificationArgs<PayoutConfirmationNotificationData>> OnPayoutConfirmation;
public event EventHandler<NotificationArgs<PendingNotificationData>> OnPending;
public event EventHandler<NotificationArgs<KycNotificationData>> OnKyc;
public event EventHandler<NotificationArgs<UnknownNotificationData>> OnUnknownNotification;

private readonly Dictionary<string, Func<string, NotificationResponseDelegate, NotificationFailResponseDelegate, int>> _methodToNotificationMapper
= new Dictionary<string, Func<string, NotificationResponseDelegate, NotificationFailResponseDelegate, int>>();
private readonly Dictionary<string, Func<string, NotificationResponseDelegate, NotificationFailResponseDelegate, NotificationCustomResponseDelegate, int>> _methodToNotificationMapper
= new Dictionary<string, Func<string, NotificationResponseDelegate, NotificationFailResponseDelegate, NotificationCustomResponseDelegate, int>>();

public TrustlyApiClient(TrustlyApiClientSettings settings)
{
this.Settings = settings;
this._signer = new JsonRpcSigner(serializer, this.Settings);

this._methodToNotificationMapper.Add("account", (json, ok, error) => this.HandleNotificationFromString(json, this.OnAccount, ok, error));
this._methodToNotificationMapper.Add("cancel", (json, ok, error) => this.HandleNotificationFromString(json, this.OnCancel, ok, error));
this._methodToNotificationMapper.Add("credit", (json, ok, error) => this.HandleNotificationFromString(json, this.OnCredit, ok, error));
this._methodToNotificationMapper.Add("debit", (json, ok, error) => this.HandleNotificationFromString(json, this.OnDebit, ok, error));
this._methodToNotificationMapper.Add("payoutconfirmation", (json, ok, error) => this.HandleNotificationFromString(json, this.OnPayoutConfirmation, ok, error));
this._methodToNotificationMapper.Add("pending", (json, ok, error) => this.HandleNotificationFromString(json, this.OnPending, ok, error));
this._methodToNotificationMapper.Add("account", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnAccount, ok, error, customStatus));
this._methodToNotificationMapper.Add("cancel", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnCancel, ok, error, customStatus));
this._methodToNotificationMapper.Add("credit", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnCredit, ok, error, customStatus));
this._methodToNotificationMapper.Add("debit", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnDebit, ok, error, customStatus));
this._methodToNotificationMapper.Add("payoutconfirmation", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnPayoutConfirmation, ok, error, customStatus));
this._methodToNotificationMapper.Add("pending", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnPending, ok, error, customStatus));
this._methodToNotificationMapper.Add("kyc", (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnKyc, ok, error, customStatus));

this._methodToNotificationMapper.Add(string.Empty, (json, ok, error) => this.HandleNotificationFromString(json, this.OnUnknownNotification, ok, error));
this._methodToNotificationMapper.Add(string.Empty, (json, ok, error, customStatus) => this.HandleNotificationFromString(json, this.OnUnknownNotification, ok, error, customStatus));

TrustlyApiClient._staticRegisteredClients.Add(this);
}
Expand Down Expand Up @@ -258,14 +260,15 @@ public TRespData SendRequest<TReqData, TRespData>(TReqData requestData, string m
return rpcResponse.Result.Data;
}

public async Task<int> HandleNotificationFromRequestAsync(HttpRequest request, NotificationResponseDelegate onOK = null, NotificationFailResponseDelegate onFailed = null)
public async Task<int> HandleNotificationFromRequestAsync(HttpRequest request, NotificationResponseDelegate onOK = null,
NotificationFailResponseDelegate onFailed = null, NotificationCustomResponseDelegate onCustomStatus = null)
{
if (string.Equals(request.Method, "post", StringComparison.InvariantCultureIgnoreCase))
{
using (var sr = new StreamReader(request.Body))
{
var requestStringBody = await sr.ReadToEndAsync();
return this.HandleNotificationFromString(requestStringBody, onOK, onFailed);
return this.HandleNotificationFromString(requestStringBody, onOK, onFailed, onCustomStatus);
}
}
else
Expand All @@ -274,7 +277,7 @@ public async Task<int> HandleNotificationFromRequestAsync(HttpRequest request, N
}
}

public int HandleNotificationFromString(string jsonString, NotificationResponseDelegate onOK = null, NotificationFailResponseDelegate onFailed = null)
public int HandleNotificationFromString(string jsonString, NotificationResponseDelegate onOK = null, NotificationFailResponseDelegate onFailed = null, NotificationCustomResponseDelegate onCustomStatus = null)
{
var jsonToken = JToken.Parse(jsonString);

Expand All @@ -287,14 +290,15 @@ public int HandleNotificationFromString(string jsonString, NotificationResponseD

// This will then call generic method HandleNotificationFromString below.
// We do it this way to keep the dynamic generic parameters intact.
return mapper(jsonString, onOK, onFailed);
return mapper(jsonString, onOK, onFailed, onCustomStatus);
}

private int HandleNotificationFromString<TReqData>(
string jsonString,
EventHandler<NotificationArgs<TReqData>> eventHandler,
NotificationResponseDelegate onOK,
NotificationFailResponseDelegate onFailed
NotificationFailResponseDelegate onFailed,
NotificationCustomResponseDelegate onCustomStatus
)
where TReqData : IRequestParamsData
{
Expand All @@ -318,7 +322,7 @@ NotificationFailResponseDelegate onFailed

try
{
eventHandler(this, new NotificationArgs<TReqData>(rpcRequest.Params.Data, rpcRequest.Method, rpcRequest.Params.UUID, onOK, onFailed));
eventHandler(this, new NotificationArgs<TReqData>(rpcRequest.Params.Data, rpcRequest.Method, rpcRequest.Params.UUID, onOK, onFailed, onCustomStatus));
}
catch (Exception ex)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Client/TrustlyApiClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ await client.HandleNotificationFromRequestAsync(
{
responseCount++;
await Respond(client, context.Response, rpcMethod, uuid, "FAILED", message, HttpStatusCode.InternalServerError);
},
onCustomStatus: async (rpcMethod, uuid, customStatus, message) =>
{
responseCount++;
await Respond(client, context.Response, rpcMethod, uuid, customStatus, message, HttpStatusCode.OK);
}
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Base\" />
<Folder Include="Notifications\" />
<Folder Include="Requests\" />
<Folder Include="Common\" />
</ItemGroup>
Expand Down
80 changes: 80 additions & 0 deletions src/Domain/Notifications/Kyc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Newtonsoft.Json;
using System;
using Trustly.Api.Domain.Base;

namespace Trustly.Api.Domain.Notifications
{
public class KycNotificationData : AbstractFromTrustlyRequestParamsData<KycNotificationDataAttributes>
{
[JsonProperty("orderid")]
public string OrderID { get; set; }

[JsonProperty("messageid")]
public string MessageID { get; set; }

[JsonProperty("kycentityid")]
public string KycEntityID { get; set; }

[JsonProperty("notificationid")]
public string NotificationID { get; set; }
}

public class KycNotificationDataAttributes: AbstractRequestParamsDataAttributes
{
/// <summary>
/// Entity’s personal number (SSN)
/// Can be considered as a unique identifier
/// Only present in markets where SSN is applicable
/// </summary>
[JsonProperty("personid")]
public string MessageID { get; set; }

/// <summary>
/// Entity’s first name.
/// </summary>
[JsonProperty("firstname")]
public string FirstName { get; set; }

/// <summary>
/// Entity’s last name.
/// </summary>
[JsonProperty("lastname")]
public string LastName { get; set; }

/// <summary>
/// Entity’s date of birth in YYYY-MM-DD format.
/// </summary>
[JsonProperty("dob")]
public DateTime DateOfBirth { get; set; }

/// <summary>
/// Entity’s street name.
/// </summary>
[JsonProperty("street")]
public string Street { get; set; }

/// <summary>
/// Entity’s ZIP code.
/// </summary>
[JsonProperty("zipcode")]
public string ZipCode { get; set; }

/// <summary>
/// Entity’s city.
/// </summary>
[JsonProperty("city")]
public string City { get; set; }

/// <summary>
/// Entity’s country of residence
/// </summary>
[JsonProperty("country")]
public string Country { get; set; }

[JsonProperty("abort")]
public int? Abort { get; set; }

[JsonProperty("abortmessage")]
public string AbortMessage { get; set; }
}
}