mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Grerenfield: Add availableStatusesForManualMarking to Invoice Data (#2934)
closes ##2933
This commit is contained in:
@@ -60,6 +60,8 @@ namespace BTCPayServer.Client.Models
|
||||
public DateTimeOffset ExpirationTime { get; set; }
|
||||
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
|
||||
public DateTimeOffset CreatedTime { get; set; }
|
||||
[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
|
||||
public InvoiceStatus[] AvailableStatusesForManualMarking { get; set; }
|
||||
}
|
||||
public enum InvoiceStatus
|
||||
{
|
||||
|
||||
@@ -1156,10 +1156,16 @@ namespace BTCPayServer.Tests
|
||||
//update
|
||||
newInvoice = await client.CreateInvoice(user.StoreId,
|
||||
new CreateInvoiceRequest() { Currency = "USD", Amount = 1 });
|
||||
Assert.True( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Settled));
|
||||
Assert.True( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Invalid));
|
||||
await client.MarkInvoiceStatus(user.StoreId, newInvoice.Id, new MarkInvoiceStatusRequest()
|
||||
{
|
||||
Status = InvoiceStatus.Settled
|
||||
});
|
||||
newInvoice = await client.GetInvoice(user.StoreId, newInvoice.Id);
|
||||
|
||||
Assert.False( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Settled));
|
||||
Assert.True( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Invalid));
|
||||
newInvoice = await client.CreateInvoice(user.StoreId,
|
||||
new CreateInvoiceRequest() { Currency = "USD", Amount = 1 });
|
||||
await client.MarkInvoiceStatus(user.StoreId, newInvoice.Id, new MarkInvoiceStatusRequest()
|
||||
@@ -1167,6 +1173,10 @@ namespace BTCPayServer.Tests
|
||||
Status = InvoiceStatus.Invalid
|
||||
});
|
||||
|
||||
newInvoice = await client.GetInvoice(user.StoreId, newInvoice.Id);
|
||||
|
||||
Assert.True( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Settled));
|
||||
Assert.False( newInvoice.AvailableStatusesForManualMarking.Contains(InvoiceStatus.Invalid));
|
||||
await AssertHttpError(403, async () =>
|
||||
{
|
||||
await viewOnly.UpdateInvoice(user.StoreId, invoice.Id,
|
||||
@@ -1316,6 +1326,8 @@ namespace BTCPayServer.Tests
|
||||
}
|
||||
});
|
||||
Assert.Equal("BTC", invoiceWithdefaultPaymentMethodOnChain.Checkout.DefaultPaymentMethod);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Globalization;
|
||||
@@ -387,6 +388,17 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
}
|
||||
private InvoiceData ToModel(InvoiceEntity entity)
|
||||
{
|
||||
var statuses = new List<InvoiceStatus>();
|
||||
var state = entity.GetInvoiceState();
|
||||
if (state.CanMarkComplete())
|
||||
{
|
||||
statuses.Add(InvoiceStatus.Settled);
|
||||
}
|
||||
|
||||
if (state.CanMarkInvalid())
|
||||
{
|
||||
statuses.Add(InvoiceStatus.Invalid);
|
||||
}
|
||||
return new InvoiceData()
|
||||
{
|
||||
StoreId = entity.StoreId,
|
||||
@@ -401,6 +413,7 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
AdditionalStatus = entity.ExceptionStatus,
|
||||
Currency = entity.Currency,
|
||||
Metadata = entity.Metadata.ToJObject(),
|
||||
AvailableStatusesForManualMarking = statuses.ToArray(),
|
||||
Checkout = new CreateInvoiceRequest.CheckoutOptions()
|
||||
{
|
||||
Expiration = entity.ExpirationTime - entity.InvoiceTime,
|
||||
|
||||
@@ -799,15 +799,27 @@
|
||||
},
|
||||
"createdTime": {
|
||||
"description": "The creation time of the invoice",
|
||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/UnixTimestamp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expirationTime": {
|
||||
"description": "The expiration time of the invoice",
|
||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/UnixTimestamp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"monitoringTime": {
|
||||
"description": "The monitoring time of the invoice",
|
||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/UnixTimestamp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/components/schemas/InvoiceStatus",
|
||||
@@ -816,6 +828,13 @@
|
||||
"additionalStatus": {
|
||||
"$ref": "#/components/schemas/InvoiceAdditionalStatus",
|
||||
"description": "a secondary status of the invoice"
|
||||
},
|
||||
"availableStatusesForManualMarking": {
|
||||
"type": "array",
|
||||
"description": "The statuses the invoice can be manually marked as",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/InvoiceStatus"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,13 +1052,21 @@
|
||||
"expirationMinutes": {
|
||||
"nullable": true,
|
||||
"description": "The number of minutes after which an invoice becomes expired. Defaults to the store's settings. (The default store settings is 15)",
|
||||
"allOf": [ { "$ref": "#/components/schemas/TimeSpanMinutes" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/TimeSpanMinutes"
|
||||
}
|
||||
]
|
||||
},
|
||||
"monitoringMinutes": {
|
||||
"type": "number",
|
||||
"nullable": true,
|
||||
"description": "The number of minutes after an invoice expired after which we are still monitoring for incoming payments. Defaults to the store's settings. (The default store settings is 1440, 1 day)",
|
||||
"allOf": [ { "$ref": "#/components/schemas/TimeSpanMinutes" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/TimeSpanMinutes"
|
||||
}
|
||||
]
|
||||
},
|
||||
"paymentTolerance": {
|
||||
"type": "number",
|
||||
@@ -1153,7 +1180,11 @@
|
||||
},
|
||||
"receivedDate": {
|
||||
"description": "The date the payment was recorded",
|
||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/UnixTimestamp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
|
||||
Reference in New Issue
Block a user