From 7543bc32d883cd3f772fe935f4f6246488056c5d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 11 Nov 2022 20:07:29 -0700 Subject: [PATCH] Add billing section --- appinfo/info.xml | 2 + lib/Controller/SettingsController.php | 6 +- lib/Sections/Billing.php | 32 ++++++++++ lib/Settings/Admin.php | 12 +++- lib/Settings/Billing.php | 87 +++++++++++++++++++++++++++ templates/settings/admin.php | 18 +++++- 6 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 lib/Sections/Billing.php create mode 100644 lib/Settings/Billing.php diff --git a/appinfo/info.xml b/appinfo/info.xml index f067c7a..c067e90 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -20,5 +20,7 @@ OCA\ExternalPassword\Settings\Admin OCA\ExternalPassword\Settings\Personal + OCA\ExternalPassword\Settings\Billing + OCA\ExternalPassword\Sections\Billing diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 3348bff..772c063 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -47,10 +47,14 @@ class SettingsController extends Controller { * @param string $descriptionText * @param string $buttonText */ - public function save(string $changePasswordUrl, string $descriptionText, string $buttonText): JSONResponse { + public function save(string $changePasswordUrl, string $descriptionText, string $buttonText, + string $billingUrl, string $billingDescriptionText, string $billingButtonText): JSONResponse { $this->config->setAppValue('externalpassword', 'changePasswordUrl', $changePasswordUrl); $this->config->setAppValue('externalpassword', 'descriptionText', $descriptionText); $this->config->setAppValue('externalpassword', 'buttonText', $buttonText); + $this->config->setAppValue('externalpassword', 'billingUrl', $billingUrl); + $this->config->setAppValue('externalpassword', 'billingDescriptionText', $billingDescriptionText); + $this->config->setAppValue('externalpassword', 'billingButtonText', $billingButtonText); $parameters = [ 'status' => 'success', 'data' => [ diff --git a/lib/Sections/Billing.php b/lib/Sections/Billing.php new file mode 100644 index 0000000..a526896 --- /dev/null +++ b/lib/Sections/Billing.php @@ -0,0 +1,32 @@ +l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('externalpassword', 'billing.svg'); + } + + public function getID(): string { + return 'billing'; + } + + public function getName(): string { + return $this->l->t('Billing'); + } + + public function getPriority(): int { + return 98; + } +} diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index d033850..f1c2793 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -50,14 +50,24 @@ class Admin implements ISettings { * @return TemplateResponse */ public function getForm() { + # Password section $changePasswordUrl = $this->config->getAppValue('externalpassword', 'changePasswordUrl', ''); $descriptionText = $this->config->getAppValue('externalpassword', 'descriptionText', 'Your password is managed externally, please click the button below to change your password.'); $buttonText = $this->config->getAppValue('externalpassword', 'buttonText', 'Change password'); + # Billing section + $billingUrl = $this->config->getAppValue('externalpassword', 'billingUrl', ''); + $billingDescriptionText = $this->config->getAppValue('externalpassword', 'billingDescriptionText', + 'Your account billing is managed externally, please click the button below to manage your account.'); + $billingButtonText = $this->config->getAppValue('externalpassword', 'billingButtonText', 'Manage billing'); + $parameters = [ 'changePasswordUrl' => $changePasswordUrl, 'descriptionText' => $descriptionText, - 'buttonText' => $buttonText + 'buttonText' => $buttonText, + 'billingUrl' => $billingUrl, + 'billingDescriptionText' => $billingDescriptionText, + 'billingButtonText' => $billingButtonText ]; return new TemplateResponse('externalpassword', 'settings/admin', $parameters); } diff --git a/lib/Settings/Billing.php b/lib/Settings/Billing.php new file mode 100644 index 0000000..872bf8a --- /dev/null +++ b/lib/Settings/Billing.php @@ -0,0 +1,87 @@ + + * + * @author Raoul Snyman + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCA\ExternalPassword\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IL10N; +use OCP\Settings\ISettings; + +class Billing implements ISettings { + + /** @var IConfig */ + private $config; + + /** @var IL10N */ + private $l; + + /** + * Admin constructor. + * + * @param IConfig $config + * @param IL10N $l + */ + public function __construct(IConfig $config, IL10N $l) { + $this->config = $config; + $this->l = $l; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $billingUrl = $this->config->getAppValue('externalpassword', 'billingUrl', ''); + $billingDescriptionText = $this->config->getAppValue('externalpassword', 'billingDescriptionText', + 'Your account billing is managed externally, please click the button below to manage your account.'); + $billingButtonText = $this->config->getAppValue('externalpassword', 'billingButtonText', 'Manage billing'); + $parameters = [ + 'billingUrl' => $billingUrl, + 'billingDescriptionText' => $billingDescriptionText, + 'billingButtonText' => $billingButtonText + ]; + return new TemplateResponse('externalpassword', 'settings/billing', $parameters); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + $billingUrl = $this->config->getAppValue('externalpassword', 'billingUrl', ''); + if (!$billingUrl) { + return null; + } + else { + return 'billing'; + } + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + */ + public function getPriority() { + return 10; + } + +} diff --git a/templates/settings/admin.php b/templates/settings/admin.php index ae08839..d01c75d 100644 --- a/templates/settings/admin.php +++ b/templates/settings/admin.php @@ -27,7 +27,7 @@ style('externalpassword', 'admin');

t('External Password'));?>

-

t('To direct users to an external website in order to change their password, set the URL below.')); ?>

+

t('To direct users to an external website in order to change their password or update their billing, set the URLs below.')); ?>

@@ -35,13 +35,25 @@ style('externalpassword', 'admin');
- +
- +
+
+ + +
+
+ + +
+
+ + +