From b26c30e2ddfbad9ade3c7f1560ef198af2e1268c Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 3 Oct 2024 06:19:47 +0200 Subject: [PATCH] Advanced settings --- resources/js/settings.js | 11 - src/Assets/AssetsModule.php | 2 +- .../ApplePayButton/ApplePayDataObjectHttp.php | 2 +- src/PaymentMethods/Alma.php | 1 + src/PaymentMethods/Applepay.php | 1 + src/PaymentMethods/Bancomatpay.php | 1 + src/PaymentMethods/Bancontact.php | 1 + src/PaymentMethods/Banktransfer.php | 1 + src/PaymentMethods/Belfius.php | 1 + src/PaymentMethods/Billie.php | 1 + src/PaymentMethods/Blik.php | 1 + src/PaymentMethods/Creditcard.php | 1 + src/PaymentMethods/Directdebit.php | 1 + src/PaymentMethods/Eps.php | 1 + src/PaymentMethods/Giftcard.php | 1 + src/PaymentMethods/Giropay.php | 1 + src/PaymentMethods/Ideal.php | 1 + src/PaymentMethods/In3.php | 1 + src/PaymentMethods/Kbc.php | 1 + src/PaymentMethods/Klarna.php | 1 + src/PaymentMethods/Klarnapaylater.php | 1 + src/PaymentMethods/Klarnapaynow.php | 1 + src/PaymentMethods/Klarnasliceit.php | 1 + src/PaymentMethods/Mybank.php | 1 + src/PaymentMethods/Payconiq.php | 1 + src/PaymentMethods/Paypal.php | 1 + src/PaymentMethods/Paysafecard.php | 1 + src/PaymentMethods/Przelewy24.php | 1 + src/PaymentMethods/Riverty.php | 1 + src/PaymentMethods/Satispay.php | 1 + src/PaymentMethods/Sofort.php | 1 + src/PaymentMethods/Trustly.php | 1 + src/PaymentMethods/Twint.php | 1 + src/PaymentMethods/Voucher.php | 1 + src/Settings/MollieSettingsPage.php | 168 ++++++++++-- .../{Page => }/MollieSettingsPageOld.php | 0 src/Settings/Page/AbstractPage.php | 53 +++- src/Settings/Page/PageAdvancedSettings.php | 29 ++- src/Settings/Page/PageApiKeys.php | 31 ++- src/Settings/Page/PageNoApiKey.php | 15 +- src/Settings/Page/PagePaymentMethods.php | 30 ++- src/Settings/Page/Section/AbstractSection.php | 32 ++- src/Settings/Page/Section/Advanced.php | 231 ++++++++++++++++ .../Page/Section/ConnectionFields.php | 33 ++- .../Page/Section/ConnectionStatusFields.php | 46 ++++ .../Page/Section/ConnectionStatusTrait.php | 36 +++ src/Settings/Page/Section/Header.php | 12 +- .../Page/Section/InstructionsConnected.php | 46 ++++ ...tions.php => InstructionsNotConnected.php} | 28 +- src/Settings/Page/Section/Notices.php | 8 +- src/Settings/Page/Section/PaymentMethods.php | 246 ++++++++++++++++++ src/Settings/Page/Section/Tabs.php | 45 ++++ src/Settings/Settings.php | 24 +- 53 files changed, 1053 insertions(+), 106 deletions(-) rename src/Settings/{Page => }/MollieSettingsPageOld.php (100%) create mode 100644 src/Settings/Page/Section/Advanced.php create mode 100644 src/Settings/Page/Section/ConnectionStatusFields.php create mode 100644 src/Settings/Page/Section/ConnectionStatusTrait.php create mode 100644 src/Settings/Page/Section/InstructionsConnected.php rename src/Settings/Page/Section/{Instructions.php => InstructionsNotConnected.php} (66%) create mode 100644 src/Settings/Page/Section/PaymentMethods.php create mode 100644 src/Settings/Page/Section/Tabs.php diff --git a/resources/js/settings.js b/resources/js/settings.js index 0cd19c22a..54eb4515c 100644 --- a/resources/js/settings.js +++ b/resources/js/settings.js @@ -4,17 +4,6 @@ const {current_section = false} = mollieSettingsData jQuery(function($) { - $('#mollie-payments-for-woocommerce_test_mode_enabled').change(function() { - if ($(this).is(':checked')) - { - $('#mollie-payments-for-woocommerce_test_api_key').attr('required', true).closest('tr').show(); - } - else - { - $('#mollie-payments-for-woocommerce_test_api_key').removeAttr('required').closest('tr').hide(); - } - }).change(); - if(_.isEmpty(mollieSettingsData)){ return } diff --git a/src/Assets/AssetsModule.php b/src/Assets/AssetsModule.php index 9cb2e3613..40277df44 100644 --- a/src/Assets/AssetsModule.php +++ b/src/Assets/AssetsModule.php @@ -490,7 +490,7 @@ public function enqueueAdvancedSettingsJS($ar) if ( $current_screen->id !== 'woocommerce_page_wc-settings' || $current_tab !== 'mollie_settings' - || $current_section !== 'advanced' + || $current_section !== 'mollie_advanced' ) { return; } diff --git a/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php b/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php index db7f6919b..38f91294b 100644 --- a/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php +++ b/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php @@ -326,7 +326,7 @@ protected function addressHasRequiredFieldsValues( sprintf('ApplePay Data Error: Missing value for %s', $requiredField) ); $this->errors[] - = [ + = [ 'errorCode' => $errorCode, 'contactField' => $errorValue, ]; diff --git a/src/PaymentMethods/Alma.php b/src/PaymentMethods/Alma.php index 57ac08fa4..d127a9864 100644 --- a/src/PaymentMethods/Alma.php +++ b/src/PaymentMethods/Alma.php @@ -26,6 +26,7 @@ protected function getConfig(): array 'billingAddress', 'shippingAddress', ], + 'docs' => 'https://www.mollie.com/gb/payments/alma', ]; } diff --git a/src/PaymentMethods/Applepay.php b/src/PaymentMethods/Applepay.php index 63a32c9ab..b1ae1f9eb 100644 --- a/src/PaymentMethods/Applepay.php +++ b/src/PaymentMethods/Applepay.php @@ -24,6 +24,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'Subscription' => true, + 'docs' => 'https://www.mollie.com/gb/payments/apple-pay', ]; } diff --git a/src/PaymentMethods/Bancomatpay.php b/src/PaymentMethods/Bancomatpay.php index 054ef951d..7f9600fa1 100644 --- a/src/PaymentMethods/Bancomatpay.php +++ b/src/PaymentMethods/Bancomatpay.php @@ -21,6 +21,7 @@ public function getConfig(): array ], 'filtersOnBuild' => false, 'confirmationDelayed' => false, + 'docs' => 'https://www.mollie.com/gb/payments/bancomat-pay', ]; } diff --git a/src/PaymentMethods/Bancontact.php b/src/PaymentMethods/Bancontact.php index 9d01c9d93..14ac3832d 100644 --- a/src/PaymentMethods/Bancontact.php +++ b/src/PaymentMethods/Bancontact.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://www.mollie.com/gb/payments/bancontact', ]; } diff --git a/src/PaymentMethods/Banktransfer.php b/src/PaymentMethods/Banktransfer.php index 93a6f3f10..6abc75866 100644 --- a/src/PaymentMethods/Banktransfer.php +++ b/src/PaymentMethods/Banktransfer.php @@ -42,6 +42,7 @@ protected function getConfig(): array 'confirmationDelayed' => true, 'SEPA' => false, 'customRedirect' => true, + 'docs' => 'https://www.mollie.com/gb/payments/bank-transfer', ]; } diff --git a/src/PaymentMethods/Belfius.php b/src/PaymentMethods/Belfius.php index ea98768f9..c8876451b 100644 --- a/src/PaymentMethods/Belfius.php +++ b/src/PaymentMethods/Belfius.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://www.mollie.com/gb/payments/belfius', ]; } diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index 369f49521..0269b9da0 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -31,6 +31,7 @@ protected function getConfig(): array 'mollie-payments-for-woocommerce' ), 'companyPlaceholder' => __('Please enter your company name here.', 'mollie-payments-for-woocommerce'), + 'docs' => 'https://www.mollie.com/gb/payments/billie', ]; } diff --git a/src/PaymentMethods/Blik.php b/src/PaymentMethods/Blik.php index 83e05ef2c..c0590dcd6 100644 --- a/src/PaymentMethods/Blik.php +++ b/src/PaymentMethods/Blik.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/blik', ]; } diff --git a/src/PaymentMethods/Creditcard.php b/src/PaymentMethods/Creditcard.php index 237ad4ce7..85e26b432 100644 --- a/src/PaymentMethods/Creditcard.php +++ b/src/PaymentMethods/Creditcard.php @@ -27,6 +27,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'Subscription' => true, + 'docs' => 'https://www.mollie.com/gb/payments/credit-card', ]; } diff --git a/src/PaymentMethods/Directdebit.php b/src/PaymentMethods/Directdebit.php index 5b4b91d34..0b7bf94fa 100644 --- a/src/PaymentMethods/Directdebit.php +++ b/src/PaymentMethods/Directdebit.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/direct-debit', ]; } diff --git a/src/PaymentMethods/Eps.php b/src/PaymentMethods/Eps.php index 15bd8eb5d..327a53acd 100644 --- a/src/PaymentMethods/Eps.php +++ b/src/PaymentMethods/Eps.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://www.mollie.com/gb/payments/eps', ]; } diff --git a/src/PaymentMethods/Giftcard.php b/src/PaymentMethods/Giftcard.php index 812e3cd7f..b5154541a 100644 --- a/src/PaymentMethods/Giftcard.php +++ b/src/PaymentMethods/Giftcard.php @@ -70,6 +70,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/gift-cards', ]; } diff --git a/src/PaymentMethods/Giropay.php b/src/PaymentMethods/Giropay.php index 440b8f0b8..8939ce56c 100644 --- a/src/PaymentMethods/Giropay.php +++ b/src/PaymentMethods/Giropay.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://help.mollie.com/hc/en-gb/articles/19745480480786-Giropay-Depreciation-FAQ', ]; } diff --git a/src/PaymentMethods/Ideal.php b/src/PaymentMethods/Ideal.php index c7638b054..d4464b366 100644 --- a/src/PaymentMethods/Ideal.php +++ b/src/PaymentMethods/Ideal.php @@ -24,6 +24,7 @@ public function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://www.mollie.com/gb/payments/ideal-2-0', ]; } diff --git a/src/PaymentMethods/In3.php b/src/PaymentMethods/In3.php index d86beb12d..f839c6e71 100644 --- a/src/PaymentMethods/In3.php +++ b/src/PaymentMethods/In3.php @@ -29,6 +29,7 @@ public function getConfig(): array ), 'phonePlaceholder' => __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'), 'birthdatePlaceholder' => __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'), + 'docs' => 'https://www.mollie.com/gb/payments/ideal-in3', ]; } diff --git a/src/PaymentMethods/Kbc.php b/src/PaymentMethods/Kbc.php index 4005b83fd..99de76e93 100644 --- a/src/PaymentMethods/Kbc.php +++ b/src/PaymentMethods/Kbc.php @@ -23,6 +23,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://www.mollie.com/gb/payments/kbc-cbc', ]; } diff --git a/src/PaymentMethods/Klarna.php b/src/PaymentMethods/Klarna.php index bdad1b516..0c0b3ccc8 100644 --- a/src/PaymentMethods/Klarna.php +++ b/src/PaymentMethods/Klarna.php @@ -26,6 +26,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, + 'docs' => 'https://www.mollie.com/gb/payments/klarna', ]; } diff --git a/src/PaymentMethods/Klarnapaylater.php b/src/PaymentMethods/Klarnapaylater.php index 99140ba4a..edd6f6c99 100644 --- a/src/PaymentMethods/Klarnapaylater.php +++ b/src/PaymentMethods/Klarnapaylater.php @@ -26,6 +26,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, + 'docs' => 'https://www.mollie.com/gb/payments/klarna', ]; } diff --git a/src/PaymentMethods/Klarnapaynow.php b/src/PaymentMethods/Klarnapaynow.php index 32cd04a98..5cdddfeb3 100644 --- a/src/PaymentMethods/Klarnapaynow.php +++ b/src/PaymentMethods/Klarnapaynow.php @@ -26,6 +26,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, + 'docs' => 'https://www.mollie.com/gb/payments/klarna', ]; } diff --git a/src/PaymentMethods/Klarnasliceit.php b/src/PaymentMethods/Klarnasliceit.php index 9b97b3db3..dd8e31c21 100644 --- a/src/PaymentMethods/Klarnasliceit.php +++ b/src/PaymentMethods/Klarnasliceit.php @@ -26,6 +26,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, + 'docs' => 'https://www.mollie.com/gb/payments/klarna', ]; } diff --git a/src/PaymentMethods/Mybank.php b/src/PaymentMethods/Mybank.php index a2f38ba23..e656d23ee 100644 --- a/src/PaymentMethods/Mybank.php +++ b/src/PaymentMethods/Mybank.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => '', ]; } diff --git a/src/PaymentMethods/Payconiq.php b/src/PaymentMethods/Payconiq.php index 59f9899af..b89696c97 100644 --- a/src/PaymentMethods/Payconiq.php +++ b/src/PaymentMethods/Payconiq.php @@ -19,6 +19,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => '', ]; } diff --git a/src/PaymentMethods/Paypal.php b/src/PaymentMethods/Paypal.php index e3713f017..07be034bf 100644 --- a/src/PaymentMethods/Paypal.php +++ b/src/PaymentMethods/Paypal.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/paypal', ]; } diff --git a/src/PaymentMethods/Paysafecard.php b/src/PaymentMethods/Paysafecard.php index b1e180f3d..4e1fe4d58 100644 --- a/src/PaymentMethods/Paysafecard.php +++ b/src/PaymentMethods/Paysafecard.php @@ -19,6 +19,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/paysafecard', ]; } diff --git a/src/PaymentMethods/Przelewy24.php b/src/PaymentMethods/Przelewy24.php index d3e6e9f74..58eb26922 100644 --- a/src/PaymentMethods/Przelewy24.php +++ b/src/PaymentMethods/Przelewy24.php @@ -25,6 +25,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/przelewy24', ]; } diff --git a/src/PaymentMethods/Riverty.php b/src/PaymentMethods/Riverty.php index 9482f69c5..e7db2037b 100644 --- a/src/PaymentMethods/Riverty.php +++ b/src/PaymentMethods/Riverty.php @@ -31,6 +31,7 @@ protected function getConfig(): array 'orderMandatory' => true, 'phonePlaceholder' => __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'), 'birthdatePlaceholder' => __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'), + 'docs' => 'https://www.mollie.com/gb/payments/riverty', ]; } diff --git a/src/PaymentMethods/Satispay.php b/src/PaymentMethods/Satispay.php index 5919e9d69..61bd49f7b 100644 --- a/src/PaymentMethods/Satispay.php +++ b/src/PaymentMethods/Satispay.php @@ -19,6 +19,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/satispay', ]; } diff --git a/src/PaymentMethods/Sofort.php b/src/PaymentMethods/Sofort.php index 625f15cd5..d33a08655 100644 --- a/src/PaymentMethods/Sofort.php +++ b/src/PaymentMethods/Sofort.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, + 'docs' => 'https://help.mollie.com/hc/en-us/articles/20904206772626-SOFORT-Deprecation-30-September-2024', ]; } diff --git a/src/PaymentMethods/Trustly.php b/src/PaymentMethods/Trustly.php index 05179fbbb..aa73fccf1 100644 --- a/src/PaymentMethods/Trustly.php +++ b/src/PaymentMethods/Trustly.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/trustly', ]; } diff --git a/src/PaymentMethods/Twint.php b/src/PaymentMethods/Twint.php index eeaa9b027..8b33f958d 100644 --- a/src/PaymentMethods/Twint.php +++ b/src/PaymentMethods/Twint.php @@ -22,6 +22,7 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'SEPA' => false, + 'docs' => 'https://www.mollie.com/gb/payments/twint', ]; } diff --git a/src/PaymentMethods/Voucher.php b/src/PaymentMethods/Voucher.php index 1df331bb9..80224f322 100644 --- a/src/PaymentMethods/Voucher.php +++ b/src/PaymentMethods/Voucher.php @@ -43,6 +43,7 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, + 'docs' => 'https://www.mollie.com/gb/payments/meal-eco-gift-vouchers', ]; } diff --git a/src/Settings/MollieSettingsPage.php b/src/Settings/MollieSettingsPage.php index 53cd41b1d..7c521201c 100644 --- a/src/Settings/MollieSettingsPage.php +++ b/src/Settings/MollieSettingsPage.php @@ -10,33 +10,36 @@ use Mollie\WooCommerce\Settings\Page\PageNoApiKey; use Mollie\WooCommerce\Settings\Page\PagePaymentMethods; use Mollie\WooCommerce\Shared\Data; +use Mollie\WooCommerce\PaymentMethods\Constants; +use WC_Gateway_BACS; use WC_Settings_Page; class MollieSettingsPage extends WC_Settings_Page { - protected Settings $settingsHelper; + protected Settings $settings; protected string $pluginPath; protected string $pluginUrl; - protected array $gateways; + protected array $mollieGateways; 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 + Settings $settings, + string $pluginPath, + string $pluginUrl, + array $mollieGateways, + array $paymentMethods, + bool $isTestModeEnabled, + Data $dataHelper ) { + $this->id = 'mollie_settings'; $this->label = __('Mollie Settings', 'mollie-payments-for-woocommerce'); - $this->settingsHelper = $settingsHelper; + $this->settings = $settings; $this->pluginPath = $pluginPath; $this->pluginUrl = $pluginUrl; - $this->gateways = $gateways; + $this->mollieGateways = $mollieGateways; $this->isTestModeEnabled = $isTestModeEnabled; $this->dataHelper = $dataHelper; $this->paymentMethods = $paymentMethods; @@ -57,9 +60,15 @@ public function registerContentFieldType(): void + if (!empty($value['value'])) : ?> + + +

