mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Allowing for POS to be displayed at website root
This commit is contained in:
parent
c4d0b061c9
commit
b947749382
3 changed files with 91 additions and 76 deletions
|
@ -91,6 +91,77 @@ namespace BTCPayServer.Controllers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("/apps/{appId}/pos")]
|
||||||
|
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[EnableCors(CorsPolicies.All)]
|
||||||
|
public async Task<IActionResult> 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<PointOfSaleSettings>();
|
||||||
|
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<string>() { AppService.GetAppInternalTag(appId) },
|
||||||
|
cancellationToken);
|
||||||
|
return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", new { invoiceId = invoice.Data.Id });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("/apps/{appId}/crowdfund")]
|
[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<IActionResult> 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<PointOfSaleSettings>();
|
|
||||||
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<string>() { AppService.GetAppInternalTag(appId) },
|
|
||||||
cancellationToken);
|
|
||||||
return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", new { invoiceId = invoice.Data.Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private string GetUserId()
|
private string GetUserId()
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace BTCPayServer.Controllers
|
||||||
HttpClientFactory = httpClientFactory;
|
HttpClientFactory = httpClientFactory;
|
||||||
_cachedServerSettings = cachedServerSettings;
|
_cachedServerSettings = cachedServerSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
if (_cachedServerSettings.RootAppType is Services.Apps.AppType.Crowdfund)
|
if (_cachedServerSettings.RootAppType is Services.Apps.AppType.Crowdfund)
|
||||||
|
@ -40,6 +40,20 @@ namespace BTCPayServer.Controllers
|
||||||
return res; // return
|
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");
|
return View("Home");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
ViewData["Title"] = Model.Title;
|
ViewData["Title"] = Model.Title;
|
||||||
Layout = null;
|
Layout = null;
|
||||||
int[] CustomTipPercentages = Model.CustomTipPercentages;
|
int[] CustomTipPercentages = Model.CustomTipPercentages;
|
||||||
|
string postUrl = $"/apps/{Model.AppId}/pos";
|
||||||
}
|
}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -220,7 +221,7 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer bg-light">
|
<div class="modal-footer bg-light">
|
||||||
<form method="post" asp-antiforgery="false" data-buy>
|
<form method="post" action="@postUrl" asp-antiforgery="false" data-buy>
|
||||||
<input id="js-cart-amount" class="form-control" type="hidden" name="amount">
|
<input id="js-cart-amount" class="form-control" type="hidden" name="amount">
|
||||||
<input id="js-cart-posdata" class="form-control" type="hidden" name="posdata">
|
<input id="js-cart-posdata" class="form-control" type="hidden" name="posdata">
|
||||||
<button id="js-cart-pay" class="btn btn-primary btn-lg" type="submit">
|
<button id="js-cart-pay" class="btn btn-primary btn-lg" type="submit">
|
||||||
|
@ -353,7 +354,7 @@ else
|
||||||
<div class="card-footer bg-transparent border-0">
|
<div class="card-footer bg-transparent border-0">
|
||||||
@if (item.Custom)
|
@if (item.Custom)
|
||||||
{
|
{
|
||||||
<form method="post" asp-antiforgery="false" data-buy>
|
<form method="post" action="@postUrl" asp-antiforgery="false" data-buy>
|
||||||
<input type="hidden" name="choicekey" value="@item.Id"/>
|
<input type="hidden" name="choicekey" value="@item.Id"/>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
|
@ -369,7 +370,7 @@ else
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<form method="post" asp-antiforgery="false">
|
<form method="post" action="@postUrl" asp-antiforgery="false">
|
||||||
<button type="submit" name="choiceKey" class="js-add-cart btn btn-primary" value="@item.Id">
|
<button type="submit" name="choiceKey" class="js-add-cart btn btn-primary" value="@item.Id">
|
||||||
@String.Format(Model.ButtonText, @item.Price.Formatted)</button>
|
@String.Format(Model.ButtonText, @item.Price.Formatted)</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -386,7 +387,7 @@ else
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer bg-transparent border-0">
|
<div class="card-footer bg-transparent border-0">
|
||||||
<form method="post" asp-antiforgery="false" data-buy>
|
<form method="post" action="@postUrl" asp-antiforgery="false" data-buy>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text">@Model.CurrencySymbol</span>
|
<span class="input-group-text">@Model.CurrencySymbol</span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue