Exemple #1
0
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob, IPaymentMethod paymentMethod)
        {
            var paymentMethodId = paymentMethod.GetId();
            var cryptoInfo      = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network         = _networkProvider.GetNetwork <EthereumBTCPayNetwork>(model.CryptoCode);

            model.PaymentMethodName   = GetPaymentMethodName(network);
            model.CryptoImage         = GetCryptoImage(network);
            model.InvoiceBitcoinUrl   = "";
            model.InvoiceBitcoinUrlQR = cryptoInfo.Address;
        }
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob)
        {
            var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.BTCLike);

            var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network    = _networkProvider.GetNetwork <BTCPayNetwork>(model.CryptoCode);

            model.IsLightning         = false;
            model.PaymentMethodName   = GetPaymentMethodName(network);
            model.InvoiceBitcoinUrl   = cryptoInfo.PaymentUrls.BIP21;
            model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21;
        }
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob, IPaymentMethod paymentMethod)
        {
            var paymentMethodId = paymentMethod.GetId();
            var cryptoInfo      = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network         = _networkProvider.GetNetwork <BTCPayNetwork>(model.CryptoCode);

            model.ShowRecommendedFee = storeBlob.ShowRecommendedFee;
            model.FeeRate            = ((BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails()).GetFeeRate();
            model.PaymentMethodName  = GetPaymentMethodName(network);

            var lightningFallback = "";

            if (model.Activated && network.SupportLightning && storeBlob.OnChainWithLnInvoiceFallback)
            {
                var lightningInfo = invoiceResponse.CryptoInfo.FirstOrDefault(a =>
                                                                              a.GetpaymentMethodId() == new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike));
                if (!string.IsNullOrEmpty(lightningInfo?.PaymentUrls?.BOLT11))
                {
                    lightningFallback = "&" + lightningInfo.PaymentUrls.BOLT11
                                        .Replace("lightning:", "lightning=", StringComparison.OrdinalIgnoreCase)
                                        .ToUpperInvariant();
                }
            }

            if (model.Activated)
            {
                model.InvoiceBitcoinUrl   = (cryptoInfo.PaymentUrls?.BIP21 ?? "") + lightningFallback;
                model.InvoiceBitcoinUrlQR = (cryptoInfo.PaymentUrls?.BIP21 ?? "") + lightningFallback
                                            .Replace("LIGHTNING=", "lightning=", StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                model.InvoiceBitcoinUrl   = "";
                model.InvoiceBitcoinUrlQR = "";
            }

            // Most wallets still don't support GROESTLCOIN: schema, so we're leaving this for better days
            // Ref: https://github.com/btcpayserver/btcpayserver/pull/2060#issuecomment-723828348
            //model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21
            //    .Replace("groestlcoin:", "GROESTLCOIN:", StringComparison.OrdinalIgnoreCase)

            // We're leading the way in Bitcoin community with adding UPPERCASE Bech32 addresses in QR Code
            if (network.CryptoCode.Equals("BTC", StringComparison.InvariantCultureIgnoreCase) && _bech32Prefix.TryGetValue(model.CryptoCode, out var prefix) && model.BtcAddress.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrlQR.Replace(
                    $"{network.NBitcoinNetwork.UriScheme}:{model.BtcAddress}", $"{network.NBitcoinNetwork.UriScheme}:{model.BtcAddress.ToUpperInvariant()}",
                    StringComparison.OrdinalIgnoreCase
                    );
            }
        }
Exemple #4
0
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob, IPaymentMethod paymentMethod)
        {
            var paymentMethodId = paymentMethod.GetId();
            var cryptoInfo      = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network         = _networkProvider.GetNetwork <MoneroLikeSpecificBtcPayNetwork>(model.CryptoCode);

            model.PaymentMethodName = GetPaymentMethodName(network);
            model.CryptoImage       = GetCryptoImage(network);
            model.InvoiceBitcoinUrl = MoneroPaymentType.Instance.GetPaymentLink(network, new MoneroLikeOnChainPaymentMethodDetails()
            {
                DepositAddress = cryptoInfo.Address
            }, cryptoInfo.Due, null);
            model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrl;
        }
