diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 65e3fa90a..2f9dab501 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -382,7 +382,7 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("SaveSettings")).ForceClick(); s.Driver.FindElement(By.Id("ViewApp")).ForceClick(); - var posBaseUrl = s.Driver.Url; + var posBaseUrl = s.Driver.Url.Replace("/Cart", ""); Assert.True(s.Driver.PageSource.Contains("Tea shop"), "Unable to create PoS"); Assert.True(s.Driver.PageSource.Contains("Cart"), "PoS not showing correct default view"); diff --git a/BTCPayServer/Controllers/AppsController.PointOfSale.cs b/BTCPayServer/Controllers/AppsController.PointOfSale.cs index 28cad646d..32b66ce0c 100644 --- a/BTCPayServer/Controllers/AppsController.PointOfSale.cs +++ b/BTCPayServer/Controllers/AppsController.PointOfSale.cs @@ -60,6 +60,7 @@ namespace BTCPayServer.Controllers public string Title { get; set; } public string Currency { get; set; } public string Template { get; set; } + public bool EnableShoppingCart { get; set; } public PosViewType DefaultView { get; set; } public bool ShowCustomAmount { get; set; } public bool ShowDiscount { get; set; } @@ -92,6 +93,8 @@ namespace BTCPayServer.Controllers if (app == null) return NotFound(); var settings = app.GetSettings(); + settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView; + settings.EnableShoppingCart = false; var vm = new UpdatePointOfSaleViewModel() { @@ -191,7 +194,6 @@ namespace BTCPayServer.Controllers Description = vm.Description, EmbeddedCSS = vm.EmbeddedCSS, RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically) - }); await _AppService.UpdateOrCreateApp(app); TempData[WellKnownTempData.SuccessMessage] = "App updated"; diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index c476231e2..fd72fe5d1 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -38,20 +38,31 @@ namespace BTCPayServer.Controllers private readonly AppService _AppService; private readonly BTCPayServerOptions _BtcPayServerOptions; private readonly InvoiceController _InvoiceController; - private readonly UserManager _UserManager; - + private readonly UserManager _UserManager; + [HttpGet] - [Route("/apps/{appId}/pos/{viewType?}")] + [Route("/apps/{appId}/pos")] [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] - public async Task ViewPointOfSale(string appId, PosViewType viewType = PosViewType.Unspecified) + public async Task ViewPointOfSale(string appId) + { + var app = await _AppService.GetApp(appId, AppType.PointOfSale); + if (app == null) + return NotFound(); + var settings = app.GetSettings(); + PosViewType viewType = settings.DefaultView; + + return RedirectToAction(nameof(ViewPointOfSale), new { appId, viewType }); + } + + [HttpGet] + [Route("/apps/{appId}/pos/{viewType}")] + [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] + public async Task ViewPointOfSale(string appId, PosViewType viewType) { var app = await _AppService.GetApp(appId, AppType.PointOfSale); if (app == null) return NotFound(); var settings = app.GetSettings(); - if (viewType == PosViewType.Unspecified) - viewType = settings.DefaultView; - var numberFormatInfo = _AppService.Currencies.GetNumberFormatInfo(settings.Currency) ?? _AppService.Currencies.GetNumberFormatInfo("USD"); double step = Math.Pow(10, -(numberFormatInfo.CurrencyDecimalDigits)); @@ -87,11 +98,12 @@ namespace BTCPayServer.Controllers } [HttpPost] - [Route("/apps/{appId}/pos/{viewType?}")] + [Route("/apps/{appId}/pos/{viewType}")] [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] [IgnoreAntiforgeryToken] [EnableCors(CorsPolicies.All)] public async Task ViewPointOfSale(string appId, + PosViewType viewType, [ModelBinder(typeof(InvariantDecimalModelBinder))] decimal amount, string email, string orderId, @@ -110,7 +122,7 @@ namespace BTCPayServer.Controllers var settings = app.GetSettings(); if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount && settings.DefaultView != PosViewType.Cart) { - return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId }); + return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId, viewType = viewType }); } string title = null; var price = 0.0m; diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs index acf5af3cd..e6dbde397 100644 --- a/BTCPayServer/Controllers/HomeController.cs +++ b/BTCPayServer/Controllers/HomeController.cs @@ -69,7 +69,7 @@ namespace BTCPayServer.Controllers var controller = (AppsPublicController)serviceProvider.GetService(typeof(AppsPublicController)); controller.Url = Url; controller.ControllerContext = ControllerContext; - var res = await controller.ViewPointOfSale(appId, PosViewType.Unspecified) as ViewResult; + var res = await controller.ViewPointOfSale(appId) as ViewResult; if (res != null) { res.ViewName = "/Views/AppsPublic/ViewPointOfSale.cshtml"; diff --git a/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs b/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs index b2dd1d7b3..054309184 100644 --- a/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/ViewPointOfSaleViewModel.cs @@ -34,8 +34,6 @@ namespace BTCPayServer.Models.AppViewModels public CurrencyInfoData CurrencyInfo { get; set; } public PosViewType ViewType { get; set; } - - public bool IsCartView { get { return ViewType == PosViewType.Cart; } } public bool ShowCustomAmount { get; set; } public bool ShowDiscount { get; set; } public bool EnableTips { get; set; } diff --git a/BTCPayServer/Services/Apps/AppType.cs b/BTCPayServer/Services/Apps/AppType.cs index a1df057cf..328ee72b6 100644 --- a/BTCPayServer/Services/Apps/AppType.cs +++ b/BTCPayServer/Services/Apps/AppType.cs @@ -8,8 +8,7 @@ namespace BTCPayServer.Services.Apps public enum PosViewType { - Unspecified = -1, - Static = 0, - Cart = 1 + Static, + Cart } } diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 28b4482ea..ca8bf9e01 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -38,7 +38,7 @@
* - +
diff --git a/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml b/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml index a622ee83e..ab1a12965 100644 --- a/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml +++ b/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml @@ -1,6 +1,7 @@ @addTagHelper *, BundlerMinifier.TagHelpers @inject BTCPayServer.HostedServices.CssThemeManager themeManager +@using BTCPayServer.Services.Apps @model BTCPayServer.Models.AppViewModels.ViewPointOfSaleViewModel @{ ViewData["Title"] = Model.Title; @@ -27,7 +28,7 @@ } - @if (Model.IsCartView) + @if (Model.ViewType == PosViewType.Cart) {