diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index 75c33388b..880ae8d0b 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -91,6 +91,77 @@ namespace BTCPayServer.Controllers }); } + [HttpPost] + [Route("/apps/{appId}/pos")] + [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] + [IgnoreAntiforgeryToken] + [EnableCors(CorsPolicies.All)] + public async Task ViewPointOfSale(string appId, + [ModelBinder(typeof(InvariantDecimalModelBinder))] decimal amount, + string email, + string orderId, + string notificationUrl, + string redirectUrl, + string choiceKey, + string posData = null, CancellationToken cancellationToken = default) + { + var app = await _AppService.GetApp(appId, AppType.PointOfSale); + if (string.IsNullOrEmpty(choiceKey) && amount <= 0) + { + return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId }); + } + if (app == null) + return NotFound(); + var settings = app.GetSettings(); + if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount && !settings.EnableShoppingCart) + { + return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId }); + } + string title = null; + var price = 0.0m; + ViewPointOfSaleViewModel.Item choice = null; + if (!string.IsNullOrEmpty(choiceKey)) + { + var choices = _AppService.Parse(settings.Template, settings.Currency); + choice = choices.FirstOrDefault(c => c.Id == choiceKey); + if (choice == null) + return NotFound(); + title = choice.Title; + price = choice.Price.Value; + if (amount > price) + price = amount; + } + else + { + if (!settings.ShowCustomAmount && !settings.EnableShoppingCart) + return NotFound(); + price = amount; + title = settings.Title; + } + var store = await _AppService.GetStore(app); + store.AdditionalClaims.Add(new Claim(Policies.CanCreateInvoice.Key, store.Id)); + var invoice = await _InvoiceController.CreateInvoiceCore(new CreateInvoiceRequest() + { + ItemCode = choice?.Id, + ItemDesc = title, + Currency = settings.Currency, + Price = price, + BuyerEmail = email, + OrderId = orderId, + NotificationURL = + string.IsNullOrEmpty(notificationUrl) ? settings.NotificationUrl : notificationUrl, + NotificationEmail = settings.NotificationEmail, + RedirectURL = redirectUrl ?? Request.GetDisplayUrl(), + FullNotifications = true, + ExtendedNotifications = true, + PosData = string.IsNullOrEmpty(posData) ? null : posData, + RedirectAutomatically = settings.RedirectAutomatically, + }, store, HttpContext.Request.GetAbsoluteRoot(), + new List() { AppService.GetAppInternalTag(appId) }, + cancellationToken); + return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", new { invoiceId = invoice.Data.Id }); + } + [HttpGet] [Route("/apps/{appId}/crowdfund")] @@ -215,77 +286,6 @@ namespace BTCPayServer.Controllers } - [HttpPost] - [Route("/apps/{appId}/pos")] - [XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)] - [IgnoreAntiforgeryToken] - [EnableCors(CorsPolicies.All)] - public async Task ViewPointOfSale(string appId, - [ModelBinder(typeof(InvariantDecimalModelBinder))] decimal amount, - string email, - string orderId, - string notificationUrl, - string redirectUrl, - string choiceKey, - string posData = null, CancellationToken cancellationToken = default) - { - var app = await _AppService.GetApp(appId, AppType.PointOfSale); - if (string.IsNullOrEmpty(choiceKey) && amount <= 0) - { - return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId }); - } - if (app == null) - return NotFound(); - var settings = app.GetSettings(); - if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount && !settings.EnableShoppingCart) - { - return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId }); - } - string title = null; - var price = 0.0m; - ViewPointOfSaleViewModel.Item choice = null; - if (!string.IsNullOrEmpty(choiceKey)) - { - var choices = _AppService.Parse(settings.Template, settings.Currency); - choice = choices.FirstOrDefault(c => c.Id == choiceKey); - if (choice == null) - return NotFound(); - title = choice.Title; - price = choice.Price.Value; - if (amount > price) - price = amount; - } - else - { - if (!settings.ShowCustomAmount && !settings.EnableShoppingCart) - return NotFound(); - price = amount; - title = settings.Title; - } - var store = await _AppService.GetStore(app); - store.AdditionalClaims.Add(new Claim(Policies.CanCreateInvoice.Key, store.Id)); - var invoice = await _InvoiceController.CreateInvoiceCore(new CreateInvoiceRequest() - { - ItemCode = choice?.Id, - ItemDesc = title, - Currency = settings.Currency, - Price = price, - BuyerEmail = email, - OrderId = orderId, - NotificationURL = - string.IsNullOrEmpty(notificationUrl) ? settings.NotificationUrl : notificationUrl, - NotificationEmail = settings.NotificationEmail, - RedirectURL = redirectUrl ?? Request.GetDisplayUrl(), - FullNotifications = true, - ExtendedNotifications = true, - PosData = string.IsNullOrEmpty(posData) ? null : posData, - RedirectAutomatically = settings.RedirectAutomatically, - }, store, HttpContext.Request.GetAbsoluteRoot(), - new List() { AppService.GetAppInternalTag(appId) }, - cancellationToken); - return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", new { invoiceId = invoice.Data.Id }); - } - private string GetUserId() { diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs index f48b20611..c05345aff 100644 --- a/BTCPayServer/Controllers/HomeController.cs +++ b/BTCPayServer/Controllers/HomeController.cs @@ -24,7 +24,7 @@ namespace BTCPayServer.Controllers HttpClientFactory = httpClientFactory; _cachedServerSettings = cachedServerSettings; } - + public async Task Index() { if (_cachedServerSettings.RootAppType is Services.Apps.AppType.Crowdfund) @@ -40,6 +40,20 @@ namespace BTCPayServer.Controllers return res; // return } } + else if (_cachedServerSettings.RootAppType is Services.Apps.AppType.PointOfSale) + { + var serviceProvider = HttpContext.RequestServices; + var controller = (AppsPublicController)serviceProvider.GetService(typeof(AppsPublicController)); + controller.Url = Url; + controller.ControllerContext = ControllerContext; + var res = await controller.ViewPointOfSale(_cachedServerSettings.RootAppId) as ViewResult; + if (res != null) + { + res.ViewName = "/Views/AppsPublic/ViewPointOfSale.cshtml"; + return res; // return + } + + } return View("Home"); } diff --git a/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml b/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml index 4fe792a0a..9fcb00791 100644 --- a/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml +++ b/BTCPayServer/Views/AppsPublic/ViewPointOfSale.cshtml @@ -6,6 +6,7 @@ ViewData["Title"] = Model.Title; Layout = null; int[] CustomTipPercentages = Model.CustomTipPercentages; + string postUrl = $"/apps/{Model.AppId}/pos"; } @@ -220,7 +221,7 @@