-
Notifications
You must be signed in to change notification settings - Fork 115
/
TerminalLocalApi.cs
121 lines (111 loc) · 6.97 KB
/
TerminalLocalApi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Net.Security;
using System.Threading;
using System.Threading.Tasks;
using Adyen.ApiSerialization;
using Adyen.Model.TerminalApi;
using Adyen.Security;
using Adyen.Service.Resource.Terminal;
namespace Adyen.Service
{
[Obsolete("Use ITerminalApiLocalService instead.")]
public interface ITerminalLocalApi
{
/// <summary>
/// Terminal Api https call
/// </summary>
/// <param name="saleToPoiRequest"></param>
/// <param name="encryptionCredentialDetails"></param>
/// <returns></returns>
[Obsolete("Use ITerminalApiLocalService.RequestEncrypted(..) instead.")]
SaleToPOIResponse TerminalRequest(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails);
/// <summary>
/// Terminal Api async https call
/// </summary>
/// <param name="saleToPoiRequest"></param>
/// <param name="encryptionCredentialDetails"></param>
/// <returns></returns>
[Obsolete("Use ITerminalApiLocalService.RequestEncryptedAsync(..) instead.")]
Task<SaleToPOIResponse> TerminalRequestAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken = default);
/// <summary>
/// Terminal Api https call
/// </summary>
/// <param name="saleToPoiRequest"></param>
/// <param name="encryptionCredentialDetails"></param>
/// <param name="remoteCertificateValidationCallback"></param>
/// <returns></returns>
[Obsolete("Use ITerminalApiLocalService.RequestEncrypted(..) instead, you can pass the RemoteCertificateValidationCallback on the HttpClient-level.")]
SaleToPOIResponse TerminalRequest(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, RemoteCertificateValidationCallback remoteCertificateValidationCallback);
/// <summary>
/// Used to decrypt the notification received
/// </summary>
/// <param name="notification"></param>
/// <param name="encryptionCredentialDetails"></param>
/// <returns></returns>
[Obsolete("Use ITerminalApiLocalService.DecryptNotification(..) instead.")]
string DecryptNotification(string notification, EncryptionCredentialDetails encryptionCredentialDetails);
}
[Obsolete("Use TerminalApiLocalService instead.")]
public class TerminalLocalApi: AbstractService, ITerminalLocalApi
{
private readonly TerminalApiLocal _terminalApiLocal;
private readonly SaleToPoiMessageSerializer _saleToPoiMessageSerializer;
private readonly SaleToPoiMessageSecuredEncryptor _messageSecuredEncryptor;
private readonly SaleToPoiMessageSecuredSerializer _saleToPoiMessageSecuredSerializer;
[Obsolete("Use TerminalApiLocalService instead.")]
public TerminalLocalApi(Client client)
: base(client)
{
_terminalApiLocal = new TerminalApiLocal(this);
_saleToPoiMessageSerializer = new SaleToPoiMessageSerializer();
_messageSecuredEncryptor = new SaleToPoiMessageSecuredEncryptor();
_saleToPoiMessageSecuredSerializer = new SaleToPoiMessageSecuredSerializer();
}
[Obsolete("Use TerminalApiLocalService.RequestEncrypted(..) instead.")]
public SaleToPOIResponse TerminalRequest(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails)
{
var saleToPoiRequestMessageSerialized = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + saleToPoiRequestMessageSerialized);
var saleToPoiRequestMessageSecured = _messageSecuredEncryptor.Encrypt(saleToPoiRequestMessageSerialized, saleToPoiRequest.MessageHeader, encryptionCredentialDetails);
var serializeSaleToPoiRequestMessageSecured = _saleToPoiMessageSerializer.Serialize(saleToPoiRequestMessageSecured);
var response = _terminalApiLocal.Request(serializeSaleToPoiRequestMessageSecured);
if (string.IsNullOrEmpty(response))
{
return null;
}
var saleToPoiResponseSecured = _saleToPoiMessageSecuredSerializer.Deserialize(response);
var decryptResponse = _messageSecuredEncryptor.Decrypt(saleToPoiResponseSecured, encryptionCredentialDetails);
Client.LogLine("Response: \n" + decryptResponse);
return _saleToPoiMessageSerializer.Deserialize(decryptResponse);
}
[Obsolete("Use TerminalApiLocalService.RequestEncryptedAsync(..) instead.")]
public async Task<SaleToPOIResponse> TerminalRequestAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken = default)
{
var saleToPoiRequestMessageSerialized = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + saleToPoiRequestMessageSerialized);
var saleToPoiRequestMessageSecured = _messageSecuredEncryptor.Encrypt(saleToPoiRequestMessageSerialized, saleToPoiRequest.MessageHeader, encryptionCredentialDetails);
var serializeSaleToPoiRequestMessageSecured = _saleToPoiMessageSerializer.Serialize(saleToPoiRequestMessageSecured);
var response = await _terminalApiLocal.RequestAsync(serializeSaleToPoiRequestMessageSecured, cancellationToken: cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(response))
{
return null;
}
var saleToPoiResponseSecured = _saleToPoiMessageSecuredSerializer.Deserialize(response);
var decryptResponse = _messageSecuredEncryptor.Decrypt(saleToPoiResponseSecured, encryptionCredentialDetails);
Client.LogLine("Response: \n" + decryptResponse);
return _saleToPoiMessageSerializer.Deserialize(decryptResponse);
}
[Obsolete("Use the overload of the method without passing RemoteCertificateValidationCallback. The terminal certificate validation is handled at the http request the adyen library")]
public SaleToPOIResponse TerminalRequest(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, RemoteCertificateValidationCallback remoteCertificateValidationCallback)
{
return TerminalRequest(saleToPoiRequest: saleToPoiRequest, encryptionCredentialDetails: encryptionCredentialDetails);
}
[Obsolete("Use TerminalApiLocalService.DecryptNotification(..) instead.")]
public string DecryptNotification(string notification, EncryptionCredentialDetails encryptionCredentialDetails)
{
var saleToPoiMessageSecured = _saleToPoiMessageSecuredSerializer.Deserialize(notification);
var decryptNotification = _messageSecuredEncryptor.Decrypt(saleToPoiMessageSecured, encryptionCredentialDetails);
return decryptNotification;
}
}
}