mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
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:
parent
5bccd07d7d
commit
70f71f64c4
@ -296,7 +296,7 @@ namespace BTCPayServer.Controllers
|
|||||||
FullNotifications = true,
|
FullNotifications = true,
|
||||||
BuyerEmail = result.Email,
|
BuyerEmail = result.Email,
|
||||||
RedirectURL = Request.GetDisplayUrl().Replace("/pay", "", StringComparison.InvariantCulture),
|
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)
|
if (redirectToInvoice)
|
||||||
{
|
{
|
||||||
|
@ -116,24 +116,24 @@ namespace BTCPayServer.PaymentRequest
|
|||||||
{
|
{
|
||||||
if (evt is InvoiceEvent invoiceEvent)
|
if (evt is InvoiceEvent invoiceEvent)
|
||||||
{
|
{
|
||||||
var paymentRequestId = PaymentRequestRepository.GetPaymentRequestIdFromOrderId(invoiceEvent.Invoice.OrderId);
|
foreach (var paymentId in PaymentRequestRepository.GetPaymentIdsFromInternalTags(invoiceEvent.Invoice))
|
||||||
if (paymentRequestId == null)
|
|
||||||
return;
|
|
||||||
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
|
|
||||||
{
|
{
|
||||||
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(paymentRequestId);
|
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
|
||||||
var data = invoiceEvent.Payment.GetCryptoPaymentData();
|
{
|
||||||
await _HubContext.Clients.Group(paymentRequestId).SendCoreAsync(PaymentRequestHub.PaymentReceived,
|
await _PaymentRequestService.UpdatePaymentRequestStateIfNeeded(paymentId);
|
||||||
new object[]
|
var data = invoiceEvent.Payment.GetCryptoPaymentData();
|
||||||
{
|
await _HubContext.Clients.Group(paymentId).SendCoreAsync(PaymentRequestHub.PaymentReceived,
|
||||||
|
new object[]
|
||||||
|
{
|
||||||
data.GetValue(),
|
data.GetValue(),
|
||||||
invoiceEvent.Payment.GetCryptoCode(),
|
invoiceEvent.Payment.GetCryptoCode(),
|
||||||
Enum.GetName(typeof(PaymentTypes),
|
Enum.GetName(typeof(PaymentTypes),
|
||||||
invoiceEvent.Payment.GetPaymentMethodId().PaymentType)
|
invoiceEvent.Payment.GetPaymentMethodId().PaymentType)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await InfoUpdated(paymentRequestId);
|
await InfoUpdated(paymentId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (evt is PaymentRequestUpdated updated)
|
else if (evt is PaymentRequestUpdated updated)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ namespace BTCPayServer.Services.Apps
|
|||||||
{
|
{
|
||||||
if (evt is InvoiceEvent invoiceEvent)
|
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)
|
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
|
||||||
{
|
{
|
||||||
|
@ -167,11 +167,9 @@ namespace BTCPayServer.Services.Apps
|
|||||||
|
|
||||||
public static string GetCrowdfundOrderId(string appId) => $"crowdfund-app_{appId}";
|
public static string GetCrowdfundOrderId(string appId) => $"crowdfund-app_{appId}";
|
||||||
public static string GetAppInternalTag(string appId) => $"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
|
return invoice.GetInternalTags("APP#");
|
||||||
.Where(t => t.StartsWith("APP#", StringComparison.InvariantCulture))
|
|
||||||
.Select(t => t.Substring("APP#".Length)).ToArray();
|
|
||||||
}
|
}
|
||||||
private async Task<InvoiceEntity[]> GetInvoicesForApp(AppData appData, DateTime? startDate = null)
|
private async Task<InvoiceEntity[]> GetInvoicesForApp(AppData appData, DateTime? startDate = null)
|
||||||
{
|
{
|
||||||
|
@ -169,6 +169,13 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public HashSet<string> InternalTags { get; set; } = new HashSet<string>();
|
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")]
|
[Obsolete("Use GetDerivationStrategies instead")]
|
||||||
public string DerivationStrategy
|
public string DerivationStrategy
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -171,6 +172,15 @@ namespace BTCPayServer.Services.PaymentRequests
|
|||||||
|
|
||||||
return invoiceOrderId.Replace("PAY_REQUEST_", "", StringComparison.InvariantCulture);
|
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
|
public class PaymentRequestUpdated
|
||||||
|
Loading…
Reference in New Issue
Block a user