mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Point of Sale returns correct currency information (#450)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using BTCPayServer.Tests.Logging;
|
using BTCPayServer.Tests.Logging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using NBitcoin.DataEncoders;
|
using NBitcoin.DataEncoders;
|
||||||
@@ -340,13 +340,14 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
foreach (var test in new[]
|
foreach (var test in new[]
|
||||||
{
|
{
|
||||||
(0.0005m, "$0.0005 (USD)"),
|
(0.0005m, "$0.0005 (USD)", "USD"),
|
||||||
(0.001m, "$0.001 (USD)"),
|
(0.001m, "$0.001 (USD)", "USD"),
|
||||||
(0.01m, "$0.01 (USD)"),
|
(0.01m, "$0.01 (USD)", "USD"),
|
||||||
(0.1m, "$0.10 (USD)"),
|
(0.1m, "$0.10 (USD)", "USD"),
|
||||||
|
(1000.0001m, "₹ 1,000.00 (INR)", "INR")
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
var actual = new CurrencyNameTable().DisplayFormatCurrency(test.Item1, "USD");
|
var actual = new CurrencyNameTable().DisplayFormatCurrency(test.Item1, test.Item3);
|
||||||
Assert.Equal(test.Item2, actual);
|
Assert.Equal(test.Item2, actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1467,6 +1468,43 @@ donation:
|
|||||||
Assert.NotNull(donationInvoice);
|
Assert.NotNull(donationInvoice);
|
||||||
Assert.Equal("CAD", donationInvoice.Currency);
|
Assert.Equal("CAD", donationInvoice.Currency);
|
||||||
Assert.Equal("donation", donationInvoice.ItemDesc);
|
Assert.Equal("donation", donationInvoice.ItemDesc);
|
||||||
|
|
||||||
|
foreach(var test in new[]
|
||||||
|
{
|
||||||
|
(Code: "EUR", ExpectedSymbol: "€", ExpectedDecimalSeparator: ",", ExpectedDivisibility: 2, ExpectedThousandSeparator: "\xa0", ExpectedPrefixed: false, ExpectedSymbolSpace: true),
|
||||||
|
(Code: "INR", ExpectedSymbol: "₹", ExpectedDecimalSeparator: ".", ExpectedDivisibility: 2, ExpectedThousandSeparator: ",", ExpectedPrefixed: true, ExpectedSymbolSpace: true),
|
||||||
|
(Code: "JPY", ExpectedSymbol: "¥", ExpectedDecimalSeparator: ".", ExpectedDivisibility: 0, ExpectedThousandSeparator: ",", ExpectedPrefixed: true, ExpectedSymbolSpace: false),
|
||||||
|
(Code: "BTC", ExpectedSymbol: "BTC", ExpectedDecimalSeparator: ".", ExpectedDivisibility: 8, ExpectedThousandSeparator: ",", ExpectedPrefixed: false, ExpectedSymbolSpace: true),
|
||||||
|
})
|
||||||
|
{
|
||||||
|
vmpos = Assert.IsType<UpdatePointOfSaleViewModel>(Assert.IsType<ViewResult>(apps.UpdatePointOfSale(appId).Result).Model);
|
||||||
|
vmpos.Title = "hello";
|
||||||
|
vmpos.Currency = test.Item1;
|
||||||
|
vmpos.ButtonText = "{0} Purchase";
|
||||||
|
vmpos.CustomButtonText = "Nicolas Sexy Hair";
|
||||||
|
vmpos.CustomTipText = "Wanna tip?";
|
||||||
|
vmpos.Template = @"
|
||||||
|
apple:
|
||||||
|
price: 1000.0
|
||||||
|
title: good apple
|
||||||
|
orange:
|
||||||
|
price: 10.0
|
||||||
|
donation:
|
||||||
|
price: 1.02
|
||||||
|
custom: true
|
||||||
|
";
|
||||||
|
Assert.IsType<RedirectToActionResult>(apps.UpdatePointOfSale(appId, vmpos).Result);
|
||||||
|
publicApps = user.GetController<AppsPublicController>();
|
||||||
|
vmview = Assert.IsType<ViewPointOfSaleViewModel>(Assert.IsType<ViewResult>(publicApps.ViewPointOfSale(appId).Result).Model);
|
||||||
|
Assert.Equal(test.Code, vmview.CurrencyCode);
|
||||||
|
Assert.Equal(test.ExpectedSymbol, vmview.CurrencySymbol);
|
||||||
|
Assert.Equal(test.ExpectedSymbol, vmview.CurrencyInfo.CurrencySymbol);
|
||||||
|
Assert.Equal(test.ExpectedDecimalSeparator, vmview.CurrencyInfo.DecimalSeparator);
|
||||||
|
Assert.Equal(test.ExpectedThousandSeparator, vmview.CurrencyInfo.ThousandSeparator);
|
||||||
|
Assert.Equal(test.ExpectedPrefixed, vmview.CurrencyInfo.Prefixed);
|
||||||
|
Assert.Equal(test.ExpectedDivisibility, vmview.CurrencyInfo.Divisibility);
|
||||||
|
Assert.Equal(test.ExpectedSymbolSpace, vmview.CurrencyInfo.SymbolSpace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,25 +40,26 @@ namespace BTCPayServer.Controllers
|
|||||||
if (app == null)
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
var settings = app.GetSettings<PointOfSaleSettings>();
|
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||||
var currency = _AppsHelper.GetCurrencyData(settings.Currency, false);
|
|
||||||
double step = currency == null ? 1 : Math.Pow(10, -(currency.Divisibility));
|
|
||||||
|
|
||||||
var numberFormatInfo = _AppsHelper.Currencies.GetNumberFormatInfo(currency.Code) ?? _AppsHelper.Currencies.GetNumberFormatInfo("USD");
|
var numberFormatInfo = _AppsHelper.Currencies.GetNumberFormatInfo(settings.Currency) ?? _AppsHelper.Currencies.GetNumberFormatInfo("USD");
|
||||||
|
double step = Math.Pow(10, -(numberFormatInfo.CurrencyDecimalDigits));
|
||||||
|
|
||||||
return View(new ViewPointOfSaleViewModel()
|
return View(new ViewPointOfSaleViewModel()
|
||||||
{
|
{
|
||||||
Title = settings.Title,
|
Title = settings.Title,
|
||||||
Step = step.ToString(CultureInfo.InvariantCulture),
|
Step = step.ToString(CultureInfo.InvariantCulture),
|
||||||
EnableShoppingCart = settings.EnableShoppingCart,
|
EnableShoppingCart = settings.EnableShoppingCart,
|
||||||
ShowCustomAmount = settings.ShowCustomAmount,
|
ShowCustomAmount = settings.ShowCustomAmount,
|
||||||
CurrencyCode = currency.Code,
|
CurrencyCode = settings.Currency,
|
||||||
CurrencySymbol = currency.Symbol,
|
CurrencySymbol = numberFormatInfo.CurrencySymbol,
|
||||||
CurrencyInfo = new ViewPointOfSaleViewModel.CurrencyInfoData()
|
CurrencyInfo = new ViewPointOfSaleViewModel.CurrencyInfoData()
|
||||||
{
|
{
|
||||||
CurrencySymbol = string.IsNullOrEmpty(currency.Symbol) ? currency.Code : currency.Symbol,
|
CurrencySymbol = string.IsNullOrEmpty(numberFormatInfo.CurrencySymbol) ? settings.Currency : numberFormatInfo.CurrencySymbol,
|
||||||
Divisibility = currency.Divisibility,
|
Divisibility = numberFormatInfo.CurrencyDecimalDigits,
|
||||||
DecimalSeparator = numberFormatInfo.CurrencyDecimalSeparator,
|
DecimalSeparator = numberFormatInfo.CurrencyDecimalSeparator,
|
||||||
ThousandSeparator = numberFormatInfo.NumberGroupSeparator,
|
ThousandSeparator = numberFormatInfo.NumberGroupSeparator,
|
||||||
Prefixed = new[] { 0, 2 }.Contains(numberFormatInfo.CurrencyPositivePattern)
|
Prefixed = new[] { 0, 2 }.Contains(numberFormatInfo.CurrencyPositivePattern),
|
||||||
|
SymbolSpace = new[] { 2, 3 }.Contains(numberFormatInfo.CurrencyPositivePattern)
|
||||||
},
|
},
|
||||||
Items = _AppsHelper.Parse(settings.Template, settings.Currency),
|
Items = _AppsHelper.Parse(settings.Template, settings.Currency),
|
||||||
ButtonText = settings.ButtonText,
|
ButtonText = settings.ButtonText,
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ namespace BTCPayServer.Models.AppViewModels
|
|||||||
public string CurrencySymbol { get; set; }
|
public string CurrencySymbol { get; set; }
|
||||||
public string ThousandSeparator { get; set; }
|
public string ThousandSeparator { get; set; }
|
||||||
public string DecimalSeparator { get; set; }
|
public string DecimalSeparator { get; set; }
|
||||||
public int Divisibility { get; internal set; }
|
public int Divisibility { get; set; }
|
||||||
|
public bool SymbolSpace { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyInfoData CurrencyInfo { get; set; }
|
public CurrencyInfoData CurrencyInfo { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user