diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 5bebb05a7..d0839c056 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -127,10 +127,10 @@ $(IncludeRazorContentInPack) - + $(IncludeRazorContentInPack) - + $(IncludeRazorContentInPack) diff --git a/BTCPayServer/Controllers/PublicController.cs b/BTCPayServer/Controllers/PublicController.cs new file mode 100644 index 000000000..1ddefaaed --- /dev/null +++ b/BTCPayServer/Controllers/PublicController.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using BTCPayServer.Models.StoreViewModels; +using BTCPayServer.Services.Stores; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; + +namespace BTCPayServer.Controllers +{ + public class PublicController : Controller + { + public PublicController(InvoiceController invoiceController, + StoreRepository storeRepository) + { + _InvoiceController = invoiceController; + _StoreRepository = storeRepository; + } + + private InvoiceController _InvoiceController; + private StoreRepository _StoreRepository; + + [HttpPost] + [Route("/pay/{storeId}")] + [IgnoreAntiforgeryToken] + [EnableCors(CorsPolicies.All)] + public async Task PayButtonHandle(string storeId, [FromForm]PayButtonViewModel model) + { + var store = await _StoreRepository.FindStore(storeId); + if (store == null) + ModelState.AddModelError("Store", "Invalid store"); + + // TODO: extract validation to model + if (model.Price <= 0) + ModelState.AddModelError("Price", "Price must be greater than 0"); + + if (!ModelState.IsValid) + return View(); + + var invoice = await _InvoiceController.CreateInvoiceCore(new NBitpayClient.Invoice() + { + Price = model.Price, + Currency = model.Currency, + ItemDesc = model.CheckoutDesc, + OrderId = model.OrderId, + BuyerEmail = model.NotifyEmail, + NotificationURL = model.ServerIpn, + RedirectURL = model.BrowserRedirect, + FullNotifications = true + }, store, HttpContext.Request.GetAbsoluteRoot()); + return Redirect(invoice.Data.Url); + } + + [HttpGet] + [Route("/paybuttontest")] + public IActionResult PayButtonTest() + { + return View(); + } + } +} diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index fc6f2c247..897e83140 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -48,8 +48,7 @@ namespace BTCPayServer.Controllers ExplorerClientProvider explorerProvider, IFeeProviderFactory feeRateProvider, LanguageService langService, - IHostingEnvironment env, - InvoiceController invoiceController) + IHostingEnvironment env) { _RateFactory = rateFactory; _Repo = repo; @@ -65,7 +64,6 @@ namespace BTCPayServer.Controllers _ServiceProvider = serviceProvider; _BtcpayServerOptions = btcpayServerOptions; _BTCPayEnv = btcpayEnv; - _InvoiceController = invoiceController; } BTCPayServerOptions _BtcpayServerOptions; BTCPayServerEnvironment _BTCPayEnv; @@ -80,7 +78,6 @@ namespace BTCPayServer.Controllers UserManager _UserManager; private LanguageService _LangService; IHostingEnvironment _Env; - InvoiceController _InvoiceController; [TempData] public string StatusMessage @@ -791,41 +788,5 @@ namespace BTCPayServer.Controllers }; return View(model); } - - [HttpPost] - [Route("{storeId}/pay")] - [IgnoreAntiforgeryToken] - [EnableCors(CorsPolicies.All)] - public async Task PayButtonHandle(string storeId, [FromForm]PayButtonViewModel model) - { - var store = StoreData; - - // TODO: extract validation to model - if (model.Price <= 0) - ModelState.AddModelError("Price", "Price must be greater than 0"); - - if (!ModelState.IsValid) - return View(); - - var invoice = await _InvoiceController.CreateInvoiceCore(new NBitpayClient.Invoice() - { - Price = model.Price, - Currency = model.Currency, - ItemDesc = model.CheckoutDesc, - OrderId = model.OrderId, - BuyerEmail = model.NotifyEmail, - NotificationURL = model.ServerIpn, - RedirectURL = model.BrowserRedirect, - FullNotifications = true - }, store, HttpContext.Request.GetAbsoluteRoot()); - return Redirect(invoice.Data.Url); - } - - [HttpGet] - [Route("{storeId}/paybuttontest")] - public IActionResult PayButtonTest(string storeId) - { - return View(); - } } } diff --git a/BTCPayServer/Views/Stores/PayButtonHandle.cshtml b/BTCPayServer/Views/Public/PayButtonHandle.cshtml similarity index 100% rename from BTCPayServer/Views/Stores/PayButtonHandle.cshtml rename to BTCPayServer/Views/Public/PayButtonHandle.cshtml diff --git a/BTCPayServer/Views/Stores/PayButtonTest.cshtml b/BTCPayServer/Views/Public/PayButtonTest.cshtml similarity index 79% rename from BTCPayServer/Views/Stores/PayButtonTest.cshtml rename to BTCPayServer/Views/Public/PayButtonTest.cshtml index c7eb1b307..538e5602b 100644 --- a/BTCPayServer/Views/Stores/PayButtonTest.cshtml +++ b/BTCPayServer/Views/Public/PayButtonTest.cshtml @@ -3,7 +3,7 @@
-
+ diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index ea8636959..ba544e882 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -42,7 +42,7 @@ function inputChanges(event, buttonSize) { srvModel.buttonSize = buttonSize; } - var html = ''; + var html = ''; html += addinput("price", srvModel.price); if (srvModel.currency) { html += addinput("currency", srvModel.currency);