Exemple #5
0
        private void AddPaymentMethods(StoreData store, StoreBlob storeBlob, StoreViewModel vm)
        {
            var excludeFilters         = storeBlob.GetExcludedPaymentMethods();
            var derivationByCryptoCode =
                store
                .GetSupportedPaymentMethods(_NetworkProvider)
                .OfType <DerivationStrategy>()
                .ToDictionary(c => c.Network.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var strategy = derivationByCryptoCode.TryGet(network.CryptoCode);
                vm.DerivationSchemes.Add(new StoreViewModel.DerivationScheme()
                {
                    Crypto   = network.CryptoCode,
                    Value    = strategy?.DerivationStrategyBase?.ToString() ?? string.Empty,
                    WalletId = new WalletId(store.Id, network.CryptoCode),
                    Enabled  = !excludeFilters.Match(new Payments.PaymentMethodId(network.CryptoCode, Payments.PaymentTypes.BTCLike))
                });
            }

            var lightningByCryptoCode = store
                                        .GetSupportedPaymentMethods(_NetworkProvider)
                                        .OfType <Payments.Lightning.LightningSupportedPaymentMethod>()
                                        .ToDictionary(c => c.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var lightning = lightningByCryptoCode.TryGet(network.CryptoCode);
                var paymentId = new Payments.PaymentMethodId(network.CryptoCode, Payments.PaymentTypes.LightningLike);
                vm.LightningNodes.Add(new StoreViewModel.LightningNode()
                {
                    CryptoCode = network.CryptoCode,
                    Address    = lightning?.GetLightningUrl()?.BaseUri.AbsoluteUri ?? string.Empty,
                    Enabled    = !excludeFilters.Match(paymentId)
                });
            }


            var changellyEnabled = storeBlob.ChangellySettings != null && storeBlob.ChangellySettings.Enabled;

            vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod()
            {
                Enabled  = changellyEnabled,
                Action   = nameof(UpdateChangellySettings),
                Provider = "Changelly"
            });
        }
        public static ShopifySettings GetShopifySettings(this StoreBlob storeBlob)
        {
            if (storeBlob.AdditionalData.TryGetValue(StoreBlobKey, out var rawS))
            {
                if (rawS is JObject rawObj)
                {
                    return(new Serializer(null).ToObject <ShopifySettings>(rawObj));
                }
                else if (rawS.Type == JTokenType.String)
                {
                    return(new Serializer(null).ToObject <ShopifySettings>(rawS.Value <string>()));
                }
            }

            return(null);
        }
