From 7f15fce2466f0c3568a14d46298d5540d316dba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Sat, 11 Sep 2021 12:15:17 +0200 Subject: [PATCH] Display a specific error message for banned users [MAILPOET-3667] --- assets/js/src/listing/notices.jsx | 22 ++++++++ lib/Mailer/MailerError.php | 3 ++ .../Methods/ErrorMappers/MailPoetMapper.php | 53 ++++++++++++++----- views/newsletters.html | 1 + 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/assets/js/src/listing/notices.jsx b/assets/js/src/listing/notices.jsx index 97a2b03fc4..440329eebb 100644 --- a/assets/js/src/listing/notices.jsx +++ b/assets/js/src/listing/notices.jsx @@ -73,6 +73,28 @@ const MailerError = (props) => { () =>
// eslint-disable-line no-plusplus ); + if (props.mta_log.error.operation === 'insufficient_privileges') { + return ( +
+

+ { message } +

+

+ { + event.preventDefault(); + resumeMailerSending(event); + }} + > + { MailPoet.I18n.t('mailerResumeSendingAfterUpgradeButton') } + +

+
+ ); + } + return (

diff --git a/lib/Mailer/MailerError.php b/lib/Mailer/MailerError.php index 539b05e9c3..bea162e970 100644 --- a/lib/Mailer/MailerError.php +++ b/lib/Mailer/MailerError.php @@ -8,10 +8,13 @@ class MailerError { const OPERATION_CONNECT = 'connect'; const OPERATION_SEND = 'send'; const OPERATION_AUTHORIZATION = 'authorization'; + const OPERATION_INSUFFICIENT_PRIVILEGES = 'insufficient_privileges'; const LEVEL_HARD = 'hard'; const LEVEL_SOFT = 'soft'; + const MESSAGE_EMAIL_FORBIDDEN_ACTION = 'Key is valid, but the action is forbidden'; + const MESSAGE_EMAIL_INSUFFICIENT_PRIVILEGES = 'Insufficient privileges'; const MESSAGE_EMAIL_NOT_AUTHORIZED = 'The email address is not authorized'; /** @var string */ diff --git a/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php b/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php index 3a75e8c9f0..a5706fcd2b 100644 --- a/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php +++ b/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php @@ -56,7 +56,10 @@ class MailPoetMapper { $retryInterval = self::TEMPORARY_UNAVAILABLE_RETRY_INTERVAL; break; case API::RESPONSE_CODE_CAN_NOT_SEND: - if ($result['message'] === MailerError::MESSAGE_EMAIL_NOT_AUTHORIZED) { + if ($result['message'] === MailerError::MESSAGE_EMAIL_INSUFFICIENT_PRIVILEGES) { + $operation = MailerError::OPERATION_INSUFFICIENT_PRIVILEGES; + $message = $this->getInsufficientPrivilegesMessage(); + } elseif ($result['message'] === MailerError::MESSAGE_EMAIL_NOT_AUTHORIZED) { $operation = MailerError::OPERATION_AUTHORIZATION; $message = $this->getUnauthorizedEmailMessage($sender); } else { @@ -108,27 +111,51 @@ class MailPoetMapper { return $message; } - private function getAccountBannedMessage() { - $message = WPFunctions::get()->__('The MailPoet Sending Service has stopped sending your emails for one of the following reasons:', 'mailpoet'); - - $subscriberLimitMessage = Helpers::replaceLinkTags( - WPFunctions::get()->__('You may have reached the subscriber limit of your plan. [link]Manage your subscriptions[/link].', 'mailpoet'), - 'https://account.mailpoet.com/account', + private function getInsufficientPrivilegesMessage(): string { + $message = __('You have reached the subscriber limit of your plan. Please [link1]upgrade your plan[/link1], or [link2]contact our support team[/link2] if you have any questions.', 'mailpoet'); + $message = Helpers::replaceLinkTags( + $message, + 'https://account.mailpoet.com/account/', [ 'target' => '_blank', 'rel' => 'noopener noreferrer', - ] + ], + 'link1' ); - - $deliverabilityMessage = Helpers::replaceLinkTags( - WPFunctions::get()->__('You may have had a poor deliverability rate. Please [link]contact our support team[/link] to resolve the issue.', 'mailpoet'), + $message = Helpers::replaceLinkTags( + $message, 'https://www.mailpoet.com/support/', [ 'target' => '_blank', 'rel' => 'noopener noreferrer', - ] + ], + 'link2' ); - return "$message

$subscriberLimitMessage
$deliverabilityMessage
"; + return "{$message}
"; + } + + private function getAccountBannedMessage(): string { + $message = __('MailPoet Sending Service has been temporarily suspended for your site due to [link1]degraded email deliverability[/link1]. Please [link2]contact our support team[/link2] to resolve the issue.', 'mailpoet'); + $message = Helpers::replaceLinkTags( + $message, + 'https://kb.mailpoet.com/article/231-sending-does-not-work#suspended', + [ + 'target' => '_blank', + 'rel' => 'noopener noreferrer', + ], + 'link1' + ); + $message = Helpers::replaceLinkTags( + $message, + 'https://www.mailpoet.com/support/', + [ + 'target' => '_blank', + 'rel' => 'noopener noreferrer', + ], + 'link2' + ); + + return "{$message}
"; } } diff --git a/views/newsletters.html b/views/newsletters.html index e6ff631b4d..0104e05ab8 100644 --- a/views/newsletters.html +++ b/views/newsletters.html @@ -333,6 +333,7 @@ 'mailerErrorCode': __('Error code: %$1s'), 'mailerCheckSettingsNotice': __('Check your [link]sending method settings[/link].'), 'mailerResumeSendingButton': __('Resume sending'), + 'mailerResumeSendingAfterUpgradeButton': __('I have upgraded my subscription, resume sending'), 'confirmEdit': __('Sending is in progress. Do you want to pause sending and edit the newsletter?'), 'confirmTitle': __('Confirm to proceed'), 'confirmLabel': __('Confirm'),