Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Nov 4, 2024
1 parent 4d467ec commit 39d2111
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 63 deletions.
58 changes: 34 additions & 24 deletions src/Settings/MollieSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,40 +206,21 @@ protected function saveApiKeys($settings)
'valueInDb' => get_option('mollie-payments-for-woocommerce_live_api_key'),
'postedValue' => isset($_POST['mollie-payments-for-woocommerce_live_api_key'])
? sanitize_text_field(wp_unslash($_POST['mollie-payments-for-woocommerce_live_api_key']))
: ''
: '',
],
'test' => [
'keyName' => 'mollie-payments-for-woocommerce_test_api_key',
'pattern' => '/^test_\w{30,}$/',
'valueInDb' => get_option('mollie-payments-for-woocommerce_test_api_key'),
'postedValue' => isset($_POST['mollie-payments-for-woocommerce_test_api_key'])
? sanitize_text_field(wp_unslash($_POST['mollie-payments-for-woocommerce_test_api_key']))
: ''
]
: '',
],
];

foreach ($settings as $setting) {
foreach ($apiKeys as $type => $apiKey) {
if ($setting['id'] === $apiKey['keyName']) {
if ($apiKey['postedValue'] === '**********') {
// If placeholder is detected but no DB value, validate as new key
if (!$apiKey['valueInDb']) {
$this->validateApiKeyOrRemove(
$apiKey['pattern'],
'', // No DB value; treat as new
$apiKey['keyName']
);
} else {
$_POST[$apiKey['keyName']] = $apiKey['valueInDb'];
}
} else {
$this->validateApiKeyOrRemove(
$apiKey['pattern'],
$apiKey['postedValue'],
$apiKey['keyName']
);
}
}
foreach ($apiKeys as $apiKey) {
$this->processApiKeys($setting['id'], $apiKey);
}
}
return $settings;
Expand All @@ -266,4 +247,33 @@ protected function validateApiKeyOrRemove($pattern, $value, $keyName)
unset($_POST[$keyName]);
}
}

/**
* @param $id
* @param array $apiKey
* @return void
*/
public function processApiKeys($id, array $apiKey): void
{
if ($id === $apiKey['keyName']) {
if ($apiKey['postedValue'] === '**********') {
// If placeholder is detected but no DB value, validate as new key
if (!$apiKey['valueInDb']) {
$this->validateApiKeyOrRemove(
$apiKey['pattern'],
'', // No DB value; treat as new
$apiKey['keyName']
);
} else {
$_POST[$apiKey['keyName']] = $apiKey['valueInDb'];
}
} else {
$this->validateApiKeyOrRemove(
$apiKey['pattern'],
$apiKey['postedValue'],
$apiKey['keyName']
);
}
}
}
}
15 changes: 7 additions & 8 deletions src/Settings/Page/Section/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function config(): array
'type' => 'select',
'options' => [
SharedDataDictionary::SETTING_LOCALE_WP_LANGUAGE => __(
'Automatically send WordPress language',
'mollie-payments-for-woocommerce'
) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')',
'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'
Expand Down Expand Up @@ -111,8 +111,8 @@ public function config(): array
'type' => 'select',
'options' => [
PaymentService::PAYMENT_METHOD_TYPE_ORDER => ucfirst(
PaymentService::PAYMENT_METHOD_TYPE_ORDER
) . ' (' . __('default', 'mollie-payments-for-woocommerce')
PaymentService::PAYMENT_METHOD_TYPE_ORDER
) . ' (' . __('default', 'mollie-payments-for-woocommerce')
. ')',
PaymentService::PAYMENT_METHOD_TYPE_PAYMENT => ucfirst(
PaymentService::PAYMENT_METHOD_TYPE_PAYMENT
Expand Down Expand Up @@ -203,8 +203,8 @@ class="mollie-settings-advanced-payment-desc-label button button-secondary butto
'type' => 'checkbox',
'default' => 'no',
'desc' => __("Remove options and scheduled actions from database when uninstalling the plugin.", "mollie-payments-for-woocommerce") . ' (<a href="' . esc_url($this->cleanDbUrl()) . '">' . strtolower(
__('Clear now', 'mollie-payments-for-woocommerce')
) . '</a>)',
__('Clear now', 'mollie-payments-for-woocommerce')
) . '</a>)',
],
[
'id' => $this->settings->getSettingId('sectionend'),
Expand Down Expand Up @@ -263,5 +263,4 @@ protected function cleanDbIfRequested()
}
}
}

}
62 changes: 31 additions & 31 deletions src/Settings/Page/Section/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public function renderGateways(): string
$this->refreshIfRequested();

