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:
@ -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)
|
||||
{
|
||||
|
30
src/Api/Billing/Models/Responses/InvoicesResponse.cs
Normal file
30
src/Api/Billing/Models/Responses/InvoicesResponse.cs
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user