mirror of
https://github.com/NecroticBamboo/QRBee.git
synced 2025-12-21 12:11:53 +00:00
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using QRBee.Api.Services.Database;
|
|
using QRBee.Core.Data;
|
|
|
|
namespace QRBee.Api.Services;
|
|
|
|
internal class PaymentGateway : IPaymentGateway
|
|
{
|
|
private readonly ILogger<Storage> _logger;
|
|
|
|
public PaymentGateway(ILogger<Storage> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public Task<GatewayResponse> Payment(TransactionInfo info, ClientCardData clientCardData)
|
|
{
|
|
if (info.Request.ClientResponse.MerchantRequest.Amount > 100)
|
|
{
|
|
_logger.LogInformation($"Transaction with id: {info.Id} failed");
|
|
return Task.FromResult(new GatewayResponse
|
|
{
|
|
Success = false,
|
|
ErrorMessage = "Amount is too high",
|
|
GatewayTransactionId = Guid.NewGuid().ToString()
|
|
});
|
|
}
|
|
_logger.LogInformation($"Transaction with id: {info.Id} succeeded");
|
|
return Task.FromResult(new GatewayResponse
|
|
{
|
|
Success = true,
|
|
GatewayTransactionId = Guid.NewGuid().ToString()
|
|
});
|
|
}
|
|
|
|
public Task<GatewayResponse> CancelPayment(TransactionInfo info)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(info.GatewayTransactionId))
|
|
{
|
|
_logger.LogInformation($"Transaction with id: {info.Id} was cancelled");
|
|
return Task.FromResult(new GatewayResponse
|
|
{
|
|
Success = false,
|
|
ErrorMessage = "Either payment gateway isn't working or the transaction is old",
|
|
GatewayTransactionId = info.GatewayTransactionId
|
|
});
|
|
}
|
|
|
|
_logger.LogInformation($"Transaction with id: {info.Id} succeeded");
|
|
return Task.FromResult(new GatewayResponse
|
|
{
|
|
Success = true,
|
|
GatewayTransactionId = info.GatewayTransactionId
|
|
});
|
|
}
|
|
} |