add new properties and change types to decimal

This commit is contained in:
Andrew Camilleri
2018-05-11 11:31:21 +02:00
parent 5ffe118159
commit 239a011e60
4 changed files with 74 additions and 32 deletions

View File

@@ -276,7 +276,7 @@ namespace BTCPayServer.Tests
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Buyer = new Buyer() { email = "test@fwf.com" },
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -308,7 +308,7 @@ namespace BTCPayServer.Tests
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Buyer = new Buyer() { email = "test@fwf.com" },
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -440,7 +440,7 @@ namespace BTCPayServer.Tests
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 0.01,
Price = 0.01m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -473,7 +473,7 @@ namespace BTCPayServer.Tests
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 0.01,
Price = 0.01m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -501,7 +501,7 @@ namespace BTCPayServer.Tests
await Task.Delay(TimeSpan.FromSeconds(RandomUtils.GetUInt32() % 5));
var invoice = await user.BitPay.CreateInvoiceAsync(new Invoice()
{
Price = 0.01,
Price = 0.01m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -554,7 +554,7 @@ namespace BTCPayServer.Tests
acc.RegisterDerivationScheme("BTC");
var invoice = acc.BitPay.CreateInvoice(new Invoice()
{
Price = 5.0,
Price = 5.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -656,7 +656,7 @@ namespace BTCPayServer.Tests
user.RegisterDerivationScheme("BTC");
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD"
}, Facade.Merchant);
var payment1 = invoice.BtcDue + Money.Coins(0.0001m);
@@ -756,7 +756,7 @@ namespace BTCPayServer.Tests
message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Encoders.Base64.EncodeData(Encoders.ASCII.DecodeData(apiKey)));
var invoice = new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD"
};
message.Content = new StringContent(JsonConvert.SerializeObject(invoice), Encoding.UTF8, "application/json");
@@ -798,7 +798,7 @@ namespace BTCPayServer.Tests
storeController.Rates(vm).Wait();
var invoice2 = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -822,7 +822,7 @@ namespace BTCPayServer.Tests
// First we try payment with a merchant having only BTC
var invoice1 = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -840,7 +840,7 @@ namespace BTCPayServer.Tests
var invoice2 = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -896,7 +896,7 @@ namespace BTCPayServer.Tests
// Despite it is called BitcoinAddress it should be LTC because BTC is not available
Assert.Null(invoice.BitcoinAddress);
Assert.NotEqual(1.0, invoice.Rate);
Assert.NotEqual(1.0m, invoice.Rate);
Assert.NotEqual(invoice.BtcDue, invoice.CryptoInfo[0].Due); // Should be BTC rate
cashCow.SendToAddress(invoiceAddress, invoice.CryptoInfo[0].Due);
@@ -983,7 +983,7 @@ namespace BTCPayServer.Tests
// First we try payment with a merchant having only BTC
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -1015,7 +1015,7 @@ namespace BTCPayServer.Tests
user.RegisterDerivationScheme("LTC");
invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -1137,7 +1137,7 @@ namespace BTCPayServer.Tests
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 1.5,
Price = 1.5m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -1150,7 +1150,7 @@ namespace BTCPayServer.Tests
invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5.5,
Price = 5.5m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -1199,7 +1199,7 @@ namespace BTCPayServer.Tests
Assert.Equal("$5.00", vmview.Items[0].Price.Formatted);
Assert.IsType<RedirectResult>(apps.ViewPointOfSale(appId, 0, "orange").Result);
var invoice = user.BitPay.GetInvoices().First();
Assert.Equal(10.00, invoice.Price);
Assert.Equal(10.00m, invoice.Price);
Assert.Equal("CAD", invoice.Currency);
Assert.Equal("orange", invoice.ItemDesc);
}
@@ -1250,7 +1250,7 @@ namespace BTCPayServer.Tests
user.RegisterDerivationScheme("BTC");
var invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",
@@ -1355,12 +1355,12 @@ namespace BTCPayServer.Tests
{
var localInvoice = user.BitPay.GetInvoice(invoice.Id, Facade.Merchant);
Assert.Equal("complete", localInvoice.Status);
Assert.NotEqual(0.0, localInvoice.Rate);
Assert.NotEqual(0.0m, localInvoice.Rate);
});
invoice = user.BitPay.CreateInvoice(new Invoice()
{
Price = 5000.0,
Price = 5000.0m,
Currency = "USD",
PosData = "posData",
OrderId = "orderId",

View File

@@ -207,7 +207,7 @@ namespace BTCPayServer.HostedServices
if (btcCryptoInfo != null)
{
#pragma warning disable CS0618
notification.Rate = (double)dto.Rate;
notification.Rate = dto.Rate;
notification.Url = dto.Url;
notification.BTCDue = dto.BTCDue;
notification.BTCPaid = dto.BTCPaid;

View File

@@ -79,7 +79,7 @@ namespace BTCPayServer.Models
//"price":5
[JsonProperty("price")]
public double Price
public decimal Price
{
get; set;
}
@@ -94,7 +94,7 @@ namespace BTCPayServer.Models
//"exRates":{"USD":4320.02}
[JsonProperty("exRates")]
[Obsolete("Use CryptoInfo.ExRates instead")]
public Dictionary<string, double> ExRates
public Dictionary<string, decimal> ExRates
{
get; set;
}
@@ -224,6 +224,24 @@ namespace BTCPayServer.Models
{
get; set;
}
[JsonProperty("paymentSubtotals")]
public Dictionary<string, decimal> PaymentSubtotals { get; set; }
[JsonProperty("paymentTotals")]
public Dictionary<string, decimal> PaymentTotals { get; set; }
[JsonProperty("amountPaid")]
public decimal AmountPaid { get; set; }
[JsonProperty("exchangeRates")]
public Dictionary<string, Dictionary<string, decimal>> ExchangeRates{ get; set; }
[JsonProperty("supportedTransactionCurrencies")]
public Dictionary<string, NBitpayClient.InvoiceSupportedTransactionCurrency> SupportedTransactionCurrencies { get; set; }
[JsonProperty("addresses")]
public Dictionary<string, string> Addresses { get; set; }
[JsonProperty("paymentCodes")]
public Dictionary<string, NBitpayClient.InvoicePaymentUrls> PaymentCodes{get; set;}
}
public class Flags
{
@@ -233,4 +251,5 @@ namespace BTCPayServer.Models
get; set;
}
}
}

