1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-28 14:54:50 -05:00

api settings for our address

This commit is contained in:
Kyle Spearrin 2017-10-25 10:59:30 -04:00
parent e7b565d007
commit 461be7a14f
6 changed files with 40 additions and 19 deletions

9
src/Api/ApiSettings.cs Normal file
View File

@ -0,0 +1,9 @@
namespace Bit.Api
{
public class ApiSettings
{
public string OurAddress1 { get; set; }
public string OurAddress2 { get; set; }
public string OurAddress3 { get; set; }
}
}

View File

@ -16,6 +16,7 @@ using jsreport.AspNetCore;
using jsreport.Types;
using Bit.Api.Models;
using Stripe;
using Microsoft.Extensions.Options;
namespace Bit.Api.Controllers
{
@ -29,6 +30,7 @@ namespace Bit.Api.Controllers
private readonly IUserService _userService;
private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
private readonly ApiSettings _apiSettings;
private readonly UserManager<User> _userManager;
public OrganizationsController(
@ -38,6 +40,7 @@ namespace Bit.Api.Controllers
IUserService userService,
CurrentContext currentContext,
GlobalSettings globalSettings,
IOptions<ApiSettings> apiSettings,
UserManager<User> userManager)
{
_organizationRepository = organizationRepository;
@ -47,6 +50,7 @@ namespace Bit.Api.Controllers
_currentContext = currentContext;
_userManager = userManager;
_globalSettings = globalSettings;
_apiSettings = apiSettings.Value;
}
[HttpGet("{id}")]
@ -123,8 +127,10 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
var model = new InvoiceModel(organization, invoice);
HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf);
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)

View File

@ -7,19 +7,19 @@ namespace Bit.Api.Models
{
public class InvoiceModel
{
public InvoiceModel(Organization organization, StripeInvoice invoice)
public InvoiceModel(Organization organization, StripeInvoice invoice, ApiSettings apiSettings)
{
// TODO: address
OurAddress1 = "567 Green St";
OurAddress2 = "Jacksonville, FL 32256";
OurAddress3 = "United States";
OurAddress1 = apiSettings.OurAddress1;
OurAddress2 = apiSettings.OurAddress2;
OurAddress3 = apiSettings.OurAddress3;
CustomerName = organization.BusinessName ?? "--";
// TODO: address and vat
CustomerAddress1 = "123 Any St";
CustomerAddress2 = "New York, NY 10001";
CustomerAddress3 = "United States";
CustomerVatNumber = "PT 123456789";
CustomerAddress4 = null;
CustomerVatNumber = "PT123456789";
InvoiceDate = invoice.Date?.ToLongDateString();
InvoiceDueDate = invoice.DueDate?.ToLongDateString();
@ -43,6 +43,7 @@ namespace Bit.Api.Models
public string CustomerAddress1 { get; set; }
public string CustomerAddress2 { get; set; }
public string CustomerAddress3 { get; set; }
public string CustomerAddress4 { get; set; }
public IEnumerable<Item> Items { get; set; }
public string SubtotalAmount { get; set; }
public string VatTotalAmount { get; set; }
@ -54,13 +55,11 @@ namespace Bit.Api.Models
{
public Item(StripeInvoiceLineItem item)
{
Quantity = item.Quantity?.ToString() ?? "-";
Amount = (item.Amount / 100).ToString("F");
Description = item.Description ?? "--";
}
public string Description { get; set; }
public string Quantity { get; set; }
public string Amount { get; set; }
}
}

View File

@ -44,6 +44,7 @@ namespace Bit.Api
// Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration);
services.Configure<ApiSettings>(Configuration.GetSection("apiSettings"));
if(!globalSettings.SelfHosted)
{
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
@ -145,8 +146,7 @@ namespace Bit.Api
// PDF generation
if(!globalSettings.SelfHosted)
{
services
.AddJsReport(new jsreport.Local.LocalReporting()
services.AddJsReport(new jsreport.Local.LocalReporting()
.UseBinary(jsreport.Binary.JsReportBinary.GetBinary())
.AsUtility()
.Create());

View File

@ -78,10 +78,6 @@
<h2>To</h2>
<p>
<b>@Model.CustomerName</b><br />
@if(Model.UsesVat)
{
@:VAT @Model.CustomerVatNumber<br />
}
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress1))
{
@Model.CustomerAddress1<br />
@ -92,9 +88,17 @@
}
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress3))
{
@Model.CustomerAddress3
@Model.CustomerAddress3<br />
}
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress4))
{
@Model.CustomerAddress4
}
</p>
@if(Model.UsesVat)
{
<p>VAT @Model.CustomerVatNumber</p>
}
</td>
</tr>
</tbody>
@ -104,7 +108,6 @@
<thead>
<tr>
<th>Description</th>
<th class="right" style="width: 100px;">Qty</th>
@if(Model.UsesVat)
{
<th class="right" style="width: 100px;">VAT %</th>
@ -118,7 +121,6 @@
{
<tr>
<td>@item.Description</td>
<td class="right">@item.Quantity</td>
@if(Model.UsesVat)
{
<td class="right">0</td>

View File

@ -52,6 +52,11 @@
"privateKey": "SECRET"
}
},
"apiSettings": {
"ourAddress1": "123 Green St.",
"ourAddress2": "New York, NY 10001",
"ourAddress3": "United States"
},
"IpRateLimitOptions": {
"EnableEndpointRateLimiting": true,
"StackBlockedRequests": false,