Fix NotificationUrl and RedirectUrl templating

This commit is contained in:
nicolas.dorier 2019-09-04 18:01:26 +09:00
parent 8e15707dc7
commit f17a359893
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 12 additions and 17 deletions

View File

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

View File

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

View File

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