mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Switching to using simple base WebhookInvoiceEvent class
This commit is contained in:
@@ -18,7 +18,7 @@ namespace BTCPayServer.Client.Models
|
|||||||
[JsonProperty(Order = 2)] public string PayoutId { get; set; }
|
[JsonProperty(Order = 2)] public string PayoutId { get; set; }
|
||||||
[JsonProperty(Order = 3)] public string PullPaymentId { get; set; }
|
[JsonProperty(Order = 3)] public string PullPaymentId { get; set; }
|
||||||
[JsonProperty(Order = 4)] [JsonConverter(typeof(StringEnumConverter))]public PayoutState PayoutState { get; set; }
|
[JsonProperty(Order = 4)] [JsonConverter(typeof(StringEnumConverter))]public PayoutState PayoutState { get; set; }
|
||||||
}
|
}
|
||||||
public class WebhookPaymentRequestEvent : StoreWebhookEvent
|
public class WebhookPaymentRequestEvent : StoreWebhookEvent
|
||||||
{
|
{
|
||||||
public WebhookPaymentRequestEvent(string type, string storeId)
|
public WebhookPaymentRequestEvent(string type, string storeId)
|
||||||
@@ -32,12 +32,12 @@ namespace BTCPayServer.Client.Models
|
|||||||
[JsonProperty(Order = 2)] public string PaymentRequestId { get; set; }
|
[JsonProperty(Order = 2)] public string PaymentRequestId { get; set; }
|
||||||
[JsonProperty(Order = 3)] [JsonConverter(typeof(StringEnumConverter))]public PaymentRequestStatus Status { get; set; }
|
[JsonProperty(Order = 3)] [JsonConverter(typeof(StringEnumConverter))]public PaymentRequestStatus Status { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class StoreWebhookEvent : WebhookEvent
|
public abstract class StoreWebhookEvent : WebhookEvent
|
||||||
{
|
{
|
||||||
[JsonProperty(Order = 1)] public string StoreId { get; set; }
|
[JsonProperty(Order = 1)] public string StoreId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WebhookInvoiceEvent : StoreWebhookEvent
|
public class WebhookInvoiceEvent : StoreWebhookEvent
|
||||||
{
|
{
|
||||||
public WebhookInvoiceEvent()
|
public WebhookInvoiceEvent()
|
||||||
@@ -45,7 +45,7 @@ namespace BTCPayServer.Client.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WebhookInvoiceEvent(string evtType, string storeId)
|
public WebhookInvoiceEvent(string evtType, string storeId)
|
||||||
{
|
{
|
||||||
if (!evtType.StartsWith("invoice", StringComparison.InvariantCultureIgnoreCase))
|
if (!evtType.StartsWith("invoice", StringComparison.InvariantCultureIgnoreCase))
|
||||||
throw new ArgumentException("Invalid event type", nameof(evtType));
|
throw new ArgumentException("Invalid event type", nameof(evtType));
|
||||||
Type = evtType;
|
Type = evtType;
|
||||||
|
|||||||
@@ -2128,10 +2128,9 @@ namespace BTCPayServer.Tests
|
|||||||
await tester.ExplorerNode.SendToAddressAsync(inv.Address, Money.Coins(inv.Amount.ToDecimal(MoneyUnit.BTC)));
|
await tester.ExplorerNode.SendToAddressAsync(inv.Address, Money.Coins(inv.Amount.ToDecimal(MoneyUnit.BTC)));
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
|
|
||||||
await user.AssertHasWebhookEvent(WebhookEventType.InvoicePaidAfterExpiration, (WebhookInvoiceReceivedPaymentEvent evt) =>
|
await user.AssertHasWebhookEvent(WebhookEventType.InvoicePaidAfterExpiration, (WebhookInvoiceEvent evt) =>
|
||||||
{
|
{
|
||||||
Assert.Equal(invoicePaidAfterExpiration.Id, evt.InvoiceId);
|
Assert.Equal(invoicePaidAfterExpiration.Id, evt.InvoiceId);
|
||||||
Assert.True(evt.AfterExpiration);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ExpiredPaidPartial
|
// ExpiredPaidPartial
|
||||||
@@ -2153,10 +2152,9 @@ namespace BTCPayServer.Tests
|
|||||||
await Task.Delay(2000); // give it time to expire and process payments
|
await Task.Delay(2000); // give it time to expire and process payments
|
||||||
|
|
||||||
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceExpired, (WebhookInvoiceEvent x) => Assert.Equal(invoiceExpiredPartial.Id, x.InvoiceId));
|
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceExpired, (WebhookInvoiceEvent x) => Assert.Equal(invoiceExpiredPartial.Id, x.InvoiceId));
|
||||||
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceExpiredPaidPartial, (WebhookInvoiceReceivedPaymentEvent evt) =>
|
await user.AssertHasWebhookEvent(WebhookEventType.InvoiceExpiredPaidPartial, (WebhookInvoiceEvent evt) =>
|
||||||
{
|
{
|
||||||
Assert.Equal(invoiceExpiredPartial.Id, evt.InvoiceId);
|
Assert.Equal(invoiceExpiredPartial.Id, evt.InvoiceId);
|
||||||
Assert.True(evt.AfterExpiration);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,17 +116,9 @@ public class InvoiceWebhookProvider : WebhookProvider<InvoiceEvent>
|
|||||||
StoreId = invoiceEvent.Invoice.StoreId
|
StoreId = invoiceEvent.Invoice.StoreId
|
||||||
};
|
};
|
||||||
case InvoiceEventCode.ExpiredPaidPartial:
|
case InvoiceEventCode.ExpiredPaidPartial:
|
||||||
return new WebhookInvoiceReceivedPaymentEvent(WebhookEventType.InvoiceExpiredPaidPartial, storeId)
|
return new WebhookInvoiceEvent(WebhookEventType.InvoiceExpiredPaidPartial, storeId);
|
||||||
{
|
|
||||||
AfterExpiration = true,
|
|
||||||
StoreId = invoiceEvent.Invoice.StoreId
|
|
||||||
};
|
|
||||||
case InvoiceEventCode.PaidAfterExpiration:
|
case InvoiceEventCode.PaidAfterExpiration:
|
||||||
return new WebhookInvoiceReceivedPaymentEvent(WebhookEventType.InvoicePaidAfterExpiration, storeId)
|
return new WebhookInvoiceEvent(WebhookEventType.InvoicePaidAfterExpiration, storeId);
|
||||||
{
|
|
||||||
AfterExpiration = true,
|
|
||||||
StoreId = invoiceEvent.Invoice.StoreId
|
|
||||||
};
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user