Allow Placeholders in redirectURL (Fix #169)

This commit is contained in:
nicolas.dorier 2019-09-02 16:04:41 +09:00
parent 57b436417c
commit 6bd601137a
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 21 additions and 6 deletions

View file

@ -86,7 +86,7 @@ namespace BTCPayServer.Controllers
Uri.TryCreate(invoice.NotificationURL, UriKind.Absolute, out var notificationUri) &&
(notificationUri.Scheme == "http" || notificationUri.Scheme == "https"))
{
entity.NotificationURL = notificationUri.AbsoluteUri;
entity.NotificationURLTemplate = notificationUri.AbsoluteUri;
}
entity.NotificationEmail = invoice.NotificationEmail;
entity.BuyerInformation = Map<CreateInvoiceRequest, BuyerInformation>(invoice);
@ -119,9 +119,9 @@ namespace BTCPayServer.Controllers
entity.ProductInformation = Map<CreateInvoiceRequest, ProductInformation>(invoice);
entity.RedirectURL = invoice.RedirectURL ?? store.StoreWebsite;
entity.RedirectURLTemplate = invoice.RedirectURL ?? store.StoreWebsite;
if (!Uri.IsWellFormedUriString(entity.RedirectURL, UriKind.Absolute))
entity.RedirectURL = null;
entity.RedirectURLTemplate = null;
entity.RedirectAutomatically =
invoice.RedirectAutomatically.GetValueOrDefault(storeBlob.RedirectAutomatically);

View file

@ -289,12 +289,22 @@ namespace BTCPayServer.Services.Invoices
get;
set;
}
public string RedirectURL
[JsonProperty("redirectURL")]
public string RedirectURLTemplate
{
get;
set;
}
[JsonIgnore]
public string RedirectURL => FillPlaceholders(RedirectURLTemplate);
private string FillPlaceholders(string v)
{
return (v ?? string.Empty).Replace("{OrderId}", OrderId ?? "", StringComparison.OrdinalIgnoreCase)
.Replace("{InvoiceId}", Id ?? "", StringComparison.OrdinalIgnoreCase);
}
public bool RedirectAutomatically
{
get;
@ -317,11 +327,16 @@ namespace BTCPayServer.Services.Invoices
get;
set;
}
public string NotificationURL
[JsonProperty("notificationURL")]
public string NotificationURLTemplate
{
get;
set;
}
[JsonIgnore]
public string NotificationURL => FillPlaceholders(NotificationURLTemplate);
public string ServerUrl
{
get;