-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1b821b
commit 8f3fb30
Showing
15 changed files
with
582 additions
and
75 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings; | ||
|
||
use Mollie\WooCommerce\Settings\Page\AbstractPage; | ||
use Mollie\WooCommerce\Settings\Page\PageAdvancedSettings; | ||
use Mollie\WooCommerce\Settings\Page\PageApiKeys; | ||
use Mollie\WooCommerce\Settings\Page\PageNoApiKey; | ||
use Mollie\WooCommerce\Settings\Page\PagePaymentMethods; | ||
use Mollie\WooCommerce\Shared\Data; | ||
use WC_Settings_Page; | ||
|
||
class MollieSettingsPage extends WC_Settings_Page | ||
{ | ||
protected Settings $settingsHelper; | ||
protected string $pluginPath; | ||
protected string $pluginUrl; | ||
protected array $gateways; | ||
protected array $paymentMethods; | ||
protected bool $isTestModeEnabled; | ||
protected Data $dataHelper; | ||
|
||
public function __construct( | ||
Settings $settingsHelper, | ||
string $pluginPath, | ||
string $pluginUrl, | ||
array $gateways, | ||
array $paymentMethods, | ||
bool $isTestModeEnabled, | ||
Data $dataHelper | ||
) { | ||
$this->id = 'mollie_settings'; | ||
$this->label = __('Mollie Settings', 'mollie-payments-for-woocommerce'); | ||
$this->settingsHelper = $settingsHelper; | ||
$this->pluginPath = $pluginPath; | ||
$this->pluginUrl = $pluginUrl; | ||
$this->gateways = $gateways; | ||
$this->isTestModeEnabled = $isTestModeEnabled; | ||
$this->dataHelper = $dataHelper; | ||
$this->paymentMethods = $paymentMethods; | ||
$this->registerContentFieldType(); | ||
$this->outputSections(); | ||
parent::__construct(); | ||
} | ||
|
||
public function registerContentFieldType(): void | ||
{ | ||
add_action('woocommerce_admin_field_mollie_custom_input', static function ($value): void { | ||
?> | ||
<tr valign="top"> | ||
<th scope="row" class="titledesc"> | ||
<label for="<?php | ||
echo esc_attr($value['id']); ?>"><?php | ||
echo esc_html($value['title']); ?></label> | ||
</th> | ||
<td class="forminp"> | ||
<?php | ||
if (!empty($value['value'])): ?> | ||
<?= $value['value']; ?> | ||
<?php | ||
endif; ?> | ||
</td> | ||
</tr> | ||
<?php | ||
}); | ||
|
||
add_action('woocommerce_admin_field_mollie_content', static function ($value): void { | ||
if (!empty($value['value'])) { | ||
echo $value['value']; | ||
} | ||
}); | ||
} | ||
|
||
public function outputSections() | ||
{ | ||
add_action( | ||
'woocommerce_sections_' . $this->id, | ||
[$this, 'output_sections'] | ||
); | ||
} | ||
|
||
protected function pages(): array | ||
{ | ||
return [ | ||
PageNoApiKey::class, | ||
PageApiKeys::class, | ||
PagePaymentMethods::class, | ||
PageAdvancedSettings::class | ||
]; | ||
} | ||
|
||
public function get_settings($currentSection = '') | ||
{ | ||
$mollieSettings = null; | ||
foreach ($this->pages() as $pageClass) { | ||
/** @var AbstractPage $page */ | ||
$page = new $pageClass($this->settingsHelper, $this->pluginUrl); | ||
if ($page->slug() === $currentSection) { | ||
$mollieSettings = $page->settings(); | ||
break; | ||
} | ||
} | ||
|
||
if (!$mollieSettings) { | ||
$mollieSettings = (new PageNoApiKey($this->settingsHelper, $this->pluginUrl))->settings(); | ||
} | ||
|
||
return apply_filters( | ||
'woocommerce_get_settings_' . $this->id, | ||
$mollieSettings, | ||
$currentSection | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page; | ||
|
||
use Mollie\WooCommerce\Settings\Page\Section\AbstractSection; | ||
use Mollie\WooCommerce\Settings\Settings; | ||
|
||
abstract class AbstractPage | ||
{ | ||
protected Settings $settings; | ||
protected string $pluginUrl; | ||
|
||
public function __construct(Settings $settings, string $pluginUrl) | ||
{ | ||
$this->settings = $settings; | ||
$this->pluginUrl = $pluginUrl; | ||
} | ||
|
||
abstract public function isTab(): bool; | ||
|
||
abstract public function slug(): string; | ||
|
||
public function tabName(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
protected function sections(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function settings(): array | ||
{ | ||
$settings = []; | ||
$styles = []; | ||
|
||
foreach ($this->sections() as $sectionClass) { | ||
/** @var AbstractSection $section */ | ||
$section = new $sectionClass($this->settings, $this->pluginUrl); | ||
foreach ($section->config() as $field) { | ||
$settings[] = $field; | ||
} | ||
$styles[$sectionClass] = preg_replace('/\s+/', '', $section->styles()); | ||
} | ||
array_unshift($settings, [ | ||
'id' => $this->settings->getSettingId('styles'), | ||
'type' => 'mollie_content', | ||
'value' => implode($styles) | ||
]); | ||
return $settings; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page; | ||
|
||
class PageAdvancedSettings extends AbstractPage { | ||
|
||
public function isTab(): bool | ||
{ | ||
// TODO: Implement isTab() method. | ||
} | ||
|
||
public function slug(): string | ||
{ | ||
return 'mollie_advanced'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page; | ||
|
||
class PageApiKeys extends AbstractPage { | ||
|
||
public function isTab(): bool | ||
{ | ||
// TODO: Implement isTab() method. | ||
} | ||
|
||
public function slug(): string | ||
{ | ||
return 'mollie_api_keys'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page; | ||
|
||
use Mollie\WooCommerce\Settings\Page\Section\ConnectionFields; | ||
use Mollie\WooCommerce\Settings\Page\Section\Header; | ||
use Mollie\WooCommerce\Settings\Page\Section\Instructions; | ||
use Mollie\WooCommerce\Settings\Page\Section\Notices; | ||
|
||
class PageNoApiKey extends AbstractPage { | ||
public function isTab(): bool | ||
{ | ||
// TODO: Implement isTab() method. | ||
} | ||
|
||
public function slug(): string | ||
{ | ||
return 'mollie_no_api_key'; | ||
} | ||
|
||
public function sections(): array | ||
{ | ||
return [ | ||
Header::class, | ||
Notices::class, | ||
Instructions::class, | ||
ConnectionFields::class | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page; | ||
|
||
class PagePaymentMethods extends AbstractPage { | ||
|
||
public function isTab(): bool | ||
{ | ||
// TODO: Implement isTab() method. | ||
} | ||
|
||
public function slug(): string | ||
{ | ||
return 'mollie_payment_methods'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\WooCommerce\Settings\Page\Section; | ||
|
||
use Mollie\WooCommerce\Settings\Settings; | ||
|
||
abstract class AbstractSection | ||
{ | ||
protected Settings $settings; | ||
protected string $pluginUrl; | ||
|
||
public function __construct(Settings $settings, string $pluginUrl) | ||
{ | ||
$this->settings = $settings; | ||
$this->pluginUrl = $pluginUrl; | ||
} | ||
|
||
abstract public function config(): array; | ||
|
||
public function styles(): string{ | ||
return ''; | ||
} | ||
|
||
public function images(): string | ||
{ | ||
return $this->pluginUrl . '/public/images/'; | ||
} | ||
} |
Oops, something went wrong.