View File

@@ -12,6 +12,7 @@ using NBXplorer.Models;
using NBXplorer;
using NBXplorer.DerivationStrategy;
using BTCPayServer.Payments;
using NBitpayClient;
namespace BTCPayServer.Services.Invoices
{
@@ -335,7 +336,14 @@ namespace BTCPayServer.Services.Invoices
ExpirationTime = ExpirationTime,
Status = Status,
Currency = ProductInformation.Currency,
Flags = new Flags() { Refundable = Refundable }
Flags = new Flags() { Refundable = Refundable },
PaymentSubtotals = new Dictionary<string, decimal>(),
PaymentTotals= new Dictionary<string, decimal>(),
SupportedTransactionCurrencies = new Dictionary<string, InvoiceSupportedTransactionCurrency>(),
Addresses = new Dictionary<string, string>(),
PaymentCodes = new Dictionary<string, InvoicePaymentUrls>(),
ExchangeRates = new Dictionary<string, Dictionary<string, decimal>>()
};
dto.Url = ServerUrl.WithTrailingSlash() + $"invoice?id=" + Id;
@@ -344,10 +352,18 @@ namespace BTCPayServer.Services.Invoices
{
var accounting = info.Calculate();
var cryptoInfo = new NBitpayClient.InvoiceCryptoInfo();
cryptoInfo.CryptoCode = info.GetId().CryptoCode;
var price = accounting.TotalDue - accounting.NetworkFee;
var cryptoCode = info.GetId().CryptoCode;
var address = info.GetPaymentMethodDetails()?.GetPaymentDestination();
var exrates = new Dictionary<string, decimal>
{
{ ProductInformation.Currency, cryptoInfo.Rate }
};
cryptoInfo.CryptoCode = cryptoCode;
cryptoInfo.PaymentType = info.GetId().PaymentType.ToString();
cryptoInfo.Rate = info.Rate;
cryptoInfo.Price = (accounting.TotalDue - accounting.NetworkFee).ToString();
cryptoInfo.Price = price.ToString();
cryptoInfo.Due = accounting.Due.ToString();
cryptoInfo.Paid = accounting.Paid.ToString();
@@ -356,11 +372,9 @@ namespace BTCPayServer.Services.Invoices
cryptoInfo.TxCount = accounting.TxCount;
cryptoInfo.CryptoPaid = accounting.CryptoPaid.ToString();
cryptoInfo.Address = info.GetPaymentMethodDetails()?.GetPaymentDestination();
cryptoInfo.ExRates = new Dictionary<string, double>
{
{ ProductInformation.Currency, (double)cryptoInfo.Rate }
};
cryptoInfo.Address = address;
cryptoInfo.ExRates = exrates;
var paymentId = info.GetId();
var scheme = info.Network.UriScheme;
cryptoInfo.Url = ServerUrl.WithTrailingSlash() + $"i/{paymentId}/{Id}";
@@ -395,10 +409,19 @@ namespace BTCPayServer.Services.Invoices
dto.BTCDue = cryptoInfo.Due;
dto.PaymentUrls = cryptoInfo.PaymentUrls;
}
#pragma warning restore CS0618
dto.CryptoInfo.Add(cryptoInfo);
}
dto.PaymentSubtotals.Add(cryptoCode, price.ToDecimal(MoneyUnit.BTC));
dto.PaymentTotals.Add(cryptoCode, accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC));
dto.SupportedTransactionCurrencies.Add(cryptoCode, new InvoiceSupportedTransactionCurrency()
{
Enabled = true
});
dto.Addresses.Add(cryptoCode, address);
dto.ExchangeRates.Add(cryptoCode, exrates);
}
Populate(ProductInformation, dto);
Populate(BuyerInformation, dto);