1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 08:32:50 -05:00

[AC-1942] Add endpoint to get provider invoices (#4158)

* Added endpoint to get provider invoices

* Added missing properties of invoice

* Run dotnet format'
This commit is contained in:
Alex Morask
2024-06-05 13:33:28 -04:00
committed by GitHub
parent 4a6113dc86
commit a0a7654077
6 changed files with 389 additions and 121 deletions

View File

@ -25,6 +25,23 @@ public class ProviderBillingController(
IStripeAdapter stripeAdapter,
ISubscriberService subscriberService) : Controller
{
[HttpGet("invoices")]
public async Task<IResult> GetInvoicesAsync([FromRoute] Guid providerId)
{
var (provider, result) = await GetAuthorizedBillableProviderOrResultAsync(providerId);
if (provider == null)
{
return result;
}
var invoices = await subscriberService.GetInvoices(provider);
var response = InvoicesResponse.From(invoices);
return TypedResults.Ok(response);
}
[HttpGet("payment-information")]
public async Task<IResult> GetPaymentInformationAsync([FromRoute] Guid providerId)
{

View File

@ -0,0 +1,30 @@
using Stripe;
namespace Bit.Api.Billing.Models.Responses;
public record InvoicesResponse(
List<InvoiceDTO> Invoices)
{
public static InvoicesResponse From(IEnumerable<Invoice> invoices) => new(
invoices
.Where(i => i.Status is "open" or "paid" or "uncollectible")
.OrderByDescending(i => i.Created)
.Select(InvoiceDTO.From).ToList());
}
public record InvoiceDTO(
DateTime Date,
string Number,
decimal Total,
string Status,
string Url,
string PdfUrl)
{
public static InvoiceDTO From(Invoice invoice) => new(
invoice.Created,
invoice.Number,
invoice.Total / 100M,
invoice.Status,
invoice.HostedInvoiceUrl,
invoice.InvoicePdf);
}