Exemple #7
0
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob, IPaymentMethod paymentMethod)
        {
            var paymentMethodId = paymentMethod.GetId();
            var cryptoInfo      = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network         = _networkProvider.GetNetwork <BTCPayNetwork>(model.CryptoCode);

            model.ShowRecommendedFee = storeBlob.ShowRecommendedFee;
            model.FeeRate            = ((BitcoinLikeOnChainPaymentMethod)paymentMethod.GetPaymentMethodDetails()).GetFeeRate();
            model.PaymentMethodName  = GetPaymentMethodName(network);


            var lightningFallback = "";

            if (storeBlob.OnChainWithLnInvoiceFallback)
            {
                var lightningInfo = invoiceResponse.CryptoInfo.FirstOrDefault(a =>
                                                                              a.GetpaymentMethodId() == new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike));
                if (!String.IsNullOrEmpty(lightningInfo?.PaymentUrls?.BOLT11))
                {
                    lightningFallback = "&" + lightningInfo.PaymentUrls.BOLT11.Replace("lightning:", "lightning=", StringComparison.OrdinalIgnoreCase);
                }
            }

            model.InvoiceBitcoinUrl   = cryptoInfo.PaymentUrls.BIP21 + lightningFallback;
            model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrl;

            // Standard for uppercase Bech32 addresses in QR codes is still not implemented in all wallets
            // When it is widely propagated consider uncommenting these lines

            // We're trying to make as many characters uppercase to make QR smaller
            // Ref: https://github.com/btcpayserver/btcpayserver/pull/2060#issuecomment-723828348
            //model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21
            //    .Replace("bitcoin:", "BITCOIN:", StringComparison.OrdinalIgnoreCase)
            //    + lightningFallback.ToUpperInvariant().Replace("LIGHTNING=", "lightning=", StringComparison.OrdinalIgnoreCase);

            //if (bech32Prefixes.Any(a => model.BtcAddress.StartsWith(a, StringComparison.OrdinalIgnoreCase)))
            //{
            //    model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrlQR.Replace(
            //        $"BITCOIN:{model.BtcAddress}", $"BITCOIN:{model.BtcAddress.ToUpperInvariant()}",
            //        StringComparison.OrdinalIgnoreCase
            //    );
            //}
        }
        internal void AddPaymentMethods(StoreData store, StoreBlob storeBlob,
                                        out List <StoreDerivationScheme> derivationSchemes, out List <StoreLightningNode> lightningNodes)
        {
            var excludeFilters         = storeBlob.GetExcludedPaymentMethods();
            var derivationByCryptoCode =
                store
                .GetSupportedPaymentMethods(_NetworkProvider)
                .OfType <DerivationSchemeSettings>()
                .ToDictionary(c => c.Network.CryptoCode.ToUpperInvariant());

            var lightningByCryptoCode = store
                                        .GetSupportedPaymentMethods(_NetworkProvider)
                                        .OfType <LightningSupportedPaymentMethod>()
                                        .Where(method => method.PaymentId.PaymentType == LightningPaymentType.Instance)
                                        .ToDictionary(c => c.CryptoCode.ToUpperInvariant());

            derivationSchemes = new List <StoreDerivationScheme>();
            lightningNodes    = new List <StoreLightningNode>();

            foreach (var paymentMethodId in _paymentMethodHandlerDictionary.Distinct().SelectMany(handler => handler.GetSupportedPaymentMethods()))
            {
                switch (paymentMethodId.PaymentType)
                {
                case BitcoinPaymentType _:
                    var strategy = derivationByCryptoCode.TryGet(paymentMethodId.CryptoCode);
                    var network  = _NetworkProvider.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode);
                    var value    = strategy?.ToPrettyString() ?? string.Empty;

                    derivationSchemes.Add(new StoreDerivationScheme
                    {
                        Crypto          = paymentMethodId.CryptoCode,
                        WalletSupported = network.WalletSupported,
                        Value           = value,
                        WalletId        = new WalletId(store.Id, paymentMethodId.CryptoCode),
                        Enabled         = !excludeFilters.Match(paymentMethodId) && strategy != null,
#if ALTCOINS
                        Collapsed = network is ElementsBTCPayNetwork elementsBTCPayNetwork && elementsBTCPayNetwork.NetworkCryptoCode != elementsBTCPayNetwork.CryptoCode && string.IsNullOrEmpty(value)
#endif
                    });
                    break;
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                                 StoreBlob storeBlob)
        {
            var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike);

            var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network    = _networkProvider.GetNetwork <BTCPayNetwork>(model.CryptoCode);

            model.IsLightning              = true;
            model.PaymentMethodName        = GetPaymentMethodName(network);
            model.InvoiceBitcoinUrl        = cryptoInfo.PaymentUrls.BOLT11;
            model.InvoiceBitcoinUrlQR      = $"lightning:{cryptoInfo.PaymentUrls.BOLT11.ToUpperInvariant().Substring("LIGHTNING:".Length)}";
            model.LightningAmountInSatoshi = storeBlob.LightningAmountInSatoshi;
            if (storeBlob.LightningAmountInSatoshi && model.CryptoCode == "BTC")
            {
                model.CryptoCode  = "Sats";
                model.BtcDue      = Money.Parse(model.BtcDue).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
                model.BtcPaid     = Money.Parse(model.BtcPaid).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
                model.NetworkFee  = new Money(model.NetworkFee, MoneyUnit.BTC).ToUnit(MoneyUnit.Satoshi);
                model.OrderAmount = Money.Parse(model.OrderAmount).ToUnit(MoneyUnit.Satoshi).ToString(CultureInfo.InvariantCulture);
            }
        }
        public override async Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                                       Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId)
        {
            if (storeBlob.LightningMaxValue != null)
            {
                var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, storeBlob.LightningMaxValue.Currency)];

                if (currentRateToCrypto?.BidAsk != null)
                {
                    var limitValueCrypto = Money.Coins(storeBlob.LightningMaxValue.Value / currentRateToCrypto.BidAsk.Bid);
                    if (amount > limitValueCrypto)
                    {
                        return("The amount of the invoice is too high to be paid with lightning");
                    }
                }
            }
            return(string.Empty);
        }
 public abstract Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                          Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId);
 public abstract void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
                                          StoreBlob storeBlob);
