Use internal tags, not order id in the streamer to know if the incoming invoice is for the payment request

This commit is contained in:
nicolas.dorier 2019-02-25 16:15:45 +09:00
parent 5bccd07d7d
commit 70f71f64c4
6 changed files with 33 additions and 18 deletions

View File

@ -296,7 +296,7 @@ namespace BTCPayServer.Controllers
FullNotifications = true,
BuyerEmail = result.Email,
RedirectURL = Request.GetDisplayUrl().Replace("/pay", "", StringComparison.InvariantCulture),
}, store, HttpContext.Request.GetAbsoluteRoot())).Data.Id;
}, store, HttpContext.Request.GetAbsoluteRoot(), new List<string>() { PaymentRequestRepository.GetInternalTag(id) })).Data.Id;
if (redirectToInvoice)
{

View File

@ -116,14 +116,13 @@ namespace BTCPayServer.PaymentRequest
{
if (evt is InvoiceEvent invoiceEvent)
{
var paymentRequestId = PaymentRequestRepository.GetPaymentRequestIdFromOrderId(invoiceEvent.Invoice.OrderId);
if (paymentRequestId == null)
return;
foreach (var paymentId in PaymentRequestRepository.GetPaymentIdsFromInternalTags(invoiceEvent.Invoice))
{
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
{
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(paymentRequestId);
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(paymentId);
var data = invoiceEvent.Payment.GetCryptoPaymentData();
await _HubContext.Clients.Group(paymentRequestId).SendCoreAsync(PaymentRequestHub.PaymentReceived,
await _HubContext.Clients.Group(paymentId).SendCoreAsync(PaymentRequestHub.PaymentReceived,
new object[]
{
data.GetValue(),
@ -133,7 +132,8 @@ namespace BTCPayServer.PaymentRequest
});
}
await InfoUpdated(paymentRequestId);
await InfoUpdated(paymentId);
}
}
else if (evt is PaymentRequestUpdated updated)
{

View File

@ -47,7 +47,7 @@ namespace BTCPayServer.Services.Apps
{
if (evt is InvoiceEvent invoiceEvent)
{
foreach (var appId in AppService.GetAppInternalTags(invoiceEvent.Invoice.InternalTags))
foreach (var appId in AppService.GetAppInternalTags(invoiceEvent.Invoice))
{
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
{

View File

@ -167,11 +167,9 @@ namespace BTCPayServer.Services.Apps
public static string GetCrowdfundOrderId(string appId) => $"crowdfund-app_{appId}";
public static string GetAppInternalTag(string appId) => $"APP#{appId}";
public static string[] GetAppInternalTags(IEnumerable<string> tags)
public static string[] GetAppInternalTags(InvoiceEntity invoice)
{
return tags == null ? Array.Empty<string>() : tags
.Where(t => t.StartsWith("APP#", StringComparison.InvariantCulture))
.Select(t => t.Substring("APP#".Length)).ToArray();
return invoice.GetInternalTags("APP#");
}
private async Task<InvoiceEntity[]> GetInvoicesForApp(AppData appData, DateTime? startDate = null)
{

View File

@ -170,6 +170,13 @@ namespace BTCPayServer.Services.Invoices
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public HashSet<string> InternalTags { get; set; } = new HashSet<string>();
public string[] GetInternalTags(string suffix)
{
return InternalTags == null ? Array.Empty<string>() : InternalTags
.Where(t => t.StartsWith(suffix, StringComparison.InvariantCulture))
.Select(t => t.Substring(suffix.Length)).ToArray();
}
[Obsolete("Use GetDerivationStrategies instead")]
public string DerivationStrategy
{

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -171,6 +172,15 @@ namespace BTCPayServer.Services.PaymentRequests
return invoiceOrderId.Replace("PAY_REQUEST_", "", StringComparison.InvariantCulture);
}
public static string GetInternalTag(string id)
{
return $"PAYREQ#{id}";
}
public static string[] GetPaymentIdsFromInternalTags(InvoiceEntity invoiceEntity)
{
return invoiceEntity.GetInternalTags("PAYREQ#");
}
}
public class PaymentRequestUpdated