diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj index 3944184056..b9b22b3080 100644 --- a/src/Api/Api.csproj +++ b/src/Api/Api.csproj @@ -12,9 +12,6 @@ - - - diff --git a/src/Api/ApiSettings.cs b/src/Api/ApiSettings.cs deleted file mode 100644 index 984895d81a..0000000000 --- a/src/Api/ApiSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Bit.Api -{ - public class ApiSettings - { - public string OurAddress1 { get; set; } - public string OurAddress2 { get; set; } - public string OurAddress3 { get; set; } - } -} diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index b15a05e65c..7f657db49c 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -10,9 +10,6 @@ using Bit.Core.Services; using Bit.Core; using Bit.Api.Utilities; using Bit.Core.Models.Business; -using jsreport.AspNetCore; -using jsreport.Types; -using Bit.Api.Models; using Stripe; using Microsoft.Extensions.Options; using Bit.Core.Utilities; @@ -29,7 +26,6 @@ namespace Bit.Api.Controllers private readonly IUserService _userService; private readonly CurrentContext _currentContext; private readonly GlobalSettings _globalSettings; - private readonly ApiSettings _apiSettings; public OrganizationsController( IOrganizationRepository organizationRepository, @@ -37,8 +33,7 @@ namespace Bit.Api.Controllers IOrganizationService organizationService, IUserService userService, CurrentContext currentContext, - GlobalSettings globalSettings, - IOptions apiSettings) + GlobalSettings globalSettings) { _organizationRepository = organizationRepository; _organizationUserRepository = organizationUserRepository; @@ -46,7 +41,6 @@ namespace Bit.Api.Controllers _userService = userService; _currentContext = currentContext; _globalSettings = globalSettings; - _apiSettings = apiSettings.Value; } [HttpGet("{id}")] @@ -100,7 +94,6 @@ namespace Bit.Api.Controllers [HttpGet("{id}/billing-invoice/{invoiceId}")] [SelfHosted(NotSelfHostedOnly = true)] - [MiddlewareFilter(typeof(JsReportPipeline))] public async Task GetBillingInvoice(string id, string invoiceId) { var orgIdGuid = new Guid(id); @@ -118,21 +111,15 @@ namespace Bit.Api.Controllers try { var invoice = await new StripeInvoiceService().GetAsync(invoiceId); - if(invoice == null || invoice.CustomerId != organization.GatewayCustomerId) + if(invoice != null && invoice.CustomerId == organization.GatewayCustomerId && + !string.IsNullOrWhiteSpace(invoice.HostedInvoiceUrl)) { - throw new NotFoundException(); + return new RedirectResult(invoice.HostedInvoiceUrl); } + } + catch(StripeException) { } - var model = new InvoiceModel(organization, invoice, _apiSettings); - HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf) - .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = - $"attachment; filename=\"bitwarden_{model.InvoiceNumber}.pdf\""); - return View("Invoice", model); - } - catch(StripeException) - { - throw new NotFoundException(); - } + throw new NotFoundException(); } [HttpGet("{id}/license")] @@ -234,7 +221,7 @@ namespace Bit.Api.Controllers await _organizationService.ReplacePaymentMethodAsync(orgIdGuid, model.PaymentToken); } - + [HttpPost("{id}/upgrade")] [SelfHosted(NotSelfHostedOnly = true)] public async Task PostUpgrade(string id, [FromBody]OrganizationUpgradeRequestModel model) @@ -247,7 +234,7 @@ namespace Bit.Api.Controllers await _organizationService.UpgradePlanAsync(orgIdGuid, model.PlanType, model.AdditionalSeats); } - + [HttpPost("{id}/seat")] [SelfHosted(NotSelfHostedOnly = true)] public async Task PostSeat(string id, [FromBody]OrganizationSeatRequestModel model) @@ -260,7 +247,7 @@ namespace Bit.Api.Controllers await _organizationService.AdjustSeatsAsync(orgIdGuid, model.SeatAdjustment.Value); } - + [HttpPost("{id}/storage")] [SelfHosted(NotSelfHostedOnly = true)] public async Task PostStorage(string id, [FromBody]StorageRequestModel model) @@ -286,7 +273,7 @@ namespace Bit.Api.Controllers await _organizationService.VerifyBankAsync(orgIdGuid, model.Amount1.Value, model.Amount2.Value); } - + [HttpPost("{id}/cancel")] [SelfHosted(NotSelfHostedOnly = true)] public async Task PostCancel(string id) @@ -299,7 +286,7 @@ namespace Bit.Api.Controllers await _organizationService.CancelSubscriptionAsync(orgIdGuid, true); } - + [HttpPost("{id}/reinstate")] [SelfHosted(NotSelfHostedOnly = true)] public async Task PostReinstate(string id) @@ -358,7 +345,7 @@ namespace Bit.Api.Controllers await _organizationService.DeleteAsync(organization); } } - + [HttpPost("{id}/license")] [SelfHosted(SelfHostedOnly = true)] public async Task PostLicense(string id, LicenseRequestModel model) diff --git a/src/Api/Models/InvoiceModel.cs b/src/Api/Models/InvoiceModel.cs deleted file mode 100644 index 3eda732751..0000000000 --- a/src/Api/Models/InvoiceModel.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Bit.Core.Models.Table; -using Stripe; - -namespace Bit.Api.Models -{ - public class InvoiceModel - { - public InvoiceModel(Organization organization, StripeInvoice invoice, ApiSettings apiSettings) - { - OurAddress1 = apiSettings.OurAddress1; - OurAddress2 = apiSettings.OurAddress2; - OurAddress3 = apiSettings.OurAddress3; - - CustomerName = organization.BusinessName ?? "--"; - CustomerAddress1 = organization.BusinessAddress1; - CustomerAddress2 = organization.BusinessAddress2; - CustomerAddress3 = organization.BusinessAddress3; - CustomerCountry = organization.BusinessCountry; - CustomerVatNumber = organization.BusinessTaxNumber; - - InvoiceDate = invoice.Date?.ToLongDateString(); - InvoiceDueDate = invoice.DueDate?.ToLongDateString(); - InvoiceNumber = invoice.Number; - Items = invoice.StripeInvoiceLineItems.Select(i => new Item(i)); - - SubtotalAmount = (invoice.Total / 100).ToString("C"); - VatTotalAmount = 0.ToString("C"); - TotalAmount = SubtotalAmount; - Paid = invoice.Paid; - } - - public string OurAddress1 { get; set; } - public string OurAddress2 { get; set; } - public string OurAddress3 { get; set; } - public string InvoiceDate { get; set; } - public string InvoiceDueDate { get; set; } - public string InvoiceNumber { get; set; } - public string CustomerName { get; set; } - public string CustomerVatNumber { get; set; } - public string CustomerAddress1 { get; set; } - public string CustomerAddress2 { get; set; } - public string CustomerAddress3 { get; set; } - public string CustomerCountry { get; set; } - public IEnumerable Items { get; set; } - public string SubtotalAmount { get; set; } - public string VatTotalAmount { get; set; } - public string TotalAmount { get; set; } - public bool Paid { get; set; } - public bool UsesVat => !string.IsNullOrWhiteSpace(CustomerVatNumber); - - public class Item - { - public Item(StripeInvoiceLineItem item) - { - Amount = (item.Amount / 100).ToString("F"); - if(!string.IsNullOrWhiteSpace(item.Description)) - { - Description = item.Description; - } - else if(!string.IsNullOrWhiteSpace(item.Plan?.Nickname) && item.Quantity.GetValueOrDefault() > 0) - { - Description = $"{item.Quantity} x {item.Plan.Nickname}"; - } - else - { - Description = "--"; - } - } - - public string Description { get; set; } - public string Amount { get; set; } - } - } -} diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index d4eb7dd890..9fe98cb54a 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -13,7 +13,6 @@ using Serilog.Events; using Stripe; using Bit.Core.Utilities; using IdentityModel; -using jsreport.AspNetCore; using Microsoft.AspNetCore.HttpOverrides; namespace Bit.Api @@ -38,7 +37,6 @@ namespace Bit.Api // Settings var globalSettings = services.AddGlobalSettingsServices(Configuration); - services.Configure(Configuration.GetSection("apiSettings")); if(!globalSettings.SelfHosted) { services.Configure(Configuration.GetSection("IpRateLimitOptions")); @@ -115,14 +113,6 @@ namespace Bit.Api Jobs.JobsHostedService.AddJobsServices(services); services.AddHostedService(); } - else - { - // PDF generation - services.AddJsReport(new jsreport.Local.LocalReporting() - .UseBinary(jsreport.Binary.JsReportBinary.GetBinary()) - .AsUtility() - .Create()); - } } public void Configure( diff --git a/src/Api/Views/Organizations/Invoice.cshtml b/src/Api/Views/Organizations/Invoice.cshtml deleted file mode 100644 index 4757ec3b62..0000000000 --- a/src/Api/Views/Organizations/Invoice.cshtml +++ /dev/null @@ -1,147 +0,0 @@ -@model Bit.Api.Models.InvoiceModel - - - - - -
@Model.InvoiceNumber
-

