Merge pull request #6470 from NicolasDorier/globalcheckoutmodelext

Plugin: Add IGlobalCheckoutModelExtension
This commit is contained in:
Nicolas Dorier 2024-12-10 18:59:46 +09:00 committed by GitHub
commit fe53424710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 3 deletions

View File

@ -936,10 +936,15 @@ namespace BTCPayServer.Controllers
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;
}

View File

@ -69,6 +69,7 @@ namespace BTCPayServer.Controllers
private readonly UriResolver _uriResolver;
public WebhookSender WebhookNotificationManager { get; }
public IEnumerable<IGlobalCheckoutModelExtension> GlobalCheckoutModelExtensions { get; }
public IStringLocalizer StringLocalizer { get; }
public UIInvoiceController(
@ -99,6 +100,7 @@ namespace BTCPayServer.Controllers
IAuthorizationService authorizationService,
TransactionLinkProviders transactionLinkProviders,
Dictionary<PaymentMethodId, ICheckoutModelExtension> paymentModelExtensions,
IEnumerable<IGlobalCheckoutModelExtension> globalCheckoutModelExtensions,
IStringLocalizer stringLocalizer,
PrettyNameProvider prettyName)
{
@ -124,6 +126,7 @@ namespace BTCPayServer.Controllers
_authorizationService = authorizationService;
_transactionLinkProviders = transactionLinkProviders;
_paymentModelExtensions = paymentModelExtensions;
GlobalCheckoutModelExtensions = globalCheckoutModelExtensions;
_prettyName = prettyName;
_fileService = fileService;
_uriResolver = uriResolver;

View File

@ -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);
}
}