From bafec0d9741ce6bbe0d4235bb327c8abe8040682 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Sat, 26 Feb 2022 21:19:02 -0800 Subject: [PATCH] Move PointOfSaleSettings class into own file --- .../UIAppsController.PointOfSale.cs | 74 ------------------ BTCPayServer/Controllers/UILNURLController.cs | 2 +- .../AppInventoryUpdaterHostedService.cs | 4 +- BTCPayServer/Hosting/MigrationStartupTask.cs | 2 +- BTCPayServer/Services/Apps/AppService.cs | 2 +- .../Services/Apps/PointOfSaleSettings.cs | 76 +++++++++++++++++++ 6 files changed, 81 insertions(+), 79 deletions(-) create mode 100644 BTCPayServer/Services/Apps/PointOfSaleSettings.cs diff --git a/BTCPayServer/Controllers/UIAppsController.PointOfSale.cs b/BTCPayServer/Controllers/UIAppsController.PointOfSale.cs index c0d3b9847..2bdf41f65 100644 --- a/BTCPayServer/Controllers/UIAppsController.PointOfSale.cs +++ b/BTCPayServer/Controllers/UIAppsController.PointOfSale.cs @@ -15,80 +15,6 @@ namespace BTCPayServer.Controllers { public partial class UIAppsController { - public class PointOfSaleSettings - { - public PointOfSaleSettings() - { - Title = "Tea shop"; - Template = - "green tea:\n" + - " price: 1\n" + - " title: Green Tea\n" + - " description: Lovely, fresh and tender, Meng Ding Gan Lu ('sweet dew') is grown in the lush Meng Ding Mountains of the southwestern province of Sichuan where it has been cultivated for over a thousand years.\n" + - " image: ~/img/pos-sample/green-tea.jpg\n\n" + - "black tea:\n" + - " price: 1\n" + - " title: Black Tea\n" + - " description: Tian Jian Tian Jian means 'heavenly tippy tea' in Chinese, and it describes the finest grade of dark tea. Our Tian Jian dark tea is from Hunan province which is famous for making some of the best dark teas available.\n" + - " image: ~/img/pos-sample/black-tea.jpg\n\n" + - "rooibos:\n" + - " price: 1.2\n" + - " title: Rooibos\n" + - " description: Rooibos is a dramatic red tea made from a South African herb that contains polyphenols and flavonoids. Often called 'African redbush tea', Rooibos herbal tea delights the senses and delivers potential health benefits with each caffeine-free sip.\n" + - " image: ~/img/pos-sample/rooibos.jpg\n\n" + - "pu erh:\n" + - " price: 2\n" + - " title: Pu Erh\n" + - " description: This loose pur-erh tea is produced in Yunnan Province, China. The process in a relatively high humidity environment has mellowed the elemental character of the tea when compared to young Pu-erh.\n" + - " image: ~/img/pos-sample/pu-erh.jpg\n\n" + - "herbal tea:\n" + - " price: 1.8\n" + - " title: Herbal Tea\n" + - " description: Chamomile tea is made from the flower heads of the chamomile plant. The medicinal use of chamomile dates back to the ancient Egyptians, Romans and Greeks. Pay us what you want!\n" + - " image: ~/img/pos-sample/herbal-tea.jpg\n" + - " custom: true\n\n" + - "fruit tea:\n" + - " price: 1.5\n" + - " title: Fruit Tea\n" + - " description: The Tibetan Himalayas, the land is majestic and beautiful—a spiritual place where, despite the perilous environment, many journey seeking enlightenment. Pay us what you want!\n" + - " image: ~/img/pos-sample/fruit-tea.jpg\n" + - " inventory: 5\n" + - " custom: true"; - DefaultView = PosViewType.Static; - ShowCustomAmount = true; - ShowDiscount = true; - EnableTips = true; - RequiresRefundEmail = RequiresRefundEmail.InheritFromStore; - } - public string Title { get; set; } - public string Currency { get; set; } - public string Template { get; set; } - public bool EnableShoppingCart { get; set; } - public PosViewType DefaultView { get; set; } - public bool ShowCustomAmount { get; set; } - public bool ShowDiscount { get; set; } - public bool EnableTips { get; set; } - public RequiresRefundEmail RequiresRefundEmail { get; set; } - - public const string BUTTON_TEXT_DEF = "Buy for {0}"; - public string ButtonText { get; set; } = BUTTON_TEXT_DEF; - public const string CUSTOM_BUTTON_TEXT_DEF = "Pay"; - public string CustomButtonText { get; set; } = CUSTOM_BUTTON_TEXT_DEF; - public const string CUSTOM_TIP_TEXT_DEF = "Do you want to leave a tip?"; - public string CustomTipText { get; set; } = CUSTOM_TIP_TEXT_DEF; - public static readonly int[] CUSTOM_TIP_PERCENTAGES_DEF = new int[] { 15, 18, 20 }; - public int[] CustomTipPercentages { get; set; } = CUSTOM_TIP_PERCENTAGES_DEF; - - public string CustomCSSLink { get; set; } - - public string EmbeddedCSS { get; set; } - - public string Description { get; set; } - public string NotificationUrl { get; set; } - public string RedirectUrl { get; set; } - public bool? RedirectAutomatically { get; set; } - } - [HttpGet("{appId}/settings/pos")] public IActionResult UpdatePointOfSale(string appId) { diff --git a/BTCPayServer/Controllers/UILNURLController.cs b/BTCPayServer/Controllers/UILNURLController.cs index ddca7c4b5..6d1e22df7 100644 --- a/BTCPayServer/Controllers/UILNURLController.cs +++ b/BTCPayServer/Controllers/UILNURLController.cs @@ -115,7 +115,7 @@ namespace BTCPayServer items = _appService.Parse(cfS.PerksTemplate, cfS.TargetCurrency); break; case nameof(AppType.PointOfSale): - var posS = app.GetSettings(); + var posS = app.GetSettings(); currencyCode = posS.Currency; items = _appService.Parse(posS.Template, posS.Currency); break; diff --git a/BTCPayServer/HostedServices/AppInventoryUpdaterHostedService.cs b/BTCPayServer/HostedServices/AppInventoryUpdaterHostedService.cs index c767aff18..fe7b6116c 100644 --- a/BTCPayServer/HostedServices/AppInventoryUpdaterHostedService.cs +++ b/BTCPayServer/HostedServices/AppInventoryUpdaterHostedService.cs @@ -37,7 +37,7 @@ namespace BTCPayServer.HostedServices switch (Enum.Parse(data.AppType)) { case AppType.PointOfSale: - var possettings = data.GetSettings(); + var possettings = data.GetSettings(); return (Data: data, Settings: (object)possettings, Items: _appService.Parse(possettings.Template, possettings.Currency)); case AppType.Crowdfund: @@ -69,7 +69,7 @@ namespace BTCPayServer.HostedServices { case AppType.PointOfSale: - ((UIAppsController.PointOfSaleSettings)valueTuple.Settings).Template = + ((PointOfSaleSettings)valueTuple.Settings).Template = _appService.SerializeTemplate(valueTuple.Items); break; case AppType.Crowdfund: diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index 088a68c59..65d6a9759 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -350,7 +350,7 @@ WHERE cte.""Id""=p.""Id"" case nameof(AppType.PointOfSale): - var settings2 = app.GetSettings(); + var settings2 = app.GetSettings(); if (string.IsNullOrEmpty(settings2.Currency)) { settings2.Currency = app.StoreData.GetStoreBlob().DefaultCurrency; diff --git a/BTCPayServer/Services/Apps/AppService.cs b/BTCPayServer/Services/Apps/AppService.cs index ed5572720..6a27ea20b 100644 --- a/BTCPayServer/Services/Apps/AppService.cs +++ b/BTCPayServer/Services/Apps/AppService.cs @@ -347,7 +347,7 @@ namespace BTCPayServer.Services.Apps { AppType appTypeEnum = Enum.Parse(appType); AppData appData = await GetApp(appId, appTypeEnum, false); - var settings = appData.GetSettings(); + var settings = appData.GetSettings(); string style; switch (appTypeEnum) diff --git a/BTCPayServer/Services/Apps/PointOfSaleSettings.cs b/BTCPayServer/Services/Apps/PointOfSaleSettings.cs new file mode 100644 index 000000000..f2b2d32ad --- /dev/null +++ b/BTCPayServer/Services/Apps/PointOfSaleSettings.cs @@ -0,0 +1,76 @@ +namespace BTCPayServer.Services.Apps +{ + public class PointOfSaleSettings + { + public PointOfSaleSettings() + { + Title = "Tea shop"; + Template = + "green tea:\n" + + " price: 1\n" + + " title: Green Tea\n" + + " description: Lovely, fresh and tender, Meng Ding Gan Lu ('sweet dew') is grown in the lush Meng Ding Mountains of the southwestern province of Sichuan where it has been cultivated for over a thousand years.\n" + + " image: ~/img/pos-sample/green-tea.jpg\n\n" + + "black tea:\n" + + " price: 1\n" + + " title: Black Tea\n" + + " description: Tian Jian Tian Jian means 'heavenly tippy tea' in Chinese, and it describes the finest grade of dark tea. Our Tian Jian dark tea is from Hunan province which is famous for making some of the best dark teas available.\n" + + " image: ~/img/pos-sample/black-tea.jpg\n\n" + + "rooibos:\n" + + " price: 1.2\n" + + " title: Rooibos\n" + + " description: Rooibos is a dramatic red tea made from a South African herb that contains polyphenols and flavonoids. Often called 'African redbush tea', Rooibos herbal tea delights the senses and delivers potential health benefits with each caffeine-free sip.\n" + + " image: ~/img/pos-sample/rooibos.jpg\n\n" + + "pu erh:\n" + + " price: 2\n" + + " title: Pu Erh\n" + + " description: This loose pur-erh tea is produced in Yunnan Province, China. The process in a relatively high humidity environment has mellowed the elemental character of the tea when compared to young Pu-erh.\n" + + " image: ~/img/pos-sample/pu-erh.jpg\n\n" + + "herbal tea:\n" + + " price: 1.8\n" + + " title: Herbal Tea\n" + + " description: Chamomile tea is made from the flower heads of the chamomile plant. The medicinal use of chamomile dates back to the ancient Egyptians, Romans and Greeks. Pay us what you want!\n" + + " image: ~/img/pos-sample/herbal-tea.jpg\n" + + " custom: true\n\n" + + "fruit tea:\n" + + " price: 1.5\n" + + " title: Fruit Tea\n" + + " description: The Tibetan Himalayas, the land is majestic and beautiful—a spiritual place where, despite the perilous environment, many journey seeking enlightenment. Pay us what you want!\n" + + " image: ~/img/pos-sample/fruit-tea.jpg\n" + + " inventory: 5\n" + + " custom: true"; + DefaultView = PosViewType.Static; + ShowCustomAmount = true; + ShowDiscount = true; + EnableTips = true; + RequiresRefundEmail = RequiresRefundEmail.InheritFromStore; + } + public string Title { get; set; } + public string Currency { get; set; } + public string Template { get; set; } + public bool EnableShoppingCart { get; set; } + public PosViewType DefaultView { get; set; } + public bool ShowCustomAmount { get; set; } + public bool ShowDiscount { get; set; } + public bool EnableTips { get; set; } + public RequiresRefundEmail RequiresRefundEmail { get; set; } + + public const string BUTTON_TEXT_DEF = "Buy for {0}"; + public string ButtonText { get; set; } = BUTTON_TEXT_DEF; + public const string CUSTOM_BUTTON_TEXT_DEF = "Pay"; + public string CustomButtonText { get; set; } = CUSTOM_BUTTON_TEXT_DEF; + public const string CUSTOM_TIP_TEXT_DEF = "Do you want to leave a tip?"; + public string CustomTipText { get; set; } = CUSTOM_TIP_TEXT_DEF; + public static readonly int[] CUSTOM_TIP_PERCENTAGES_DEF = new int[] { 15, 18, 20 }; + public int[] CustomTipPercentages { get; set; } = CUSTOM_TIP_PERCENTAGES_DEF; + + public string CustomCSSLink { get; set; } + + public string EmbeddedCSS { get; set; } + + public string Description { get; set; } + public string NotificationUrl { get; set; } + public string RedirectUrl { get; set; } + public bool? RedirectAutomatically { get; set; } + } +}