mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Merge pull request #179 from rockstardev/fiat
Showing exchange rate for cryptos
This commit is contained in:
commit
f9e40b209a
2 changed files with 19 additions and 15 deletions
|
@ -85,7 +85,7 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
cryptoPayment.Address = onchainMethod.DepositAddress;
|
cryptoPayment.Address = onchainMethod.DepositAddress;
|
||||||
}
|
}
|
||||||
cryptoPayment.Rate = FormatCurrency(data);
|
cryptoPayment.Rate = ExchangeRate(data);
|
||||||
cryptoPayment.PaymentUrl = cryptoInfo.PaymentUrls.BIP21;
|
cryptoPayment.PaymentUrl = cryptoInfo.PaymentUrls.BIP21;
|
||||||
model.CryptoPayments.Add(cryptoPayment);
|
model.CryptoPayments.Add(cryptoPayment);
|
||||||
}
|
}
|
||||||
|
@ -244,14 +244,14 @@ namespace BTCPayServer.Controllers
|
||||||
BtcAddress = paymentMethodDetails.GetPaymentDestination(),
|
BtcAddress = paymentMethodDetails.GetPaymentDestination(),
|
||||||
BtcDue = accounting.Due.ToString(),
|
BtcDue = accounting.Due.ToString(),
|
||||||
OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(),
|
OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(),
|
||||||
OrderAmountFiat = OrderAmountFiat(invoice.ProductInformation),
|
OrderAmountFiat = OrderAmountFromInvoice(network.CryptoCode, invoice.ProductInformation),
|
||||||
CustomerEmail = invoice.RefundMail,
|
CustomerEmail = invoice.RefundMail,
|
||||||
RequiresRefundEmail = storeBlob.RequiresRefundEmail,
|
RequiresRefundEmail = storeBlob.RequiresRefundEmail,
|
||||||
ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds),
|
ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds),
|
||||||
MaxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds,
|
MaxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds,
|
||||||
MaxTimeMinutes = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalMinutes,
|
MaxTimeMinutes = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalMinutes,
|
||||||
ItemDesc = invoice.ProductInformation.ItemDesc,
|
ItemDesc = invoice.ProductInformation.ItemDesc,
|
||||||
Rate = FormatCurrency(paymentMethod),
|
Rate = ExchangeRate(paymentMethod),
|
||||||
MerchantRefLink = invoice.RedirectURL ?? "/",
|
MerchantRefLink = invoice.RedirectURL ?? "/",
|
||||||
StoreName = store.StoreName,
|
StoreName = store.StoreName,
|
||||||
InvoiceBitcoinUrl = paymentMethodId.PaymentType == PaymentTypes.BTCLike ? cryptoInfo.PaymentUrls.BIP21 :
|
InvoiceBitcoinUrl = paymentMethodId.PaymentType == PaymentTypes.BTCLike ? cryptoInfo.PaymentUrls.BIP21 :
|
||||||
|
@ -289,11 +289,20 @@ namespace BTCPayServer.Controllers
|
||||||
return (paymentMethodId.PaymentType == PaymentTypes.BTCLike ? Url.Content(network.CryptoImagePath) : Url.Content(network.LightningImagePath));
|
return (paymentMethodId.PaymentType == PaymentTypes.BTCLike ? Url.Content(network.CryptoImagePath) : Url.Content(network.LightningImagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
private string FormatCurrency(PaymentMethod paymentMethod)
|
private string OrderAmountFromInvoice(string cryptoCode, ProductInformation productInformation)
|
||||||
|
{
|
||||||
|
// if invoice source currency is the same as currently display currency, no need for "order amount from invoice"
|
||||||
|
if (cryptoCode == productInformation.Currency)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return FormatCurrency(productInformation.Price, productInformation.Currency, _CurrencyNameTable);
|
||||||
|
}
|
||||||
|
private string ExchangeRate(PaymentMethod paymentMethod)
|
||||||
{
|
{
|
||||||
string currency = paymentMethod.ParentEntity.ProductInformation.Currency;
|
string currency = paymentMethod.ParentEntity.ProductInformation.Currency;
|
||||||
return FormatCurrency(paymentMethod.Rate, currency, _CurrencyNameTable);
|
return FormatCurrency(paymentMethod.Rate, currency, _CurrencyNameTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FormatCurrency(decimal price, string currency, CurrencyNameTable currencies)
|
public static string FormatCurrency(decimal price, string currency, CurrencyNameTable currencies)
|
||||||
{
|
{
|
||||||
var provider = currencies.GetNumberFormatInfo(currency);
|
var provider = currencies.GetNumberFormatInfo(currency);
|
||||||
|
@ -314,18 +323,13 @@ namespace BTCPayServer.Controllers
|
||||||
provider = (NumberFormatInfo)provider.Clone();
|
provider = (NumberFormatInfo)provider.Clone();
|
||||||
provider.CurrencyDecimalDigits = divisibility;
|
provider.CurrencyDecimalDigits = divisibility;
|
||||||
}
|
}
|
||||||
return price.ToString("C", provider) + $" ({currency})";
|
|
||||||
}
|
|
||||||
private string OrderAmountFiat(ProductInformation productInformation)
|
|
||||||
{
|
|
||||||
// check if invoice source currency is crypto... if it is there is no "order amount in fiat"
|
|
||||||
if (_NetworkProvider.GetNetwork(productInformation.Currency) != null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FormatCurrency(productInformation.Price, productInformation.Currency, _CurrencyNameTable);
|
if (_specialCryptoFormat.Contains(currency))
|
||||||
|
return price.ToString("C", provider);
|
||||||
|
else
|
||||||
|
return price.ToString("C", provider) + $" ({currency})";
|
||||||
}
|
}
|
||||||
|
private static readonly string[] _specialCryptoFormat = new[] { "BTC", "LTC" };
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("i/{invoiceId}/status")]
|
[Route("i/{invoiceId}/status")]
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
<span>{{ srvModel.btcDue }} {{ srvModel.cryptoCode }}</span>
|
<span>{{ srvModel.btcDue }} {{ srvModel.cryptoCode }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="single-item-order__right__ex-rate" v-if="srvModel.orderAmountFiat">
|
<div class="single-item-order__right__ex-rate" v-if="srvModel.orderAmountFiat">
|
||||||
1 {{ srvModel.cryptoCode }} = {{ srvModel.rate }}
|
1 {{ srvModel.cryptoCode }} = {{ srvModel.rate }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue