Handle error message for exceeded email limit when limit is not known
[MAILPOET-5191]
This commit is contained in:
committed by
Veljko V
parent
469b9bf85f
commit
15aeea834f
@@ -193,12 +193,21 @@ class MailPoetMapper {
|
|||||||
$partialApiKey = $this->servicesChecker->generatePartialApiKey();
|
$partialApiKey = $this->servicesChecker->generatePartialApiKey();
|
||||||
$emailVolumeLimit = $this->subscribersFeature->getEmailVolumeLimit();
|
$emailVolumeLimit = $this->subscribersFeature->getEmailVolumeLimit();
|
||||||
$date = Carbon::now()->startOfMonth()->addMonth();
|
$date = Carbon::now()->startOfMonth()->addMonth();
|
||||||
|
if ($emailVolumeLimit) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
// translators: %1$s is email volume limit and %2$s the date when you can resume sending.
|
// translators: %1$s is email volume limit and %2$s the date when you can resume sending.
|
||||||
__('You have sent more emails this month than your MailPoet plan includes (%1$s), and sending has been temporarily paused. To continue sending with MailPoet Sending Service please [link]upgrade your plan[/link], or wait until sending is automatically resumed on <b>%2$s</b>.', 'mailpoet'),
|
__('You have sent more emails this month than your MailPoet plan includes (%1$s), and sending has been temporarily paused. To continue sending with MailPoet Sending Service please [link]upgrade your plan[/link], or wait until sending is automatically resumed on %2$s.', 'mailpoet'),
|
||||||
$emailVolumeLimit,
|
$emailVolumeLimit,
|
||||||
$this->wp->dateI18n(get_option('date_format'), $date->getTimestamp())
|
$this->wp->dateI18n($this->wp->getOption('date_format'), $date->getTimestamp())
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$message = sprintf(
|
||||||
|
// translators: %1$s the date when you can resume sending.
|
||||||
|
__('You have sent more emails this month than your MailPoet plan includes, and sending has been temporarily paused. To continue sending with MailPoet Sending Service please [link]upgrade your plan[/link], or wait until sending is automatically resumed on %1$s.', 'mailpoet'),
|
||||||
|
$this->wp->dateI18n($this->wp->getOption('date_format'), $date->getTimestamp())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$message = Helpers::replaceLinkTags(
|
$message = Helpers::replaceLinkTags(
|
||||||
$message,
|
$message,
|
||||||
"https://account.mailpoet.com/orders/upgrade/{$partialApiKey}",
|
"https://account.mailpoet.com/orders/upgrade/{$partialApiKey}",
|
||||||
|
@@ -213,4 +213,56 @@ class MailPoetMapperTest extends \MailPoetUnitTest {
|
|||||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||||
expect($error->getMessage())->equals('Email service is temporarily not available, please try again in a few minutes.');
|
expect($error->getMessage())->equals('Email service is temporarily not available, please try again in a few minutes.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetErrorEmailVolumeLimitWithAndWithoutKnownLimit(): void {
|
||||||
|
$apiResult = [
|
||||||
|
'code' => API::RESPONSE_CODE_CAN_NOT_SEND,
|
||||||
|
'status' => API::SENDING_STATUS_SEND_ERROR,
|
||||||
|
'message' => API::ERROR_MESSAGE_EMAIL_VOLUME_LIMIT_REACHED,
|
||||||
|
'error' => API::ERROR_MESSAGE_EMAIL_VOLUME_LIMIT_REACHED,
|
||||||
|
];
|
||||||
|
|
||||||
|
$wpFunctions = Stub::make(new WPFunctions, [
|
||||||
|
'_x' => function ($value) {
|
||||||
|
return $value;
|
||||||
|
},
|
||||||
|
'getOption' => '',
|
||||||
|
'dateI18n' => '2023-01-31',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$subscribersWithLimit = Stub::make(Subscribers::class, [
|
||||||
|
'getEmailVolumeLimit' => 1000,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$subscribersWithoutKnownLimit = Stub::make(Subscribers::class, [
|
||||||
|
'getEmailVolumeLimit' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$serviceChecker = Stub::make(ServicesChecker::class, [
|
||||||
|
'generatePartialApiKey' => 'abc',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Check email volume error when the limit is known
|
||||||
|
$this->mapper = new MailPoetMapper(
|
||||||
|
$serviceChecker,
|
||||||
|
$subscribersWithLimit,
|
||||||
|
$wpFunctions
|
||||||
|
);
|
||||||
|
$error = $this->mapper->getErrorForResult($apiResult, $this->subscribers);
|
||||||
|
expect($error)->isInstanceOf(MailerError::class);
|
||||||
|
expect($error->getOperation())->equals(MailerError::OPERATION_EMAIL_LIMIT_REACHED);
|
||||||
|
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||||
|
expect($error->getMessage())->stringContainsString('You have sent more emails this month than your MailPoet plan includes (1000),');
|
||||||
|
expect($error->getMessage())->stringContainsString('wait until sending is automatically resumed on 2023-01-31');
|
||||||
|
|
||||||
|
// Check email volume error when the limit is unknown
|
||||||
|
$this->mapper = new MailPoetMapper(
|
||||||
|
$serviceChecker,
|
||||||
|
$subscribersWithoutKnownLimit,
|
||||||
|
$wpFunctions
|
||||||
|
);
|
||||||
|
$error = $this->mapper->getErrorForResult($apiResult, $this->subscribers);
|
||||||
|
expect($error->getMessage())->stringContainsString('You have sent more emails this month than your MailPoet plan includes,');
|
||||||
|
expect($error->getMessage())->stringContainsString('wait until sending is automatically resumed on 2023-01-31');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user