1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17:12:49 -05:00

invoice pdf generation api

This commit is contained in:
Kyle Spearrin
2017-10-25 00:45:11 -04:00
parent c9d6a7b2c0
commit e7b565d007
5 changed files with 265 additions and 0 deletions

View File

@ -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)