public PaymentMethodAccounting Calculate(Func <PaymentEntity, bool> paymentPredicate = null) { paymentPredicate = paymentPredicate ?? new Func <PaymentEntity, bool>((p) => true); var paymentMethods = ParentEntity.GetPaymentMethods(); var totalDue = ParentEntity.ProductInformation.Price / Rate; var paid = 0m; var cryptoPaid = 0.0m; int precision = 8; var totalDueNoNetworkCost = Money.Coins(Extensions.RoundUp(totalDue, precision)); bool paidEnough = paid >= Extensions.RoundUp(totalDue, precision); int txRequired = 0; _ = ParentEntity.GetPayments() .Where(p => p.Accounted && paymentPredicate(p)) .OrderBy(p => p.ReceivedTime) .Select(_ => { var txFee = _.GetValue(paymentMethods, GetId(), _.NetworkFee); paid += _.GetValue(paymentMethods, GetId()); if (!paidEnough) { totalDue += txFee; } paidEnough |= Extensions.RoundUp(paid, precision) >= Extensions.RoundUp(totalDue, precision); if (GetId() == _.GetPaymentMethodId()) { cryptoPaid += _.GetCryptoPaymentData().GetValue(); txRequired++; } return(_); }).ToArray(); var accounting = new PaymentMethodAccounting(); accounting.TxCount = txRequired; if (!paidEnough) { txRequired++; totalDue += GetTxFee(); } accounting.TotalDue = Money.Coins(Extensions.RoundUp(totalDue, precision)); accounting.Paid = Money.Coins(Extensions.RoundUp(paid, precision)); accounting.TxRequired = txRequired; accounting.CryptoPaid = Money.Coins(Extensions.RoundUp(cryptoPaid, precision)); accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero); accounting.DueUncapped = accounting.TotalDue - accounting.Paid; accounting.NetworkFee = accounting.TotalDue - totalDueNoNetworkCost; var minimumTotalDueSatoshi = Math.Max(1.0m, accounting.TotalDue.Satoshi * (1.0m - ((decimal)ParentEntity.PaymentTolerance / 100.0m))); accounting.MinimumTotalDue = Money.Satoshis(minimumTotalDueSatoshi); return(accounting); }
public PaymentMethodAccounting Calculate(Func <PaymentEntity, bool> paymentPredicate = null) { paymentPredicate = paymentPredicate ?? new Func <PaymentEntity, bool>((p) => true); var paymentMethods = ParentEntity.GetPaymentMethods(null, IsPhantomBTC); var totalDue = ParentEntity.ProductInformation.Price / Rate; var paid = 0m; var cryptoPaid = 0.0m; int precision = 8; var paidTxFee = 0m; bool paidEnough = paid >= Extensions.RoundUp(totalDue, precision); int txRequired = 0; var payments = ParentEntity.GetPayments() .Where(p => p.Accounted && paymentPredicate(p)) .OrderBy(p => p.ReceivedTime) .Select(_ => { var txFee = _.GetValue(paymentMethods, GetId(), paymentMethods[_.GetPaymentMethodId()].GetTxFee()); paid += _.GetValue(paymentMethods, GetId()); if (!paidEnough) { totalDue += txFee; paidTxFee += txFee; } paidEnough |= paid >= Extensions.RoundUp(totalDue, precision); if (GetId() == _.GetPaymentMethodId()) { cryptoPaid += _.GetCryptoPaymentData().GetValue(); txRequired++; } return(_); }) .ToArray(); var accounting = new PaymentMethodAccounting(); accounting.TxCount = txRequired; if (!paidEnough) { txRequired++; totalDue += GetTxFee(); paidTxFee += GetTxFee(); } accounting.TotalDue = Money.Coins(Extensions.RoundUp(totalDue, precision)); accounting.Paid = Money.Coins(paid); accounting.TxRequired = txRequired; accounting.CryptoPaid = Money.Coins(cryptoPaid); accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero); accounting.DueUncapped = accounting.TotalDue - accounting.Paid; accounting.NetworkFee = Money.Coins(paidTxFee); return(accounting); }
public CryptoDataAccounting Calculate() { var cryptoData = ParentEntity.GetCryptoData(null, IsPhantomBTC); var totalDue = Money.Coins(ParentEntity.ProductInformation.Price / Rate); var paid = Money.Zero; var cryptoPaid = Money.Zero; var paidTxFee = Money.Zero; bool paidEnough = totalDue <= paid; int txCount = 0; var payments = ParentEntity.GetPayments() .Where(p => p.Accounted) .OrderBy(p => p.ReceivedTime) .Select(_ => { var txFee = _.GetValue(cryptoData, CryptoCode, cryptoData[_.GetCryptoCode()].TxFee); paid += _.GetValue(cryptoData, CryptoCode); if (!paidEnough) { totalDue += txFee; paidTxFee += txFee; } paidEnough |= totalDue <= paid; if (CryptoCode == _.GetCryptoCode()) { cryptoPaid += _.GetValue(); txCount++; } return(_); }) .ToArray(); if (!paidEnough) { txCount++; totalDue += TxFee; paidTxFee += TxFee; } var accounting = new CryptoDataAccounting(); accounting.TotalDue = totalDue; accounting.Paid = paid; accounting.TxCount = txCount; accounting.CryptoPaid = cryptoPaid; accounting.Due = Money.Max(accounting.TotalDue - accounting.Paid, Money.Zero); accounting.NetworkFee = paidTxFee; return(accounting); }