public PaymentMethodDictionary GetPaymentMethods() { PaymentMethodDictionary paymentMethods = new PaymentMethodDictionary(); var serializer = new Serializer(null); #pragma warning disable CS0618 if (PaymentMethod != null) { foreach (var prop in PaymentMethod.Properties()) { var r = serializer.ToObject <PaymentMethod>(prop.Value.ToString()); if (!PaymentMethodId.TryParse(prop.Name, out var paymentMethodId)) { continue; } r.CryptoCode = paymentMethodId.CryptoCode; r.PaymentType = paymentMethodId.PaymentType.ToString(); r.ParentEntity = this; if (Networks != null) { r.Network = Networks.GetNetwork <BTCPayNetworkBase>(r.CryptoCode); if (r.Network is null) { continue; } } paymentMethods.Add(r); } } #pragma warning restore CS0618 return(paymentMethods); }
public IEnumerable <ISupportedPaymentMethod> GetSupportedPaymentMethod() { #pragma warning disable CS0618 bool btcReturned = false; if (!string.IsNullOrEmpty(DerivationStrategies)) { JObject strategies = JObject.Parse(DerivationStrategies); foreach (var strat in strategies.Properties()) { var paymentMethodId = PaymentMethodId.Parse(strat.Name); var network = Networks.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode); if (network != null) { if (network == Networks.BTC && paymentMethodId.PaymentType == PaymentTypes.BTCLike) { btcReturned = true; } yield return(paymentMethodId.PaymentType.DeserializeSupportedPaymentMethod(network, strat.Value)); } } } if (!btcReturned && !string.IsNullOrEmpty(DerivationStrategy)) { if (Networks.BTC != null) { yield return(BTCPayServer.DerivationSchemeSettings.Parse(DerivationStrategy, Networks.BTC)); } } #pragma warning restore CS0618 }
public PaymentMethodDictionary GetPaymentMethods() { PaymentMethodDictionary paymentMethods = new PaymentMethodDictionary(); var serializer = new Serializer(Dummy); #pragma warning disable CS0618 if (PaymentMethod != null) { foreach (var prop in PaymentMethod.Properties()) { var r = serializer.ToObject <PaymentMethod>(prop.Value.ToString()); var paymentMethodId = PaymentMethodId.Parse(prop.Name); r.CryptoCode = paymentMethodId.CryptoCode; r.PaymentType = paymentMethodId.PaymentType.ToString(); r.ParentEntity = this; r.Network = Networks?.GetNetwork(r.CryptoCode); if (r.Network != null || Networks == null) { paymentMethods.Add(r); } } } #pragma warning restore CS0618 return(paymentMethods); }
private IEnumerable <ExportInvoiceHolder> convertFromDb(InvoiceEntity invoice) { var exportList = new List <ExportInvoiceHolder>(); var currency = Currencies.GetNumberFormatInfo(invoice.ProductInformation.Currency, true); var invoiceDue = invoice.ProductInformation.Price; // in this first version we are only exporting invoices that were paid foreach (var payment in invoice.GetPayments()) { // not accounted payments are payments which got double spent like RBfed if (!payment.Accounted) { continue; } var cryptoCode = payment.GetPaymentMethodId().CryptoCode; var pdata = payment.GetCryptoPaymentData(); var pmethod = invoice.GetPaymentMethod(payment.GetPaymentMethodId(), Networks); var paidAfterNetworkFees = pdata.GetValue() - payment.NetworkFee; invoiceDue -= paidAfterNetworkFees * pmethod.Rate; var target = new ExportInvoiceHolder { ReceivedDate = payment.ReceivedTime.UtcDateTime, PaymentId = pdata.GetPaymentId(), CryptoCode = cryptoCode, ConversionRate = pmethod.Rate, PaymentType = payment.GetPaymentMethodId().PaymentType == Payments.PaymentTypes.BTCLike ? "OnChain" : "OffChain", Destination = payment.GetCryptoPaymentData().GetDestination(Networks.GetNetwork(cryptoCode)), Paid = pdata.GetValue().ToString(CultureInfo.InvariantCulture), PaidCurrency = Math.Round(pdata.GetValue() * pmethod.Rate, currency.NumberDecimalDigits).ToString(CultureInfo.InvariantCulture), // Adding NetworkFee because Paid doesn't take into account network fees // so if fee is 10000 satoshis, customer can essentially send infinite number of tx // and merchant effectivelly would receive 0 BTC, invoice won't be paid // while looking just at export you could sum Paid and assume merchant "received payments" NetworkFee = payment.NetworkFee.ToString(CultureInfo.InvariantCulture), InvoiceDue = Math.Round(invoiceDue, currency.NumberDecimalDigits), OrderId = invoice.OrderId, StoreId = invoice.StoreId, InvoiceId = invoice.Id, InvoiceCreatedDate = invoice.InvoiceTime.UtcDateTime, InvoiceExpirationDate = invoice.ExpirationTime.UtcDateTime, InvoiceMonitoringDate = invoice.MonitoringExpiration.UtcDateTime, #pragma warning disable CS0618 // Type or member is obsolete InvoiceFullStatus = invoice.GetInvoiceState().ToString(), InvoiceStatus = invoice.StatusString, InvoiceExceptionStatus = invoice.ExceptionStatusString, #pragma warning restore CS0618 // Type or member is obsolete InvoiceItemCode = invoice.ProductInformation.ItemCode, InvoiceItemDesc = invoice.ProductInformation.ItemDesc, InvoicePrice = invoice.ProductInformation.Price, InvoiceCurrency = invoice.ProductInformation.Currency, BuyerEmail = invoice.BuyerInformation?.BuyerEmail }; exportList.Add(target); } exportList = exportList.OrderBy(a => a.ReceivedDate).ToList(); return(exportList); }