$titleActivePaymentMethods = __(
'Currently Active Payment Methods',
'mollie-payments-for-woocommerce'
'Currently Active Payment Methods',
'mollie-payments-for-woocommerce'
);
$descriptionActivePaymentMethods = __(
'These payment methods are active in your Mollie profile.
'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'
'mollie-payments-for-woocommerce'
);
$titleInactivePaymentMethods = __('Inactive Payment Methods', 'mollie-payments-for-woocommerce');
$descriptionInactivePaymentMethods = __(
'These payment methods are available in your Mollie profile but are
'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'
'mollie-payments-for-woocommerce'
);

$activatedGateways = '';
Expand All @@ -70,14 +70,14 @@ public function renderGateways(): string
}

return $this->paymentGatewaysBlock(
$titleActivePaymentMethods,
$descriptionActivePaymentMethods,
$activatedGateways
) . $this->paymentGatewaysBlock(
$titleInactivePaymentMethods,
$descriptionInactivePaymentMethods,
$deactivatedGateways
);
$titleActivePaymentMethods,
$descriptionActivePaymentMethods,
$activatedGateways
) . $this->paymentGatewaysBlock(
$titleInactivePaymentMethods,
$descriptionInactivePaymentMethods,
$deactivatedGateways
);
}

protected function paymentGatewaysBlock(string $title, string $description, string $html): string
Expand All @@ -98,7 +98,7 @@ protected function paymentGatewaysBlock(string $title, string $description, stri
protected function getGatewaySettingsUrl(string $gatewayClassName): string
{
return admin_url(
'admin.php?page=wc-settings&tab=checkout&section=' . sanitize_title(strtolower($gatewayClassName))
'admin.php?page=wc-settings&tab=checkout&section=' . sanitize_title(strtolower($gatewayClassName))
);
}

Expand Down Expand Up @@ -177,8 +177,8 @@ protected function refreshIfRequested()
isset($_GET['refresh-methods']) &&
isset($_GET['nonce_mollie_refresh_methods']) &&
wp_verify_nonce(
filter_input(INPUT_GET, 'nonce_mollie_refresh_methods', FILTER_SANITIZE_SPECIAL_CHARS),
'nonce_mollie_refresh_methods'
filter_input(INPUT_GET, 'nonce_mollie_refresh_methods', FILTER_SANITIZE_SPECIAL_CHARS),
'nonce_mollie_refresh_methods'
)
) {
$testMode = $this->testModeEnabled;
Expand All @@ -199,30 +199,30 @@ protected function paymentGatewayButton(AbstractPaymentMethod $paymentMethod, $e
$paymentMethodId = $paymentMethod->getProperty('id');
$gatewayKey = 'mollie_wc_gateway_' . $paymentMethodId;
$button = '<a class="button-secondary" href="' . $this->getGatewaySettingsUrl(
$gatewayKey
) . '">' . esc_html(__(
'Manage Payment Method',
'mollie-payments-for-woocommerce'
)) . '</a>';
$gatewayKey
) . '">' . esc_html(__(
'Manage Payment Method',
'mollie-payments-for-woocommerce'
)) . '</a>';
$messageOrLink = '';
$enabledInWoo = ($paymentMethod->getSettings())['enabled'] === 'yes';

if ($enabledInMollie && $enabledInWoo) {
$messageOrLink = '<span class="mollie-settings-pm__status mollie-settings-pm__status--enabled">' . esc_html(__(
'enabled',
'mollie-payments-for-woocommerce'
)) . '</span>';
'enabled',
'mollie-payments-for-woocommerce'
)) . '</span>';
} elseif ($enabledInMollie && !$enabledInWoo) {
$messageOrLink = '<span class="mollie-settings-pm__status mollie-settings-pm__status--disabled">' . esc_html(__(
'disabled',
'mollie-payments-for-woocommerce'
)) . '</span>';
'disabled',
'mollie-payments-for-woocommerce'
)) . '</span>';
} else {
if ($documentationLink) {
$messageOrLink = "<a class='mollie-settings-pm__info' href='" . $documentationLink . "'>" . esc_html(__(
'More information',
'mollie-payments-for-woocommerce'
)) . '</a>';
'More information',
'mollie-payments-for-woocommerce'
)) . '</a>';
}
$button = '<a class="button-secondary" href="https://my.mollie.com/dashboard/settings/profiles?utm_source=woocommerce&utm_medium=plugin&utm_campaign=partner" target="_blank">' .
esc_html(__('Activate Payment Method', 'mollie-payments-for-woocommerce'))
Expand Down

0 comments on commit 39d2111

Please sign in to comment.