From ed1ec2300df3c6d284b8e1d7b01b547a458c2bf8 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 28 Sep 2021 10:33:11 +0200 Subject: [PATCH] Remove Coinswitch entirely --- .../GreenField/StoresController.cs | 2 - .../Controllers/InvoiceController.UI.cs | 1 - BTCPayServer/Data/StoreBlob.cs | 1 - .../CoinSwitch/CoinSwitchController.cs | 84 ----------------- .../CoinSwitch/CoinSwitchExtensions.cs | 32 ------- .../Plugins/CoinSwitch/CoinSwitchPlugin.cs | 34 ------- .../Plugins/CoinSwitch/CoinSwitchService.cs | 36 ------- .../Plugins/CoinSwitch/CoinswitchSettings.cs | 16 ---- .../UpdateCoinSwitchSettingsViewModel.cs | 27 ------ .../UpdateCoinSwitchSettings.cshtml | 49 ---------- .../CheckoutContentExtension.cshtml | 41 -------- .../Shared/CoinSwitch/CheckoutEnd.cshtml | 1 - .../CoinSwitch/CheckoutTabExtension.cshtml | 12 --- .../StoreIntegrationCoinSwitchOption.cshtml | 39 -------- .../EthereumLikeMethodCheckout.cshtml | 5 - BTCPayServer/wwwroot/checkout/coinswitch.html | 93 ------------------- .../checkout/js/coinswitchComponent.js | 66 ------------- 17 files changed, 539 deletions(-) delete mode 100644 BTCPayServer/Plugins/CoinSwitch/CoinSwitchController.cs delete mode 100644 BTCPayServer/Plugins/CoinSwitch/CoinSwitchExtensions.cs delete mode 100644 BTCPayServer/Plugins/CoinSwitch/CoinSwitchPlugin.cs delete mode 100644 BTCPayServer/Plugins/CoinSwitch/CoinSwitchService.cs delete mode 100644 BTCPayServer/Plugins/CoinSwitch/CoinswitchSettings.cs delete mode 100644 BTCPayServer/Plugins/CoinSwitch/UpdateCoinSwitchSettingsViewModel.cs delete mode 100644 BTCPayServer/Views/CoinSwitch/UpdateCoinSwitchSettings.cshtml delete mode 100644 BTCPayServer/Views/Shared/CoinSwitch/CheckoutContentExtension.cshtml delete mode 100644 BTCPayServer/Views/Shared/CoinSwitch/CheckoutEnd.cshtml delete mode 100644 BTCPayServer/Views/Shared/CoinSwitch/CheckoutTabExtension.cshtml delete mode 100644 BTCPayServer/Views/Shared/CoinSwitch/StoreIntegrationCoinSwitchOption.cshtml delete mode 100644 BTCPayServer/wwwroot/checkout/coinswitch.html delete mode 100644 BTCPayServer/wwwroot/checkout/js/coinswitchComponent.js diff --git a/BTCPayServer/Controllers/GreenField/StoresController.cs b/BTCPayServer/Controllers/GreenField/StoresController.cs index 2e85688b5..4078bbecd 100644 --- a/BTCPayServer/Controllers/GreenField/StoresController.cs +++ b/BTCPayServer/Controllers/GreenField/StoresController.cs @@ -122,7 +122,6 @@ namespace BTCPayServer.Controllers.GreenField DefaultPaymentMethod = data.GetDefaultPaymentId(_btcPayNetworkProvider)?.ToStringNormalized(), //blob //we do not include DefaultCurrencyPairs,Spread, PreferredExchange, RateScripting, RateScript in this model and instead opt to set it in stores/storeid/rates endpoints - //we do not include CoinSwitchSettings in this model and instead opt to set it in stores/storeid/coinswitch endpoints //we do not include ExcludedPaymentMethods in this model and instead opt to set it in stores/storeid/payment-methods endpoints //we do not include EmailSettings in this model and instead opt to set it in stores/storeid/email endpoints //we do not include PaymentMethodCriteria because moving the CurrencyValueJsonConverter to the Client csproj is hard and requires a refactor (#1571 & #1572) @@ -160,7 +159,6 @@ namespace BTCPayServer.Controllers.GreenField //we do not include the default payment method in this model and instead opt to set it in the stores/storeid/payment-methods endpoints //blob //we do not include DefaultCurrencyPairs;Spread; PreferredExchange; RateScripting; RateScript in this model and instead opt to set it in stores/storeid/rates endpoints - //we do not include CoinSwitchSettings in this model and instead opt to set it in stores/storeid/coinswitch endpoints //we do not include ExcludedPaymentMethods in this model and instead opt to set it in stores/storeid/payment-methods endpoints //we do not include EmailSettings in this model and instead opt to set it in stores/storeid/email endpoints //we do not include OnChainMinValue and LightningMaxValue because moving the CurrencyValueJsonConverter to the Client csproj is hard and requires a refactor (#1571 & #1572) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 45ea48083..ac6b152d5 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -21,7 +21,6 @@ using BTCPayServer.Models; using BTCPayServer.Models.InvoicingModels; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; -using BTCPayServer.Plugins.CoinSwitch; using BTCPayServer.Rating; using BTCPayServer.Security; using BTCPayServer.Services.Invoices; diff --git a/BTCPayServer/Data/StoreBlob.cs b/BTCPayServer/Data/StoreBlob.cs index 12e4f81ec..ca2ffca52 100644 --- a/BTCPayServer/Data/StoreBlob.cs +++ b/BTCPayServer/Data/StoreBlob.cs @@ -7,7 +7,6 @@ using BTCPayServer.Client.JsonConverters; using BTCPayServer.Client.Models; using BTCPayServer.JsonConverters; using BTCPayServer.Payments; -using BTCPayServer.Plugins.CoinSwitch; using BTCPayServer.Rating; using BTCPayServer.Services.Mails; using BTCPayServer.Services.Rates; diff --git a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchController.cs b/BTCPayServer/Plugins/CoinSwitch/CoinSwitchController.cs deleted file mode 100644 index 08fdb2ba4..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchController.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Constants; -using BTCPayServer.Client; -using BTCPayServer.Data; -using BTCPayServer.Models.StoreViewModels; -using BTCPayServer.Services.Stores; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BTCPayServer.Plugins.CoinSwitch -{ - [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] - [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] - [Route("plugins/{storeId}/coinswitch")] - public class CoinSwitchController : Controller - { - private readonly StoreRepository _storeRepository; - - public CoinSwitchController(StoreRepository storeRepository) - { - _storeRepository = storeRepository; - } - - [HttpGet("")] - public IActionResult UpdateCoinSwitchSettings(string storeId) - { - var store = HttpContext.GetStoreData(); - if (store == null) - return NotFound(); - UpdateCoinSwitchSettingsViewModel vm = new UpdateCoinSwitchSettingsViewModel(); - SetExistingValues(store, vm); - return View(vm); - } - - private void SetExistingValues(StoreData store, UpdateCoinSwitchSettingsViewModel vm) - { - var existing = store.GetStoreBlob().GetCoinSwitchSettings(); - if (existing == null) - return; - vm.MerchantId = existing.MerchantId; - vm.Enabled = existing.Enabled; - vm.Mode = existing.Mode; - vm.AmountMarkupPercentage = existing.AmountMarkupPercentage; - } - - [HttpPost("")] - public async Task UpdateCoinSwitchSettings(string storeId, UpdateCoinSwitchSettingsViewModel vm, - string command) - { - var store = HttpContext.GetStoreData(); - if (store == null) - return NotFound(); - if (vm.Enabled) - { - if (!ModelState.IsValid) - { - return View(vm); - } - } - - var coinSwitchSettings = new CoinSwitchSettings() - { - MerchantId = vm.MerchantId, - Enabled = vm.Enabled, - Mode = vm.Mode, - AmountMarkupPercentage = vm.AmountMarkupPercentage - }; - - switch (command) - { - case "save": - var storeBlob = store.GetStoreBlob(); - storeBlob.SetCoinSwitchSettings(coinSwitchSettings); - store.SetStoreBlob(storeBlob); - await _storeRepository.UpdateStore(store); - TempData[WellKnownTempData.SuccessMessage] = "CoinSwitch settings modified"; - return RedirectToAction(nameof(UpdateCoinSwitchSettings), new {storeId}); - - default: - return View(vm); - } - } - } -} diff --git a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchExtensions.cs b/BTCPayServer/Plugins/CoinSwitch/CoinSwitchExtensions.cs deleted file mode 100644 index dd146f891..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using BTCPayServer.Data; -using NBitcoin; -using NBXplorer; -using Newtonsoft.Json.Linq; - -namespace BTCPayServer.Plugins.CoinSwitch -{ - public static class CoinSwitchExtensions - { - public const string StoreBlobKey = "coinSwitchSettings"; - public static CoinSwitchSettings GetCoinSwitchSettings(this StoreBlob storeBlob) - { - if (storeBlob.AdditionalData.TryGetValue(StoreBlobKey, out var rawS) && rawS is JObject rawObj) - { - return new Serializer(null).ToObject(rawObj); - } - - return null; - } - public static void SetCoinSwitchSettings(this StoreBlob storeBlob, CoinSwitchSettings settings) - { - if (settings is null) - { - storeBlob.AdditionalData.Remove(StoreBlobKey); - } - else - { - storeBlob.AdditionalData.AddOrReplace(StoreBlobKey, JObject.FromObject(settings)); - } - } - } -} diff --git a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchPlugin.cs b/BTCPayServer/Plugins/CoinSwitch/CoinSwitchPlugin.cs deleted file mode 100644 index c60f284c5..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchPlugin.cs +++ /dev/null @@ -1,34 +0,0 @@ -using BTCPayServer.Abstractions.Contracts; -using BTCPayServer.Abstractions.Models; -using BTCPayServer.Abstractions.Services; -using Microsoft.Extensions.DependencyInjection; - -namespace BTCPayServer.Plugins.CoinSwitch -{ - public class CoinSwitchPlugin : BaseBTCPayServerPlugin - { - public override string Identifier => "BTCPayServer.Plugins.CoinSwitch"; - public override string Name => "CoinSwitch"; - - public override string Description => - "Allows you to embed a coinswitch conversion screen to allow customers to pay with altcoins."; - - public override void Execute(IServiceCollection applicationBuilder) - { - applicationBuilder.AddSingleton(); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/StoreIntegrationCoinSwitchOption", - "store-integrations-list")); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/CheckoutContentExtension", - "checkout-bitcoin-post-content")); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/CheckoutContentExtension", - "checkout-ethereum-post-content")); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/CheckoutTabExtension", - "checkout-bitcoin-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/CheckoutTabExtension", - "checkout-ethereum-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("CoinSwitch/CheckoutEnd", - "checkout-end")); - base.Execute(applicationBuilder); - } - } -} diff --git a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchService.cs b/BTCPayServer/Plugins/CoinSwitch/CoinSwitchService.cs deleted file mode 100644 index 96d09f775..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/CoinSwitchService.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Threading.Tasks; -using BTCPayServer.Data; -using BTCPayServer.Services.Stores; -using Microsoft.Extensions.Caching.Memory; - -namespace BTCPayServer.Plugins.CoinSwitch -{ - public class CoinSwitchService: IDisposable - { - private readonly StoreRepository _storeRepository; - private readonly IMemoryCache _memoryCache; - - public CoinSwitchService(StoreRepository storeRepository, IMemoryCache memoryCache) - { - _storeRepository = storeRepository; - _memoryCache = memoryCache; - } - - public async Task GetCoinSwitchForInvoice(string id) - { - return await _memoryCache.GetOrCreateAsync($"{nameof(CoinSwitchService)}-{id}", async entry => - { - entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1); - var d = await _storeRepository.GetStoreByInvoiceId(id); - - return d?.GetStoreBlob()?.GetCoinSwitchSettings(); - }); - } - - public void Dispose() - { - _memoryCache?.Dispose(); - } - } -} diff --git a/BTCPayServer/Plugins/CoinSwitch/CoinswitchSettings.cs b/BTCPayServer/Plugins/CoinSwitch/CoinswitchSettings.cs deleted file mode 100644 index d797f1664..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/CoinswitchSettings.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BTCPayServer.Plugins.CoinSwitch -{ - public class CoinSwitchSettings - { - public string MerchantId { get; set; } - public string Mode { get; set; } - public bool Enabled { get; set; } - public decimal AmountMarkupPercentage { get; set; } - - public bool IsConfigured() - { - return - !string.IsNullOrEmpty(MerchantId); - } - } -} diff --git a/BTCPayServer/Plugins/CoinSwitch/UpdateCoinSwitchSettingsViewModel.cs b/BTCPayServer/Plugins/CoinSwitch/UpdateCoinSwitchSettingsViewModel.cs deleted file mode 100644 index 132dc2000..000000000 --- a/BTCPayServer/Plugins/CoinSwitch/UpdateCoinSwitchSettingsViewModel.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc.Rendering; - -namespace BTCPayServer.Models.StoreViewModels -{ - public class UpdateCoinSwitchSettingsViewModel - { - public string MerchantId { get; set; } - public bool Enabled { get; set; } - - [Display(Name = "Integration Mode")] - public string Mode { get; set; } = "inline"; - - [Required] - [Range(0, 100)] - [Display(Name = - "Percentage to multiply amount requested at Coinswitch to avoid underpaid situations due to Coinswitch not guaranteeing rates. ")] - public decimal AmountMarkupPercentage { get; set; } = new decimal(2); - - public List Modes { get; } = new List - { - new SelectListItem { Value = "popup", Text = "Open in a popup" }, - new SelectListItem { Value = "inline", Text = "Embed inside Checkout UI " }, - }; - } -} diff --git a/BTCPayServer/Views/CoinSwitch/UpdateCoinSwitchSettings.cshtml b/BTCPayServer/Views/CoinSwitch/UpdateCoinSwitchSettings.cshtml deleted file mode 100644 index b99c68cfa..000000000 --- a/BTCPayServer/Views/CoinSwitch/UpdateCoinSwitchSettings.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@using BTCPayServer.Views.Stores -@using BTCPayServer.Abstractions.Extensions -@model UpdateCoinSwitchSettingsViewModel -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData["NavPartialName"] = "../Stores/_Nav"; - ViewData.SetActivePageAndTitle(StoreNavPages.Integrations, "Update Store CoinSwitch Settings", Context.GetStoreData().StoreName); -} - -

