From 4b30132d062ebea5559f8ad029081ba5f16ae319 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 6 May 2021 20:28:02 +0900 Subject: [PATCH 1/2] Make sure BTCPayServer does not take the culture of the server --- BTCPayServer/Hosting/BTCpayMiddleware.cs | 3 ++ BTCPayServer/Hosting/Startup.cs | 6 ++-- .../DefaultModelBinderProvider.cs | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 BTCPayServer/ModelBinders/DefaultModelBinderProvider.cs diff --git a/BTCPayServer/Hosting/BTCpayMiddleware.cs b/BTCPayServer/Hosting/BTCpayMiddleware.cs index 545fc0257..07560e4ab 100644 --- a/BTCPayServer/Hosting/BTCpayMiddleware.cs +++ b/BTCPayServer/Hosting/BTCpayMiddleware.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Net.WebSockets; using System.Threading.Tasks; @@ -32,6 +33,8 @@ namespace BTCPayServer.Hosting public async Task Invoke(HttpContext httpContext) { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; try { var bitpayAuth = GetBitpayAuth(httpContext, out bool isBitpayAuth); diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs index 6a9bfb4d1..662a368be 100644 --- a/BTCPayServer/Hosting/Startup.cs +++ b/BTCPayServer/Hosting/Startup.cs @@ -32,6 +32,7 @@ using Microsoft.Net.Http.Headers; using NBitcoin; using Microsoft.AspNetCore.Mvc; using BTCPayServer.Controllers.GreenField; +using System.Globalization; namespace BTCPayServer.Hosting { @@ -113,6 +114,7 @@ namespace BTCPayServer.Hosting o.Filters.Add(new XContentTypeOptionsAttribute("nosniff")); o.Filters.Add(new XXSSProtectionAttribute()); o.Filters.Add(new ReferrerPolicyAttribute("same-origin")); + o.ModelBinderProviders.Insert(0, new ModelBinders.DefaultModelBinderProvider()); //o.Filters.Add(new ContentSecurityPolicyAttribute() //{ // FontSrc = "'self' https://fonts.gstatic.com/", @@ -121,7 +123,7 @@ namespace BTCPayServer.Hosting // StyleSrc = "'self' 'unsafe-inline'", // ScriptSrc = "'self' 'unsafe-inline'" //}); - }) + }) .ConfigureApiBehaviorOptions(options => { options.InvalidModelStateResponseFactory = context => @@ -142,8 +144,6 @@ namespace BTCPayServer.Hosting .AddPlugins(services, Configuration, LoggerFactory) .AddControllersAsServices(); - - services.TryAddScoped(); services.Configure(options => { diff --git a/BTCPayServer/ModelBinders/DefaultModelBinderProvider.cs b/BTCPayServer/ModelBinders/DefaultModelBinderProvider.cs new file mode 100644 index 000000000..28e1e02d6 --- /dev/null +++ b/BTCPayServer/ModelBinders/DefaultModelBinderProvider.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using BTCPayServer.Payments; +using Microsoft.AspNetCore.Mvc.ModelBinding; + +namespace BTCPayServer.ModelBinders +{ + public class DefaultModelBinderProvider : IModelBinderProvider + { + public IModelBinder GetBinder(ModelBinderProviderContext context) + { + if (context.Metadata.ModelType == typeof(decimal) || context.Metadata.ModelType == typeof(decimal?)) + return new InvariantDecimalModelBinder(); + if (context.Metadata.ModelType == typeof(PaymentMethodId)) + return new PaymentMethodIdModelBinder(); + if (context.Metadata.ModelType == typeof(WalletIdModelBinder)) + return new ModelBinders.WalletIdModelBinder(); + if (typeof(DateTimeOffset).GetTypeInfo().IsAssignableFrom(context.Metadata.ModelType) || + typeof(DateTimeOffset?).GetTypeInfo().IsAssignableFrom(context.Metadata.ModelType)) + { + return new DateTimeOffsetModelBinder(); + } + return null; + } + } +} From 2194fe43d27614c07d769eba8241254d04bdf5c3 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 12 May 2021 17:46:57 +0900 Subject: [PATCH 2/2] Do not show payments which are not accounted in Payment request --- BTCPayServer/PaymentRequest/PaymentRequestService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BTCPayServer/PaymentRequest/PaymentRequestService.cs b/BTCPayServer/PaymentRequest/PaymentRequestService.cs index 6c39a685f..5c1c5302c 100644 --- a/BTCPayServer/PaymentRequest/PaymentRequestService.cs +++ b/BTCPayServer/PaymentRequest/PaymentRequestService.cs @@ -112,6 +112,7 @@ namespace BTCPayServer.PaymentRequest StateFormatted = state.ToString(), Payments = entity .GetPayments() + .Where(p => p.Accounted) .Select(paymentEntity => { var paymentData = paymentEntity.GetCryptoPaymentData();