From f419c56a3cb722b7068aca2b4977cfa15de6d88c Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 18 Oct 2018 12:27:46 +0900 Subject: [PATCH] Revert "Changelly Support (#267)" This reverts commit a5fca7a1c43c4d23ad1a825253fa1fe3ab26677c. --- BTCPayServer.Tests/ChangellyTests.cs | 292 ------------------ BTCPayServer/BTCPayServer.csproj | 1 - .../Controllers/ChangellyController.cs | 103 ------ .../Controllers/InvoiceController.UI.cs | 19 +- .../Controllers/StoresController.Changelly.cs | 98 ------ BTCPayServer/Controllers/StoresController.cs | 12 +- BTCPayServer/Data/StoreData.cs | 8 +- BTCPayServer/Hosting/BTCPayServerServices.cs | 3 - .../Models/InvoicingModels/PaymentModel.cs | 5 +- .../CheckoutExperienceViewModel.cs | 5 + .../Models/StoreViewModels/StoreViewModel.cs | 11 +- .../UpdateChangellySettingsViewModel.cs | 35 --- .../Changelly/ChangellyClientProvider.cs | 68 ---- .../Payments/Changelly/ChangellySettings.cs | 20 -- .../Payments/PaymentMethodExtensions.cs | 1 - .../Views/Invoice/Checkout-Body.cshtml | 41 +-- BTCPayServer/Views/Invoice/Checkout.cshtml | 129 ++++---- .../Views/Stores/CheckoutExperience.cshtml | 4 + .../Stores/UpdateChangellySettings.cshtml | 51 --- BTCPayServer/Views/Stores/UpdateStore.cshtml | 37 --- .../wwwroot/checkout/css/normalizer.css | 24 +- .../wwwroot/checkout/js/changellyComponent.js | 115 ------- BTCPayServer/wwwroot/checkout/js/core.js | 3 + 23 files changed, 99 insertions(+), 986 deletions(-) delete mode 100644 BTCPayServer.Tests/ChangellyTests.cs delete mode 100644 BTCPayServer/Controllers/ChangellyController.cs delete mode 100644 BTCPayServer/Controllers/StoresController.Changelly.cs delete mode 100644 BTCPayServer/Models/StoreViewModels/UpdateChangellySettingsViewModel.cs delete mode 100644 BTCPayServer/Payments/Changelly/ChangellyClientProvider.cs delete mode 100644 BTCPayServer/Payments/Changelly/ChangellySettings.cs delete mode 100644 BTCPayServer/Views/Stores/UpdateChangellySettings.cshtml delete mode 100644 BTCPayServer/wwwroot/checkout/js/changellyComponent.js diff --git a/BTCPayServer.Tests/ChangellyTests.cs b/BTCPayServer.Tests/ChangellyTests.cs deleted file mode 100644 index 9ffc38f76..000000000 --- a/BTCPayServer.Tests/ChangellyTests.cs +++ /dev/null @@ -1,292 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using BTCPayServer.Controllers; -using BTCPayServer.Models; -using BTCPayServer.Models.StoreViewModels; -using BTCPayServer.Payments.Changelly; -using BTCPayServer.Services.Stores; -using BTCPayServer.Tests.Logging; -using Changelly.ResponseModel; -using Microsoft.AspNetCore.Mvc; -using Xunit; -using Xunit.Abstractions; - -namespace BTCPayServer.Tests -{ - public class ChangellyTests - { - public ChangellyTests(ITestOutputHelper helper) - { - Logs.Tester = new XUnitLog(helper) {Name = "Tests"}; - Logs.LogProvider = new XUnitLogProvider(helper); - } - - [Fact] - public async void CanSetChangellyPaymentMethod() - { - using (var tester = ServerTester.Create()) - { - tester.Start(); - var user = tester.NewAccount(); - user.GrantAccess(); - var controller = tester.PayTester.GetController(user.UserId, user.StoreId); - - - var storeBlob = controller.StoreData.GetStoreBlob(); - Assert.Null(storeBlob.ChangellySettings); - - var updateModel = new UpdateChangellySettingsViewModel() - { - ApiSecret = "secret", - ApiKey = "key", - ApiUrl = "url", - ChangellyMerchantId = "aaa", - }; - - Assert.Equal("UpdateStore", Assert.IsType( - await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); - storeBlob = controller.StoreData.GetStoreBlob(); - Assert.NotNull(storeBlob.ChangellySettings); - Assert.NotNull(storeBlob.ChangellySettings); - Assert.IsType(storeBlob.ChangellySettings); - Assert.Equal(storeBlob.ChangellySettings.ApiKey, updateModel.ApiKey); - Assert.Equal(storeBlob.ChangellySettings.ApiSecret, - updateModel.ApiSecret); - Assert.Equal(storeBlob.ChangellySettings.ApiUrl, updateModel.ApiUrl); - Assert.Equal(storeBlob.ChangellySettings.ChangellyMerchantId, - updateModel.ChangellyMerchantId); - } - } - - - [Fact] - public async void CanToggleChangellyPaymentMethod() - { - using (var tester = ServerTester.Create()) - { - tester.Start(); - var user = tester.NewAccount(); - user.GrantAccess(); - var controller = tester.PayTester.GetController(user.UserId, user.StoreId); - - var updateModel = new UpdateChangellySettingsViewModel() - { - ApiSecret = "secret", - ApiKey = "key", - ApiUrl = "url", - ChangellyMerchantId = "aaa", - }; - Assert.Equal("UpdateStore", Assert.IsType( - await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - - var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); - - Assert.True(store.GetStoreBlob().ChangellySettings.Enabled); - - updateModel.Enabled = false; - - Assert.Equal("UpdateStore", Assert.IsType( - await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - store = await tester.PayTester.StoreRepository.FindStore(user.StoreId); - - Assert.False(store.GetStoreBlob().ChangellySettings.Enabled); - } - } - - [Fact] - public async void CannotUseChangellyApiWithoutChangellyPaymentMethodSet() - { - using (var tester = ServerTester.Create()) - { - tester.Start(); - var user = tester.NewAccount(); - user.GrantAccess(); - var changellyController = - tester.PayTester.GetController(user.UserId, user.StoreId); - - //test non existing payment method - Assert.IsType(Assert - .IsType(await changellyController.GetCurrencyList(user.StoreId)) - .Value); - - var updateModel = new UpdateChangellySettingsViewModel() - { - ApiSecret = "secret", - ApiKey = "key", - ApiUrl = "url", - ChangellyMerchantId = "aaa", - Enabled = false - }; - var storesController = tester.PayTester.GetController(user.UserId, user.StoreId); - //set payment method but disabled - - - Assert.Equal("UpdateStore", Assert.IsType( - await storesController.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - - Assert.IsType(Assert - .IsType(await changellyController.GetCurrencyList(user.StoreId)) - .Value); - - updateModel.Enabled = true; - //test with enabled method - - Assert.Equal("UpdateStore", Assert.IsType( - await storesController.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - Assert.IsNotType(Assert - .IsType(await changellyController.GetCurrencyList(user.StoreId)) - .Value); - } - } - - [Fact] - public async void CanGetCurrencyListFromChangelly() - { - using (var tester = ServerTester.Create()) - { - tester.Start(); - var user = tester.NewAccount(); - user.GrantAccess(); - - var updateModel = new UpdateChangellySettingsViewModel() - { - ApiSecret = "secret", - ApiKey = "key", - ApiUrl = "url", - ChangellyMerchantId = "aaa" - }; - var storesController = tester.PayTester.GetController(user.UserId, user.StoreId); - - - Assert.Equal("UpdateStore", Assert.IsType( - await storesController.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - - var mock = new MockChangellyClientProvider(tester.PayTester.StoreRepository, tester.NetworkProvider); - var changellyController = new ChangellyController(mock); - - mock.GetCurrenciesFullResult = (new List() - { - new CurrencyFull() - { - Name = "a", - Enable = true, - PayInConfirmations = 10, - FullName = "aa", - ImageLink = "" - } - }, true, ""); - var result = ((IList currency, bool Success, string Error))Assert - .IsType(await changellyController.GetCurrencyList(user.StoreId)).Value; - Assert.Equal(1, mock.GetCurrenciesFullCallCount); - Assert.Equal(mock.GetCurrenciesFullResult.currency.Count, result.currency.Count); - - mock.GetCurrenciesFullResult = (new List() - { - new CurrencyFull() - { - Name = "a", - Enable = true, - PayInConfirmations = 10, - FullName = "aa", - ImageLink = "" - } - }, false, ""); - Assert - .IsType(await changellyController.GetCurrencyList(user.StoreId)); - Assert.Equal(2, mock.GetCurrenciesFullCallCount); - } - } - - - [Fact] - public async void CanCalculateToAmountForChangelly() - { - using (var tester = ServerTester.Create()) - { - tester.Start(); - var user = tester.NewAccount(); - user.GrantAccess(); - - var updateModel = new UpdateChangellySettingsViewModel() - { - ApiSecret = "secret", - ApiKey = "key", - ApiUrl = "url", - ChangellyMerchantId = "aaa" - }; - var storesController = tester.PayTester.GetController(user.UserId, user.StoreId); - - Assert.Equal("UpdateStore", Assert.IsType( - await storesController.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName); - - var mock = new MockChangellyClientProvider(tester.PayTester.StoreRepository, tester.NetworkProvider); - var changellyController = new ChangellyController(mock); - - mock.GetExchangeAmountResult = (from, to, amount) => - { - Assert.Equal("A", from); - Assert.Equal("B", to); - - switch (mock.GetExchangeAmountCallCount) - { - case 1: - return (0.5, true, null); - break; - default: - return (1.01, true, null); - break; - } - }; - - Assert.IsType(Assert - .IsType(changellyController.CalculateAmount(user.StoreId, "A", "B", 1.0)).Value); - Assert.True(mock.GetExchangeAmountCallCount > 1); - } - } - } - - public class MockChangellyClientProvider : ChangellyClientProvider - { - public MockChangellyClientProvider( - StoreRepository storeRepository, - BTCPayNetworkProvider btcPayNetworkProvider) : base(storeRepository, btcPayNetworkProvider) - { - } - - public (IList currency, bool Success, string Error) GetCurrenciesFullResult { get; set; } - - public delegate TResult ParamsFunc(T1 arg1, T2 arg2, T3 arg3); - - public ParamsFunc GetExchangeAmountResult - { - get; - set; - } - - public int GetCurrenciesFullCallCount { get; set; } = 0; - public int GetExchangeAmountCallCount { get; set; } = 0; - - public override (IList currency, bool Success, string Error) GetCurrenciesFull( - Changelly.Changelly client) - { - GetCurrenciesFullCallCount++; - return GetCurrenciesFullResult; - } - - public override (double amount, bool Success, string Error) GetExchangeAmount(Changelly.Changelly client, - string fromCurrency, string toCurrency, - double amount) - { - GetExchangeAmountCallCount++; - return GetExchangeAmountResult.Invoke(fromCurrency, toCurrency, amount); - } - } -} diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 581532a83..3cc8fdc53 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -35,7 +35,6 @@ - diff --git a/BTCPayServer/Controllers/ChangellyController.cs b/BTCPayServer/Controllers/ChangellyController.cs deleted file mode 100644 index 05e6c74f6..000000000 --- a/BTCPayServer/Controllers/ChangellyController.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using BTCPayServer.Models; -using BTCPayServer.Payments.Changelly; -using Changelly.ResponseModel; -using Microsoft.AspNetCore.Mvc; - -namespace BTCPayServer.Controllers -{ - [Route("[controller]/{storeId}")] - public class ChangellyController : Controller - { - private readonly ChangellyClientProvider _changellyClientProvider; - - public ChangellyController(ChangellyClientProvider changellyClientProvider) - { - _changellyClientProvider = changellyClientProvider; - } - - [HttpGet] - [Route("currencies")] - public async Task GetCurrencyList(string storeId) - { - if (!TryGetChangellyClient(storeId, out var actionResult, out var client)) - { - return actionResult; - } - - var result = _changellyClientProvider.GetCurrenciesFull(client); - if (result.Success) - { - return Ok(result); - } - - return BadRequest(result); - } - - [HttpGet] - [Route("calculate")] - public IActionResult CalculateAmount(string storeId, string fromCurrency, string toCurrency, - double toCurrencyAmount) - { - if (!TryGetChangellyClient(storeId, out var actionResult, out var client)) - { - return actionResult; - } - - double? currentAmount = null; - var callCounter = 0; - - var response1 = _changellyClientProvider.GetExchangeAmount(client,fromCurrency, toCurrency, 1); - if (!response1.Success) return BadRequest(response1); - currentAmount = response1.amount; - - while (true) - { - if (callCounter > 10) - { - BadRequest(); - } - - //Client needs to be reset between same calls for some reason - if (!TryGetChangellyClient(storeId, out actionResult, out client)) - { - return actionResult; - } - - var response2 = _changellyClientProvider.GetExchangeAmount(client,fromCurrency, toCurrency, currentAmount.Value); - callCounter++; - if (!response2.Success) return BadRequest(response2); - if (response2.amount < toCurrencyAmount) - { - var newCurrentAmount = ((toCurrencyAmount / response2.amount) * 1) * currentAmount.Value; - currentAmount = newCurrentAmount; - } - else - { - return Ok(currentAmount.Value); - } - } - } - - private bool TryGetChangellyClient(string storeId, out IActionResult actionResult, - out Changelly.Changelly changelly) - { - changelly = null; - actionResult = null; - storeId = storeId ?? HttpContext.GetStoreData()?.Id; - - if (!_changellyClientProvider.TryGetChangellyClient(storeId, out var error, out changelly)) - { - actionResult = BadRequest(new BitpayErrorModel() - { - Error = error - }); - return false; - } - - return true; - } - } -} diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index aa266603e..1987b5ea0 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -10,7 +10,6 @@ using BTCPayServer.Events; using BTCPayServer.Filters; using BTCPayServer.Models.InvoicingModels; using BTCPayServer.Payments; -using BTCPayServer.Payments.Changelly; using BTCPayServer.Payments.Lightning; using BTCPayServer.Security; using BTCPayServer.Services.Invoices; @@ -214,6 +213,7 @@ namespace BTCPayServer.Controllers paymentMethodIdStr = store.GetDefaultCrypto(_NetworkProvider); isDefaultCrypto = true; } + var paymentMethodId = PaymentMethodId.Parse(paymentMethodIdStr); var network = _NetworkProvider.GetNetwork(paymentMethodId.CryptoCode); if (network == null && isDefaultCrypto) @@ -245,18 +245,6 @@ namespace BTCPayServer.Controllers var storeBlob = store.GetStoreBlob(); var currency = invoice.ProductInformation.Currency; var accounting = paymentMethod.Calculate(); - - ChangellySettings changelly = (storeBlob.ChangellySettings != null && storeBlob.ChangellySettings.Enabled && - storeBlob.ChangellySettings.IsConfigured()) - ? storeBlob.ChangellySettings - : null; - - - var changellyAmountDue = changelly != null - ? (accounting.Due.ToDecimal(MoneyUnit.BTC) * - (1m + (changelly.AmountMarkupPercentage / 100m))) - : (decimal?)null; - var model = new PaymentModel() { CryptoCode = network.CryptoCode, @@ -296,10 +284,7 @@ namespace BTCPayServer.Controllers Status = invoice.Status, NetworkFee = paymentMethodDetails.GetTxFee(), IsMultiCurrency = invoice.GetPayments().Select(p => p.GetPaymentMethodId()).Concat(new[] { paymentMethod.GetId() }).Distinct().Count() > 1, - ChangellyEnabled = changelly != null, - ChangellyMerchantId = changelly?.ChangellyMerchantId, - ChangellyAmountDue = changellyAmountDue, - StoreId = store.Id, + AllowCoinConversion = storeBlob.AllowCoinConversion, AvailableCryptos = invoice.GetPaymentMethods(_NetworkProvider) .Where(i => i.Network != null) .Select(kv => new PaymentModel.AvailableCrypto() diff --git a/BTCPayServer/Controllers/StoresController.Changelly.cs b/BTCPayServer/Controllers/StoresController.Changelly.cs deleted file mode 100644 index 0b234d1d1..000000000 --- a/BTCPayServer/Controllers/StoresController.Changelly.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using BTCPayServer.Data; -using BTCPayServer.Models.StoreViewModels; -using BTCPayServer.Payments.Changelly; -using Microsoft.AspNetCore.Mvc; - -namespace BTCPayServer.Controllers -{ - public partial class StoresController - { - [HttpGet] - [Route("{storeId}/changelly")] - public IActionResult UpdateChangellySettings(string storeId) - { - var store = HttpContext.GetStoreData(); - if (store == null) - return NotFound(); - UpdateChangellySettingsViewModel vm = new UpdateChangellySettingsViewModel(); - SetExistingValues(store, vm); - return View(vm); - } - - private void SetExistingValues(StoreData store, UpdateChangellySettingsViewModel vm) - { - - var existing = store.GetStoreBlob().ChangellySettings; - if (existing == null) return; - vm.ApiKey = existing.ApiKey; - vm.ApiSecret = existing.ApiSecret; - vm.ApiUrl = existing.ApiUrl; - vm.ChangellyMerchantId = existing.ChangellyMerchantId; - vm.Enabled = existing.Enabled; - vm.AmountMarkupPercentage = existing.AmountMarkupPercentage; - - } - - [HttpPost] - [Route("{storeId}/changelly")] - public async Task UpdateChangellySettings(string storeId, UpdateChangellySettingsViewModel vm, - string command) - { - var store = HttpContext.GetStoreData(); - if (store == null) - return NotFound(); - if (vm.Enabled) - { - if (!ModelState.IsValid) - { - return View(vm); - } - } - - var changellySettings = new ChangellySettings() - { - ApiKey = vm.ApiKey, - ApiSecret = vm.ApiSecret, - ApiUrl = vm.ApiUrl, - ChangellyMerchantId = vm.ChangellyMerchantId, - Enabled = vm.Enabled, - AmountMarkupPercentage = vm.AmountMarkupPercentage - }; - - switch (command) - { - case "save": - var storeBlob = store.GetStoreBlob(); - storeBlob.ChangellySettings = changellySettings; - store.SetStoreBlob(storeBlob); - await _Repo.UpdateStore(store); - StatusMessage = "Changelly settings modified"; - return RedirectToAction(nameof(UpdateStore), new { - storeId}); - case "test": - try - { - var client = new Changelly.Changelly(changellySettings.ApiKey, changellySettings.ApiSecret, - changellySettings.ApiUrl); - var result = client.GetCurrenciesFull(); - vm.StatusMessage = !result.Success - ? $"Error: {result.Error}" - : "Test Successful"; - return View(vm); - } - catch (Exception ex) - { - vm.StatusMessage = $"Error: {ex.Message}"; - return View(vm); - } - - break; - default: - return View(vm); - } - } - } -} diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 0fe7515e3..a50ad4b21 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -9,7 +9,6 @@ using BTCPayServer.Data; using BTCPayServer.Models; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.StoreViewModels; -using BTCPayServer.Payments.Changelly; using BTCPayServer.Rating; using BTCPayServer.Security; using BTCPayServer.Services; @@ -319,6 +318,7 @@ namespace BTCPayServer.Controllers vm.SetLanguages(_LangService, storeBlob.DefaultLang); vm.LightningMaxValue = storeBlob.LightningMaxValue?.ToString() ?? ""; vm.OnChainMinValue = storeBlob.OnChainMinValue?.ToString() ?? ""; + vm.AllowCoinConversion = storeBlob.AllowCoinConversion; vm.RequiresRefundEmail = storeBlob.RequiresRefundEmail; vm.CustomCSS = storeBlob.CustomCSS?.AbsoluteUri; vm.CustomLogo = storeBlob.CustomLogo?.AbsoluteUri; @@ -362,6 +362,7 @@ namespace BTCPayServer.Controllers return View(model); } blob.DefaultLang = model.DefaultLang; + blob.AllowCoinConversion = model.AllowCoinConversion; blob.RequiresRefundEmail = model.RequiresRefundEmail; blob.LightningMaxValue = lightningMaxValue; blob.OnChainMinValue = onchainMinValue; @@ -446,15 +447,6 @@ namespace BTCPayServer.Controllers 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" - }); } [HttpPost] diff --git a/BTCPayServer/Data/StoreData.cs b/BTCPayServer/Data/StoreData.cs index ab2955047..19fcdfc25 100644 --- a/BTCPayServer/Data/StoreData.cs +++ b/BTCPayServer/Data/StoreData.cs @@ -17,7 +17,6 @@ using BTCPayServer.JsonConverters; using System.ComponentModel.DataAnnotations; using BTCPayServer.Services; using System.Security.Claims; -using BTCPayServer.Payments.Changelly; using BTCPayServer.Security; using BTCPayServer.Rating; @@ -262,6 +261,11 @@ namespace BTCPayServer.Data { get; set; } + public bool AllowCoinConversion + { + get; set; + } + public bool RequiresRefundEmail { get; set; } public string DefaultLang { get; set; } @@ -303,8 +307,6 @@ namespace BTCPayServer.Data public string RateScript { get; set; } public bool AnyoneCanInvoice { get; set; } - - public ChangellySettings ChangellySettings { get; set; } string _LightningDescriptionTemplate; diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index ba0294710..80569bec4 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -38,7 +38,6 @@ using BTCPayServer.Logging; using BTCPayServer.HostedServices; using Meziantou.AspNetCore.BundleTagHelpers; using System.Security.Claims; -using BTCPayServer.Payments.Changelly; using BTCPayServer.Security; using Microsoft.AspNetCore.Mvc.ModelBinding; using NBXplorer.DerivationStrategy; @@ -126,8 +125,6 @@ namespace BTCPayServer.Hosting services.AddSingleton, Payments.Lightning.LightningLikePaymentHandler>(); services.AddSingleton(); - - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index 8f1dffeaa..78a13d50b 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -55,10 +55,7 @@ namespace BTCPayServer.Models.InvoicingModels public string PaymentMethodName { get; set; } public string CryptoImage { get; set; } - public bool ChangellyEnabled { get; set; } - public string StoreId { get; set; } + public bool AllowCoinConversion { get; set; } public string PeerInfo { get; set; } - public string ChangellyMerchantId { get; set; } - public decimal? ChangellyAmountDue { get; set; } } } diff --git a/BTCPayServer/Models/StoreViewModels/CheckoutExperienceViewModel.cs b/BTCPayServer/Models/StoreViewModels/CheckoutExperienceViewModel.cs index a77cccd0c..ae5176ffd 100644 --- a/BTCPayServer/Models/StoreViewModels/CheckoutExperienceViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/CheckoutExperienceViewModel.cs @@ -23,6 +23,11 @@ namespace BTCPayServer.Models.StoreViewModels public string DefaultCryptoCurrency { get; set; } [Display(Name = "Default language on checkout")] public string DefaultLang { get; set; } + [Display(Name = "Allow conversion through third party (Shapeshift, Changelly...)")] + public bool AllowCoinConversion + { + get; set; + } [Display(Name = "Do not propose lightning payment if value of the invoice is above...")] [MaxLength(20)] public string LightningMaxValue { get; set; } diff --git a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs index 6c899bf6d..9401bb957 100644 --- a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs @@ -21,13 +21,7 @@ namespace BTCPayServer.Models.StoreViewModels public WalletId WalletId { get; set; } public bool Enabled { get; set; } } - - public class ThirdPartyPaymentMethod - { - public string Provider { get; set; } - public bool Enabled { get; set; } - public string Action { get; set; } - } + public StoreViewModel() { @@ -58,9 +52,6 @@ namespace BTCPayServer.Models.StoreViewModels public List DerivationSchemes { get; set; } = new List(); - public List ThirdPartyPaymentMethods { get; set; } = - new List(); - [Display(Name = "Invoice expires if the full amount has not been paid after ... minutes")] [Range(1, 60 * 24 * 24)] public int InvoiceExpiration diff --git a/BTCPayServer/Models/StoreViewModels/UpdateChangellySettingsViewModel.cs b/BTCPayServer/Models/StoreViewModels/UpdateChangellySettingsViewModel.cs deleted file mode 100644 index 62c468a45..000000000 --- a/BTCPayServer/Models/StoreViewModels/UpdateChangellySettingsViewModel.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Runtime.InteropServices; -using BTCPayServer.Payments; -using Microsoft.AspNetCore.Mvc.Rendering; - -namespace BTCPayServer.Models.StoreViewModels -{ - public class UpdateChangellySettingsViewModel - { - [Required] - public string ApiKey { get; set; } - - [Required] - public string ApiSecret { get; set; } - - [Required] - public string ApiUrl { get; set; } = "https://api.changelly.com"; - - [Display(Name="Optional, Changelly Merchant Id")] - public string ChangellyMerchantId { get; set; } = "804298eb5753"; - - public bool Enabled { get; set; } = true; - - public string StatusMessage { get; set; } - - [Required] - [Range(0, 100)] - [Display(Name = "Percentage to multiply amount requested at Changelly to avoid underpaid situations due to Changelly not guaranteeing rates. ")] - public decimal AmountMarkupPercentage { get; set; } = new decimal(2); - - - - } -} diff --git a/BTCPayServer/Payments/Changelly/ChangellyClientProvider.cs b/BTCPayServer/Payments/Changelly/ChangellyClientProvider.cs deleted file mode 100644 index 0233e1940..000000000 --- a/BTCPayServer/Payments/Changelly/ChangellyClientProvider.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using BTCPayServer.Services.Stores; -using Changelly.ResponseModel; - -namespace BTCPayServer.Payments.Changelly -{ - public class ChangellyClientProvider - { - private readonly StoreRepository _storeRepository; - private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - - - public ChangellyClientProvider(StoreRepository storeRepository, BTCPayNetworkProvider btcPayNetworkProvider) - { - _storeRepository = storeRepository; - _btcPayNetworkProvider = btcPayNetworkProvider; - } - - - public virtual bool TryGetChangellyClient(string storeId, out string error, - out global::Changelly.Changelly changelly) - { - changelly = null; - - - var store = _storeRepository.FindStore(storeId).Result; - if (store == null) - { - error = "Store not found"; - return false; - } - - var blob = store.GetStoreBlob(); - var changellySettings = blob.ChangellySettings; - - - if (changellySettings == null || !changellySettings.IsConfigured()) - { - error = "Changelly not configured for this store"; - return false; - } - - if (!changellySettings.Enabled) - { - error = "Changelly not enabled for this store"; - return false; - } - - changelly = new global::Changelly.Changelly(changellySettings.ApiKey, changellySettings.ApiSecret, - changellySettings.ApiUrl); - error = null; - return true; - } - - public virtual (IList currency, bool Success, string Error) GetCurrenciesFull(global::Changelly.Changelly client) - { - return client.GetCurrenciesFull(); - } - - public virtual (double amount, bool Success, string Error) GetExchangeAmount(global::Changelly.Changelly client, string fromCurrency, string toCurrency, - double amount) - { - - return client.GetExchangeAmount(fromCurrency, toCurrency, amount); - } - } -} diff --git a/BTCPayServer/Payments/Changelly/ChangellySettings.cs b/BTCPayServer/Payments/Changelly/ChangellySettings.cs deleted file mode 100644 index 784852a49..000000000 --- a/BTCPayServer/Payments/Changelly/ChangellySettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace BTCPayServer.Payments.Changelly -{ - public class ChangellySettings - { - public string ApiKey { get; set; } - public string ApiSecret { get; set; } - public string ApiUrl { get; set; } - public bool Enabled { get; set; } - public string ChangellyMerchantId { get; set; } - public decimal AmountMarkupPercentage { get; set; } - - public bool IsConfigured() - { - return - !string.IsNullOrEmpty(ApiKey) || - !string.IsNullOrEmpty(ApiSecret) || - !string.IsNullOrEmpty(ApiUrl); - } - } -} diff --git a/BTCPayServer/Payments/PaymentMethodExtensions.cs b/BTCPayServer/Payments/PaymentMethodExtensions.cs index b63fe4364..af1f45e81 100644 --- a/BTCPayServer/Payments/PaymentMethodExtensions.cs +++ b/BTCPayServer/Payments/PaymentMethodExtensions.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using BTCPayServer.Payments.Changelly; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml index fb28f7a15..308b0e8fb 100644 --- a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml @@ -148,7 +148,7 @@
{{$t("Copy")}}
- @if (Model.ChangellyEnabled) + @if (Model.AllowCoinConversion) {
{{$t("Conversion")}} @@ -253,7 +253,7 @@
- @if (Model.ChangellyEnabled) + @if (Model.AllowCoinConversion) {
-
- -
-
- -
- - Changelly - -
- -
-
-
+
+ + + + + + @*Changelly doesn't have TO_AMOUNT support so we can't include it + + + Changelly + *@
diff --git a/BTCPayServer/Views/Invoice/Checkout.cshtml b/BTCPayServer/Views/Invoice/Checkout.cshtml index c5f86fdba..1a4bbd190 100644 --- a/BTCPayServer/Views/Invoice/Checkout.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout.cshtml @@ -53,53 +53,49 @@
- -
-