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; }
|
public DateTimeOffset ExpirationTime { get; set; }
|
||||||
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
|
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
|
||||||
public DateTimeOffset CreatedTime { get; set; }
|
public DateTimeOffset CreatedTime { get; set; }
|
||||||
|
[JsonProperty(ItemConverterType = typeof(StringEnumConverter))]
|
||||||
|
public InvoiceStatus[] AvailableStatusesForManualMarking { get; set; }
|
||||||
}
|
}
|
||||||
public enum InvoiceStatus
|
public enum InvoiceStatus
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1156,10 +1156,16 @@ namespace BTCPayServer.Tests
|
|||||||
//update
|
//update
|
||||||
newInvoice = await client.CreateInvoice(user.StoreId,
|
newInvoice = await client.CreateInvoice(user.StoreId,
|
||||||
new CreateInvoiceRequest() { Currency = "USD", Amount = 1 });
|
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()
|
await client.MarkInvoiceStatus(user.StoreId, newInvoice.Id, new MarkInvoiceStatusRequest()
|
||||||
{
|
{
|
||||||
Status = InvoiceStatus.Settled
|
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,
|
newInvoice = await client.CreateInvoice(user.StoreId,
|
||||||
new CreateInvoiceRequest() { Currency = "USD", Amount = 1 });
|
new CreateInvoiceRequest() { Currency = "USD", Amount = 1 });
|
||||||
await client.MarkInvoiceStatus(user.StoreId, newInvoice.Id, new MarkInvoiceStatusRequest()
|
await client.MarkInvoiceStatus(user.StoreId, newInvoice.Id, new MarkInvoiceStatusRequest()
|
||||||
@@ -1167,6 +1173,10 @@ namespace BTCPayServer.Tests
|
|||||||
Status = InvoiceStatus.Invalid
|
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 AssertHttpError(403, async () =>
|
||||||
{
|
{
|
||||||
await viewOnly.UpdateInvoice(user.StoreId, invoice.Id,
|
await viewOnly.UpdateInvoice(user.StoreId, invoice.Id,
|
||||||
@@ -1316,6 +1326,8 @@ namespace BTCPayServer.Tests
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
Assert.Equal("BTC", invoiceWithdefaultPaymentMethodOnChain.Checkout.DefaultPaymentMethod);
|
Assert.Equal("BTC", invoiceWithdefaultPaymentMethodOnChain.Checkout.DefaultPaymentMethod);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -387,6 +388,17 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
}
|
}
|
||||||
private InvoiceData ToModel(InvoiceEntity entity)
|
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()
|
return new InvoiceData()
|
||||||
{
|
{
|
||||||
StoreId = entity.StoreId,
|
StoreId = entity.StoreId,
|
||||||
@@ -401,6 +413,7 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
AdditionalStatus = entity.ExceptionStatus,
|
AdditionalStatus = entity.ExceptionStatus,
|
||||||
Currency = entity.Currency,
|
Currency = entity.Currency,
|
||||||
Metadata = entity.Metadata.ToJObject(),
|
Metadata = entity.Metadata.ToJObject(),
|
||||||
|
AvailableStatusesForManualMarking = statuses.ToArray(),
|
||||||
Checkout = new CreateInvoiceRequest.CheckoutOptions()
|
Checkout = new CreateInvoiceRequest.CheckoutOptions()
|
||||||
{
|
{
|
||||||
Expiration = entity.ExpirationTime - entity.InvoiceTime,
|
Expiration = entity.ExpirationTime - entity.InvoiceTime,
|
||||||
|
|||||||
@@ -799,15 +799,27 @@
|
|||||||
},
|
},
|
||||||
"createdTime": {
|
"createdTime": {
|
||||||
"description": "The creation time of the invoice",
|
"description": "The creation time of the invoice",
|
||||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UnixTimestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"expirationTime": {
|
"expirationTime": {
|
||||||
"description": "The expiration time of the invoice",
|
"description": "The expiration time of the invoice",
|
||||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UnixTimestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"monitoringTime": {
|
"monitoringTime": {
|
||||||
"description": "The monitoring time of the invoice",
|
"description": "The monitoring time of the invoice",
|
||||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UnixTimestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"$ref": "#/components/schemas/InvoiceStatus",
|
"$ref": "#/components/schemas/InvoiceStatus",
|
||||||
@@ -816,6 +828,13 @@
|
|||||||
"additionalStatus": {
|
"additionalStatus": {
|
||||||
"$ref": "#/components/schemas/InvoiceAdditionalStatus",
|
"$ref": "#/components/schemas/InvoiceAdditionalStatus",
|
||||||
"description": "a secondary status of the invoice"
|
"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": {
|
"expirationMinutes": {
|
||||||
"nullable": true,
|
"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)",
|
"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": {
|
"monitoringMinutes": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"nullable": true,
|
"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)",
|
"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": {
|
"paymentTolerance": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
@@ -1153,7 +1180,11 @@
|
|||||||
},
|
},
|
||||||
"receivedDate": {
|
"receivedDate": {
|
||||||
"description": "The date the payment was recorded",
|
"description": "The date the payment was recorded",
|
||||||
"allOf": [ { "$ref": "#/components/schemas/UnixTimestamp" } ]
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UnixTimestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"value": {
|
"value": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
Reference in New Issue
Block a user