Added first implementation of subscriptions

This commit is contained in:
Marcel Baumgartner
2023-03-03 17:46:23 +01:00
parent 6fe9a0a1bd
commit 2504ebe750
37 changed files with 4291 additions and 84 deletions

View File

@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Mvc;
using Moonlight.App.Services;
namespace Moonlight.App.Http.Controllers.Api.Moonlight;
[ApiController]
[Route("api/moonlight/payments")]
public class PaymentsController : Controller
{
private readonly ConfigService ConfigService;
private readonly SubscriptionService SubscriptionService;
public PaymentsController(ConfigService configService, SubscriptionService subscriptionService)
{
ConfigService = configService;
SubscriptionService = subscriptionService;
}
[HttpGet("generate")]
public async Task<ActionResult> GenerateGet([FromQuery] string key, [FromQuery] int subscriptionId)
{
var validKey = ConfigService
.GetSection("Moonlight")
.GetSection("Payments")
.GetValue<string>("Key");
if (key != validKey)
return StatusCode(403);
var token = await SubscriptionService.ProcessGenerate(subscriptionId);
return Ok(token);
}
[HttpPost("generate")]
public async Task<ActionResult> GeneratePost([FromQuery] string key, [FromQuery] int subscriptionId)
{
var validKey = ConfigService
.GetSection("Moonlight")
.GetSection("Payments")
.GetValue<string>("Key");
if (key != validKey)
return StatusCode(403);
var token = await SubscriptionService.ProcessGenerate(subscriptionId);
return Ok(token);
}
}