1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 01:52:49 -05: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:
Conner Turnbull
2024-09-09 09:38:58 -04:00
committed by GitHub
parent ebf8bc0b85
commit 46ac2a9b3b
16 changed files with 385 additions and 34 deletions

View File

@ -19,7 +19,8 @@ public class OrganizationBillingController(
IOrganizationBillingService organizationBillingService,
IOrganizationRepository organizationRepository,
IPaymentService paymentService,
ISubscriberService subscriberService) : BaseBillingController
ISubscriberService subscriberService,
IPaymentHistoryService paymentHistoryService) : BaseBillingController
{
[HttpGet("metadata")]
public async Task<IResult> GetMetadataAsync([FromRoute] Guid organizationId)
@ -61,6 +62,52 @@ public class OrganizationBillingController(
return TypedResults.Ok(billingInfo);
}
[HttpGet("invoices")]
public async Task<IResult> GetInvoicesAsync([FromRoute] Guid organizationId, [FromQuery] string startAfter = null)
{
if (!await currentContext.ViewBillingHistory(organizationId))
{
return TypedResults.Unauthorized();
}
var organization = await organizationRepository.GetByIdAsync(organizationId);
if (organization == null)
{
return TypedResults.NotFound();
}
var invoices = await paymentHistoryService.GetInvoiceHistoryAsync(
organization,
5,
startAfter);
return TypedResults.Ok(invoices);
}
[HttpGet("transactions")]
public async Task<IResult> GetTransactionsAsync([FromRoute] Guid organizationId, [FromQuery] DateTime? startAfter = null)
{
if (!await currentContext.ViewBillingHistory(organizationId))
{
return TypedResults.Unauthorized();
}
var organization = await organizationRepository.GetByIdAsync(organizationId);
if (organization == null)
{
return TypedResults.NotFound();
}
var transactions = await paymentHistoryService.GetTransactionHistoryAsync(
organization,
5,
startAfter);
return TypedResults.Ok(transactions);
}
[HttpGet]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task<IResult> GetBillingAsync(Guid organizationId)