mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
invoice pdf generation api
This commit is contained in:
@ -12,6 +12,10 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Business;
|
||||
using jsreport.AspNetCore;
|
||||
using jsreport.Types;
|
||||
using Bit.Api.Models;
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
@ -94,6 +98,41 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id}/billing-invoice/{invoiceId}")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
[MiddlewareFilter(typeof(JsReportPipeline))]
|
||||
public async Task<IActionResult> GetBillingInvoice(string id, string invoiceId)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
|
||||
if(organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var invoice = await new StripeInvoiceService().GetAsync(invoiceId);
|
||||
if(invoice == null || invoice.CustomerId != organization.GatewayCustomerId)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var model = new InvoiceModel(organization, invoice);
|
||||
HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf);
|
||||
return View("Invoice", model);
|
||||
}
|
||||
catch(StripeException)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id}/license")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
public async Task<OrganizationLicense> GetLicense(string id, [FromQuery]Guid installationId)
|
||||
|
Reference in New Issue
Block a user