mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Make CanUseWebhooks more resilient
This commit is contained in:
@@ -42,6 +42,8 @@ namespace BTCPayServer.Client
|
|||||||
public virtual async Task<WebhookDeliveryData> GetWebhookDelivery(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
|
public virtual async Task<WebhookDeliveryData> GetWebhookDelivery(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}"), token);
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}"), token);
|
||||||
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||||
|
return null;
|
||||||
return await HandleResponse<WebhookDeliveryData>(response);
|
return await HandleResponse<WebhookDeliveryData>(response);
|
||||||
}
|
}
|
||||||
public virtual async Task<string> RedeliverWebhook(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
|
public virtual async Task<string> RedeliverWebhook(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
|
||||||
|
|||||||
@@ -781,9 +781,10 @@ namespace BTCPayServer.Tests
|
|||||||
var newDeliveryId = await clientProfile.RedeliverWebhook(user.StoreId, hook.Id, delivery.Id);
|
var newDeliveryId = await clientProfile.RedeliverWebhook(user.StoreId, hook.Id, delivery.Id);
|
||||||
req = await fakeServer.GetNextRequest();
|
req = await fakeServer.GetNextRequest();
|
||||||
req.Response.StatusCode = 404;
|
req.Response.StatusCode = 404;
|
||||||
fakeServer.Done();
|
|
||||||
await TestUtils.EventuallyAsync(async () =>
|
await TestUtils.EventuallyAsync(async () =>
|
||||||
{
|
{
|
||||||
|
// Releasing semaphore several times may help making this test less flaky
|
||||||
|
fakeServer.Done();
|
||||||
var newDelivery = await clientProfile.GetWebhookDelivery(user.StoreId, hook.Id, newDeliveryId);
|
var newDelivery = await clientProfile.GetWebhookDelivery(user.StoreId, hook.Id, newDeliveryId);
|
||||||
Assert.NotNull(newDelivery);
|
Assert.NotNull(newDelivery);
|
||||||
Assert.Equal(404, newDelivery.HttpCode);
|
Assert.Equal(404, newDelivery.HttpCode);
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ namespace BTCPayServer.Controllers
|
|||||||
.Include(i => i.CurrentRefund)
|
.Include(i => i.CurrentRefund)
|
||||||
.Include(i => i.CurrentRefund.PullPaymentData)
|
.Include(i => i.CurrentRefund.PullPaymentData)
|
||||||
.Where(i => i.Id == invoiceId)
|
.Where(i => i.Id == invoiceId)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync(cancellationToken: cancellationToken);
|
||||||
if (invoice is null)
|
if (invoice is null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
if (invoice.CurrentRefund?.PullPaymentDataId is null && GetUserId() is null)
|
if (invoice.CurrentRefund?.PullPaymentDataId is null && GetUserId() is null)
|
||||||
@@ -342,7 +342,7 @@ namespace BTCPayServer.Controllers
|
|||||||
Html = "Refund successfully created!<br />Share the link to this page with a customer.<br />The customer needs to enter their address and claim the refund.<br />Once a customer claims the refund, you will get a notification and would need to approve and initiate it from your Wallet > Manage > Payouts.",
|
Html = "Refund successfully created!<br />Share the link to this page with a customer.<br />The customer needs to enter their address and claim the refund.<br />Once a customer claims the refund, you will get a notification and would need to approve and initiate it from your Wallet > Manage > Payouts.",
|
||||||
Severity = StatusMessageModel.StatusSeverity.Success
|
Severity = StatusMessageModel.StatusSeverity.Success
|
||||||
});
|
});
|
||||||
(await ctx.Invoices.FindAsync(invoice.Id)).CurrentRefundId = ppId;
|
(await ctx.Invoices.FindAsync(new[] { invoice.Id }, cancellationToken: cancellationToken)).CurrentRefundId = ppId;
|
||||||
ctx.Refunds.Add(new RefundData()
|
ctx.Refunds.Add(new RefundData()
|
||||||
{
|
{
|
||||||
InvoiceDataId = invoice.Id,
|
InvoiceDataId = invoice.Id,
|
||||||
|
|||||||
Reference in New Issue
Block a user