mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Fix NotificationUrl and RedirectUrl templating
This commit is contained in:
@@ -81,13 +81,7 @@ namespace BTCPayServer.Controllers
|
|||||||
entity.ServerUrl = serverUrl;
|
entity.ServerUrl = serverUrl;
|
||||||
entity.FullNotifications = invoice.FullNotifications || invoice.ExtendedNotifications;
|
entity.FullNotifications = invoice.FullNotifications || invoice.ExtendedNotifications;
|
||||||
entity.ExtendedNotifications = invoice.ExtendedNotifications;
|
entity.ExtendedNotifications = invoice.ExtendedNotifications;
|
||||||
|
entity.NotificationURLTemplate = invoice.NotificationURL;
|
||||||
if (invoice.NotificationURL != null &&
|
|
||||||
Uri.TryCreate(invoice.NotificationURL, UriKind.Absolute, out var notificationUri) &&
|
|
||||||
(notificationUri.Scheme == "http" || notificationUri.Scheme == "https"))
|
|
||||||
{
|
|
||||||
entity.NotificationURLTemplate = notificationUri.AbsoluteUri;
|
|
||||||
}
|
|
||||||
entity.NotificationEmail = invoice.NotificationEmail;
|
entity.NotificationEmail = invoice.NotificationEmail;
|
||||||
entity.BuyerInformation = Map<CreateInvoiceRequest, BuyerInformation>(invoice);
|
entity.BuyerInformation = Map<CreateInvoiceRequest, BuyerInformation>(invoice);
|
||||||
entity.PaymentTolerance = storeBlob.PaymentTolerance;
|
entity.PaymentTolerance = storeBlob.PaymentTolerance;
|
||||||
@@ -120,8 +114,6 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
|
|
||||||
entity.RedirectURLTemplate = invoice.RedirectURL ?? store.StoreWebsite;
|
entity.RedirectURLTemplate = invoice.RedirectURL ?? store.StoreWebsite;
|
||||||
if (!Uri.IsWellFormedUriString(entity.RedirectURL, UriKind.Absolute))
|
|
||||||
entity.RedirectURLTemplate = null;
|
|
||||||
|
|
||||||
entity.RedirectAutomatically =
|
entity.RedirectAutomatically =
|
||||||
invoice.RedirectAutomatically.GetValueOrDefault(storeBlob.RedirectAutomatically);
|
invoice.RedirectAutomatically.GetValueOrDefault(storeBlob.RedirectAutomatically);
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ namespace BTCPayServer.HostedServices
|
|||||||
emailBody);
|
emailBody);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(invoice.NotificationURL) || !Uri.IsWellFormedUriString(invoice.NotificationURL, UriKind.Absolute))
|
if (invoice.NotificationURL != null)
|
||||||
return;
|
{
|
||||||
var invoiceStr = NBitcoin.JsonConverters.Serializer.ToString(new ScheduledJob() { TryCount = 0, Notification = notification });
|
var invoiceStr = NBitcoin.JsonConverters.Serializer.ToString(new ScheduledJob() { TryCount = 0, Notification = notification });
|
||||||
if (!string.IsNullOrEmpty(invoice.NotificationURL))
|
|
||||||
_JobClient.Schedule((cancellation) => NotifyHttp(invoiceStr, cancellation), TimeSpan.Zero);
|
_JobClient.Schedule((cancellation) => NotifyHttp(invoiceStr, cancellation), TimeSpan.Zero);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NotifyHttp(string invoiceData, CancellationToken cancellationToken)
|
public async Task NotifyHttp(string invoiceData, CancellationToken cancellationToken)
|
||||||
|
|||||||
@@ -297,12 +297,15 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string RedirectURL => FillPlaceholders(RedirectURLTemplate);
|
public string RedirectURL => FillPlaceholdersUri(RedirectURLTemplate);
|
||||||
|
|
||||||
private string FillPlaceholders(string v)
|
private string FillPlaceholdersUri(string v)
|
||||||
{
|
{
|
||||||
return (v ?? string.Empty).Replace("{OrderId}", OrderId ?? "", StringComparison.OrdinalIgnoreCase)
|
var uriStr = (v ?? string.Empty).Replace("{OrderId}", OrderId ?? "", StringComparison.OrdinalIgnoreCase)
|
||||||
.Replace("{InvoiceId}", Id ?? "", StringComparison.OrdinalIgnoreCase);
|
.Replace("{InvoiceId}", Id ?? "", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (Uri.TryCreate(uriStr, UriKind.Absolute, out var uri) && (uri.Scheme == "http" || uri.Scheme == "https"))
|
||||||
|
return uri.AbsoluteUri;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RedirectAutomatically
|
public bool RedirectAutomatically
|
||||||
@@ -336,7 +339,7 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string NotificationURL => FillPlaceholders(NotificationURLTemplate);
|
public string NotificationURL => FillPlaceholdersUri(NotificationURLTemplate);
|
||||||
public string ServerUrl
|
public string ServerUrl
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
Reference in New Issue
Block a user