Properly handle InvoiceMetadata string properties (Fix #2906)

This commit is contained in:
nicolas.dorier 2021-09-27 11:44:55 +09:00
parent 920955657d
commit bd6c7a8c3d
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 19 additions and 2 deletions

View file

@ -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,11 +2910,12 @@ 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()
{
Amount = 0m,

View file

@ -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);