mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 02:08:32 +01:00
Merge pull request #1784 from Kukks/paymentlink
Generate Payment link from PaymentType
This commit is contained in:
commit
8156fce81a
8 changed files with 50 additions and 20 deletions
|
@ -20,7 +20,8 @@ namespace BTCPayServer
|
||||||
"XMR_X = XMR_BTC * BTC_X",
|
"XMR_X = XMR_BTC * BTC_X",
|
||||||
"XMR_BTC = kraken(XMR_BTC)"
|
"XMR_BTC = kraken(XMR_BTC)"
|
||||||
},
|
},
|
||||||
CryptoImagePath = "/imlegacy/monero.svg"
|
CryptoImagePath = "/imlegacy/monero.svg",
|
||||||
|
UriScheme = "monero"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,6 @@ namespace BTCPayServer
|
||||||
public class MoneroLikeSpecificBtcPayNetwork : BTCPayNetworkBase
|
public class MoneroLikeSpecificBtcPayNetwork : BTCPayNetworkBase
|
||||||
{
|
{
|
||||||
public int MaxTrackedConfirmation = 10;
|
public int MaxTrackedConfirmation = 10;
|
||||||
|
public string UriScheme { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BTCPayServer.Payments.Bitcoin;
|
using BTCPayServer.Payments.Bitcoin;
|
||||||
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
using NBitcoin;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace BTCPayServer.Payments
|
namespace BTCPayServer.Payments
|
||||||
|
@ -64,6 +66,19 @@ namespace BTCPayServer.Payments
|
||||||
txId = txId.Split('-').First();
|
txId = txId.Split('-').First();
|
||||||
return string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, txId);
|
return string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
||||||
|
Money cryptoInfoDue, string serverUri)
|
||||||
|
{
|
||||||
|
var bip21 = ((BTCPayNetwork)network).GenerateBIP21(paymentMethodDetails.GetPaymentDestination(), cryptoInfoDue);
|
||||||
|
|
||||||
|
if ((paymentMethodDetails as BitcoinLikeOnChainPaymentMethod)?.PayjoinEnabled is true)
|
||||||
|
{
|
||||||
|
bip21 += $"&{PayjoinClient.BIP21EndpointKey}={serverUri.WithTrailingSlash()}{network.CryptoCode}/{PayjoinClient.BIP21EndpointKey}";
|
||||||
|
}
|
||||||
|
return bip21;
|
||||||
|
}
|
||||||
|
|
||||||
public override string InvoiceViewPaymentPartialName { get; } = "ViewBitcoinLikePaymentData";
|
public override string InvoiceViewPaymentPartialName { get; } = "ViewBitcoinLikePaymentData";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
using System;
|
||||||
using BTCPayServer.Payments.Lightning;
|
using BTCPayServer.Payments.Lightning;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
using NBitcoin;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
@ -8,13 +10,14 @@ namespace BTCPayServer.Payments
|
||||||
public class LightningPaymentType : PaymentType
|
public class LightningPaymentType : PaymentType
|
||||||
{
|
{
|
||||||
public static LightningPaymentType Instance { get; } = new LightningPaymentType();
|
public static LightningPaymentType Instance { get; } = new LightningPaymentType();
|
||||||
|
|
||||||
private LightningPaymentType()
|
private LightningPaymentType()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToPrettyString() => "Off-Chain";
|
public override string ToPrettyString() => "Off-Chain";
|
||||||
public override string GetId() => "LightningLike";
|
public override string GetId() => "LightningLike";
|
||||||
|
|
||||||
public override CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str)
|
public override CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str)
|
||||||
{
|
{
|
||||||
return ((BTCPayNetwork)network).ToObject<LightningLikePaymentData>(str);
|
return ((BTCPayNetwork)network).ToObject<LightningLikePaymentData>(str);
|
||||||
|
@ -35,7 +38,8 @@ namespace BTCPayServer.Payments
|
||||||
return JsonConvert.SerializeObject(details);
|
return JsonConvert.SerializeObject(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value)
|
public override ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network,
|
||||||
|
JToken value)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<LightningSupportedPaymentMethod>(value.ToString());
|
return JsonConvert.DeserializeObject<LightningSupportedPaymentMethod>(value.ToString());
|
||||||
}
|
}
|
||||||
|
@ -44,6 +48,14 @@ namespace BTCPayServer.Payments
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
||||||
|
Money cryptoInfoDue, string serverUri)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$"lightning:{paymentMethodDetails.GetPaymentDestination().ToUpperInvariant().Replace("LIGHTNING:", "", StringComparison.InvariantCultureIgnoreCase)}";
|
||||||
|
}
|
||||||
|
|
||||||
public override string InvoiceViewPaymentPartialName { get; } = "ViewLightningLikePaymentData";
|
public override string InvoiceViewPaymentPartialName { get; } = "ViewLightningLikePaymentData";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using BTCPayServer.Services.Altcoins.Monero.Payments;
|
using BTCPayServer.Services.Altcoins.Monero.Payments;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
using NBitcoin;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace BTCPayServer.Payments
|
namespace BTCPayServer.Payments
|
||||||
|
@ -63,6 +64,8 @@ namespace BTCPayServer.Payments
|
||||||
public abstract string SerializePaymentMethodDetails(BTCPayNetworkBase network, IPaymentMethodDetails details);
|
public abstract string SerializePaymentMethodDetails(BTCPayNetworkBase network, IPaymentMethodDetails details);
|
||||||
public abstract ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value);
|
public abstract ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value);
|
||||||
public abstract string GetTransactionLink(BTCPayNetworkBase network, string txId);
|
public abstract string GetTransactionLink(BTCPayNetworkBase network, string txId);
|
||||||
|
public abstract string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
||||||
|
Money cryptoInfoDue, string serverUri);
|
||||||
public abstract string InvoiceViewPaymentPartialName { get; }
|
public abstract string InvoiceViewPaymentPartialName { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,20 +75,15 @@ namespace BTCPayServer.Services.Altcoins.Monero.Payments
|
||||||
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob)
|
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob)
|
||||||
{
|
{
|
||||||
var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentType);
|
var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentType);
|
||||||
|
|
||||||
var client = _moneroRpcProvider.WalletRpcClients[model.CryptoCode];
|
|
||||||
|
|
||||||
var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
|
var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
|
||||||
var network = _networkProvider.GetNetwork<MoneroLikeSpecificBtcPayNetwork>(model.CryptoCode);
|
var network = _networkProvider.GetNetwork<MoneroLikeSpecificBtcPayNetwork>(model.CryptoCode);
|
||||||
model.IsLightning = false;
|
model.IsLightning = false;
|
||||||
model.PaymentMethodName = GetPaymentMethodName(network);
|
model.PaymentMethodName = GetPaymentMethodName(network);
|
||||||
model.CryptoImage = GetCryptoImage(network);
|
model.CryptoImage = GetCryptoImage(network);
|
||||||
model.InvoiceBitcoinUrl = client.SendCommandAsync<MakeUriRequest, MakeUriResponse>("make_uri", new MakeUriRequest()
|
model.InvoiceBitcoinUrl = MoneroPaymentType.Instance.GetPaymentLink(network, new MoneroLikeOnChainPaymentMethodDetails()
|
||||||
{
|
{
|
||||||
Address = cryptoInfo.Address,
|
DepositAddress = cryptoInfo.Address
|
||||||
Amount = MoneroMoney.Convert(decimal.Parse(cryptoInfo.Due, CultureInfo.InvariantCulture))
|
}, cryptoInfo.Due, null);
|
||||||
}).GetAwaiter()
|
|
||||||
.GetResult().Uri;
|
|
||||||
model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrl;
|
model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrl;
|
||||||
}
|
}
|
||||||
public override string GetCryptoImage(PaymentMethodId paymentMethodId)
|
public override string GetCryptoImage(PaymentMethodId paymentMethodId)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using BTCPayServer.Payments;
|
using BTCPayServer.Payments;
|
||||||
using BTCPayServer.Services.Invoices;
|
using BTCPayServer.Services.Invoices;
|
||||||
|
using NBitcoin;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
@ -44,6 +45,12 @@ namespace BTCPayServer.Services.Altcoins.Monero.Payments
|
||||||
return string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, txId);
|
return string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails, Money cryptoInfoDue, string serverUri)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
$"{(network as MoneroLikeSpecificBtcPayNetwork).UriScheme}:{paymentMethodDetails.GetPaymentDestination()}?tx_amount={cryptoInfoDue.ToDecimal(MoneyUnit.BTC)}";
|
||||||
|
}
|
||||||
|
|
||||||
public override string InvoiceViewPaymentPartialName { get; } = "Monero/ViewMoneroLikePaymentData";
|
public override string InvoiceViewPaymentPartialName { get; } = "Monero/ViewMoneroLikePaymentData";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -456,7 +456,8 @@ namespace BTCPayServer.Services.Invoices
|
||||||
{
|
{
|
||||||
cryptoInfo.PaymentUrls = new InvoicePaymentUrls()
|
cryptoInfo.PaymentUrls = new InvoicePaymentUrls()
|
||||||
{
|
{
|
||||||
BOLT11 = $"lightning:{cryptoInfo.Address}"
|
BOLT11 = paymentId.PaymentType.GetPaymentLink(info.Network, details, cryptoInfo.Due,
|
||||||
|
ServerUrl)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (paymentId.PaymentType == PaymentTypes.BTCLike)
|
else if (paymentId.PaymentType == PaymentTypes.BTCLike)
|
||||||
|
@ -466,15 +467,10 @@ namespace BTCPayServer.Services.Invoices
|
||||||
minerInfo.SatoshiPerBytes = ((BitcoinLikeOnChainPaymentMethod)details).FeeRate
|
minerInfo.SatoshiPerBytes = ((BitcoinLikeOnChainPaymentMethod)details).FeeRate
|
||||||
.GetFee(1).Satoshi;
|
.GetFee(1).Satoshi;
|
||||||
dto.MinerFees.TryAdd(cryptoInfo.CryptoCode, minerInfo);
|
dto.MinerFees.TryAdd(cryptoInfo.CryptoCode, minerInfo);
|
||||||
var bip21 = ((BTCPayNetwork)info.Network).GenerateBIP21(cryptoInfo.Address, cryptoInfo.Due);
|
cryptoInfo.PaymentUrls = new InvoicePaymentUrls()
|
||||||
|
|
||||||
if ((details as BitcoinLikeOnChainPaymentMethod)?.PayjoinEnabled is true)
|
|
||||||
{
|
{
|
||||||
bip21 += $"&{PayjoinClient.BIP21EndpointKey}={ServerUrl.WithTrailingSlash()}{cryptoCode}/{PayjoinClient.BIP21EndpointKey}";
|
BIP21 = paymentId.PaymentType.GetPaymentLink(info.Network, details, cryptoInfo.Due,
|
||||||
}
|
ServerUrl)
|
||||||
cryptoInfo.PaymentUrls = new NBitpayClient.InvoicePaymentUrls()
|
|
||||||
{
|
|
||||||
BIP21 = bip21,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma warning disable 618
|
#pragma warning disable 618
|
||||||
|
|
Loading…
Add table
Reference in a new issue