INVOICE

-

- @if(!string.IsNullOrWhiteSpace(Model.InvoiceDate)) - { - Date: @Model.InvoiceDate
- } - @if(!string.IsNullOrWhiteSpace(Model.InvoiceDueDate)) - { - Due Date: @Model.InvoiceDueDate - } -

- - - - - - - -
-

From

-

- 8bit Solutions LLC
- @Model.OurAddress1
- @Model.OurAddress2
- @Model.OurAddress3 -

-
-

To

-

- @Model.CustomerName
- @if(!string.IsNullOrWhiteSpace(Model.CustomerAddress1)) - { - @Model.CustomerAddress1
- } - @if(!string.IsNullOrWhiteSpace(Model.CustomerAddress2)) - { - @Model.CustomerAddress2
- } - @if(!string.IsNullOrWhiteSpace(Model.CustomerAddress3)) - { - @Model.CustomerAddress3
- } - @if(!string.IsNullOrWhiteSpace(Model.CustomerCountry)) - { - @Model.CustomerCountry - } -

- @if(Model.UsesVat) - { -

VAT @Model.CustomerVatNumber

- } -
-

Items

- - - - - @if(Model.UsesVat) - { - - - } - - - - - @foreach(var item in Model.Items) - { - - - @if(Model.UsesVat) - { - - - } - - - } - -
DescriptionVAT %VATTotal
@item.Description00.00@item.Amount
-

Totals

- Subtotal: @Model.SubtotalAmount
- @if(Model.UsesVat) - { - Total VAT: @Model.VatTotalAmount
- } -
- Total: USD @Model.TotalAmount - @if(Model.Paid) - { - - } - - diff --git a/src/Api/appsettings.json b/src/Api/appsettings.json index 417bd81bd7..ad899e0d54 100644 --- a/src/Api/appsettings.json +++ b/src/Api/appsettings.json @@ -64,11 +64,6 @@ "privateKey": "SECRET" } }, - "apiSettings": { - "ourAddress1": "123 Green St.", - "ourAddress2": "New York, NY 10001", - "ourAddress3": "United States" - }, "IpRateLimitOptions": { "EnableEndpointRateLimiting": true, "StackBlockedRequests": false,