mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Move back ToPrettyString() in PaymentMethodId to fix crash if a payment method as been disabled
This commit is contained in:
@@ -2252,14 +2252,13 @@ donation:
|
|||||||
var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, cashCow.Network);
|
var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, cashCow.Network);
|
||||||
var firstPayment = invoice.CryptoInfo[0].TotalDue - Money.Coins(0.001m);
|
var firstPayment = invoice.CryptoInfo[0].TotalDue - Money.Coins(0.001m);
|
||||||
cashCow.SendToAddress(invoiceAddress, firstPayment);
|
cashCow.SendToAddress(invoiceAddress, firstPayment);
|
||||||
var handler = tester.PayTester.GetService<BitcoinLikePaymentHandler>();
|
|
||||||
TestUtils.Eventually(() =>
|
TestUtils.Eventually(() =>
|
||||||
{
|
{
|
||||||
var exportResultPaid = user.GetController<InvoiceController>().Export("csv").GetAwaiter().GetResult();
|
var exportResultPaid = user.GetController<InvoiceController>().Export("csv").GetAwaiter().GetResult();
|
||||||
var paidresult = Assert.IsType<ContentResult>(exportResultPaid);
|
var paidresult = Assert.IsType<ContentResult>(exportResultPaid);
|
||||||
Assert.Equal("application/csv", paidresult.ContentType);
|
Assert.Equal("application/csv", paidresult.ContentType);
|
||||||
Assert.Contains($",\"orderId\",\"{invoice.Id}\",", paidresult.Content);
|
Assert.Contains($",\"orderId\",\"{invoice.Id}\",", paidresult.Content);
|
||||||
Assert.Contains($",\"{handler.PrettyDescription}\",\"BTC\",\"0.0991\",\"0.0001\",\"5000.0\"", paidresult.Content);
|
Assert.Contains($",\"On-Chain\",\"BTC\",\"0.0991\",\"0.0001\",\"5000.0\"", paidresult.Content);
|
||||||
Assert.Contains($",\"USD\",\"5.00", paidresult.Content); // Seems hacky but some plateform does not render this decimal the same
|
Assert.Contains($",\"USD\",\"5.00", paidresult.Content); // Seems hacky but some plateform does not render this decimal the same
|
||||||
Assert.Contains($"0\",\"500.0\",\"\",\"Some ``, description\",\"new (paidPartial)\"", paidresult.Content);
|
Assert.Contains($"0\",\"500.0\",\"\",\"Some ``, description\",\"new (paidPartial)\"", paidresult.Content);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ namespace BTCPayServer.Controllers
|
|||||||
new InvoiceDetailsModel.AddressModel
|
new InvoiceDetailsModel.AddressModel
|
||||||
{
|
{
|
||||||
Destination = h.GetAddress(),
|
Destination = h.GetAddress(),
|
||||||
PaymentMethod =
|
PaymentMethod = h.GetPaymentMethodId().ToPrettyString(),
|
||||||
invoice.PaymentMethodHandlerDictionary[h.GetPaymentMethodId()]
|
|
||||||
.ToPrettyString(h.GetPaymentMethodId()),
|
|
||||||
Current = !h.UnAssigned.HasValue
|
Current = !h.UnAssigned.HasValue
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
@@ -101,8 +99,7 @@ namespace BTCPayServer.Controllers
|
|||||||
var accounting = data.Calculate();
|
var accounting = data.Calculate();
|
||||||
var paymentMethodId = data.GetId();
|
var paymentMethodId = data.GetId();
|
||||||
var cryptoPayment = new InvoiceDetailsModel.CryptoPayment();
|
var cryptoPayment = new InvoiceDetailsModel.CryptoPayment();
|
||||||
cryptoPayment.PaymentMethod = invoice.PaymentMethodHandlerDictionary[paymentMethodId]
|
cryptoPayment.PaymentMethod = paymentMethodId.ToPrettyString();
|
||||||
.ToPrettyString(data.GetId());
|
|
||||||
cryptoPayment.Due = _CurrencyNameTable.DisplayFormatCurrency(accounting.Due.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
cryptoPayment.Due = _CurrencyNameTable.DisplayFormatCurrency(accounting.Due.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
||||||
cryptoPayment.Paid = _CurrencyNameTable.DisplayFormatCurrency(accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
cryptoPayment.Paid = _CurrencyNameTable.DisplayFormatCurrency(accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
||||||
cryptoPayment.Overpaid = _CurrencyNameTable.DisplayFormatCurrency(accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
cryptoPayment.Overpaid = _CurrencyNameTable.DisplayFormatCurrency(accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
|
||||||
@@ -525,7 +522,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
return new SelectList(_paymentMethodHandlerDictionary.Distinct().SelectMany(handler =>
|
return new SelectList(_paymentMethodHandlerDictionary.Distinct().SelectMany(handler =>
|
||||||
handler.GetSupportedPaymentMethods()
|
handler.GetSupportedPaymentMethods()
|
||||||
.Select(id => new SelectListItem(handler.ToPrettyString(id), id.ToString()))),
|
.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString()))),
|
||||||
nameof(SelectListItem.Value),
|
nameof(SelectListItem.Value),
|
||||||
nameof(SelectListItem.Text));
|
nameof(SelectListItem.Text));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var logPrefix = $"{handler.ToPrettyString(supportedPaymentMethod.PaymentId)}:";
|
var logPrefix = $"{supportedPaymentMethod.PaymentId.ToPrettyString()}:";
|
||||||
var storeBlob = store.GetStoreBlob();
|
var storeBlob = store.GetStoreBlob();
|
||||||
var preparePayment = handler.PreparePayment(supportedPaymentMethod, store, network);
|
var preparePayment = handler.PreparePayment(supportedPaymentMethod, store, network);
|
||||||
var rate = await fetchingByCurrencyPair[new CurrencyPair(network.CryptoCode, entity.ProductInformation.Currency)];
|
var rate = await fetchingByCurrencyPair[new CurrencyPair(network.CryptoCode, entity.ProductInformation.Currency)];
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ namespace BTCPayServer.Controllers
|
|||||||
void SetCryptoCurrencies(CheckoutExperienceViewModel vm, Data.StoreData storeData)
|
void SetCryptoCurrencies(CheckoutExperienceViewModel vm, Data.StoreData storeData)
|
||||||
{
|
{
|
||||||
var choices = storeData.GetEnabledPaymentIds(_NetworkProvider)
|
var choices = storeData.GetEnabledPaymentIds(_NetworkProvider)
|
||||||
.Select(o => new CheckoutExperienceViewModel.Format() { Name = _paymentMethodHandlerDictionary[o].ToPrettyString(o), Value = o.ToString(), PaymentId = o }).ToArray();
|
.Select(o => new CheckoutExperienceViewModel.Format() { Name = o.ToPrettyString(), Value = o.ToString(), PaymentId = o }).ToArray();
|
||||||
|
|
||||||
var defaultPaymentId = storeData.GetDefaultPaymentId(_NetworkProvider);
|
var defaultPaymentId = storeData.GetDefaultPaymentId(_NetworkProvider);
|
||||||
var chosen = choices.FirstOrDefault(c => c.PaymentId == defaultPaymentId);
|
var chosen = choices.FirstOrDefault(c => c.PaymentId == defaultPaymentId);
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string PrettyDescription => "On-Chain";
|
|
||||||
public override PaymentTypes PaymentType => PaymentTypes.BTCLike;
|
public override PaymentTypes PaymentType => PaymentTypes.BTCLike;
|
||||||
|
|
||||||
public override async Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
public override async Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace BTCPayServer.Payments
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPaymentMethodHandler
|
public interface IPaymentMethodHandler
|
||||||
{
|
{
|
||||||
string PrettyDescription { get; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create needed to track payments of this invoice
|
/// Create needed to track payments of this invoice
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -45,8 +44,6 @@ namespace BTCPayServer.Payments
|
|||||||
PaymentMethodAccounting accounting, PaymentMethod info);
|
PaymentMethodAccounting accounting, PaymentMethod info);
|
||||||
|
|
||||||
|
|
||||||
string ToPrettyString(PaymentMethodId paymentMethodId);
|
|
||||||
|
|
||||||
void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse);
|
void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse);
|
||||||
string GetCryptoImage(PaymentMethodId paymentMethodId);
|
string GetCryptoImage(PaymentMethodId paymentMethodId);
|
||||||
string GetPaymentMethodName(PaymentMethodId paymentMethodId);
|
string GetPaymentMethodName(PaymentMethodId paymentMethodId);
|
||||||
@@ -77,7 +74,6 @@ namespace BTCPayServer.Payments
|
|||||||
where TSupportedPaymentMethod : ISupportedPaymentMethod
|
where TSupportedPaymentMethod : ISupportedPaymentMethod
|
||||||
where TBTCPayNetwork : BTCPayNetworkBase
|
where TBTCPayNetwork : BTCPayNetworkBase
|
||||||
{
|
{
|
||||||
public abstract string PrettyDescription { get; }
|
|
||||||
public abstract PaymentTypes PaymentType { get; }
|
public abstract PaymentTypes PaymentType { get; }
|
||||||
|
|
||||||
public abstract Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
public abstract Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
||||||
@@ -129,10 +125,5 @@ namespace BTCPayServer.Payments
|
|||||||
|
|
||||||
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToPrettyString(PaymentMethodId paymentMethodId)
|
|
||||||
{
|
|
||||||
return $"{paymentMethodId.CryptoCode} ({PrettyDescription})";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
_socketFactory = socketFactory;
|
_socketFactory = socketFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string PrettyDescription => "Off-Chain";
|
|
||||||
public override PaymentTypes PaymentType => PaymentTypes.LightningLike;
|
public override PaymentTypes PaymentType => PaymentTypes.LightningLike;
|
||||||
public override async Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
public override async Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
||||||
LightningSupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store,
|
LightningSupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store,
|
||||||
|
|||||||
@@ -66,6 +66,24 @@ namespace BTCPayServer.Payments
|
|||||||
return PaymentType == PaymentTypes.BTCLike ? CryptoCode : $"{CryptoCode}_{PaymentType}";
|
return PaymentType == PaymentTypes.BTCLike ? CryptoCode : $"{CryptoCode}_{PaymentType}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ToPrettyPaymentType()
|
||||||
|
{
|
||||||
|
switch (PaymentType)
|
||||||
|
{
|
||||||
|
case PaymentTypes.BTCLike:
|
||||||
|
return "On-Chain";
|
||||||
|
case PaymentTypes.LightningLike:
|
||||||
|
return "Off-Chain";
|
||||||
|
default:
|
||||||
|
return PaymentType.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToPrettyString()
|
||||||
|
{
|
||||||
|
return $"{CryptoCode} ({ToPrettyPaymentType()})";
|
||||||
|
}
|
||||||
|
|
||||||
public static bool TryParse(string str, out PaymentMethodId paymentMethodId)
|
public static bool TryParse(string str, out PaymentMethodId paymentMethodId)
|
||||||
{
|
{
|
||||||
paymentMethodId = null;
|
paymentMethodId = null;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace BTCPayServer.Services.Invoices.Export
|
|||||||
PaymentId = pdata.GetPaymentId(),
|
PaymentId = pdata.GetPaymentId(),
|
||||||
CryptoCode = cryptoCode,
|
CryptoCode = cryptoCode,
|
||||||
ConversionRate = pmethod.Rate,
|
ConversionRate = pmethod.Rate,
|
||||||
PaymentType = invoice.PaymentMethodHandlerDictionary[payment.GetPaymentMethodId()].PrettyDescription,
|
PaymentType = payment.GetPaymentMethodId().ToPrettyPaymentType(),
|
||||||
Destination = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork<BTCPayNetworkBase>(cryptoCode)),
|
Destination = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork<BTCPayNetworkBase>(cryptoCode)),
|
||||||
Paid = pdata.GetValue().ToString(CultureInfo.InvariantCulture),
|
Paid = pdata.GetValue().ToString(CultureInfo.InvariantCulture),
|
||||||
PaidCurrency = Math.Round(pdata.GetValue() * pmethod.Rate, currency.NumberDecimalDigits).ToString(CultureInfo.InvariantCulture),
|
PaidCurrency = Math.Round(pdata.GetValue() * pmethod.Rate, currency.NumberDecimalDigits).ToString(CultureInfo.InvariantCulture),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.3.108</Version>
|
<Version>1.0.3.109</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user