Skip to content

Commit

Permalink
Plugin: Add IGlobalCheckoutModelExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Dec 9, 2024
1 parent 1214367 commit 4f63f08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions BTCPayServer/Controllers/UIInvoiceController.UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,15 @@ _ when PaymentTypes.LN.GetPaymentMethodId(_NetworkProvider.DefaultNetwork.Crypto
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);
model.TimeLeft = expiration.PrettyPrint();

if (_paymentModelExtensions.TryGetValue(paymentMethodId, out var extension) &&
_handlers.TryGetValue(paymentMethodId, out var h))
if (_handlers.TryGetValue(paymentMethodId, out var h))
{
extension.ModifyCheckoutModel(new CheckoutModelContext(model, store, storeBlob, invoice, Url, prompt, h));
var ctx = new CheckoutModelContext(model, store, storeBlob, invoice, Url, prompt, h);
if (_paymentModelExtensions.TryGetValue(paymentMethodId, out var extension))
{
extension.ModifyCheckoutModel(ctx);
}
foreach (var global in GlobalCheckoutModelExtensions)
global.ModifyCheckoutModel(ctx);
}
return model;
}
Expand Down
3 changes: 3 additions & 0 deletions BTCPayServer/Controllers/UIInvoiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public partial class UIInvoiceController : Controller
private readonly UriResolver _uriResolver;

public WebhookSender WebhookNotificationManager { get; }
public IEnumerable<IGlobalCheckoutModelExtension> GlobalCheckoutModelExtensions { get; }
public IStringLocalizer StringLocalizer { get; }

public UIInvoiceController(
Expand Down Expand Up @@ -99,6 +100,7 @@ public UIInvoiceController(
IAuthorizationService authorizationService,
TransactionLinkProviders transactionLinkProviders,
Dictionary<PaymentMethodId, ICheckoutModelExtension> paymentModelExtensions,
IEnumerable<IGlobalCheckoutModelExtension> globalCheckoutModelExtensions,
IStringLocalizer stringLocalizer,
PrettyNameProvider prettyName)
{
Expand All @@ -124,6 +126,7 @@ public UIInvoiceController(
_authorizationService = authorizationService;
_transactionLinkProviders = transactionLinkProviders;
_paymentModelExtensions = paymentModelExtensions;
GlobalCheckoutModelExtensions = globalCheckoutModelExtensions;
_prettyName = prettyName;
_fileService = fileService;
_uriResolver = uriResolver;
Expand Down
10 changes: 10 additions & 0 deletions BTCPayServer/Payments/IGlobalCheckoutModelExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BTCPayServer.Payments
{
/// <summary>
/// <see cref="ModifyCheckoutModel"/> will always run when showing the checkout page
/// </summary>
public interface IGlobalCheckoutModelExtension
{
void ModifyCheckoutModel(CheckoutModelContext context);
}
}

0 comments on commit 4f63f08

Please sign in to comment.