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