Exemple #13
0
        private void AddPaymentMethods(StoreData store, StoreBlob storeBlob, StoreViewModel vm)
        {
            var excludeFilters         = storeBlob.GetExcludedPaymentMethods();
            var derivationByCryptoCode =
                store
                .GetSupportedPaymentMethods(_NetworkProvider)
                .OfType <DerivationSchemeSettings>()
                .ToDictionary(c => c.Network.CryptoCode.ToUpperInvariant());

            var lightningByCryptoCode = store
                                        .GetSupportedPaymentMethods(_NetworkProvider)
                                        .OfType <LightningSupportedPaymentMethod>()
                                        .ToDictionary(c => c.CryptoCode.ToUpperInvariant());

            foreach (var paymentMethodId in _paymentMethodHandlerDictionary.Distinct().SelectMany(handler => handler.GetSupportedPaymentMethods()))
            {
                switch (paymentMethodId.PaymentType)
                {
                case BitcoinPaymentType _:
                    var strategy = derivationByCryptoCode.TryGet(paymentMethodId.CryptoCode);
                    var network  = _NetworkProvider.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode);
                    vm.DerivationSchemes.Add(new StoreViewModel.DerivationScheme()
                    {
                        Crypto          = paymentMethodId.CryptoCode,
                        WalletSupported = network.WalletSupported,
                        Value           = strategy?.ToPrettyString() ?? string.Empty,
                        WalletId        = new WalletId(store.Id, paymentMethodId.CryptoCode),
                        Enabled         = !excludeFilters.Match(paymentMethodId) && strategy != null
                    });
                    break;

                case LightningPaymentType _:
                    var lightning = lightningByCryptoCode.TryGet(paymentMethodId.CryptoCode);
                    vm.LightningNodes.Add(new StoreViewModel.LightningNode()
                    {
                        CryptoCode = paymentMethodId.CryptoCode,
                        Address    = lightning?.GetLightningUrl()?.BaseUri.AbsoluteUri ?? string.Empty,
                        Enabled    = !excludeFilters.Match(paymentMethodId) && lightning?.GetLightningUrl() != null
                    });
                    break;
                }
            }

            var changellyEnabled = storeBlob.ChangellySettings != null && storeBlob.ChangellySettings.Enabled;

            vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.AdditionalPaymentMethod()
            {
                Enabled  = changellyEnabled,
                Action   = nameof(UpdateChangellySettings),
                Provider = "Changelly"
            });

            var coinSwitchEnabled = storeBlob.CoinSwitchSettings != null && storeBlob.CoinSwitchSettings.Enabled;

            vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.AdditionalPaymentMethod()
            {
                Enabled  = coinSwitchEnabled,
                Action   = nameof(UpdateCoinSwitchSettings),
                Provider = "CoinSwitch"
            });
        }
