Fix order accounting

This commit is contained in:
nicolas.dorier
2018-01-09 17:27:26 +09:00
parent 3069fe0dd9
commit 98b7ad62af
4 changed files with 20 additions and 14 deletions

View File

@@ -139,8 +139,7 @@ namespace BTCPayServer.Controllers
OrderId = invoice.OrderId, OrderId = invoice.OrderId,
InvoiceId = invoice.Id, InvoiceId = invoice.Id,
BtcAddress = cryptoData.DepositAddress, BtcAddress = cryptoData.DepositAddress,
BtcAmount = (accounting.TotalDue - cryptoData.TxFee).ToString(), OrderAmount = (accounting.TotalDue - accounting.NetworkFee).ToString(),
BtcTotalDue = accounting.TotalDue.ToString(),
BtcDue = accounting.Due.ToString(), BtcDue = accounting.Due.ToString(),
CustomerEmail = invoice.RefundMail, CustomerEmail = invoice.RefundMail,
ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds), ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds),
@@ -149,14 +148,18 @@ namespace BTCPayServer.Controllers
Rate = FormatCurrency(cryptoData), Rate = FormatCurrency(cryptoData),
MerchantRefLink = invoice.RedirectURL ?? "/", MerchantRefLink = invoice.RedirectURL ?? "/",
StoreName = store.StoreName, StoreName = store.StoreName,
TxFees = cryptoData.TxFee.ToString(),
InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BIP21, InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BIP21,
TxCount = accounting.TxCount, TxCount = accounting.TxCount,
BtcPaid = accounting.Paid.ToString(), BtcPaid = accounting.Paid.ToString(),
Status = invoice.Status, Status = invoice.Status,
CryptoImage = "/" + Url.Content(network.CryptoImagePath) CryptoImage = "/" + Url.Content(network.CryptoImagePath),
NetworkFeeDescription = $"{accounting.TxCount} transaction{(accounting.TxCount > 1 ? "s" : "")} x {cryptoData.TxFee} {network.CryptoCode}"
}; };
var isMultiCurrency = invoice.Payments.Select(p=>p.GetCryptoCode()).Concat(new[] { network.CryptoCode }).Distinct().Count() > 1;
if (isMultiCurrency)
model.NetworkFeeDescription = $"{accounting.NetworkFee} {network.CryptoCode}";
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds); var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);
model.TimeLeft = PrettyPrint(expiration); model.TimeLeft = PrettyPrint(expiration);
return model; return model;

View File

@@ -23,15 +23,14 @@ namespace BTCPayServer.Models.InvoicingModels
public string ItemDesc { get; set; } public string ItemDesc { get; set; }
public string TimeLeft { get; set; } public string TimeLeft { get; set; }
public string Rate { get; set; } public string Rate { get; set; }
public string BtcAmount { get; set; } public string OrderAmount { get; set; }
public string TxFees { get; set; }
public string InvoiceBitcoinUrl { get; set; } public string InvoiceBitcoinUrl { get; set; }
public string BtcTotalDue { get; set; }
public int TxCount { get; set; } public int TxCount { get; set; }
public string BtcPaid { get; set; } public string BtcPaid { get; set; }
public string StoreEmail { get; set; } public string StoreEmail { get; set; }
public string OrderId { get; set; } public string OrderId { get; set; }
public string CryptoImage { get; set; } public string CryptoImage { get; set; }
public string NetworkFeeDescription { get; internal set; }
} }
} }

View File

@@ -495,10 +495,13 @@ namespace BTCPayServer.Services.Invoices
.OrderByDescending(p => p.ReceivedTime) .OrderByDescending(p => p.ReceivedTime)
.Select(_ => .Select(_ =>
{ {
paidTxFee = _.GetValue(cryptoData, CryptoCode, cryptoData[_.GetCryptoCode()].TxFee); var txFee = _.GetValue(cryptoData, CryptoCode, cryptoData[_.GetCryptoCode()].TxFee);
paid += _.GetValue(cryptoData, CryptoCode); paid += _.GetValue(cryptoData, CryptoCode);
if(!paidEnough) if (!paidEnough)
totalDue += paidTxFee; {
totalDue += txFee;
paidTxFee += txFee;
}
paidEnough |= totalDue <= paid; paidEnough |= totalDue <= paid;
if (CryptoCode == _.GetCryptoCode()) if (CryptoCode == _.GetCryptoCode())
{ {
@@ -513,6 +516,7 @@ namespace BTCPayServer.Services.Invoices
{ {
txCount++; txCount++;
totalDue += TxFee; totalDue += TxFee;
paidTxFee += TxFee;
} }
var accounting = new CryptoDataAccounting(); var accounting = new CryptoDataAccounting();
accounting.TotalDue = totalDue; accounting.TotalDue = totalDue;
@@ -520,7 +524,7 @@ namespace BTCPayServer.Services.Invoices
accounting.TxCount = txCount; accounting.TxCount = txCount;
accounting.CryptoPaid = cryptoPaid; accounting.CryptoPaid = cryptoPaid;
accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero); accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero);
accounting.NetworkFee = TxFee * txCount; accounting.NetworkFee = paidTxFee;
return accounting; return accounting;
} }

View File

@@ -123,14 +123,14 @@
<div class="line-items"> <div class="line-items">
<!----> <!---->
<div class="line-items__item"> <div class="line-items__item">
<div class="line-items__item__label" i18n="">Payment Amount</div> <div class="line-items__item__label" i18n="">Order Amount</div>
<div class="line-items__item__value">{{srvModel.btcAmount}} {{ srvModel.cryptoCode }}</div> <div class="line-items__item__value">{{srvModel.orderAmount}} {{ srvModel.cryptoCode }}</div>
</div> </div>
<div class="line-items__item"> <div class="line-items__item">
<div class="line-items__item__label"> <div class="line-items__item__label">
<span i18n="">Network Cost</span> <span i18n="">Network Cost</span>
</div> </div>
<div class="line-items__item__value" i18n="">{{srvModel.txCount }} transaction x {{ srvModel.txFees}} {{ srvModel.cryptoCode }}</div> <div class="line-items__item__value" i18n="">{{srvModel.networkFeeDescription }}</div>
</div> </div>
<div class="line-items__item"> <div class="line-items__item">
<div class="line-items__item__label"> <div class="line-items__item__label">