+ @@ -76,8 +85,8 @@ public function registerContentFieldType(): void public function outputSections() { add_action( - 'woocommerce_sections_' . $this->id, - [$this, 'output_sections'] + 'woocommerce_sections_' . $this->id, + [$this, 'output_sections'] ); } @@ -87,30 +96,141 @@ protected function pages(): array PageNoApiKey::class, PageApiKeys::class, PagePaymentMethods::class, - PageAdvancedSettings::class + PageAdvancedSettings::class, ]; } public function get_settings($currentSection = '') { + $defaultSection = $currentSection; + $connectionStatus = $this->settings->getConnectionStatus(); + + if (!$connectionStatus) { + $defaultSection = PageNoApiKey::slug(); + } + + if ($connectionStatus && $defaultSection === PageNoApiKey::slug()) { + $defaultSection = PageApiKeys::slug(); + } + + if ($defaultSection === '') { + $defaultSection = PageApiKeys::slug(); + } + $mollieSettings = null; foreach ($this->pages() as $pageClass) { /** @var AbstractPage $page */ - $page = new $pageClass($this->settingsHelper, $this->pluginUrl); - if ($page->slug() === $currentSection) { + $page = new $pageClass( + $this->settings, + $this->pluginUrl, + $this->pages(), + $defaultSection, + $connectionStatus, + $this->isTestModeEnabled, + $this->mollieGateways, + $this->paymentMethods, + $this->dataHelper + ); + if ($page::slug() === $defaultSection) { $mollieSettings = $page->settings(); break; } } - if (!$mollieSettings) { - $mollieSettings = (new PageNoApiKey($this->settingsHelper, $this->pluginUrl))->settings(); - } - return apply_filters( - 'woocommerce_get_settings_' . $this->id, - $mollieSettings, - $currentSection + 'woocommerce_get_settings_' . $this->id, + $mollieSettings, + $currentSection ); } + + protected function checkDirectDebitStatus($content): string + { + $hasCustomSepaSettings = $this->paymentMethods["directdebit"]->getProperty('enabled') !== false; + $isSepaEnabled = !$hasCustomSepaSettings || $this->paymentMethods["directdebit"]->getProperty('enabled') === 'yes'; + $sepaGatewayAllowed = !empty($this->registeredGateways["mollie_wc_gateway_directdebit"]); + if ($sepaGatewayAllowed && !$isSepaEnabled) { + $warning_message = __( + "You have WooCommerce Subscriptions activated, but not SEPA Direct Debit. Enable SEPA Direct Debit if you want to allow customers to pay subscriptions with iDEAL and/or other 'first' payment methods.", + 'mollie-payments-for-woocommerce' + ); + + $content .= '

'; + $content .= $warning_message; + $content .= '

'; + + return $content; + } + + return $content; + } + + /** + * @param $content + * + * @return string + */ + protected function checkMollieBankTransferNotBACS($content): string + { + $woocommerce_banktransfer_gateway = new WC_Gateway_BACS(); + + if ($woocommerce_banktransfer_gateway->is_available()) { + $content .= '

'; + $content .= __( + 'You have the WooCommerce default Direct Bank Transfer (BACS) payment gateway enabled in WooCommerce. Mollie strongly advices only using Bank Transfer via Mollie and disabling the default WooCommerce BACS payment gateway to prevent possible conflicts.', + 'mollie-payments-for-woocommerce' + ); + $content .= '

'; + + return $content; + } + + return $content; + } + + /** + * @param $content + * + * @return string + */ + protected function warnAboutRequiredCheckoutFieldForKlarna($content): string + { + $isKlarnaEnabled = $this->isKlarnaEnabled(); + if ($isKlarnaEnabled) { + $content .= '

'; + $content .= sprintf( + /* translators: Placeholder 1: Opening link tag. Placeholder 2: Closing link tag. Placeholder 3: Opening link tag. Placeholder 4: Closing link tag. */ + __( + 'You have activated Klarna. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. For more information, go to %1$sKlarna Pay Later documentation%2$s or %3$sKlarna Slice it documentation%4$s', + 'mollie-payments-for-woocommerce' + ), + '', + '', + '', + '' + ); + $content .= '

'; + + return $content; + } + + return $content; + } + + protected function isKlarnaEnabled(): bool + { + $klarnaGateways = [Constants::KLARNAPAYLATER, Constants::KLARNASLICEIT, Constants::KLARNAPAYNOW, Constants::KLARNA]; + $isKlarnaEnabled = false; + foreach ($klarnaGateways as $klarnaGateway) { + if ( + array_key_exists('mollie_wc_gateway_' . $klarnaGateway, $this->mollieGateways) + && array_key_exists($klarnaGateway, $this->paymentMethods) + && $this->paymentMethods[$klarnaGateway]->getProperty('enabled') === 'yes' + ) { + $isKlarnaEnabled = true; + break; + } + } + return $isKlarnaEnabled; + } } diff --git a/src/Settings/Page/MollieSettingsPageOld.php b/src/Settings/MollieSettingsPageOld.php similarity index 100% rename from src/Settings/Page/MollieSettingsPageOld.php rename to src/Settings/MollieSettingsPageOld.php diff --git a/src/Settings/Page/AbstractPage.php b/src/Settings/Page/AbstractPage.php index 5a9864cf3..86ce33627 100644 --- a/src/Settings/Page/AbstractPage.php +++ b/src/Settings/Page/AbstractPage.php @@ -6,25 +6,50 @@ use Mollie\WooCommerce\Settings\Page\Section\AbstractSection; use Mollie\WooCommerce\Settings\Settings; +use Mollie\WooCommerce\Shared\Data; abstract class AbstractPage { protected Settings $settings; protected string $pluginUrl; + protected string $currentSection; + protected bool $connectionStatus; + protected bool $testModeEnabled; + protected array $pages; + protected array $mollieGateways; + protected array $paymentMethods; + protected Data $dataHelper; + + public function __construct( + Settings $settings, + string $pluginUrl, + array $pages, + string $currentSection, + bool $connectionStatus, + bool $testModeEnabled, + array $mollieGateways, + array $paymentMethods, + Data $dataHelper + ) { - public function __construct(Settings $settings, string $pluginUrl) - { $this->settings = $settings; $this->pluginUrl = $pluginUrl; + $this->currentSection = $currentSection; + $this->connectionStatus = $connectionStatus; + $this->testModeEnabled = $testModeEnabled; + $this->pages = $pages; + $this->mollieGateways = $mollieGateways; + $this->paymentMethods = $paymentMethods; + $this->dataHelper = $dataHelper; } - abstract public function isTab(): bool; + abstract public static function isTab(): bool; - abstract public function slug(): string; + abstract public static function slug(): string; - public function tabName(): string + public static function tabName(): string { - return ''; + return 'tabName'; } protected function sections(): array @@ -39,16 +64,26 @@ public function settings(): array foreach ($this->sections() as $sectionClass) { /** @var AbstractSection $section */ - $section = new $sectionClass($this->settings, $this->pluginUrl); + $section = new $sectionClass( + $this->settings, + $this->pluginUrl, + $this->pages, + $this->currentSection, + $this->connectionStatus, + $this->testModeEnabled, + $this->mollieGateways, + $this->paymentMethods, + $this->dataHelper + ); foreach ($section->config() as $field) { $settings[] = $field; } - $styles[$sectionClass] = preg_replace('/\s+/', '', $section->styles()); + $styles[$sectionClass] = $section->styles(); } array_unshift($settings, [ 'id' => $this->settings->getSettingId('styles'), 'type' => 'mollie_content', - 'value' => implode($styles) + 'value' => implode($styles), ]); return $settings; } diff --git a/src/Settings/Page/PageAdvancedSettings.php b/src/Settings/Page/PageAdvancedSettings.php index 5f21e8b09..8f9aaadab 100644 --- a/src/Settings/Page/PageAdvancedSettings.php +++ b/src/Settings/Page/PageAdvancedSettings.php @@ -4,15 +4,36 @@ namespace Mollie\WooCommerce\Settings\Page; -class PageAdvancedSettings extends AbstractPage { +use Mollie\WooCommerce\Settings\Page\Section\Advanced; +use Mollie\WooCommerce\Settings\Page\Section\ConnectionFields; +use Mollie\WooCommerce\Settings\Page\Section\Header; +use Mollie\WooCommerce\Settings\Page\Section\Notices; +use Mollie\WooCommerce\Settings\Page\Section\Tabs; - public function isTab(): bool +class PageAdvancedSettings extends AbstractPage +{ + public static function isTab(): bool { - // TODO: Implement isTab() method. + return true; } - public function slug(): string + public static function tabName(): string + { + return __('Advanced settings', 'mollie-payments-for-woocommerce'); + } + + public static function slug(): string { return 'mollie_advanced'; } + + public function sections(): array + { + return [ + Header::class, + Notices::class, + Tabs::class, + Advanced::class + ]; + } } diff --git a/src/Settings/Page/PageApiKeys.php b/src/Settings/Page/PageApiKeys.php index b393248c5..99fcd7b56 100644 --- a/src/Settings/Page/PageApiKeys.php +++ b/src/Settings/Page/PageApiKeys.php @@ -4,15 +4,38 @@ namespace Mollie\WooCommerce\Settings\Page; -class PageApiKeys extends AbstractPage { +use Mollie\WooCommerce\Settings\Page\Section\ConnectionFields; +use Mollie\WooCommerce\Settings\Page\Section\Header; +use Mollie\WooCommerce\Settings\Page\Section\InstructionsNotConnected; +use Mollie\WooCommerce\Settings\Page\Section\InstructionsConnected; +use Mollie\WooCommerce\Settings\Page\Section\Notices; +use Mollie\WooCommerce\Settings\Page\Section\Tabs; - public function isTab(): bool +class PageApiKeys extends AbstractPage +{ + public static function isTab(): bool { - // TODO: Implement isTab() method. + return true; } - public function slug(): string + public static function slug(): string { return 'mollie_api_keys'; } + + public static function tabName(): string + { + return __('API keys', 'mollie-payments-for-woocommerce'); + } + + public function sections(): array + { + return [ + Header::class, + Notices::class, + Tabs::class, + InstructionsConnected::class, + ConnectionFields::class, + ]; + } } diff --git a/src/Settings/Page/PageNoApiKey.php b/src/Settings/Page/PageNoApiKey.php index 4763e18df..172b01ca0 100644 --- a/src/Settings/Page/PageNoApiKey.php +++ b/src/Settings/Page/PageNoApiKey.php @@ -6,16 +6,17 @@ 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\InstructionsNotConnected; use Mollie\WooCommerce\Settings\Page\Section\Notices; -class PageNoApiKey extends AbstractPage { - public function isTab(): bool +class PageNoApiKey extends AbstractPage +{ + public static function isTab(): bool { - // TODO: Implement isTab() method. + return false; } - public function slug(): string + public static function slug(): string { return 'mollie_no_api_key'; } @@ -25,8 +26,8 @@ public function sections(): array return [ Header::class, Notices::class, - Instructions::class, - ConnectionFields::class + InstructionsNotConnected::class, + ConnectionFields::class, ]; } } diff --git a/src/Settings/Page/PagePaymentMethods.php b/src/Settings/Page/PagePaymentMethods.php index f15c9f460..04eb9d684 100644 --- a/src/Settings/Page/PagePaymentMethods.php +++ b/src/Settings/Page/PagePaymentMethods.php @@ -4,15 +4,37 @@ namespace Mollie\WooCommerce\Settings\Page; -class PagePaymentMethods extends AbstractPage { +use Mollie\WooCommerce\Settings\Page\Section\ConnectionStatusFields; +use Mollie\WooCommerce\Settings\Page\Section\Header; +use Mollie\WooCommerce\Settings\Page\Section\Notices; +use Mollie\WooCommerce\Settings\Page\Section\PaymentMethods; +use Mollie\WooCommerce\Settings\Page\Section\Tabs; - public function isTab(): bool +class PagePaymentMethods extends AbstractPage +{ + public static function isTab(): bool { - // TODO: Implement isTab() method. + return true; } - public function slug(): string + public static function tabName(): string + { + return __('Payment methods', 'mollie-payments-for-woocommerce'); + } + + public static function slug(): string { return 'mollie_payment_methods'; } + + public function sections(): array + { + return [ + Header::class, + Notices::class, + Tabs::class, + ConnectionStatusFields::class, + PaymentMethods::class, + ]; + } } diff --git a/src/Settings/Page/Section/AbstractSection.php b/src/Settings/Page/Section/AbstractSection.php index 89549ae76..2a47e23c8 100644 --- a/src/Settings/Page/Section/AbstractSection.php +++ b/src/Settings/Page/Section/AbstractSection.php @@ -5,21 +5,47 @@ namespace Mollie\WooCommerce\Settings\Page\Section; use Mollie\WooCommerce\Settings\Settings; +use Mollie\WooCommerce\Shared\Data; abstract class AbstractSection { protected Settings $settings; protected string $pluginUrl; + protected string $currentSection; + protected bool $connectionStatus; + protected bool $testModeEnabled; + protected array $pages; + protected array $mollieGateways; + protected array $paymentMethods; + protected Data $dataHelper; + + public function __construct( + Settings $settings, + string $pluginUrl, + array $pages, + string $currentSection, + bool $connectionStatus, + bool $testModeEnabled, + array $mollieGateways, + array $paymentMethods, + Data $dataHelper + ) { - public function __construct(Settings $settings, string $pluginUrl) - { $this->settings = $settings; $this->pluginUrl = $pluginUrl; + $this->currentSection = $currentSection; + $this->connectionStatus = $connectionStatus; + $this->testModeEnabled = $testModeEnabled; + $this->pages = $pages; + $this->mollieGateways = $mollieGateways; + $this->paymentMethods = $paymentMethods; + $this->dataHelper = $dataHelper; } abstract public function config(): array; - public function styles(): string{ + public function styles(): string + { return ''; } diff --git a/src/Settings/Page/Section/Advanced.php b/src/Settings/Page/Section/Advanced.php new file mode 100644 index 000000000..e8a4637ac --- /dev/null +++ b/src/Settings/Page/Section/Advanced.php @@ -0,0 +1,231 @@ + $this->settings->getSettingId('title'), + 'title' => __('Mollie advanced settings', 'mollie-payments-for-woocommerce'), + 'type' => 'title', + 'desc' => '

' . __('The following options are required to use the plugin and are used by all Mollie payment methods', 'mollie-payments-for-woocommerce') . '

', + ], + [ + 'id' => $this->settings->getSettingId('order_status_cancelled_payments'), + 'title' => __('Order status after cancelled payment', 'mollie-payments-for-woocommerce'), + 'type' => 'select', + 'options' => [ + 'pending' => __('Pending', 'woocommerce'), + 'cancelled' => __('Cancelled', 'woocommerce'), + ], + 'desc' => __('Status for orders when a payment (not a Mollie order via the Orders API) is cancelled. Default: pending. Orders with status Pending can be paid with another payment method, customers can try again. Cancelled orders are final. Set this to Cancelled if you only have one payment method or don\'t want customers to re-try paying with a different payment method. This doesn\'t apply to payments for orders via the new Orders API and Klarna payments.', 'mollie-payments-for-woocommerce'), + 'default' => 'pending', + ], + [ + 'id' => $this->settings->getSettingId(SharedDataDictionary::SETTING_NAME_PAYMENT_LOCALE), + 'title' => __('Payment screen language', 'mollie-payments-for-woocommerce'), + 'type' => 'select', + 'options' => [ + SharedDataDictionary::SETTING_LOCALE_WP_LANGUAGE => __( + 'Automatically send WordPress language', + 'mollie-payments-for-woocommerce' + ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', + SharedDataDictionary::SETTING_LOCALE_DETECT_BY_BROWSER => __( + 'Detect using browser language', + 'mollie-payments-for-woocommerce' + ), + 'en_US' => __('English', 'mollie-payments-for-woocommerce'), + 'nl_NL' => __('Dutch', 'mollie-payments-for-woocommerce'), + 'nl_BE' => __('Flemish (Belgium)', 'mollie-payments-for-woocommerce'), + 'fr_FR' => __('French', 'mollie-payments-for-woocommerce'), + 'fr_BE' => __('French (Belgium)', 'mollie-payments-for-woocommerce'), + 'de_DE' => __('German', 'mollie-payments-for-woocommerce'), + 'de_AT' => __('Austrian German', 'mollie-payments-for-woocommerce'), + 'de_CH' => __('Swiss German', 'mollie-payments-for-woocommerce'), + 'es_ES' => __('Spanish', 'mollie-payments-for-woocommerce'), + 'ca_ES' => __('Catalan', 'mollie-payments-for-woocommerce'), + 'pt_PT' => __('Portuguese', 'mollie-payments-for-woocommerce'), + 'it_IT' => __('Italian', 'mollie-payments-for-woocommerce'), + 'nb_NO' => __('Norwegian', 'mollie-payments-for-woocommerce'), + 'sv_SE' => __('Swedish', 'mollie-payments-for-woocommerce'), + 'fi_FI' => __('Finnish', 'mollie-payments-for-woocommerce'), + 'da_DK' => __('Danish', 'mollie-payments-for-woocommerce'), + 'is_IS' => __('Icelandic', 'mollie-payments-for-woocommerce'), + 'hu_HU' => __('Hungarian', 'mollie-payments-for-woocommerce'), + 'pl_PL' => __('Polish', 'mollie-payments-for-woocommerce'), + 'lv_LV' => __('Latvian', 'mollie-payments-for-woocommerce'), + 'lt_LT' => __('Lithuanian', 'mollie-payments-for-woocommerce'), + ], + 'desc' => sprintf( + /* translators: Placeholder 1: link tag Placeholder 2: closing tag */ + __('Sending a language (or locale) is required. The option \'Automatically send WordPress language\' will try to get the customer\'s language in WordPress (and respects multilanguage plugins) and convert it to a format Mollie understands. If this fails, or if the language is not supported, it will fall back to American English. You can also select one of the locales currently supported by Mollie, that will then be used for all customers.', 'mollie-payments-for-woocommerce'), + '', + '' + ), + 'default' => SharedDataDictionary::SETTING_LOCALE_WP_LANGUAGE, + ], + [ + 'id' => $this->settings->getSettingId('customer_details'), + 'title' => __('Store customer details at Mollie', 'mollie-payments-for-woocommerce'), + 'desc' => sprintf( + /* translators: Placeholder 1: enabled or disabled Placeholder 2: translated string */ + __( + 'Should Mollie store customers name and email address for Single Click Payments? Default %1$s. Required if WooCommerce Subscriptions is being used! Read more about %2$s and how it improves your conversion.', + 'mollie-payments-for-woocommerce' + ), + strtolower(__('Enabled', 'mollie-payments-for-woocommerce')), + __('Single Click Payments', 'mollie-payments-for-woocommerce') + ), + 'type' => 'checkbox', + 'default' => 'yes', + + ], + [ + 'id' => $this->settings->getSettingId('api_switch'), + 'title' => __( + 'Select API Method', + 'mollie-payments-for-woocommerce' + ), + 'type' => 'select', + 'options' => [ + PaymentService::PAYMENT_METHOD_TYPE_ORDER => ucfirst( + PaymentService::PAYMENT_METHOD_TYPE_ORDER + ) . ' (' . __('default', 'mollie-payments-for-woocommerce') + . ')', + PaymentService::PAYMENT_METHOD_TYPE_PAYMENT => ucfirst( + PaymentService::PAYMENT_METHOD_TYPE_PAYMENT + ), + ], + 'default' => PaymentService::PAYMENT_METHOD_TYPE_ORDER, + 'desc' => sprintf( + /* translators: Placeholder 1: opening link tag, placeholder 2: closing link tag */ + __( + 'Click %1$shere%2$s to read more about the differences between the Payments and Orders API', + 'mollie-payments-for-woocommerce' + ), + '', + '' + ), + ], + [ + 'id' => $this->settings->getSettingId('api_payment_description'), + 'title' => __( + 'API Payment Description', + 'mollie-payments-for-woocommerce' + ), + 'type' => 'text', + 'default' => '{orderNumber}', + 'desc' => sprintf( + '

+
+

%1$s:

+ +
+
+

%3$s', + _x('Available variables', 'Payment description options', 'mollie-payments-for-woocommerce'), + implode('', array_map( + static function ($label, $labelDescription) { + return sprintf( + '

  • + +
  • ', + $label, + substr($label, 1, -1), + $labelDescription + ); + }, + array_keys($this->paymentDescriptionLabels()), + $this->paymentDescriptionLabels() + )), + sprintf( + /* translators: Placeholder 1: Opening paragraph tag, placeholder 2: Closing paragraph tag */ + __( + 'Select among the available variables the description to be used for this transaction.%1$s(Note: this only works when the method is set to Payments API)%2$s', + 'mollie-payments-for-woocommerce' + ), + '

    ', + '

    ' + ) + ), + ], + [ + 'id' => $this->settings->getSettingId('gatewayFeeLabel'), + 'title' => __( + 'Surcharge gateway fee label', + 'mollie-payments-for-woocommerce' + ), + 'type' => 'text', + 'custom_attributes' => ['maxlength' => '30'], + 'default' => __('Gateway Fee', 'mollie-payments-for-woocommerce'), + 'desc' => __( + 'This is the label will appear in frontend when the surcharge applies', + 'mollie-payments-for-woocommerce' + ), + ], + [ + 'id' => $this->settings->getSettingId('removeOptionsAndTransients'), + 'title' => __( + 'Remove Mollie data from Database on uninstall', + 'mollie-payments-for-woocommerce' + ), + 'type' => 'checkbox', + 'default' => 'no', + 'desc' => __("Remove options and scheduled actions from database when uninstalling the plugin.", "mollie-payments-for-woocommerce") . ' (' . strtolower( + __('Clear now', 'mollie-payments-for-woocommerce') + ) . ')', + ], + [ + 'id' => $this->settings->getSettingId('sectionend'), + 'type' => 'sectionend', + ], + ]; + + return apply_filters( + 'inpsyde.mollie-advanced-settings', + $config, + $this->settings->getPluginId() + ); + } + + protected function paymentDescriptionLabels(): array{ + return [ + '{orderNumber}' => _x('Order number', 'Label {orderNumber} description for payment description options', 'mollie-payments-for-woocommerce'), + '{storeName}' => _x('Site Title', 'Label {storeName} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.firstname}' => _x('Customer\'s first name', 'Label {customer.firstname} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.lastname}' => _x('Customer\'s last name', 'Label {customer.lastname} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.company}' => _x('Customer\'s company name', 'Label {customer.company} description for payment description options', 'mollie-payments-for-woocommerce'), + ]; + } + + protected function cleanDbUrl(): string{ + return add_query_arg( + ['cleanDB-mollie' => 1, 'nonce_mollie_cleanDb' => wp_create_nonce('nonce_mollie_cleanDb')] + ); + } + + protected function content(): string + { + ob_start(); + ?> + $this->settings->getSettingId('title'), 'title' => '', - 'type' => 'title' + 'type' => 'title', ], + $this->connectionStatusField($this->settings, $this->connectionStatus), [ 'id' => $this->settings->getSettingId('test_mode_enabled'), 'title' => __('Mollie Payment Mode', 'mollie-payments-for-woocommerce'), @@ -21,8 +24,12 @@ public function config(): array 'type' => 'select', 'options' => [ 'no' => 'Live API', - 'yes' => 'Test API' + 'yes' => 'Test API', ], + 'desc' => __( + 'Select Live API to receive real payments and Test API to test transactions without a fee.', + 'mollie-payments-for-woocommerce' + ), 'desc_tip' => __( 'Enable test mode if you want to test the plugin without using real payments.', 'mollie-payments-for-woocommerce' @@ -34,14 +41,11 @@ public function config(): array 'default' => '', 'type' => 'text', 'desc' => sprintf( - /* translators: Placeholder 1: API key mode (live or test). The surrounding %s's Will be replaced by a link to the Mollie profile */ __( - 'The API key is used to connect to Mollie. You can find your %1$s API key in your %2$sMollie account%3$s', + "Use your Live API key when you're ready to receive real payments.", 'mollie-payments-for-woocommerce' ), - 'live', - '', - '' + 'https://my.mollie.com/dashboard/developers/api-keys?utm_source=woocommerce&utm_medium=plugin&utm_campaign=partner' ), 'css' => 'width: 350px', 'placeholder' => __( @@ -55,14 +59,11 @@ public function config(): array 'default' => '', 'type' => 'text', 'desc' => sprintf( - /* translators: Placeholder 1: API key mode (live or test). The surrounding %s's Will be replaced by a link to the Mollie profile */ __( - 'The API key is used to connect to Mollie. You can find your %1$s API key in your %2$sMollie account%3$s', + "Use your Test APl key to check the connection and test transactions without a fee.", 'mollie-payments-for-woocommerce' ), - 'test', - '', - '' + 'https://my.mollie.com/dashboard/developers/api-keys?utm_source=woocommerce&utm_medium=plugin&utm_campaign=partner' ), 'css' => 'width: 350px', 'placeholder' => __( @@ -74,7 +75,13 @@ public function config(): array 'id' => $this->settings->getSettingId('debug'), 'title' => __('Debug Log', 'mollie-payments-for-woocommerce'), 'type' => 'checkbox', - 'desc' => __('Log plugin events.', 'mollie-payments-for-woocommerce'), + 'desc' => sprintf( + __( + "Log plugin events. View logs", + 'mollie-payments-for-woocommerce' + ), + $this->settings->getLogsUrl() + ), 'default' => 'yes', ], [ diff --git a/src/Settings/Page/Section/ConnectionStatusFields.php b/src/Settings/Page/Section/ConnectionStatusFields.php new file mode 100644 index 000000000..68312324d --- /dev/null +++ b/src/Settings/Page/Section/ConnectionStatusFields.php @@ -0,0 +1,46 @@ + $this->settings->getSettingId('title'), + 'title' => '', + 'type' => 'title', + ], + $this->connectionStatusField($this->settings, $this->connectionStatus), + $this->refreshStatusField(), + [ + 'id' => $this->settings->getSettingId('sectionend'), + 'type' => 'sectionend', + ], + ]; + } + + public function refreshStatusField(): array + { + $refreshNonce = wp_create_nonce('nonce_mollie_refresh_methods'); + $refreshUrl = add_query_arg( + ['refresh-methods' => 1, 'nonce_mollie_refresh_methods' => $refreshNonce] + ); + + return [ + 'id' => $this->settings->getSettingId('refresh_status'), + 'title' => __('Payment method availability', 'mollie-payments-for-woocommerce'), + 'value' => '' . __('Refresh Mollie payment methods', 'mollie-payments-for-woocommerce') . '', + 'desc' => __( + 'Click this button to refresh your payment methods, e.g. if you recently enabled new payment methods in your Mollie profile', + 'mollie-payments-for-woocommerce' + ), + 'type' => 'mollie_custom_input', + ]; + } +} diff --git a/src/Settings/Page/Section/ConnectionStatusTrait.php b/src/Settings/Page/Section/ConnectionStatusTrait.php new file mode 100644 index 000000000..ff1c0514c --- /dev/null +++ b/src/Settings/Page/Section/ConnectionStatusTrait.php @@ -0,0 +1,36 @@ + $settings->getSettingId('connection_status'), + 'title' => __('Mollie Connection Status', 'mollie-payments-for-woocommerce'), + 'value' => $this->connectionStatus($settings, $connectionStatus), + 'type' => 'mollie_custom_input', + ]; + } + + protected function connectionStatus(Settings $settings, bool $connectionStatus): ?string + { + $testMode = $settings->isTestModeEnabled(); + if (!$connectionStatus) { + return __( + 'Failed to connect to Mollie API - check your API keys ✖', + 'mollie-payments-for-woocommerce' + ); + } + if ($testMode) { + return __('Successfully connected with Test API ✓', 'mollie-payments-for-woocommerce'); + } + return __('Successfully connected with Live API ✓', 'mollie-payments-for-woocommerce'); + } +} diff --git a/src/Settings/Page/Section/Header.php b/src/Settings/Page/Section/Header.php index c6408fcea..0f07b0309 100644 --- a/src/Settings/Page/Section/Header.php +++ b/src/Settings/Page/Section/Header.php @@ -10,10 +10,10 @@ public function config(): array { return [ [ - 'id' => $this->settings->getSettingId('header'), - 'type' => 'mollie_content', - 'value' => $this->content() - ] + 'id' => $this->settings->getSettingId('header'), + 'type' => 'mollie_content', + 'value' => $this->content(), + ], ]; } @@ -62,8 +62,8 @@ protected function content(): string

    diff --git a/src/Settings/Page/Section/InstructionsConnected.php b/src/Settings/Page/Section/InstructionsConnected.php new file mode 100644 index 000000000..689e9dbf8 --- /dev/null +++ b/src/Settings/Page/Section/InstructionsConnected.php @@ -0,0 +1,46 @@ + $this->settings->getSettingId('instructions'), + 'type' => 'mollie_content', + 'value' => $this->content(), + ], + ]; + } + + protected function content(): string + { + ob_start(); + ?> +

    +

    + API key.", + 'mollie-payments-for-woocommerce' + ), + 'https://my.mollie.com/dashboard/developers/api-keys?utm_source=woocommerce&utm_medium=plugin&utm_campaign=partner' + ); ?> +

    +

    + +

    + $this->settings->getSettingId('instructions'), 'type' => 'mollie_content', - 'value' => $this->content() - ] + 'value' => $this->content(), + ], ]; } @@ -24,9 +24,9 @@ protected function content(): string

    @@ -37,11 +37,11 @@ protected function content(): string

    1. Mollie Dashboard", - 'mollie-payments-for-woocommerce' - ), - 'https://my.mollie.com/dashboard/login?lang=en' + __( + "Log in to your Mollie Dashboard", + 'mollie-payments-for-woocommerce' + ), + 'https://my.mollie.com/dashboard/login?lang=en' ); ?>
    2. @@ -52,16 +52,16 @@ protected function content(): string
    3. Live API key or Test API key fields below.", - 'mollie-payments-for-woocommerce' + "Paste the copied API key into the Live API key or Test API key fields below.", + 'mollie-payments-for-woocommerce' ); ?>

    $this->settings->getSettingId('notices'), - 'type' => 'mollie_content', - 'value' => $this->content() - ] + 'id' => $this->settings->getSettingId('notices'), + 'type' => 'mollie_content', + 'value' => $this->content(), + ], ]; } diff --git a/src/Settings/Page/Section/PaymentMethods.php b/src/Settings/Page/Section/PaymentMethods.php new file mode 100644 index 000000000..9bf80ea80 --- /dev/null +++ b/src/Settings/Page/Section/PaymentMethods.php @@ -0,0 +1,246 @@ + $this->settings->getSettingId('notices'), + 'type' => 'mollie_content', + 'value' => $this->content(), + ], + ]; + } + + protected function content(): string + { + ob_start(); + ?> +
    +
    + renderGateways(); ?> +
    +
    + refreshIfRequested(); + $this->cleanDbIfRequested(); + + $messageEnabled = '' . __( + 'enabled', + 'mollie-payments-for-woocommerce' + ) . ''; + + $messageDisabled = '' . __( + 'disabled', + 'mollie-payments-for-woocommerce' + ) . ''; + + $titleActivePaymentMethods = __( + 'Currently Active Payment Methods', + 'mollie-payments-for-woocommerce' + ); + $descriptionActivePaymentMethods = __( + 'These payment methods are active in your Mollie profile. + You can enable these payment methods in their settings to make them available for your customers.', + 'mollie-payments-for-woocommerce' + ); + $titleInactivePaymentMethods = __('Inactive Payment Methods', 'mollie-payments-for-woocommerce'); + $descriptionInactivePaymentMethods = __( + 'These payment methods are available in your Mollie profile but are + not currently active. Activate them to offer more payment options to your customers.', + 'mollie-payments-for-woocommerce' + ); + + $activatedGateways = ''; + $deactivatedGateways = ''; + + /** @var AbstractPaymentMethod $paymentMethod */ + foreach ($this->paymentMethods as $paymentMethod) { + $paymentMethodId = $paymentMethod->getProperty('id'); + $gatewayKey = 'mollie_wc_gateway_' . $paymentMethodId; + $enabledAtMollie = array_key_exists($gatewayKey, $this->mollieGateways); + $enabledInWoo = ($paymentMethod->getSettings())['enabled'] === 'yes'; + $paymentGatewayButton = '
    '; + $paymentGatewayButton .= $paymentMethod->getIconUrl(); + $paymentGatewayButton .= $paymentMethod->title(); + $documentationLink = $paymentMethod->getProperty('docs'); + $moreInformation = ''; + + if ($documentationLink) { + $moreInformation = "" . __( + 'More information', + 'mollie-payments-for-woocommerce' + ) . ''; + } + + if ($enabledAtMollie) { + if ($enabledInWoo) { + $paymentGatewayButton .= $messageEnabled; + } else { + $paymentGatewayButton .= $messageDisabled; + } + $paymentGatewayButton .= '' . __( + 'Manage Payment Method', + 'mollie-payments-for-woocommerce' + ) . ''; + } else { + $paymentGatewayButton .= $moreInformation; + $paymentGatewayButton .= ' ' . + __('Activate Payment Method', 'mollie-payments-for-woocommerce') + . ''; + } + + $paymentGatewayButton .= '
    '; + if ($enabledAtMollie) { + $activatedGateways .= $paymentGatewayButton; + } else { + $deactivatedGateways .= $paymentGatewayButton; + } + } + + return $this->paymentGatewaysBlock( + $titleActivePaymentMethods, + $descriptionActivePaymentMethods, + $activatedGateways + ) . $this->paymentGatewaysBlock( + $titleInactivePaymentMethods, + $descriptionInactivePaymentMethods, + $deactivatedGateways + ); + } + + protected function paymentGatewaysBlock(string $title, string $description, string $html): string + { + ob_start(); + ?> +
    +

    +

    +
    + +
    +
    + + + + testModeEnabled; + $apiKey = $this->settings->getApiKey(); + /* Reload active Mollie methods */ + $methods = $this->dataHelper->getAllPaymentMethods($apiKey, $testMode, false); + foreach ($methods as $key => $method) { + $methods['mollie_wc_gateway_' . $method['id']] = $method; + unset($methods[$key]); + } + $this->mollieGateways = $methods; + } + } + + protected function cleanDbIfRequested() + { + + if ( + isset($_GET['cleanDB-mollie']) && wp_verify_nonce( + filter_input(INPUT_GET, 'nonce_mollie_cleanDb', FILTER_SANITIZE_SPECIAL_CHARS), + 'nonce_mollie_cleanDb' + ) + ) { + $cleaner = $this->settings->cleanDb(); + $cleaner->cleanAll(); + //set default settings + foreach ($this->paymentMethods as $paymentMethod) { + $paymentMethod->getSettings(); + } + } + } +} diff --git a/src/Settings/Page/Section/Tabs.php b/src/Settings/Page/Section/Tabs.php new file mode 100644 index 000000000..4e373d444 --- /dev/null +++ b/src/Settings/Page/Section/Tabs.php @@ -0,0 +1,45 @@ + $this->settings->getSettingId('notices'), + 'type' => 'mollie_content', + 'value' => $this->content(), + ], + ]; + } + + protected function content(): string + { + + $content = ''; + + return $content; + } + + protected function pageUrl(string $sectionId): string + { + return admin_url('admin.php?page=wc-settings&tab=mollie_settings§ion=' . sanitize_title($sectionId)); + } +} diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index c93589641..2d03aa453 100644 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -332,7 +332,7 @@ public function isDebugEnabled() /** * @return string */ - public function getLogsUrl() + public function getLogsUrl(): string { return admin_url('admin.php?page=wc-status&tab=logs'); } @@ -384,6 +384,24 @@ public function updateMerchantIdAfterApiKeyChanges($oldValue, $value, $optionNam $this->updateMerchantIdOnApiKeyChanges($value, $option); } + public function getConnectionStatus(): bool + { + + $status = $this->statusHelper; + if (!$status->isCompatible()) { + return false; + } + + try { + $apiKey = $this->getApiKey(); + $apiClient = $this->apiHelper->getApiClient($apiKey); + $status->getMollieApiStatus($apiClient); + return true; + } catch (\Mollie\Api\Exceptions\ApiException $e) { + return false; + } + } + /** * Get plugin status * @@ -447,6 +465,10 @@ public function getPaymentConfirmationCheckTime() return $date->getTimestamp(); } + public function getPluginId() + { + return $this->pluginId; + } /** * @param string $setting *