Exemple #14
0
        public override async Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                                       Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId)
        {
            if (storeBlob.OnChainMinValue != null)
            {
                var currentRateTobitcoin =
                    await rate[new CurrencyPair(paymentMethodId.bitcoinCode, storeBlob.OnChainMinValue.Currency)];
                if (currentRateTobitcoin?.BidAsk != null)
                {
                    var limitValuebitcoin =
                        Money.Coins(storeBlob.OnChainMinValue.Value / currentRateTobitcoin.BidAsk.Bid);
                    if (amount < limitValuebitcoin)
                    {
                        return("The amount of the invoice is too low to be paid on chain");
                    }
                }
            }

            return(string.Empty);
        }
        private async Task <PaymentMethod> CreatePaymentMethodAsync(IPaymentMethodHandler handler, ISupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network, InvoiceEntity entity, StoreBlob storeBlob)
        {
            var rate = await storeBlob.ApplyRateRules(network, _RateProviders.GetRateProvider(network, false)).GetRateAsync(entity.ProductInformation.Currency);

            PaymentMethod paymentMethod = new PaymentMethod();

            paymentMethod.ParentEntity = entity;
            paymentMethod.Network      = network;
            paymentMethod.SetId(supportedPaymentMethod.PaymentId);
            paymentMethod.Rate = rate;
            var paymentDetails = await handler.CreatePaymentMethodDetails(supportedPaymentMethod, paymentMethod, network);

            if (storeBlob.NetworkFeeDisabled)
            {
                paymentDetails.SetNoTxFee();
            }
            paymentMethod.SetPaymentMethodDetails(paymentDetails);

            // Check if Lightning Max value is exceeded
            if (supportedPaymentMethod.PaymentId.PaymentType == PaymentTypes.LightningLike &&
                storeBlob.LightningMaxValue != null)
            {
                var lightningMaxValue     = storeBlob.LightningMaxValue;
                var lightningMaxValueRate = 0.0m;
                if (lightningMaxValue.Currency == entity.ProductInformation.Currency)
                {
                    lightningMaxValueRate = paymentMethod.Rate;
                }
                else
                {
                    lightningMaxValueRate = await storeBlob.ApplyRateRules(network, _RateProviders.GetRateProvider(network, false)).GetRateAsync(lightningMaxValue.Currency);
                }

                var lightningMaxValueCrypto = Money.Coins(lightningMaxValue.Value / lightningMaxValueRate);
                if (paymentMethod.Calculate().Due > lightningMaxValueCrypto)
                {
                    throw new PaymentMethodUnavailableException("Lightning max value exceeded");
                }
            }
            ///////////////


#pragma warning disable CS0618
            if (paymentMethod.GetId().IsBTCOnChain)
            {
                entity.TxFee          = paymentMethod.TxFee;
                entity.Rate           = paymentMethod.Rate;
                entity.DepositAddress = paymentMethod.DepositAddress;
            }
#pragma warning restore CS0618
            return(paymentMethod);
        }
Exemple #16
0
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob)
        {
            var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.BTCLike);

            var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network    = _networkProvider.GetNetwork <BTCPayNetwork>(model.CryptoCode);

            model.IsLightning       = false;
            model.PaymentMethodName = GetPaymentMethodName(network);


            var lightningFallback = "";

            if (storeBlob.OnChainWithLnInvoiceFallback)
            {
                var lightningInfo = invoiceResponse.CryptoInfo.FirstOrDefault(a =>
                                                                              a.GetpaymentMethodId() == new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike));
                if (!String.IsNullOrEmpty(lightningInfo?.PaymentUrls?.BOLT11))
                {
                    lightningFallback = "&" + lightningInfo.PaymentUrls.BOLT11.Replace("lightning:", "lightning=", StringComparison.OrdinalIgnoreCase);
                }
            }

            model.InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BIP21 + lightningFallback;
            // We're trying to make as many characters uppercase to make QR smaller
            // Ref: https://github.com/btcpayserver/btcpayserver/pull/2060#issuecomment-723828348
            model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21
                                        .Replace("bitcoin:", "BITCOIN:", StringComparison.OrdinalIgnoreCase)
                                        + lightningFallback.ToUpperInvariant().Replace("LIGHTNING=", "lightning=", StringComparison.OrdinalIgnoreCase);

            if (bech32Prefixes.Any(a => model.BtcAddress.StartsWith(a, StringComparison.OrdinalIgnoreCase)))
            {
                model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrlQR.Replace(
                    $"BITCOIN:{model.BtcAddress}", $"BITCOIN:{model.BtcAddress.ToUpperInvariant()}",
                    StringComparison.OrdinalIgnoreCase
                    );
            }
        }
 public override Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob, Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount,
                                                                          PaymentMethodId paymentMethodId)
 {
     return(Task.FromResult <string>(null));
 }
