public override void PrepareInvoiceDto(InvoiceResponse invoiceResponse, InvoiceEntity invoiceEntity, InvoiceCryptoInfo invoiceCryptoInfo, PaymentMethodAccounting accounting, PaymentMethod info) { var scheme = info.Network.UriScheme; var minerInfo = new MinerFeeInfo(); minerInfo.TotalFee = accounting.NetworkFee.Satoshi; minerInfo.SatoshiPerBytes = ((BitcoinLikeOnChainPaymentMethod)info.GetPaymentMethodDetails()).FeeRate .GetFee(1).Satoshi; invoiceResponse.MinerFees.TryAdd(invoiceCryptoInfo.CryptoCode, minerInfo); invoiceCryptoInfo.PaymentUrls = new NBitpayClient.InvoicePaymentUrls() { BIP21 = $"{scheme}:{invoiceCryptoInfo.Address}?amount={invoiceCryptoInfo.Due}", }; #pragma warning disable 618 if (info.CryptoCode == "BTC") { invoiceResponse.BTCPrice = invoiceCryptoInfo.Price; invoiceResponse.Rate = invoiceCryptoInfo.Rate; invoiceResponse.ExRates = invoiceCryptoInfo.ExRates; invoiceResponse.BitcoinAddress = invoiceCryptoInfo.Address; invoiceResponse.BTCPaid = invoiceCryptoInfo.Paid; invoiceResponse.BTCDue = invoiceCryptoInfo.Due; invoiceResponse.PaymentUrls = invoiceCryptoInfo.PaymentUrls; } #pragma warning restore 618 }
public override void PopulateCryptoInfo(PaymentMethod details, InvoiceCryptoInfo invoiceCryptoInfo, string serverUrl) { invoiceCryptoInfo.PaymentUrls = new InvoiceCryptoInfo.InvoicePaymentUrls() { BOLT11 = GetPaymentLink(details.Network, details.GetPaymentMethodDetails(), invoiceCryptoInfo.Due, serverUrl) }; }
public override void PopulateCryptoInfo(PaymentMethod details, InvoiceCryptoInfo invoiceCryptoInfo, string serverUrl) { invoiceCryptoInfo.PaymentUrls = new InvoiceCryptoInfo.InvoicePaymentUrls() { AdditionalData = new Dictionary <string, JToken>() { { "LNURLP", JToken.FromObject(GetPaymentLink(details.Network, details.GetPaymentMethodDetails(), invoiceCryptoInfo.Due, serverUrl)) } } }; }
public override async Task <IPaymentMethodDetails> CreatePaymentMethodDetails( InvoiceLogs logs, LNURLPaySupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, Data.StoreData store, BTCPayNetwork network, object preparePaymentObject, IEnumerable <PaymentMethodId> invoicePaymentMethods) { var lnPmi = new PaymentMethodId(supportedPaymentMethod.CryptoCode, PaymentTypes.LightningLike); if (!supportedPaymentMethod.EnableForStandardInvoices && paymentMethod.ParentEntity.Type == InvoiceType.Standard && invoicePaymentMethods.Contains(lnPmi)) { throw new PaymentMethodUnavailableException("LNURL is not enabled for standard invoices"); } if (string.IsNullOrEmpty(paymentMethod.ParentEntity.Id)) { var lnSupported = store.GetSupportedPaymentMethods(_networkProvider) .OfType <LightningSupportedPaymentMethod>().SingleOrDefault(method => method.PaymentId.CryptoCode == supportedPaymentMethod.CryptoCode && method.PaymentId.PaymentType == LightningPaymentType.Instance); if (lnSupported is null) { throw new PaymentMethodUnavailableException("LNURL requires a lightning node to be configured for the store."); } return(new LNURLPayPaymentMethodDetails() { Activated = false, LightningSupportedPaymentMethod = lnSupported }); } var lnLightningSupportedPaymentMethod = ((LNURLPayPaymentMethodDetails)paymentMethod.GetPaymentMethodDetails()).LightningSupportedPaymentMethod; NodeInfo?nodeInfo = null; if (lnLightningSupportedPaymentMethod != null) { nodeInfo = (await _lightningLikePaymentHandler.GetNodeInfo(lnLightningSupportedPaymentMethod, _networkProvider.GetNetwork <BTCPayNetwork>(supportedPaymentMethod.CryptoCode), logs, paymentMethod.PreferOnion)).FirstOrDefault(); } return(new LNURLPayPaymentMethodDetails { Activated = true, LightningSupportedPaymentMethod = lnLightningSupportedPaymentMethod, BTCPayInvoiceId = paymentMethod.ParentEntity.Id, Bech32Mode = supportedPaymentMethod.UseBech32Scheme, NodeInfo = nodeInfo?.ToString() }); }
//MultiValueDictionary<string,string> private async Task Listen(InvoiceEntity invoice, PaymentMethod paymentMethod, BTCPayNetwork network) { var lightningMethod = paymentMethod.GetPaymentMethodDetails() as LightningLikePaymentMethodDetails; if (lightningMethod == null) { return; } var lightningSupportedMethod = invoice.GetSupportedPaymentMethod <LightningSupportedPaymentMethod>(_NetworkProvider) .FirstOrDefault(c => c.CryptoCode == network.CryptoCode); if (lightningSupportedMethod == null) { return; } var charge = new ChargeClient(lightningSupportedMethod.GetLightningChargeUrl(true), network.NBitcoinNetwork); var session = await charge.Listen(); while (true) { var notification = await session.NextEvent(); if (notification.Id == lightningMethod.InvoiceId && notification.PaymentRequest == lightningMethod.BOLT11) { if (notification.Status == "paid" && notification.PaidAt.HasValue) { await _InvoiceRepository.AddPayment(invoice.Id, notification.PaidAt.Value, new LightningLikePaymentData() { BOLT11 = notification.PaymentRequest, Amount = notification.MilliSatoshi }, network.CryptoCode, accounted : true); _Aggregator.Publish(new InvoiceEvent(invoice.Id, 1002, "invoice_receivedPayment")); break; } if (notification.Status == "expired") { break; } } } }