mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Allow payment methods to modify all the payment model
This commit is contained in:
@@ -922,7 +922,6 @@ namespace BTCPayServer.Controllers
|
|||||||
Status = invoice.Status.ToString(),
|
Status = invoice.Status.ToString(),
|
||||||
// The Tweak is part of the PaymentMethodFee, but let's not show it in the UI as it's negligible.
|
// The Tweak is part of the PaymentMethodFee, but let's not show it in the UI as it's negligible.
|
||||||
NetworkFee = prompt.PaymentMethodFee - prompt.TweakFee,
|
NetworkFee = prompt.PaymentMethodFee - prompt.TweakFee,
|
||||||
IsMultiCurrency = invoice.GetPayments(false).Select(p => p.PaymentMethodId).Concat(new[] { prompt.PaymentMethodId }).Distinct().Count() > 1,
|
|
||||||
StoreId = store.Id,
|
StoreId = store.Id,
|
||||||
AvailableCryptos = invoice.GetPaymentPrompts()
|
AvailableCryptos = invoice.GetPaymentPrompts()
|
||||||
.Select(kv =>
|
.Select(kv =>
|
||||||
@@ -930,8 +929,9 @@ namespace BTCPayServer.Controllers
|
|||||||
var handler = _handlers[kv.PaymentMethodId];
|
var handler = _handlers[kv.PaymentMethodId];
|
||||||
return new PaymentModel.AvailableCrypto
|
return new PaymentModel.AvailableCrypto
|
||||||
{
|
{
|
||||||
|
Handler = handler,
|
||||||
Displayed = displayedPaymentMethods.Contains(kv.PaymentMethodId),
|
Displayed = displayedPaymentMethods.Contains(kv.PaymentMethodId),
|
||||||
PaymentMethodId = kv.PaymentMethodId.ToString(),
|
PaymentMethodId = kv.PaymentMethodId,
|
||||||
CryptoCode = kv.Currency,
|
CryptoCode = kv.Currency,
|
||||||
PaymentMethodName = _prettyName.PrettyName(kv.PaymentMethodId),
|
PaymentMethodName = _prettyName.PrettyName(kv.PaymentMethodId),
|
||||||
IsLightning = handler is ILightningPaymentHandler,
|
IsLightning = handler is ILightningPaymentHandler,
|
||||||
@@ -947,8 +947,15 @@ namespace BTCPayServer.Controllers
|
|||||||
.OrderByDescending(a => a.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode).ThenBy(a => a.PaymentMethodName).ThenBy(a => a.IsLightning ? 1 : 0)
|
.OrderByDescending(a => a.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode).ThenBy(a => a.PaymentMethodName).ThenBy(a => a.IsLightning ? 1 : 0)
|
||||||
.ToList()
|
.ToList()
|
||||||
};
|
};
|
||||||
if (_paymentModelExtensions.TryGetValue(paymentMethodId, out var extension))
|
|
||||||
extension.ModifyPaymentModel(new PaymentModelContext(model, store, storeBlob, invoice, Url, prompt, handler));
|
foreach (var kv in invoice.GetPaymentPrompts())
|
||||||
|
{
|
||||||
|
if (_paymentModelExtensions.TryGetValue(kv.PaymentMethodId, out var extension) &&
|
||||||
|
_handlers.TryGetValue(kv.PaymentMethodId, out var h))
|
||||||
|
{
|
||||||
|
extension.ModifyPaymentModel(new PaymentModelContext(model, store, storeBlob, invoice, Url, kv, h, paymentMethodId == kv.PaymentMethodId));
|
||||||
|
}
|
||||||
|
}
|
||||||
model.UISettings = _viewProvider.TryGetViewViewModel(prompt, "CheckoutUI")?.View as CheckoutUIPaymentMethodSettings;
|
model.UISettings = _viewProvider.TryGetViewViewModel(prompt, "CheckoutUI")?.View as CheckoutUIPaymentMethodSettings;
|
||||||
model.PaymentMethodId = paymentMethodId.ToString();
|
model.PaymentMethodId = paymentMethodId.ToString();
|
||||||
model.OrderAmountFiat = OrderAmountFromInvoice(model.CryptoCode, invoice, DisplayFormatter.CurrencyFormat.Symbol);
|
model.OrderAmountFiat = OrderAmountFromInvoice(model.CryptoCode, invoice, DisplayFormatter.CurrencyFormat.Symbol);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using BTCPayServer.Client.Models;
|
using BTCPayServer.Client.Models;
|
||||||
|
using BTCPayServer.JsonConverters;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace BTCPayServer.Models.InvoicingModels
|
namespace BTCPayServer.Models.InvoicingModels
|
||||||
{
|
{
|
||||||
@@ -9,13 +12,19 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
public CheckoutUIPaymentMethodSettings UISettings;
|
public CheckoutUIPaymentMethodSettings UISettings;
|
||||||
public class AvailableCrypto
|
public class AvailableCrypto
|
||||||
{
|
{
|
||||||
public string PaymentMethodId { get; set; }
|
[JsonConverter(typeof(PaymentMethodIdJsonConverter))]
|
||||||
|
public PaymentMethodId PaymentMethodId { get; set; }
|
||||||
public string CryptoImage { get; set; }
|
public string CryptoImage { get; set; }
|
||||||
public string Link { get; set; }
|
public string Link { get; set; }
|
||||||
public string PaymentMethodName { get; set; }
|
public string PaymentMethodName { get; set; }
|
||||||
public bool IsLightning { get; set; }
|
public bool IsLightning { get; set; }
|
||||||
public string CryptoCode { get; set; }
|
public string CryptoCode { get; set; }
|
||||||
public bool Displayed { get; set; }
|
public bool Displayed { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public IPaymentMethodHandler Handler { get; internal set; }
|
||||||
|
|
||||||
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JToken> AdditionalData { get; set; } = new();
|
||||||
}
|
}
|
||||||
public StoreBrandingViewModel StoreBranding { get; set; }
|
public StoreBrandingViewModel StoreBranding { get; set; }
|
||||||
public string PaymentSoundUrl { get; set; }
|
public string PaymentSoundUrl { get; set; }
|
||||||
@@ -58,7 +67,6 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
|
|
||||||
public string OrderId { get; set; }
|
public string OrderId { get; set; }
|
||||||
public decimal NetworkFee { get; set; }
|
public decimal NetworkFee { get; set; }
|
||||||
public bool IsMultiCurrency { get; set; }
|
|
||||||
public int MaxTimeMinutes { get; set; }
|
public int MaxTimeMinutes { get; set; }
|
||||||
public string PaymentMethodId { get; set; }
|
public string PaymentMethodId { get; set; }
|
||||||
public string PaymentMethodName { get; set; }
|
public string PaymentMethodName { get; set; }
|
||||||
@@ -73,6 +81,9 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
public int? RequiredConfirmations { get; set; }
|
public int? RequiredConfirmations { get; set; }
|
||||||
public long? ReceivedConfirmations { get; set; }
|
public long? ReceivedConfirmations { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public HashSet<string> ExtensionPartials { get; } = new HashSet<string>();
|
public HashSet<string> ExtensionPartials { get; } = new HashSet<string>();
|
||||||
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JToken> AdditionalData { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
public PaymentMethodId PaymentMethodId { get; }
|
public PaymentMethodId PaymentMethodId { get; }
|
||||||
public void ModifyPaymentModel(PaymentModelContext context)
|
public void ModifyPaymentModel(PaymentModelContext context)
|
||||||
{
|
{
|
||||||
var prompt = context.Prompt;
|
if (context is not { IsSelected: true, Handler: BitcoinLikePaymentHandler handler})
|
||||||
if (!_handlers.TryGetValue(PaymentMethodId, out var o) || o is not BitcoinLikePaymentHandler handler)
|
|
||||||
return;
|
return;
|
||||||
|
var prompt = context.Prompt;
|
||||||
var details = handler.ParsePaymentPromptDetails(prompt.Details);
|
var details = handler.ParsePaymentPromptDetails(prompt.Details);
|
||||||
context.Model.ShowRecommendedFee = context.StoreBlob.ShowRecommendedFee;
|
context.Model.ShowRecommendedFee = context.StoreBlob.ShowRecommendedFee;
|
||||||
context.Model.FeeRate = details.RecommendedFeeRate.SatoshiPerByte;
|
context.Model.FeeRate = details.RecommendedFeeRate.SatoshiPerByte;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ namespace BTCPayServer.Payments
|
|||||||
InvoiceEntity InvoiceEntity,
|
InvoiceEntity InvoiceEntity,
|
||||||
IUrlHelper UrlHelper,
|
IUrlHelper UrlHelper,
|
||||||
PaymentPrompt Prompt,
|
PaymentPrompt Prompt,
|
||||||
IPaymentMethodHandler Handler);
|
IPaymentMethodHandler Handler,
|
||||||
|
bool IsSelected);
|
||||||
public interface IPaymentModelExtension
|
public interface IPaymentModelExtension
|
||||||
{
|
{
|
||||||
public PaymentMethodId PaymentMethodId { get; }
|
public PaymentMethodId PaymentMethodId { get; }
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ namespace BTCPayServer.Payments.LNURLPay
|
|||||||
private const string UriScheme = "lightning:";
|
private const string UriScheme = "lightning:";
|
||||||
public void ModifyPaymentModel(PaymentModelContext context)
|
public void ModifyPaymentModel(PaymentModelContext context)
|
||||||
{
|
{
|
||||||
|
if (context is not { IsSelected: true, Handler: LNURLPayPaymentHandler handler })
|
||||||
|
return;
|
||||||
var lnurl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
var lnurl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
||||||
if (lnurl is not null)
|
if (lnurl is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
public string Badge => "⚡";
|
public string Badge => "⚡";
|
||||||
public void ModifyPaymentModel(PaymentModelContext context)
|
public void ModifyPaymentModel(PaymentModelContext context)
|
||||||
{
|
{
|
||||||
if (!Handlers.TryGetValue(PaymentMethodId, out var o) || o is not LightningLikePaymentHandler handler)
|
if (context is not { IsSelected: true, Handler: LightningLikePaymentHandler handler })
|
||||||
return;
|
return;
|
||||||
var paymentPrompt = context.InvoiceEntity.GetPaymentPrompt(PaymentMethodId);
|
var paymentPrompt = context.InvoiceEntity.GetPaymentPrompt(PaymentMethodId);
|
||||||
if (paymentPrompt is null)
|
if (paymentPrompt is null)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
using BTCPayServer.Payments.Bitcoin;
|
using BTCPayServer.Payments.Bitcoin;
|
||||||
|
using BTCPayServer.Payments.Lightning;
|
||||||
using BTCPayServer.Services.Altcoins.Monero.Services;
|
using BTCPayServer.Services.Altcoins.Monero.Services;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
|
||||||
@@ -33,20 +34,20 @@ namespace BTCPayServer.Services.Altcoins.Monero.Payments
|
|||||||
|
|
||||||
public void ModifyPaymentModel(PaymentModelContext context)
|
public void ModifyPaymentModel(PaymentModelContext context)
|
||||||
{
|
{
|
||||||
|
if (context is not { IsSelected: true, Handler: MoneroLikePaymentMethodHandler handler })
|
||||||
|
return;
|
||||||
if (context.Model.Activated)
|
if (context.Model.Activated)
|
||||||
{
|
{
|
||||||
if (_handlers.TryGetValue(PaymentMethodId, out var handler))
|
var details = context.InvoiceEntity.GetPayments(true)
|
||||||
|
.Select(p => p.GetDetails<MoneroLikePaymentData>(handler))
|
||||||
|
.Where(p => p is not null)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (details is not null)
|
||||||
{
|
{
|
||||||
var details = context.InvoiceEntity.GetPayments(true)
|
context.Model.ReceivedConfirmations = details.ConfirmationCount;
|
||||||
.Select(p => p.GetDetails<MoneroLikePaymentData>(handler))
|
context.Model.RequiredConfirmations = (int)MoneroListener.ConfirmationsRequired(details, context.InvoiceEntity.SpeedPolicy);
|
||||||
.Where(p => p is not null)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (details is not null)
|
|
||||||
{
|
|
||||||
context.Model.ReceivedConfirmations = details.ConfirmationCount;
|
|
||||||
context.Model.RequiredConfirmations = (int)MoneroListener.ConfirmationsRequired(details, context.InvoiceEntity.SpeedPolicy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Model.InvoiceBitcoinUrl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
context.Model.InvoiceBitcoinUrl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
||||||
context.Model.InvoiceBitcoinUrlQR = context.Model.InvoiceBitcoinUrl;
|
context.Model.InvoiceBitcoinUrlQR = context.Model.InvoiceBitcoinUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
|
using BTCPayServer.Services.Altcoins.Monero.Payments;
|
||||||
using BTCPayServer.Services.Altcoins.Zcash.Services;
|
using BTCPayServer.Services.Altcoins.Zcash.Services;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
|
||||||
@@ -32,19 +33,18 @@ namespace BTCPayServer.Services.Altcoins.Zcash.Payments
|
|||||||
|
|
||||||
public void ModifyPaymentModel(PaymentModelContext context)
|
public void ModifyPaymentModel(PaymentModelContext context)
|
||||||
{
|
{
|
||||||
|
if (context is not { IsSelected: true, Handler: ZcashLikePaymentMethodHandler handler })
|
||||||
|
return;
|
||||||
if (context.Model.Activated)
|
if (context.Model.Activated)
|
||||||
{
|
{
|
||||||
if (_handlers.TryGetValue(PaymentMethodId, out var handler))
|
var details = context.InvoiceEntity.GetPayments(true)
|
||||||
|
.Select(p => p.GetDetails<ZcashLikePaymentData>(handler))
|
||||||
|
.Where(p => p is not null)
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (details is not null)
|
||||||
{
|
{
|
||||||
var details = context.InvoiceEntity.GetPayments(true)
|
context.Model.ReceivedConfirmations = details.ConfirmationCount;
|
||||||
.Select(p => p.GetDetails<ZcashLikePaymentData>(handler))
|
context.Model.RequiredConfirmations = (int)ZcashListener.ConfirmationsRequired(context.InvoiceEntity.SpeedPolicy);
|
||||||
.Where(p => p is not null)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (details is not null)
|
|
||||||
{
|
|
||||||
context.Model.ReceivedConfirmations = details.ConfirmationCount;
|
|
||||||
context.Model.RequiredConfirmations = (int)ZcashListener.ConfirmationsRequired(context.InvoiceEntity.SpeedPolicy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
context.Model.InvoiceBitcoinUrl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
context.Model.InvoiceBitcoinUrl = paymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper);
|
||||||
context.Model.InvoiceBitcoinUrlQR = context.Model.InvoiceBitcoinUrl;
|
context.Model.InvoiceBitcoinUrlQR = context.Model.InvoiceBitcoinUrl;
|
||||||
|
|||||||
Reference in New Issue
Block a user