#pragma warning disable CS0618
        private static Money GetTxFee(StoreBlob storeBlob, FeeRate feeRate)
        {
            return(storeBlob.NetworkFeeDisabled ? Money.Zero : feeRate.GetFee(100));
        }
        public override async Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                                       Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId)
        {
            if (storeBlob.OnChainMinValue == null)
            {
                return(null);
            }

            var limitValueRate = await rate[new CurrencyPair(paymentMethodId.CryptoCode, storeBlob.OnChainMinValue.Currency)];

            if (limitValueRate.BidAsk != null)
            {
                var limitValueCrypto = Money.Coins(storeBlob.OnChainMinValue.Value / limitValueRate.BidAsk.Bid);

                if (amount < limitValueCrypto)
                {
                    return(null);
                }
            }
            return("The amount of the invoice is too high to be paid with lightning");
        }
Exemple #20
0
        public override async Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                                       Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId)
        {
            Func <Money, Money, bool> compare    = null;
            CurrencyValue             limitValue = null;
            string errorMessage = null;

            if (paymentMethodId.PaymentType == PaymentTypes.LightningLike &&
                storeBlob.LightningMaxValue != null)
            {
                compare      = (a, b) => a > b;
                limitValue   = storeBlob.LightningMaxValue;
                errorMessage = "The amount of the invoice is too high to be paid with lightning";
            }
            else if (paymentMethodId.PaymentType == PaymentTypes.BTCLike &&
                     storeBlob.OnChainMinValue != null)
            {
                compare      = (a, b) => a < b;
                limitValue   = storeBlob.OnChainMinValue;
                errorMessage = "The amount of the invoice is too low to be paid on chain";
            }

            if (compare != null)
            {
                var limitValueRate = await rate[new CurrencyPair(paymentMethodId.CryptoCode, storeBlob.OnChainMinValue.Currency)];
                if (limitValueRate.BidAsk != null)
                {
                    var limitValueCrypto = Money.Coins(limitValue.Value / limitValueRate.BidAsk.Bid);
                    if (compare(amount, limitValueCrypto))
                    {
                        return(errorMessage);
                    }
                }
            }
            return(string.Empty);
        }
        public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob)
        {
            var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentType);

            var client = _moneroRpcProvider.WalletRpcClients[model.CryptoCode];

            var cryptoInfo = invoiceResponse.CryptoInfo.First(o => o.GetpaymentMethodId() == paymentMethodId);
            var network    = _networkProvider.GetNetwork <MoneroLikeSpecificBtcPayNetwork>(model.CryptoCode);

            model.IsLightning       = false;
            model.PaymentMethodName = GetPaymentMethodName(network);
            model.CryptoImage       = GetCryptoImage(network);
            model.InvoiceBitcoinUrl = client.SendCommandAsync <MakeUriRequest, MakeUriResponse>("make_uri", new MakeUriRequest()
            {
                Address = cryptoInfo.Address,
                Amount  = LightMoney.Parse(cryptoInfo.Due).MilliSatoshi
            }).GetAwaiter()
                                      .GetResult().Uri;
            model.InvoiceBitcoinUrlQR = model.InvoiceBitcoinUrl;
        }
Exemple #22
0
        public override async Task <string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
                                                                                       Dictionary <CurrencyPair, Task <RateResult> > rate, Money amount, PaymentMethodId paymentMethodId)
        {
            Func <Money, Money, bool> compare    = null;
            CurrencyValue             limitValue = null;
            string errorMessage = null;

            if (storeBlob.LightningMaxValue != null)
            {
                compare      = (value, limit) => value > limit;
                limitValue   = storeBlob.LightningMaxValue;
                errorMessage = "The amount of the invoice is too high to be paid with lightning";
            }


            if (compare != null)
            {
                var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, limitValue.Currency)];

                if (currentRateToCrypto.BidAsk != null)
                {
                    var limitValueCrypto = Money.Coins(limitValue.Value / currentRateToCrypto.BidAsk.Bid);
                    if (compare(amount, limitValueCrypto))
                    {
                        return(errorMessage);
                    }
                }
            }

            return(string.Empty);
        }