mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 15:04:19 +01:00
Merge remote-tracking branch 'btcpayserver/master' into feature/extended-invoice
This commit is contained in:
@@ -1454,7 +1454,7 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
private static BTCPayRateProviderFactory CreateBTCPayRateFactory(BTCPayNetworkProvider provider)
|
private static BTCPayRateProviderFactory CreateBTCPayRateFactory(BTCPayNetworkProvider provider)
|
||||||
{
|
{
|
||||||
return new BTCPayRateProviderFactory(new MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }, provider, new CoinAverageSettings());
|
return new BTCPayRateProviderFactory(new MemoryCacheOptions() { ExpirationScanFrequency = TimeSpan.FromSeconds(1.0) }, provider, null, new CoinAverageSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<Version>1.0.2.13</Version>
|
<Version>1.0.2.15</Version>
|
||||||
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
<PackageReference Include="NBitcoin" Version="4.1.1.7" />
|
<PackageReference Include="NBitcoin" Version="4.1.1.7" />
|
||||||
<PackageReference Include="NBitpayClient" Version="1.0.0.20" />
|
<PackageReference Include="NBitpayClient" Version="1.0.0.20" />
|
||||||
<PackageReference Include="DBreeze" Version="1.87.0" />
|
<PackageReference Include="DBreeze" Version="1.87.0" />
|
||||||
<PackageReference Include="NBXplorer.Client" Version="1.0.2.7" />
|
<PackageReference Include="NBXplorer.Client" Version="1.0.2.8" />
|
||||||
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.1" />
|
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.1" />
|
||||||
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.2" />
|
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.2" />
|
||||||
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.13" />
|
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.13" />
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{appId}/pos")]
|
[Route("{appId}/pos")]
|
||||||
[IgnoreAntiforgeryToken]
|
[IgnoreAntiforgeryToken]
|
||||||
public async Task<IActionResult> ViewPointOfSale(string appId, double amount, string choiceKey)
|
public async Task<IActionResult> ViewPointOfSale(string appId, decimal amount, string choiceKey)
|
||||||
{
|
{
|
||||||
var app = await GetApp(appId, AppType.PointOfSale);
|
var app = await GetApp(appId, AppType.PointOfSale);
|
||||||
if (string.IsNullOrEmpty(choiceKey) && amount <= 0)
|
if (string.IsNullOrEmpty(choiceKey) && amount <= 0)
|
||||||
@@ -178,7 +178,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId });
|
return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId });
|
||||||
}
|
}
|
||||||
string title = null;
|
string title = null;
|
||||||
double price = 0.0;
|
var price = 0.0m;
|
||||||
if (!string.IsNullOrEmpty(choiceKey))
|
if (!string.IsNullOrEmpty(choiceKey))
|
||||||
{
|
{
|
||||||
var choices = Parse(settings.Template, settings.Currency);
|
var choices = Parse(settings.Template, settings.Currency);
|
||||||
@@ -186,7 +186,7 @@ namespace BTCPayServer.Controllers
|
|||||||
if (choice == null)
|
if (choice == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
title = choice.Title;
|
title = choice.Title;
|
||||||
price = (double)choice.Price.Value;
|
price = choice.Price.Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ namespace BTCPayServer.Controllers
|
|||||||
StoreLink = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
|
StoreLink = Url.Action(nameof(StoresController.UpdateStore), "Stores", new { storeId = store.Id }),
|
||||||
Id = invoice.Id,
|
Id = invoice.Id,
|
||||||
Status = invoice.Status,
|
Status = invoice.Status,
|
||||||
TransactionSpeed = invoice.SpeedPolicy == SpeedPolicy.HighSpeed ? "high" : invoice.SpeedPolicy == SpeedPolicy.MediumSpeed ? "medium" : "low",
|
TransactionSpeed = invoice.SpeedPolicy == SpeedPolicy.HighSpeed ? "high" :
|
||||||
|
invoice.SpeedPolicy == SpeedPolicy.MediumSpeed ? "medium" :
|
||||||
|
invoice.SpeedPolicy == SpeedPolicy.LowMediumSpeed ? "low-medium" :
|
||||||
|
"low",
|
||||||
RefundEmail = invoice.RefundMail,
|
RefundEmail = invoice.RefundMail,
|
||||||
CreatedDate = invoice.InvoiceTime,
|
CreatedDate = invoice.InvoiceTime,
|
||||||
ExpirationDate = invoice.ExpirationTime,
|
ExpirationDate = invoice.ExpirationTime,
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return defaultPolicy;
|
return defaultPolicy;
|
||||||
var mappings = new Dictionary<string, SpeedPolicy>();
|
var mappings = new Dictionary<string, SpeedPolicy>();
|
||||||
mappings.Add("low", SpeedPolicy.LowSpeed);
|
mappings.Add("low", SpeedPolicy.LowSpeed);
|
||||||
|
mappings.Add("low-medium", SpeedPolicy.LowMediumSpeed);
|
||||||
mappings.Add("medium", SpeedPolicy.MediumSpeed);
|
mappings.Add("medium", SpeedPolicy.MediumSpeed);
|
||||||
mappings.Add("high", SpeedPolicy.HighSpeed);
|
mappings.Add("high", SpeedPolicy.HighSpeed);
|
||||||
if (!mappings.TryGetValue(transactionSpeed, out SpeedPolicy policy))
|
if (!mappings.TryGetValue(transactionSpeed, out SpeedPolicy policy))
|
||||||
|
|||||||
@@ -79,12 +79,13 @@ namespace BTCPayServer.Hosting
|
|||||||
if (!httpContext.Request.Path.HasValue)
|
if (!httpContext.Request.Path.HasValue)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var isJson = (httpContext.Request.ContentType ?? string.Empty).StartsWith("application/json", StringComparison.OrdinalIgnoreCase);
|
||||||
var path = httpContext.Request.Path.Value;
|
var path = httpContext.Request.Path.Value;
|
||||||
if (
|
if (
|
||||||
bitpayAuth &&
|
bitpayAuth &&
|
||||||
path == "/invoices" &&
|
path == "/invoices" &&
|
||||||
httpContext.Request.Method == "POST" &&
|
httpContext.Request.Method == "POST" &&
|
||||||
(httpContext.Request.ContentType ?? string.Empty).StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
|
isJson)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -96,7 +97,7 @@ namespace BTCPayServer.Hosting
|
|||||||
if (
|
if (
|
||||||
path.StartsWith("/invoices/", StringComparison.OrdinalIgnoreCase) &&
|
path.StartsWith("/invoices/", StringComparison.OrdinalIgnoreCase) &&
|
||||||
httpContext.Request.Method == "GET" &&
|
httpContext.Request.Method == "GET" &&
|
||||||
(httpContext.Request.ContentType ?? string.Empty).StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
|
(isJson || httpContext.Request.Query.ContainsKey("token")))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (path.Equals("/rates", StringComparison.OrdinalIgnoreCase) &&
|
if (path.Equals("/rates", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
Currency = "USD";
|
Currency = "USD";
|
||||||
}
|
}
|
||||||
[Required]
|
[Required]
|
||||||
public double? Amount
|
public decimal? Amount
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
{
|
{
|
||||||
return ConfirmationCount >= 1;
|
return ConfirmationCount >= 1;
|
||||||
}
|
}
|
||||||
|
else if (speedPolicy == SpeedPolicy.LowMediumSpeed)
|
||||||
|
{
|
||||||
|
return ConfirmationCount >= 2;
|
||||||
|
}
|
||||||
else if (speedPolicy == SpeedPolicy.LowSpeed)
|
else if (speedPolicy == SpeedPolicy.LowSpeed)
|
||||||
{
|
{
|
||||||
return ConfirmationCount >= 6;
|
return ConfirmationCount >= 6;
|
||||||
|
|||||||
@@ -417,10 +417,21 @@ namespace BTCPayServer.Rating
|
|||||||
|
|
||||||
public RateRule(RateRules parent, CurrencyPair currencyPair, SyntaxNode candidate)
|
public RateRule(RateRules parent, CurrencyPair currencyPair, SyntaxNode candidate)
|
||||||
{
|
{
|
||||||
|
_CurrencyPair = currencyPair;
|
||||||
flatten = new FlattenExpressionRewriter(parent, currencyPair);
|
flatten = new FlattenExpressionRewriter(parent, currencyPair);
|
||||||
this.expression = flatten.Visit(candidate);
|
this.expression = flatten.Visit(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private readonly CurrencyPair _CurrencyPair;
|
||||||
|
public CurrencyPair CurrencyPair
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _CurrencyPair;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ExchangeRates ExchangeRates
|
public ExchangeRates ExchangeRates
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
{
|
{
|
||||||
HighSpeed = 0,
|
HighSpeed = 0,
|
||||||
MediumSpeed = 1,
|
MediumSpeed = 1,
|
||||||
LowSpeed = 2
|
LowSpeed = 2,
|
||||||
|
LowMediumSpeed = 3
|
||||||
}
|
}
|
||||||
public class InvoiceEntity
|
public class InvoiceEntity
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
IMemoryCache _Cache;
|
IMemoryCache _Cache;
|
||||||
private IOptions<MemoryCacheOptions> _CacheOptions;
|
private IOptions<MemoryCacheOptions> _CacheOptions;
|
||||||
|
CurrencyNameTable _CurrencyTable;
|
||||||
public IMemoryCache Cache
|
public IMemoryCache Cache
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -46,10 +46,12 @@ namespace BTCPayServer.Services.Rates
|
|||||||
CoinAverageSettings _CoinAverageSettings;
|
CoinAverageSettings _CoinAverageSettings;
|
||||||
public BTCPayRateProviderFactory(IOptions<MemoryCacheOptions> cacheOptions,
|
public BTCPayRateProviderFactory(IOptions<MemoryCacheOptions> cacheOptions,
|
||||||
BTCPayNetworkProvider btcpayNetworkProvider,
|
BTCPayNetworkProvider btcpayNetworkProvider,
|
||||||
|
CurrencyNameTable currencyTable,
|
||||||
CoinAverageSettings coinAverageSettings)
|
CoinAverageSettings coinAverageSettings)
|
||||||
{
|
{
|
||||||
if (cacheOptions == null)
|
if (cacheOptions == null)
|
||||||
throw new ArgumentNullException(nameof(cacheOptions));
|
throw new ArgumentNullException(nameof(cacheOptions));
|
||||||
|
_CurrencyTable = currencyTable;
|
||||||
_CoinAverageSettings = coinAverageSettings;
|
_CoinAverageSettings = coinAverageSettings;
|
||||||
_Cache = new MemoryCache(cacheOptions);
|
_Cache = new MemoryCache(cacheOptions);
|
||||||
_CacheOptions = cacheOptions;
|
_CacheOptions = cacheOptions;
|
||||||
@@ -161,6 +163,13 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
rateRule.Reevaluate();
|
rateRule.Reevaluate();
|
||||||
result.Value = rateRule.Value;
|
result.Value = rateRule.Value;
|
||||||
|
|
||||||
|
var currencyData = _CurrencyTable?.GetCurrencyData(rateRule.CurrencyPair.Right);
|
||||||
|
if(currencyData != null && result.Value.HasValue)
|
||||||
|
{
|
||||||
|
result.Value = decimal.Round(result.Value.Value, currencyData.Divisibility, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors = rateRule.Errors;
|
result.Errors = rateRule.Errors;
|
||||||
result.EvaluatedRule = rateRule.ToString(true);
|
result.EvaluatedRule = rateRule.ToString(true);
|
||||||
result.Rule = rateRule.ToString(false);
|
result.Rule = rateRule.ToString(false);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<div class="container d-flex h-100">
|
<div class="container d-flex h-100">
|
||||||
<div class="justify-content-center align-self-center text-center mx-auto" style="margin: auto;">
|
<div class="justify-content-center align-self-center text-center mx-auto" style="margin: auto;">
|
||||||
<h1 class="mb-4">@Model.Title</h1>
|
<h1 class="mb-4">@Model.Title</h1>
|
||||||
<form method="post">
|
<form method="post" asp-antiforgery="false">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@for(int i = 0; i < Model.Items.Length; i++)
|
@for(int i = 0; i < Model.Items.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
{
|
{
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col-md-4 offset-md-4 col-sm-6 offset-sm-3">
|
<div class="col-md-4 offset-md-4 col-sm-6 offset-sm-3">
|
||||||
<form method="post" data-buy>
|
<form method="post" asp-antiforgery="false" data-buy>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input class="form-control" type="number" min="0" step="@Model.Step" name="amount" placeholder="amount"><div class="input-group-append">
|
<input class="form-control" type="number" min="0" step="@Model.Step" name="amount" placeholder="amount"><div class="input-group-append">
|
||||||
<button class="btn btn-primary" type="submit">Pay</button>
|
<button class="btn btn-primary" type="submit">Pay</button>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
<select asp-for="SpeedPolicy" class="form-control">
|
<select asp-for="SpeedPolicy" class="form-control">
|
||||||
<option value="0">Is unconfirmed</option>
|
<option value="0">Is unconfirmed</option>
|
||||||
<option value="1">Has at least 1 confirmation</option>
|
<option value="1">Has at least 1 confirmation</option>
|
||||||
|
<option value="3">Has at least 2 confirmations</option>
|
||||||
<option value="2">Has at least 6 confirmations</option>
|
<option value="2">Has at least 6 confirmations</option>
|
||||||
</select>
|
</select>
|
||||||
<span asp-validation-for="SpeedPolicy" class="text-danger"></span>
|
<span asp-validation-for="SpeedPolicy" class="text-danger"></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user