@ViewData["PageTitle"]

- -
-
-
- -

- You can obtain a merchant id at - - https://coinswitch.co/switch/setup/btcpay - -

-
- - - -
-
- - -
-
- - - -
-
- - -
- -
-
-
- -@section PageFootContent { - -} diff --git a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutContentExtension.cshtml b/BTCPayServer/Views/Shared/CoinSwitch/CheckoutContentExtension.cshtml deleted file mode 100644 index 52acad9d0..000000000 --- a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutContentExtension.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@using BTCPayServer.Plugins.CoinSwitch -@inject CoinSwitchService CoinSwitchService -@{ - var invoiceId = this.Context.GetRouteValue("invoiceId")?.ToString(); - var settings = await CoinSwitchService.GetCoinSwitchForInvoice(invoiceId); - if (settings?.IsConfigured() is true && settings.Enabled) - { -
- -
- } -} diff --git a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutEnd.cshtml b/BTCPayServer/Views/Shared/CoinSwitch/CheckoutEnd.cshtml deleted file mode 100644 index 79a0b3a47..000000000 --- a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutEnd.cshtml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutTabExtension.cshtml b/BTCPayServer/Views/Shared/CoinSwitch/CheckoutTabExtension.cshtml deleted file mode 100644 index 740376ab2..000000000 --- a/BTCPayServer/Views/Shared/CoinSwitch/CheckoutTabExtension.cshtml +++ /dev/null @@ -1,12 +0,0 @@ -@using BTCPayServer.Plugins.CoinSwitch -@inject CoinSwitchService CoinSwitchService -@{ - var invoiceId = this.Context.GetRouteValue("invoiceId")?.ToString(); - var settings = await CoinSwitchService.GetCoinSwitchForInvoice(invoiceId); -} -@if (settings?.IsConfigured() is true) -{ -
- {{$t("Conversion")}} -
-} diff --git a/BTCPayServer/Views/Shared/CoinSwitch/StoreIntegrationCoinSwitchOption.cshtml b/BTCPayServer/Views/Shared/CoinSwitch/StoreIntegrationCoinSwitchOption.cshtml deleted file mode 100644 index 2d397c9ec..000000000 --- a/BTCPayServer/Views/Shared/CoinSwitch/StoreIntegrationCoinSwitchOption.cshtml +++ /dev/null @@ -1,39 +0,0 @@ -@using BTCPayServer.Plugins.CoinSwitch -@{ - var settings = Context.GetStoreData().GetStoreBlob().GetCoinSwitchSettings(); -} -
  • -
    - - - CoinSwitch - - - Accept payments in altcoins that are not supported by BTCPay Server. - - - - @if (settings?.IsConfigured() is true && settings?.Enabled is true) - { - - - Enabled - - | - - Modify - - } - else - { - - - Disabled - - - Setup - - } - -
    -
  • diff --git a/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml b/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml index 1e76846e9..5d8303f93 100644 --- a/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml +++ b/BTCPayServer/Views/Shared/Ethereum/EthereumLikeMethodCheckout.cshtml @@ -90,11 +90,6 @@ } return r; }, - coinswitchAmountDue: function() { - return this.srvModel.coinSwitchAmountMarkupPercentage - ? this.srvModel.btcDue * (1 + (this.srvModel.coinSwitchAmountMarkupPercentage / 100)) - : this.srvModel.btcDue; - }, scanDisplayQr: function() { return this.srvModel.invoiceBitcoinUrlQR; } diff --git a/BTCPayServer/wwwroot/checkout/coinswitch.html b/BTCPayServer/wwwroot/checkout/coinswitch.html deleted file mode 100644 index ab0ee8210..000000000 --- a/BTCPayServer/wwwroot/checkout/coinswitch.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - CoinSwitch - - - - - - diff --git a/BTCPayServer/wwwroot/checkout/js/coinswitchComponent.js b/BTCPayServer/wwwroot/checkout/js/coinswitchComponent.js deleted file mode 100644 index 14f5e694d..000000000 --- a/BTCPayServer/wwwroot/checkout/js/coinswitchComponent.js +++ /dev/null @@ -1,66 +0,0 @@ -Vue.component("coinswitch" , - { - props: ["toCurrency", "toCurrencyDue", "toCurrencyAddress", "merchantId", "autoload", "mode"], - data: function () { - return { - opened: false - }; - }, - computed: { - showInlineIFrame: function () { - return this.url && this.opened; - }, - url: function () { - return window.location.origin + "/checkout/coinswitch.html?" + - "&toCurrency=" + - this.toCurrency + - "&toCurrencyAddress=" + - this.toCurrencyAddress + - "&toCurrencyDue=" + - this.toCurrencyDue + - "&mode=" + - this.mode + - (this.merchantId ? "&merchant_id=" + this.merchantId : ""); - } - }, - methods: { - openDialog: function (e) { - if (e && e.preventDefault) { - e.preventDefault(); - } - - if (this.mode === 'inline') { - this.opened = true; - - } else if (this.mode === "popup") { - var coinSwitchWindow = window.open( - this.url, - 'CoinSwitch', - 'width=360,height=650,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0'); - coinSwitchWindow.opener = null; - coinSwitchWindow.focus(); - } - }, - closeDialog: function () { - if (this.mode === 'inline') { - this.opened = false; - } - }, - onLoadIframe: function (event) { - $("#prettydropdown-DefaultLang").hide(); - var c = this.closeDialog.bind(this); - event.currentTarget.contentWindow.addEventListener("message", function (evt) { - if (evt && evt.data == "popup-closed") { - c(); - - $("#prettydropdown-DefaultLang").show(); - } - }); - } - }, - mounted: function () { - if (this.autoload) { - this.openDialog(); - } - } - });