Skip to content

Commit

Permalink
fix error messaging in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Jan 10, 2025
1 parent 78e55c2 commit 0094d00
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Controller/Admin/ModuleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private function saveMerchantKey(string $systemMode): void
$oldValue = $this->moduleSettings->getApplePayMerchantCertKey();

$this->setIsUpdate($oldValue, $newValue);
$isValidMerchantKey = $this->validateCredentialsForSaving($oldValue, $newValue, $errorIds);
$isValidMerchantKey = $this->validateCredentialsForSaving($newValue, $errorIds);

if ($isValidMerchantKey) {
$service = $this->getServiceFromContainer(AppleMerchantCertificate::class);
Expand All @@ -315,7 +315,7 @@ private function saveMerchantIdentifier(string $systemMode): void

$this->setIsUpdate($oldValue, $newValue);

$isValid = $this->validateCredentialsForSaving($oldValue, $newValue, $errorIds);
$isValid = $this->validateCredentialsForSaving($newValue, $errorIds);

if ($isValid) {
$this->moduleSettings->setApplePayMerchantIdentifier($newValue);
Expand All @@ -337,7 +337,7 @@ private function saveMerchantCert(string $systemMode): void

$this->setIsUpdate($oldValue, $newValue);

$isValidMerchantCert = $this->validateCredentialsForSaving($oldValue, $newValue, $errorIds);
$isValidMerchantCert = $this->validateCredentialsForSaving($newValue, $errorIds);

if ($isValidMerchantCert) {
$service = $this->getServiceFromContainer(AppleMerchantCertificate::class);
Expand All @@ -362,7 +362,7 @@ private function savePaymentKey(string $systemMode): void
$oldValue = $this->moduleSettings->getApplePayPaymentPrivateKey();

$this->setIsUpdate($oldValue, $newValue);
$isValidPaymentKey = $this->validateCredentialsForSaving($oldValue, $newValue, $errorIds);
$isValidPaymentKey = $this->validateCredentialsForSaving($newValue, $errorIds);

if ($isValidPaymentKey) {
$service = $this->getServiceFromContainer(ApplePaymentProcessingCertificate::class);
Expand All @@ -388,17 +388,17 @@ private function savePaymentCert(string $systemMode): void

$this->setIsUpdate($oldValue, $newValue);

$isValidPaymentKey = $this->validateCredentialsForSaving($oldValue, $newValue, $errorIds);
$isValidPaymentKey = $this->validateCredentialsForSaving($newValue, $errorIds);

if ($isValidPaymentKey) {
$service = $this->getServiceFromContainer(ApplePaymentProcessingCertificate::class);
$service->saveCertificate($newValue);
}
}

private function validateCredentialsForSaving(?string $oldValue, ?string $newValue, array $errors): bool
private function validateCredentialsForSaving(?string $newValue, array $errors): bool
{
if (($newValue === null || strlen($newValue) === 0) && !empty($oldValue)) {
if (($newValue === null || strlen($newValue) === 0)) {
if ($this->getIsUpdate()) {
$this->addErrorToDisplay($errors['onEmpty']);
}
Expand Down Expand Up @@ -427,7 +427,7 @@ private function addErrorToDisplay(string $translateId): void

private function setIsUpdate(?string $oldValue, ?string $newValue): bool
{
$this->isUpdate = ($oldValue !== $newValue);
$this->isUpdate = ($oldValue !== $newValue) && !empty($newValue);
return $this->isUpdate;
}

Expand Down

0 comments on commit 0094d00

Please sign in to comment.