mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Round up invoice price
This commit is contained in:
@@ -1856,6 +1856,50 @@ donation:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("Integration", "Integration")]
|
||||||
|
public void CanCreateStrangeInvoice()
|
||||||
|
{
|
||||||
|
using (var tester = ServerTester.Create())
|
||||||
|
{
|
||||||
|
tester.Start();
|
||||||
|
var user = tester.NewAccount();
|
||||||
|
user.GrantAccess();
|
||||||
|
user.RegisterDerivationScheme("BTC");
|
||||||
|
var invoice1 = user.BitPay.CreateInvoice(new Invoice()
|
||||||
|
{
|
||||||
|
Price = 0.000000012m,
|
||||||
|
Currency = "BTC",
|
||||||
|
PosData = "posData",
|
||||||
|
OrderId = "orderId",
|
||||||
|
ItemDesc = "Some description",
|
||||||
|
FullNotifications = true
|
||||||
|
}, Facade.Merchant);
|
||||||
|
var invoice2 = user.BitPay.CreateInvoice(new Invoice()
|
||||||
|
{
|
||||||
|
Price = 0.000000019m,
|
||||||
|
Currency = "BTC",
|
||||||
|
PosData = "posData",
|
||||||
|
OrderId = "orderId",
|
||||||
|
ItemDesc = "Some description",
|
||||||
|
FullNotifications = true
|
||||||
|
}, Facade.Merchant);
|
||||||
|
Assert.Equal(0.00000001m, invoice1.Price);
|
||||||
|
Assert.Equal(0.00000002m, invoice2.Price);
|
||||||
|
|
||||||
|
var invoice = user.BitPay.CreateInvoice(new Invoice()
|
||||||
|
{
|
||||||
|
Price = -0.1m,
|
||||||
|
Currency = "BTC",
|
||||||
|
PosData = "posData",
|
||||||
|
OrderId = "orderId",
|
||||||
|
ItemDesc = "Some description",
|
||||||
|
FullNotifications = true
|
||||||
|
}, Facade.Merchant);
|
||||||
|
Assert.Equal(0.0m, invoice.Price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Integration", "Integration")]
|
[Trait("Integration", "Integration")]
|
||||||
public void InvoiceFlowThroughDifferentStatesCorrectly()
|
public void InvoiceFlowThroughDifferentStatesCorrectly()
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
InvoiceTime = DateTimeOffset.UtcNow
|
InvoiceTime = DateTimeOffset.UtcNow
|
||||||
};
|
};
|
||||||
|
|
||||||
var storeBlob = store.GetStoreBlob();
|
var storeBlob = store.GetStoreBlob();
|
||||||
Uri notificationUri = Uri.IsWellFormedUriString(invoice.NotificationURL, UriKind.Absolute) ? new Uri(invoice.NotificationURL, UriKind.Absolute) : null;
|
Uri notificationUri = Uri.IsWellFormedUriString(invoice.NotificationURL, UriKind.Absolute) ? new Uri(invoice.NotificationURL, UriKind.Absolute) : null;
|
||||||
if (notificationUri == null || (notificationUri.Scheme != "http" && notificationUri.Scheme != "https")) //TODO: Filer non routable addresses ?
|
if (notificationUri == null || (notificationUri.Scheme != "http" && notificationUri.Scheme != "https")) //TODO: Filer non routable addresses ?
|
||||||
@@ -95,7 +94,16 @@ namespace BTCPayServer.Controllers
|
|||||||
throw new BitpayHttpException(400, "Invalid email");
|
throw new BitpayHttpException(400, "Invalid email");
|
||||||
entity.RefundMail = entity.BuyerInformation.BuyerEmail;
|
entity.RefundMail = entity.BuyerInformation.BuyerEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currencyInfo = _CurrencyNameTable.GetNumberFormatInfo(invoice.Currency, false);
|
||||||
|
if (currencyInfo != null)
|
||||||
|
{
|
||||||
|
invoice.Price = Math.Round(invoice.Price, currencyInfo.CurrencyDecimalDigits);
|
||||||
|
}
|
||||||
|
invoice.Price = Math.Max(0.0m, invoice.Price);
|
||||||
entity.ProductInformation = Map<Invoice, ProductInformation>(invoice);
|
entity.ProductInformation = Map<Invoice, ProductInformation>(invoice);
|
||||||
|
|
||||||
|
|
||||||
entity.RedirectURL = invoice.RedirectURL ?? store.StoreWebsite;
|
entity.RedirectURL = invoice.RedirectURL ?? store.StoreWebsite;
|
||||||
if (!Uri.IsWellFormedUriString(entity.RedirectURL, UriKind.Absolute))
|
if (!Uri.IsWellFormedUriString(entity.RedirectURL, UriKind.Absolute))
|
||||||
entity.RedirectURL = null;
|
entity.RedirectURL = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user