Skip to content

BUGFIX: validate Merchant Emails field on save#329

Open
TLabutis wants to merge 1 commit into
SL-346/accessibility-eaa-compliancefrom
BUGFIX/merchant-emails-validation
Open

BUGFIX: validate Merchant Emails field on save#329
TLabutis wants to merge 1 commit into
SL-346/accessibility-eaa-compliancefrom
BUGFIX/merchant-emails-validation

Conversation

@TLabutis
Copy link
Copy Markdown

Summary

  • Issue: Merchant Emails input accepted any string (e.g. demo@p§1312312EWRWrestashop.com) and the controller persisted it verbatim. Notifications would silently bounce / never be sent.
  • Frontend (api-credentials.tsx): on every change, split by ,, trim, validate each part against an email regex. When any entry is invalid → input shows red border + inline error listing the bad values; Save button disabled.
  • Backend (AdminSaferPayOfficialSettingsController::ajaxProcessSaveCredentials): new findInvalidEmail() helper walks both testMerchantEmails and liveMerchantEmails and rejects the save with a clear message if Validate::isEmail() fails. Guards against curl / devtools bypass.
  • Translation key invalidMerchantEmails added.
  • Changelog entry added under [2.0.2].

Test plan

  • Frontend: typing foo@bar.com, not-an-email shows red border + "Invalid email address: not-an-email"; Save disabled.
  • Frontend: clearing the invalid part restores Save.
  • Backend: direct POST to ?action=saveCredentials with testMerchantEmails="demo@p§1.com" returns {"success":false,"message":"Invalid merchant email address: demo@p§1.com"}; DB unchanged.
  • Backend: valid comma-separated list (a@x.com, b@y.com) saves successfully.
  • Visual: red border + error message render under the input on the Settings → API Credentials tab.

Frontend (api-credentials.tsx): show inline error and disable Save when
any comma-separated entry fails an email regex.

Backend (AdminSaferPayOfficialSettingsController): reject save when
testMerchantEmails or liveMerchantEmails contains a value that fails
Validate::isEmail() — guards against curl/devtools bypass.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces frontend and backend validation for merchant email addresses to ensure only valid, comma-separated lists are saved. Key changes include a new validation helper in the PHP controller, updated translation strings, and React UI enhancements to display error messages and disable the save button. Feedback suggests optimizing the backend validation order to check local inputs before making API calls and improving the frontend logic to validate both test and live email fields simultaneously to prevent UX inconsistencies.

Comment on lines +182 to +191
$testMerchantEmails = $this->getStringValue($data, 'testMerchantEmails');
$liveMerchantEmails = $this->getStringValue($data, 'liveMerchantEmails');
$invalidEmail = $this->findInvalidEmail($testMerchantEmails) ?: $this->findInvalidEmail($liveMerchantEmails);
if ($invalidEmail !== null) {
$this->ajaxResponse(false, sprintf(
$this->module->l('Invalid merchant email address: %s', self::FILE_NAME),
$invalidEmail
));
return;
}
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 email validation logic should be moved before the API credentials validation (lines 166-180). Validating local input data first is more efficient as it avoids unnecessary and potentially slow remote API calls if the merchant emails are already invalid.

Comment on lines +41 to +45
const invalidEmails = merchantEmails
.split(',')
.map(e => e.trim())
.filter(e => e.length > 0 && !EMAIL_RE.test(e))
const merchantEmailsInvalid = invalidEmails.length > 0
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 merchantEmailsInvalid flag currently only validates the emails for the active environment (Test or Live). However, the backend validates both fields upon saving. This can lead to a confusing UX where the 'Save' button is enabled but the save operation fails due to invalid data in the hidden tab. Consider validating both testMerchantEmails and liveMerchantEmails to determine the disabled state of the Save button, while keeping the inline error message specific to the current tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant