mirror of
https://github.com/bitwarden/server
synced 2025-12-21 02:33:30 +00:00
[AC-2568] Added invoices and transaction history endpoints. Added cursor paging for each (#4692)
* Added invoices and transaction history endpoints. Added cursor paging for each * Removed try/catch since it's handled by middleware. Updated condition to use pattern matching * Added unit tests for PaymentHistoryService * Removed organizationId from account billing controller endpoints
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Bit.Api.Billing.Models.Responses;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -10,7 +11,8 @@ namespace Bit.Api.Billing.Controllers;
|
||||
[Authorize("Application")]
|
||||
public class AccountsBillingController(
|
||||
IPaymentService paymentService,
|
||||
IUserService userService) : Controller
|
||||
IUserService userService,
|
||||
IPaymentHistoryService paymentHistoryService) : Controller
|
||||
{
|
||||
[HttpGet("history")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
@@ -39,4 +41,38 @@ public class AccountsBillingController(
|
||||
var billingInfo = await paymentService.GetBillingAsync(user);
|
||||
return new BillingPaymentResponseModel(billingInfo);
|
||||
}
|
||||
|
||||
[HttpGet("invoices")]
|
||||
public async Task<IResult> GetInvoicesAsync([FromQuery] string startAfter = null)
|
||||
{
|
||||
var user = await userService.GetUserByPrincipalAsync(User);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var invoices = await paymentHistoryService.GetInvoiceHistoryAsync(
|
||||
user,
|
||||
5,
|
||||
startAfter);
|
||||
|
||||
return TypedResults.Ok(invoices);
|
||||
}
|
||||
|
||||
[HttpGet("transactions")]
|
||||
public async Task<IResult> GetTransactionsAsync([FromQuery] DateTime? startAfter = null)
|
||||
{
|
||||
var user = await userService.GetUserByPrincipalAsync(User);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var transactions = await paymentHistoryService.GetTransactionHistoryAsync(
|
||||
user,
|
||||
5,
|
||||
startAfter);
|
||||
|
||||
return TypedResults.Ok(transactions);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user