Skip to content

Commit 845e925

Browse files
authored
Add logs for payment status check (#2778)
1 parent e553d38 commit 845e925

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/JoinRpg.Services.Impl/PaymentsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private ApiConfiguration GetApiConfiguration(int projectId, int claimId)
7474
}
7575

7676
private BankApi GetApi(int projectId, int claimId)
77-
=> new(clientFactory, GetApiConfiguration(projectId, claimId));
77+
=> new(clientFactory, GetApiConfiguration(projectId, claimId), logger);
7878

7979
private async Task<Claim> GetClaimAsync(int projectId, int claimId)
8080
{

src/PscbApi/BankApi.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net;
33
using System.Security.Cryptography;
44
using System.Text;
5+
using Microsoft.Extensions.Logging;
56
using Newtonsoft.Json;
67
using PscbApi.Models;
78

@@ -14,7 +15,7 @@ public class BankApi
1415
{
1516
private readonly IHttpClientFactory clientFactory;
1617
private readonly ApiConfiguration _configuration;
17-
18+
private readonly ILogger logger;
1819
private readonly byte[] _keyAsUtf8;
1920

2021
/// <summary>
@@ -38,10 +39,11 @@ public class BankApi
3839
/// <summary>
3940
/// Creates new instance of PSCB API object
4041
/// </summary>
41-
public BankApi(IHttpClientFactory clientFactory, ApiConfiguration configuration)
42+
public BankApi(IHttpClientFactory clientFactory, ApiConfiguration configuration, ILogger logger)
4243
{
4344
this.clientFactory = clientFactory;
4445
_configuration = configuration;
46+
this.logger = logger;
4547
_keyAsUtf8 = ActualApiKey.ToUtf8Bytes();
4648
}
4749

@@ -59,9 +61,8 @@ protected async Task<TResponse> ApiRequestAsync<TRequest, TResponse>(string url,
5961
{
6062
if (DebugOutput)
6163
{
62-
System.Diagnostics.Debug.WriteLine("Request to bank:");
63-
System.Diagnostics.Debug.WriteLine(url);
64-
System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(request, Formatting.Indented));
64+
// This could contain senstive information, so it will work only with DebugOutput=true
65+
logger.LogDebug("Request to bank to {url} {bankRequest}", url, JsonConvert.SerializeObject(request, Formatting.Indented));
6566
}
6667

6768
var requestAsJson = JsonConvert.SerializeObject(request, Formatting.None);
@@ -81,8 +82,8 @@ protected async Task<TResponse> ApiRequestAsync<TRequest, TResponse>(string url,
8182

8283
if (DebugOutput)
8384
{
84-
System.Diagnostics.Debug.WriteLine("Response from bank:");
85-
System.Diagnostics.Debug.WriteLine(
85+
// This could contain senstive information, so it will work only with DebugOutput=true
86+
logger.LogDebug("Response from bank: {bankResponse}",
8687
result is null
8788
? "empty"
8889
: JsonConvert.SerializeObject(result, Formatting.Indented));
@@ -91,12 +92,6 @@ result is null
9192
return result ?? throw new PscbApiRequestException<TRequest>(url, request, signature, "Response was empty");
9293
}
9394

94-
if (DebugOutput)
95-
{
96-
System.Diagnostics.Debug.WriteLine("Response from bank:");
97-
System.Diagnostics.Debug.WriteLine($"{httpResponse.StatusCode} {httpResponse.ReasonPhrase}");
98-
}
99-
10095
throw new PscbApiRequestException<TRequest>(url, request, signature, $"{httpResponse.StatusCode} {httpResponse.ReasonPhrase}");
10196
}
10297

@@ -194,10 +189,7 @@ public static BankResponseInfo HandlePaymentResponse(string description)
194189
public async Task<T> GetPaymentInfoAsync<T>(string orderId, bool getCardData = false, bool getFiscalData = false)
195190
where T : PaymentInfoBase, new()
196191
{
197-
if (string.IsNullOrWhiteSpace(orderId))
198-
{
199-
throw new ArgumentNullException(nameof(orderId));
200-
}
192+
ArgumentNullException.ThrowIfNullOrWhiteSpace(orderId);
201193

202194
var queryParams = new PaymentInfoQueryParams
203195
{
@@ -212,8 +204,13 @@ public async Task<T> GetPaymentInfoAsync<T>(string orderId, bool getCardData = f
212204
queryParams);
213205
}
214206

215-
public Task<PaymentInfo> GetPaymentInfoAsync(string orderId, bool getCardData = false, bool getFiscalData = false)
216-
=> GetPaymentInfoAsync<PaymentInfo>(orderId, getCardData, getFiscalData);
207+
public async Task<PaymentInfo> GetPaymentInfoAsync(string orderId, bool getCardData = false, bool getFiscalData = false)
208+
{
209+
logger.LogDebug("Getting payment info by {orderId}. GetCardData={getCardData}, GetFiscalData={getFiscalData}", orderId, getCardData, getFiscalData);
210+
var result = await GetPaymentInfoAsync<PaymentInfo>(orderId, getCardData, getFiscalData);
211+
logger.LogInformation("Received payment info for {orderId} from bank, status={paymentStatus} ({paymentSubStatus})", orderId, result.Payment?.Status, result.Payment?.SubStatus);
212+
return result;
213+
}
217214

218215

219216
/// <summary>

0 commit comments

Comments
 (0)