- Removed all BTCPay references from services and configuration
- Implemented SilverPAY as sole payment provider (no fallback)
- Fixed JWT authentication with proper key length (256+ bits)
- Added UsersController with full CRUD operations
- Updated User model with Email and Role properties
- Configured TeleBot with real Telegram bot token
- Fixed launchSettings.json with JWT environment variable
- E2E tests passing for authentication, catalog, orders
- Payment creation pending SilverPAY server fix
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
190 lines
6.2 KiB
C#
190 lines
6.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using LittleShop.Services;
|
|
using LittleShop.Enums;
|
|
|
|
namespace LittleShop.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/silverpay-test")]
|
|
public class SilverPayTestController : ControllerBase
|
|
{
|
|
private readonly ISilverPayService _silverPayService;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILogger<SilverPayTestController> _logger;
|
|
|
|
public SilverPayTestController(
|
|
ISilverPayService silverPayService,
|
|
IConfiguration configuration,
|
|
ILogger<SilverPayTestController> logger)
|
|
{
|
|
_silverPayService = silverPayService;
|
|
_configuration = configuration;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test SilverPAY connection and configuration
|
|
/// </summary>
|
|
[HttpGet("connection")]
|
|
public async Task<IActionResult> TestConnection()
|
|
{
|
|
try
|
|
{
|
|
var baseUrl = _configuration["SilverPay:BaseUrl"];
|
|
var hasApiKey = !string.IsNullOrEmpty(_configuration["SilverPay:ApiKey"]);
|
|
var useSilverPay = _configuration.GetValue<bool>("PaymentProvider:UseSilverPay", false);
|
|
|
|
// Try to get exchange rate as a simple connectivity test
|
|
decimal? rate = null;
|
|
string? error = null;
|
|
try
|
|
{
|
|
rate = await _silverPayService.GetExchangeRateAsync("BTC", "GBP");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
error = ex.Message;
|
|
}
|
|
|
|
return Ok(new
|
|
{
|
|
service = "SilverPAY",
|
|
enabled = useSilverPay,
|
|
baseUrl,
|
|
hasApiKey,
|
|
connectionTest = rate.HasValue ? "Success" : "Failed",
|
|
exchangeRate = rate,
|
|
error,
|
|
timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error testing SilverPAY connection");
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test creating a SilverPAY order
|
|
/// </summary>
|
|
[HttpPost("create-order")]
|
|
public async Task<IActionResult> TestCreateOrder([FromBody] TestOrderRequest request)
|
|
{
|
|
try
|
|
{
|
|
var useSilverPay = _configuration.GetValue<bool>("PaymentProvider:UseSilverPay", false);
|
|
if (!useSilverPay)
|
|
{
|
|
return BadRequest(new { error = "SilverPAY is not enabled. Set PaymentProvider:UseSilverPay to true in configuration." });
|
|
}
|
|
|
|
// Create a test order
|
|
var order = await _silverPayService.CreateOrderAsync(
|
|
request.ExternalId ?? $"TEST-{Guid.NewGuid():N}",
|
|
request.Amount,
|
|
request.Currency,
|
|
$"Test order - {request.Amount} GBP in {request.Currency}",
|
|
request.WebhookUrl
|
|
);
|
|
|
|
_logger.LogInformation("Created test SilverPAY order: {OrderId}", order.Id);
|
|
|
|
return Ok(new
|
|
{
|
|
success = true,
|
|
orderId = order.Id,
|
|
externalId = order.ExternalId,
|
|
amount = order.Amount,
|
|
currency = order.Currency,
|
|
paymentAddress = order.PaymentAddress,
|
|
cryptoAmount = order.CryptoAmount,
|
|
status = order.Status,
|
|
expiresAt = order.ExpiresAt,
|
|
message = $"Send {order.CryptoAmount ?? order.Amount} {order.Currency} to {order.PaymentAddress}"
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error creating test SilverPAY order");
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get status of a SilverPAY order
|
|
/// </summary>
|
|
[HttpGet("order/{orderId}")]
|
|
public async Task<IActionResult> GetOrderStatus(string orderId)
|
|
{
|
|
try
|
|
{
|
|
var order = await _silverPayService.GetOrderStatusAsync(orderId);
|
|
if (order == null)
|
|
{
|
|
return NotFound(new { error = $"Order {orderId} not found" });
|
|
}
|
|
|
|
return Ok(new
|
|
{
|
|
orderId = order.Id,
|
|
externalId = order.ExternalId,
|
|
amount = order.Amount,
|
|
currency = order.Currency,
|
|
paymentAddress = order.PaymentAddress,
|
|
cryptoAmount = order.CryptoAmount,
|
|
status = order.Status,
|
|
createdAt = order.CreatedAt,
|
|
expiresAt = order.ExpiresAt,
|
|
paidAt = order.PaidAt,
|
|
transactionHash = order.TransactionHash,
|
|
confirmations = order.Confirmations,
|
|
paymentDetails = order.PaymentDetails
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting SilverPAY order status");
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test exchange rate conversion
|
|
/// </summary>
|
|
[HttpGet("exchange-rate")]
|
|
public async Task<IActionResult> GetExchangeRate([FromQuery] string crypto = "BTC", [FromQuery] string fiat = "GBP")
|
|
{
|
|
try
|
|
{
|
|
var rate = await _silverPayService.GetExchangeRateAsync(crypto.ToUpper(), fiat.ToUpper());
|
|
|
|
if (!rate.HasValue)
|
|
{
|
|
return NotFound(new { error = $"Exchange rate not available for {crypto}/{fiat}" });
|
|
}
|
|
|
|
return Ok(new
|
|
{
|
|
crypto = crypto.ToUpper(),
|
|
fiat = fiat.ToUpper(),
|
|
rate = rate.Value,
|
|
message = $"1 {crypto.ToUpper()} = {rate.Value:F2} {fiat.ToUpper()}",
|
|
timestamp = DateTime.UtcNow
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting exchange rate");
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
public class TestOrderRequest
|
|
{
|
|
public string? ExternalId { get; set; }
|
|
public decimal Amount { get; set; } = 10.00m; // Default £10
|
|
public CryptoCurrency Currency { get; set; } = CryptoCurrency.BTC;
|
|
public string? WebhookUrl { get; set; }
|
|
}
|
|
} |