2025-12-05 17:27:38 +03:30
|
|
|
using BackOffice.BFF.Application.Common.Interfaces;
|
2025-12-08 21:10:21 +03:30
|
|
|
using BackOffice.BFF.ManualPayment.Protobuf;
|
2025-12-05 17:27:38 +03:30
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace BackOffice.BFF.Application.ManualPaymentCQ.Commands.CreateManualPayment;
|
|
|
|
|
|
|
|
|
|
public class CreateManualPaymentCommandHandler : IRequestHandler<CreateManualPaymentCommand, CreateManualPaymentResponseDto>
|
|
|
|
|
{
|
|
|
|
|
private readonly IApplicationContractContext _context;
|
|
|
|
|
private readonly ILogger<CreateManualPaymentCommandHandler> _logger;
|
|
|
|
|
|
|
|
|
|
public CreateManualPaymentCommandHandler(
|
|
|
|
|
IApplicationContractContext context,
|
|
|
|
|
ILogger<CreateManualPaymentCommandHandler> logger)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<CreateManualPaymentResponseDto> Handle(CreateManualPaymentCommand request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation(
|
|
|
|
|
"Creating manual payment via BFF for UserId {UserId}, Amount {Amount}, Type {Type}",
|
|
|
|
|
request.UserId,
|
|
|
|
|
request.Amount,
|
|
|
|
|
request.Type);
|
|
|
|
|
|
|
|
|
|
var grpcRequest = new CreateManualPaymentRequest
|
|
|
|
|
{
|
|
|
|
|
UserId = request.UserId,
|
|
|
|
|
Amount = request.Amount,
|
2025-12-08 21:10:21 +03:30
|
|
|
Type = request.Type,
|
2025-12-05 17:27:38 +03:30
|
|
|
Description = request.Description
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.ReferenceNumber))
|
|
|
|
|
{
|
2025-12-08 21:10:21 +03:30
|
|
|
grpcRequest.ReferenceNumber = request.ReferenceNumber;
|
2025-12-05 17:27:38 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response = await _context.ManualPayments.CreateManualPaymentAsync(grpcRequest, cancellationToken: cancellationToken);
|
|
|
|
|
|
|
|
|
|
return new CreateManualPaymentResponseDto
|
|
|
|
|
{
|
|
|
|
|
Id = response.Id
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|