When creating a new apps, the default currency of the store should be used

This commit is contained in:
nicolas.dorier
2021-10-25 16:54:36 +09:00
parent 951bfeefb1
commit a73383cd87
7 changed files with 50 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using BTCPayServer.Data;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.RegularExpressions;
@@ -17,7 +18,6 @@ namespace BTCPayServer.Controllers
public PointOfSaleSettings()
{
Title = "Tea shop";
Currency = "USD";
Template =
"green tea:\n" +
" price: 1\n" +
@@ -96,7 +96,6 @@ namespace BTCPayServer.Controllers
var settings = app.GetSettings<PointOfSaleSettings>();
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
settings.EnableShoppingCart = false;
var vm = new UpdatePointOfSaleViewModel
{
Id = appId,
@@ -123,7 +122,7 @@ namespace BTCPayServer.Controllers
};
if (HttpContext?.Request != null)
{
var appUrl = HttpContext.Request.GetAbsoluteRoot().WithTrailingSlash() + $"apps/{appId}/pos";
var appUrl = HttpContext.Request.GetAbsoluteUri($"/apps/{appId}/pos");
var encoder = HtmlEncoder.Default;
if (settings.ShowCustomAmount)
{
@@ -140,6 +139,7 @@ namespace BTCPayServer.Controllers
}
try
{
var items = _AppService.Parse(settings.Template, settings.Currency);
var builder = new StringBuilder();
builder.AppendLine($"<form method=\"POST\" action=\"{encoder.Encode(appUrl)}\">");
@@ -162,11 +162,14 @@ namespace BTCPayServer.Controllers
[Route("{appId}/settings/pos")]
public async Task<IActionResult> UpdatePointOfSale(string appId, UpdatePointOfSaleViewModel vm)
{
var app = await GetOwnedApp(appId, AppType.PointOfSale);
if (app == null)
return NotFound();
if (!ModelState.IsValid)
{
return View(vm);
}
vm.Currency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.Currency);
if (_currencies.GetCurrencyData(vm.Currency, false) == null)
ModelState.AddModelError(nameof(vm.Currency), "Invalid currency");
try
@@ -181,9 +184,6 @@ namespace BTCPayServer.Controllers
{
return View(vm);
}
var app = await GetOwnedApp(appId, AppType.PointOfSale);
if (app == null)
return NotFound();
app.SetSettings(new PointOfSaleSettings
{
Title = vm.Title,
@@ -191,7 +191,7 @@ namespace BTCPayServer.Controllers
ShowCustomAmount = vm.ShowCustomAmount,
ShowDiscount = vm.ShowDiscount,
EnableTips = vm.EnableTips,
Currency = vm.Currency.ToUpperInvariant(),
Currency = vm.Currency,
Template = vm.Template,
ButtonText = vm.ButtonText,
CustomButtonText = vm.CustomButtonText,