mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Fix test
This commit is contained in:
@@ -157,12 +157,9 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
string formResponse = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (!(await _authorizationService.AuthorizeAsync(HttpContext.User, appId, Policies.CanViewInvoices)).Succeeded &&
|
||||
!await _rateLimitService.Throttle(ZoneLimits.PublicInvoices, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.RequestAborted))
|
||||
{
|
||||
if (await Throttle(appId))
|
||||
return new TooManyRequestsResult(ZoneLimits.PublicInvoices);
|
||||
}
|
||||
|
||||
|
||||
var app = await _appService.GetApp(appId, PointOfSaleAppType.AppType);
|
||||
|
||||
// not allowing negative tips or discounts
|
||||
@@ -174,7 +171,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
|
||||
if (app == null)
|
||||
return NotFound();
|
||||
|
||||
|
||||
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
|
||||
var currentView = viewType ?? settings.DefaultView;
|
||||
@@ -247,7 +244,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
var expectedCartItemPrice = itemChoice.PriceType != AppItemPriceType.Topup
|
||||
? itemChoice.Price ?? 0
|
||||
: 0;
|
||||
|
||||
|
||||
if (cartItem.Price < expectedCartItemPrice)
|
||||
cartItem.Price = expectedCartItemPrice;
|
||||
|
||||
@@ -256,7 +253,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
if (customAmount is { } c)
|
||||
price += c;
|
||||
if (discount is { } d)
|
||||
price -= price * d/100.0m;
|
||||
price -= price * d / 100.0m;
|
||||
if (tip is { } t)
|
||||
price += t;
|
||||
}
|
||||
@@ -277,7 +274,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
{
|
||||
var vm = new PostRedirectViewModel
|
||||
{
|
||||
FormUrl = Url.Action(nameof(POSForm), "UIPointOfSale", new {appId, buyerEmail = email}),
|
||||
FormUrl = Url.Action(nameof(POSForm), "UIPointOfSale", new { appId, buyerEmail = email }),
|
||||
FormParameters = new MultiValueDictionary<string, string>(Request.Form.Select(pair =>
|
||||
new KeyValuePair<string, IReadOnlyCollection<string>>(pair.Key, pair.Value)))
|
||||
};
|
||||
@@ -314,7 +311,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
amtField.Value = price?.ToString();
|
||||
}
|
||||
formResponseJObject = FormDataService.GetValues(form);
|
||||
|
||||
|
||||
var invoiceRequest = FormDataService.GenerateInvoiceParametersFromForm(form);
|
||||
if (invoiceRequest.Amount is not null)
|
||||
{
|
||||
@@ -343,7 +340,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
: Request.GetAbsoluteUri(Url.Action(nameof(ViewPointOfSale), "UIPointOfSale", new { appId, viewType })),
|
||||
PaymentMethods = paymentMethods?.Where(p => p.Value.Enabled).Select(p => p.Key).ToArray()
|
||||
},
|
||||
AdditionalSearchTerms = new [] { AppService.GetAppSearchTerm(app) }
|
||||
AdditionalSearchTerms = new[] { AppService.GetAppSearchTerm(app) }
|
||||
}, store, HttpContext.Request.GetAbsoluteRoot(),
|
||||
new List<string> { AppService.GetAppInternalTag(appId) },
|
||||
cancellationToken, entity =>
|
||||
@@ -358,7 +355,8 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
if (choice is not null)
|
||||
{
|
||||
var dict = new Dictionary<string, string> { { "Title", choice.Title } };
|
||||
if (!string.IsNullOrEmpty(choice.Description)) dict["Description"] = choice.Description;
|
||||
if (!string.IsNullOrEmpty(choice.Description))
|
||||
dict["Description"] = choice.Description;
|
||||
receiptData = JObject.FromObject(dict);
|
||||
}
|
||||
else if (jposData is not null)
|
||||
@@ -374,7 +372,8 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
var cartData = new JObject();
|
||||
foreach (PosCartItem cartItem in posCartItems)
|
||||
{
|
||||
if (!selectedChoices.TryGetValue(cartItem.Id, out var selectedChoice)) continue;
|
||||
if (!selectedChoices.TryGetValue(cartItem.Id, out var selectedChoice))
|
||||
continue;
|
||||
var singlePrice = _displayFormatter.Currency(cartItem.Price, settings.Currency, DisplayFormatter.CurrencyFormat.Symbol);
|
||||
var totalPrice = _displayFormatter.Currency(cartItem.Price * cartItem.Count, settings.Currency, DisplayFormatter.CurrencyFormat.Symbol);
|
||||
var ident = selectedChoice.Title ?? selectedChoice.Id;
|
||||
@@ -386,7 +385,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
{
|
||||
for (var i = 0; i < amountsArray.Count; i++)
|
||||
{
|
||||
cartData.Add($"Custom Amount {i+1}", _displayFormatter.Currency(amountsArray[i].ToObject<decimal>(), settings.Currency, DisplayFormatter.CurrencyFormat.Symbol));
|
||||
cartData.Add($"Custom Amount {i + 1}", _displayFormatter.Currency(amountsArray[i].ToObject<decimal>(), settings.Currency, DisplayFormatter.CurrencyFormat.Symbol));
|
||||
}
|
||||
}
|
||||
receiptData.Add("Cart", cartData);
|
||||
@@ -430,6 +429,11 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> Throttle(string appId) =>
|
||||
!(await _authorizationService.AuthorizeAsync(HttpContext.User, appId, Policies.CanViewInvoices)).Succeeded &&
|
||||
HttpContext.Connection?.RemoteIpAddress is not null &&
|
||||
!await _rateLimitService.Throttle(ZoneLimits.PublicInvoices, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.RequestAborted);
|
||||
|
||||
private JObject TryParseJObject(string posData)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user