Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions controllers/admin/AdminSaferPayOfficialSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Invertus\SaferPay\Service\SaferPayRestrictionCreator;
use Invertus\SaferPay\Exception\Api\SaferPayApiException;
use Invertus\SaferPay\Exception\Restriction\RestrictionException;
use Invertus\SaferPay\Logger\LoggerInterface;

require_once dirname(__FILE__) . '/../../vendor/autoload.php';

Expand Down Expand Up @@ -209,8 +210,8 @@ public function ajaxProcessSaveCredentials()

// Auto-detect license features from Saferpay Management API
$suffix = $isTestMode ? SaferPayConfig::TEST_SUFFIX : '';
$licenseMessage = '';
$hasBusinessLicense = false;
$licenseFetchFailed = false;

if (!empty($activeUsername) && !empty($activePassword) && !empty($activeCustomerId)) {
try {
Expand All @@ -227,18 +228,28 @@ public function ajaxProcessSaveCredentials()
$configuration->set(SaferPayConfig::BUSINESS_LICENSE . $suffix, $hasBusinessLicense ? 1 : 0);
} catch (\Exception $e) {
$configuration->set(SaferPayConfig::BUSINESS_LICENSE . $suffix, 0);
$licenseFetchFailed = true;

$licenseMessage = ' ' . $this->module->l('Could not retrieve license information. Please verify your credentials.', self::FILE_NAME);
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);
$logger->error('License fetch failed on credentials save: ' . $e->getMessage(), [
'context' => ['exception_class' => get_class($e)],
]);
Comment on lines +235 to +237

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The LoggerInterface extends \Psr\Log\LoggerInterface, which follows the PSR-3 standard. In PSR-3, the second argument to logging methods is the context array itself. Wrapping the context data in a redundant 'context' key is unnecessary and may lead to nested structures in the log output (e.g., context.context.exception_class instead of context.exception_class).

                $logger->error('License fetch failed on credentials save: ' . $e->getMessage(), [
                    'exception_class' => get_class($e),
                ]);

}
} else {
$configuration->set(SaferPayConfig::BUSINESS_LICENSE . $suffix, 0);
}

$message = $licenseFetchFailed
? $this->module->l('Settings saved, but Saferpay Fields availability could not be confirmed. Please try again later or check the module Logs for details.', self::FILE_NAME)
: $this->module->l('Settings saved successfully.', self::FILE_NAME);

$this->ajaxResponse(
true,
$this->module->l('Settings saved successfully.', self::FILE_NAME) . $licenseMessage,
$message,
[
'hasBusinessLicense' => $hasBusinessLicense,
'warning' => $licenseFetchFailed,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function ToastContainer() {
className={`sp-rounded-lg sp-border sp-px-4 sp-py-3 sp-shadow-lg sp-text-sm sp-animate-in sp-slide-in-from-bottom-2 ${
t.variant === 'destructive'
? 'sp-bg-destructive sp-text-destructive-foreground sp-border-destructive'
: 'sp-bg-emerald-600 sp-text-white sp-border-emerald-700'
: t.variant === 'warning'
? 'sp-bg-amber-500 sp-text-white sp-border-amber-600'
: 'sp-bg-emerald-600 sp-text-white sp-border-emerald-700'
}`}
>
{t.title && <div className="sp-font-medium">{t.title}</div>}
Expand Down
7 changes: 4 additions & 3 deletions views/js/admin/settings-app/src/context/settings-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ export function SettingsProvider({ children }: { children: React.ReactNode }) {
}, [])

const handleSave = useCallback(async (
saveFn: () => Promise<{ success: boolean; message?: string }>,
saveFn: () => Promise<{ success: boolean; message?: string; warning?: boolean }>,
label: string,
section: SavingSection,
) => {
setSavingSections((prev) => new Set(prev).add(section))
try {
const result = await saveFn()
if (result.success) {
toast({ title: result.message || t('savedSuccessfully', label), variant: 'default' })
const variant = result.warning ? 'warning' : 'default'
toast({ title: result.message || t('savedSuccessfully', label), variant })
} else {
toast({ title: result.message || t('failedToSave', label), variant: 'destructive' })
}
Expand Down Expand Up @@ -94,7 +95,7 @@ export function SettingsProvider({ children }: { children: React.ReactNode }) {
if (result.success && typeof data.hasBusinessLicense === 'boolean') {
setSettings((prev) => ({ ...prev, hasBusinessLicense: data.hasBusinessLicense as boolean }))
}
return result
return { ...result, warning: data.warning === true }
}, 'API Credentials', 'credentials')
}, [handleSave])

Expand Down
2 changes: 1 addition & 1 deletion views/js/admin/settings-app/src/hooks/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ToasterToast {
id: string
title?: string
description?: string
variant?: 'default' | 'destructive'
variant?: 'default' | 'destructive' | 'warning'
}

type Action =
Expand Down
Loading