mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Properly handle InvoiceMetadata string properties (Fix #2906)
This commit is contained in:
parent
920955657d
commit
bd6c7a8c3d
2 changed files with 19 additions and 2 deletions
|
@ -2266,6 +2266,15 @@ namespace BTCPayServer.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Fast", "Fast")]
|
||||
public void SetOrderIdMetadataDoesntConvertInOctal()
|
||||
{
|
||||
var m = new InvoiceMetadata();
|
||||
m.OrderId = "000000161";
|
||||
Assert.Equal("000000161", m.OrderId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Fast", "Fast")]
|
||||
public void CanParseCurrencyValue()
|
||||
|
@ -2901,10 +2910,11 @@ namespace BTCPayServer.Tests
|
|||
{
|
||||
Amount = 50.513m,
|
||||
Currency = "USD",
|
||||
Metadata = new JObject() { new JProperty("taxIncluded", 50.516m) }
|
||||
Metadata = new JObject() { new JProperty("taxIncluded", 50.516m), new JProperty("orderId", "000000161") }
|
||||
});
|
||||
Assert.Equal(50.51m, invoice5g.Amount);
|
||||
Assert.Equal(50.51m, (decimal)invoice5g.Metadata["taxIncluded"]);
|
||||
Assert.Equal("000000161", (string)invoice5g.Metadata["orderId"]);
|
||||
|
||||
var zeroInvoice = await greenfield.CreateInvoice(user.StoreId, new CreateInvoiceRequest()
|
||||
{
|
||||
|
|
|
@ -146,6 +146,13 @@ namespace BTCPayServer.Services.Invoices
|
|||
public void SetMetadata<T>(string propName, T value)
|
||||
{
|
||||
JToken data;
|
||||
if (typeof(T) == typeof(string) && value is string v)
|
||||
{
|
||||
data = new JValue(v);
|
||||
AdditionalData ??= new Dictionary<string, JToken>();
|
||||
AdditionalData.AddOrReplace(propName, data);
|
||||
return;
|
||||
}
|
||||
if (value is null)
|
||||
{
|
||||
AdditionalData?.Remove(propName);
|
||||
|
|
Loading…
Add table
Reference in a new issue