diff --git a/BTCPayServer.Tests/PaymentHandlerTest.cs b/BTCPayServer.Tests/PaymentHandlerTest.cs index 6a71f3a08..f456c62be 100644 --- a/BTCPayServer.Tests/PaymentHandlerTest.cs +++ b/BTCPayServer.Tests/PaymentHandlerTest.cs @@ -126,118 +126,7 @@ namespace BTCPayServer.Tests #pragma warning restore CS0618 } - - - [Fact] - public void CanPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsGreater() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike); - - //When - var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.Equal(errorMessage.Result, string.Empty); -#pragma warning restore CS0618 - } - - - [Fact] - public void CanPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsLower() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike); - - //When - var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.Equal(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - - - [Fact] - public void CannotPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsGreater() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike); - - //When - var totalInvoiceAmount = new Money(105m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.NotEqual(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - - - [Fact] - public void CannotPayWithLightningWhenInvoiceTotalUnderLightningMaxValueWhenOnChainMinValueIsLower() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.LightningLike); - - //When - var totalInvoiceAmount = new Money(105m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerLN.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.NotEqual(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - - //---- - - [Fact] public void CanPayWithBitcoinWhenInvoiceTotalAboveOnChainMinValue() { @@ -317,88 +206,7 @@ namespace BTCPayServer.Tests #pragma warning restore CS0618 } - - - [Fact] - public void CanPayWithBitcoinWhenInvoiceTotalAboveOnchainMinValueWhenLightningMaxValueIsLower() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike); - - //When - var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.Equal(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - - - [Fact] - public void CanPayWithBitcoinWhenInvoiceTotalAboveOnChainMinValueWhenLightningMaxValueIsGreater() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike); - - //When - var totalInvoiceAmount = new Money(80m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.Equal(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - - - [Fact] - public void CannotPayWithBitcoinWhenInvoiceTotalUnderOnChainMinValueWhenLightningMaxValueIsLower() - { - -#pragma warning disable CS0618 - - //Given - var store = new StoreBlob - { - OnChainMinValue = new CurrencyValue() {Value = 100.00m, Currency = "USD"}, - LightningMaxValue = new CurrencyValue() {Value = 50.00m, Currency = "USD"} - }; - var paymentMethodId = new PaymentMethodId("BTC", PaymentTypes.BTCLike); - - //When - var totalInvoiceAmount = new Money(45m, MoneyUnit.BTC); - - //Then - var errorMessage = handlerBTC.IsPaymentMethodAllowedBasedOnInvoiceAmount(store, currencyPairRateResult, - totalInvoiceAmount, paymentMethodId); - - Assert.NotEqual(errorMessage.Result, string.Empty); - -#pragma warning restore CS0618 - } - + [Fact] public void CannotPayWithBitcoinWhenInvoiceTotalUnderOnChainMinValueWhenLightningMaxValueIsGreater() @@ -426,5 +234,6 @@ namespace BTCPayServer.Tests #pragma warning restore CS0618 } + } } diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index bcb09b668..c2cbb71d1 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -74,38 +74,11 @@ namespace BTCPayServer.Payments.Bitcoin CurrencyValue limitValue = null; string errorMessage = null; - if (paymentMethodId.PaymentType == PaymentTypes.BTCLike) + if (storeBlob.OnChainMinValue != null) { - if (storeBlob.LightningMaxValue == null && - storeBlob.OnChainMinValue != null) - { - compare = (value, limit) => value < limit; - limitValue = storeBlob.OnChainMinValue; - errorMessage = "The amount of the invoice is too low to be paid on chain"; - } - else if (storeBlob.LightningMaxValue != null && - storeBlob.OnChainMinValue != null) - { - if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency && - storeBlob.LightningMaxValue.Value <= storeBlob.OnChainMinValue.Value) - { - //Case where both fields are set but OnChainMinValue is greater - // --> then use LightningMaxValue as limit - compare = (value, limit) => value < limit; - limitValue = storeBlob.LightningMaxValue; - errorMessage = "The amount of the invoice is too low to be paid on chain"; - } - else if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency && - storeBlob.LightningMaxValue.Value > storeBlob.OnChainMinValue.Value) - { - //Case where both fields are set but LightningMaxValue is greater - // --> then use OnChainMinValue as limit - // (Otherwise a gap of price value with no payment method is possible) - compare = (value, limit) => value < limit; - limitValue = storeBlob.OnChainMinValue; - errorMessage = "The amount of the invoice is too low to be paid on chain"; - } - } + compare = (value, limit) => value < limit; + limitValue = storeBlob.OnChainMinValue; + errorMessage = "The amount of the invoice is too low to be paid on chain"; } diff --git a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs index 10167709e..0018fdea3 100644 --- a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs @@ -151,38 +151,11 @@ namespace BTCPayServer.Payments.Lightning CurrencyValue limitValue = null; string errorMessage = null; - if (paymentMethodId.PaymentType == PaymentTypes.LightningLike) + if (storeBlob.LightningMaxValue != null) { - if (storeBlob.LightningMaxValue != null && - storeBlob.OnChainMinValue == null) - { - compare = (value, limit) => value > limit; - limitValue = storeBlob.LightningMaxValue; - errorMessage = "The amount of the invoice is too high to be paid with lightning"; - } - else if (storeBlob.LightningMaxValue != null && - storeBlob.OnChainMinValue != null) - { - if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency && - storeBlob.LightningMaxValue.Value >= storeBlob.OnChainMinValue.Value) - { - //Case where both fields are set but LightningMaxValue is greater - // --> then use LightningMaxValue as limit - compare = (value, limit) => value > limit; - limitValue = storeBlob.LightningMaxValue; - errorMessage = "The amount of the invoice is too high to be paid with lightning"; - } - else if (storeBlob.LightningMaxValue.Currency == storeBlob.OnChainMinValue.Currency && - storeBlob.LightningMaxValue.Value < storeBlob.OnChainMinValue.Value) - { - //Case where both fields are set but OnChainMinValue is greater - // --> then use OnChainMinValue as limit - // (Otherwise a gap of price value with no payment method is possible) - compare = (value, limit) => value > limit; - limitValue = storeBlob.OnChainMinValue; - errorMessage = "The amount of the invoice is too high to be paid with lightning"; - } - } + compare = (value, limit) => value > limit; + limitValue = storeBlob.LightningMaxValue; + errorMessage = "The amount of the invoice is too high to be paid with lightning"; }