Change warning when user hasw an API key
[MAILPOET-2396]
This commit is contained in:
committed by
Jack Kitterhing
parent
e1de593174
commit
55f8626493
@@ -4,29 +4,43 @@ import Notice from 'notices/notice.jsx';
|
||||
|
||||
const SubscribersLimitNotice = () => {
|
||||
if (!window.mailpoet_subscribers_limit_reached) return null;
|
||||
const hasKey = window.mailpoet_has_api_key;
|
||||
const title = MailPoet.I18n.t('subscribersLimitNoticeTitle')
|
||||
.replace('[subscribersLimit]', window.mailpoet_subscribers_limit);
|
||||
const youReachedTheLimit = MailPoet.I18n.t(hasKey ? 'yourPlanLimit' : 'freeVersionLimit')
|
||||
.replace('[subscribersLimit]', window.mailpoet_subscribers_limit);
|
||||
const upgradeLink = hasKey
|
||||
? 'https://account.mailpoet.com/upgrade'
|
||||
: `https://account.mailpoet.com/?s=${window.mailpoet_subscribers_count + 1}`;
|
||||
const refreshSubscribers = () => {
|
||||
console.log('Refresh subscribers ...');
|
||||
};
|
||||
return (
|
||||
<Notice type="error" timeout={false} closable={false}>
|
||||
<h3>
|
||||
{
|
||||
MailPoet.I18n.t('subscribersLimitNoticeTitle')
|
||||
.replace('[subscribersLimit]', window.mailpoet_subscribers_limit)
|
||||
}
|
||||
</h3>
|
||||
<h3>{title}</h3>
|
||||
<p>
|
||||
{
|
||||
MailPoet.I18n.t('subscribersLimitNoticeContent')
|
||||
.replace('[subscribersLimit]', window.mailpoet_subscribers_limit)
|
||||
}
|
||||
{youReachedTheLimit}
|
||||
{' '}
|
||||
{MailPoet.I18n.t('youNeedToUpgrade')}
|
||||
</p>
|
||||
<p>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="button button-primary"
|
||||
href={`https://account.mailpoet.com/?s=${window.mailpoet_subscribers_count + 1}`}
|
||||
href={upgradeLink}
|
||||
>
|
||||
{MailPoet.I18n.t('upgradeNow')}
|
||||
</a>
|
||||
{hasKey && (
|
||||
<button
|
||||
type="button"
|
||||
className="button button-primary"
|
||||
onClick={refreshSubscribers}
|
||||
>
|
||||
{MailPoet.I18n.t('refreshMySubscribers')}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
</Notice>
|
||||
);
|
||||
|
@@ -97,6 +97,7 @@ class Newsletters {
|
||||
$data['installed_days_ago'] = (int)$installedAtDateTime->diff(new \DateTime())->format('%a');
|
||||
$data['subscribers_limit'] = $this->subscribers_feature->getSubscribersLimit();
|
||||
$data['subscribers_limit_reached'] = $this->subscribers_feature->check();
|
||||
$data['has_api_key'] = $this->subscribers_feature->hasAPIKey();
|
||||
|
||||
$date_time = new DateTime();
|
||||
$data['current_date'] = $date_time->getCurrentDate(DateTime::DEFAULT_DATE_FORMAT);
|
||||
|
@@ -128,6 +128,7 @@ class Worker {
|
||||
$unsubscribed = ($statistics->getUnsubscribeCount() * 100) / $statistics->getTotalSentCount();
|
||||
$subject = $newsletter->getLatestQueue()->getNewsletterRenderedSubject();
|
||||
$subscribers_count = $this->subscribers_repository->getTotalSubscribers();
|
||||
$has_key = $this->subscribers_feature->hasAPIKey();
|
||||
$context = [
|
||||
'subject' => $subject,
|
||||
'preheader' => sprintf(_x(
|
||||
@@ -142,8 +143,9 @@ class Worker {
|
||||
'clicked' => $clicked,
|
||||
'opened' => $opened,
|
||||
'subscribersLimitReached' => $this->subscribers_feature->check(),
|
||||
'hasKey' => $has_key,
|
||||
'subscribersLimit' => $this->subscribers_feature->getSubscribersLimit(),
|
||||
'upgradeNowLink' => 'https://account.mailpoet.com/?s=' . ($subscribers_count + 1),
|
||||
'upgradeNowLink' => $has_key ? 'https://account.mailpoet.com/upgrade' : 'https://account.mailpoet.com/?s=' . ($subscribers_count + 1),
|
||||
];
|
||||
if ($link) {
|
||||
$context['topLinkClicks'] = $link->getTotalClicksCount();
|
||||
|
@@ -10,6 +10,8 @@ class Subscribers {
|
||||
const SUBSCRIBERS_OLD_LIMIT = 2000;
|
||||
const SUBSCRIBERS_NEW_LIMIT = 1000;
|
||||
const NEW_LIMIT_DATE = '2019-11-00';
|
||||
const MSS_SUBSCRIBERS_LIMIT_SETTING_KEY = 'mta.mailpoet_api_key_state.data.site_active_subscriber_limit';
|
||||
const PREMIUM_SUBSCRIBERS_LIMIT_SETTING_KEY = 'premium.premium_key_state.data.site_active_subscriber_limit';
|
||||
|
||||
/** @var SettingsController */
|
||||
private $settings;
|
||||
@@ -24,13 +26,24 @@ class Subscribers {
|
||||
|
||||
public function check() {
|
||||
$subscribers_count = $this->subscribers_repository->getTotalSubscribers();
|
||||
$has_mss_key = !empty($this->settings->get(Bridge::API_KEY_SETTING_NAME));
|
||||
$has_premium_key = !empty($this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME));
|
||||
if ($has_mss_key || $has_premium_key) return false;
|
||||
return $subscribers_count > $this->getSubscribersLimit();
|
||||
}
|
||||
|
||||
public function hasAPIKey() {
|
||||
$has_mss_key = !empty($this->settings->get(Bridge::API_KEY_SETTING_NAME));
|
||||
$has_premium_key = !empty($this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME));
|
||||
return $has_mss_key || $has_premium_key;
|
||||
}
|
||||
|
||||
public function getSubscribersLimit() {
|
||||
$has_mss_key = !empty($this->settings->get(Bridge::API_KEY_SETTING_NAME));
|
||||
$mss_subscribers_limit = $this->settings->get(self::MSS_SUBSCRIBERS_LIMIT_SETTING_KEY);
|
||||
if ($has_mss_key && !empty($mss_subscribers_limit)) return (int)$mss_subscribers_limit;
|
||||
|
||||
$has_premium_key = !empty($this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME));
|
||||
$premium_subscribers_limit = $this->settings->get(self::PREMIUM_SUBSCRIBERS_LIMIT_SETTING_KEY);
|
||||
if ($has_premium_key && !empty($premium_subscribers_limit)) return (int)$premium_subscribers_limit;
|
||||
|
||||
$installation_time = strtotime($this->settings->get('installed_at'));
|
||||
$old_user = $installation_time < strtotime(self::NEW_LIMIT_DATE);
|
||||
return $old_user ? self::SUBSCRIBERS_OLD_LIMIT : self::SUBSCRIBERS_NEW_LIMIT;
|
||||
|
@@ -16,6 +16,8 @@ class SubscribersTest extends \MailPoetUnitTest {
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2018-11-11',
|
||||
'subscribers_count' => 2500,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->true();
|
||||
}
|
||||
@@ -26,6 +28,8 @@ class SubscribersTest extends \MailPoetUnitTest {
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2018-11-11',
|
||||
'subscribers_count' => 1500,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->false();
|
||||
}
|
||||
@@ -36,6 +40,8 @@ class SubscribersTest extends \MailPoetUnitTest {
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 1500,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->true();
|
||||
}
|
||||
@@ -46,36 +52,68 @@ class SubscribersTest extends \MailPoetUnitTest {
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 900,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->false();
|
||||
}
|
||||
|
||||
public function testCheckReturnsFalseIfMSSKeyExists() {
|
||||
public function testCheckReturnsFalseIfMSSKeyExistsAndDidntReachLimit() {
|
||||
$subscribers_feature = $this->constructWith([
|
||||
'has_mss_key' => true,
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 1500,
|
||||
'subscribers_count' => 2500,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 3500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->false();
|
||||
}
|
||||
|
||||
public function testCheckReturnsFalseIfPremiumKeyExists() {
|
||||
public function testCheckReturnsTrueIfMSSKeyExistsAndReachedLimit() {
|
||||
$subscribers_feature = $this->constructWith([
|
||||
'has_mss_key' => true,
|
||||
'has_premium_key' => false,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 3000,
|
||||
'premium_subscribers_limit' => 500,
|
||||
'mss_subscribers_limit' => 2500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->true();
|
||||
}
|
||||
|
||||
public function testCheckReturnsFalseIfPremiumKeyExistsAndDidntReachLimit() {
|
||||
$subscribers_feature = $this->constructWith([
|
||||
'has_mss_key' => false,
|
||||
'has_premium_key' => true,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 1500,
|
||||
'subscribers_count' => 2500,
|
||||
'premium_subscribers_limit' => 3500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->false();
|
||||
}
|
||||
|
||||
public function testCheckReturnsTrueIfPremiumKeyExistsAndReachedLimit() {
|
||||
$subscribers_feature = $this->constructWith([
|
||||
'has_mss_key' => false,
|
||||
'has_premium_key' => true,
|
||||
'installed_at' => '2019-11-11',
|
||||
'subscribers_count' => 3000,
|
||||
'premium_subscribers_limit' => 2500,
|
||||
'mss_subscribers_limit' => 500,
|
||||
]);
|
||||
expect($subscribers_feature->check())->true();
|
||||
}
|
||||
|
||||
private function constructWith($specs) {
|
||||
$settings = Stub::make(SettingsController::class, [
|
||||
'get' => function($name) use($specs) {
|
||||
if ($name === 'installed_at') return $specs['installed_at'];
|
||||
if ($name === Bridge::API_KEY_SETTING_NAME) return $specs['has_mss_key'];
|
||||
if ($name === Bridge::PREMIUM_KEY_SETTING_NAME) return $specs['has_premium_key'];
|
||||
if ($name === SubscribersFeature::PREMIUM_SUBSCRIBERS_LIMIT_SETTING_KEY) return $specs['premium_subscribers_limit'];
|
||||
if ($name === SubscribersFeature::MSS_SUBSCRIBERS_LIMIT_SETTING_KEY) return $specs['mss_subscribers_limit'];
|
||||
},
|
||||
]);
|
||||
$subscribers_repository = Stub::make(SubscribersRepository::class, [
|
||||
|
@@ -8,7 +8,12 @@
|
||||
<% if subscribersLimitReached %>
|
||||
<%= __('Congratulations, you now have more than [subscribersLimit] subscribers!')|replace({'[subscribersLimit]': subscribersLimit}) %>
|
||||
|
||||
<%= __('Our free version is limited to [subscribersLimit] subscribers. You need to upgrade now to be able to continue using MailPoet.')|replace({'[subscribersLimit]': subscribersLimit}) %>
|
||||
<% if hasKey %>
|
||||
<%= __('Your plan is limited to [subscribersLimit] subscribers.')|replace({'[subscribersLimit]': subscribersLimit}) %>
|
||||
<% else %>
|
||||
<%= __('Our free version is limited to [subscribersLimit] subscribers.')|replace({'[subscribersLimit]': subscribersLimit}) %>
|
||||
<% endif %>
|
||||
<%= __('You need to upgrade now to be able to continue using MailPoet.') %>
|
||||
|
||||
<%= __('Upgrade Now') %>
|
||||
<%= upgradeNowLink %>
|
||||
|
@@ -10,6 +10,7 @@
|
||||
var mailpoet_display_nps_poll = <%= (sent_newsletters_count > 0 and settings.display_nps_poll) ? 'true' : 'false' %>;
|
||||
var mailpoet_subscribers_limit = <%= subscribers_limit %>;
|
||||
var mailpoet_subscribers_limit_reached = <%= subscribers_limit_reached ? 'true' : 'false' %>;
|
||||
var mailpoet_has_api_key = <%= has_api_key ? 'true' : 'false' %>;
|
||||
var mailpoet_segments = <%= json_encode(segments) %>;
|
||||
var mailpoet_show_congratulate_after_first_newsletter = <%= show_congratulate_after_first_newsletter %>;
|
||||
var mailpoet_installed_days_ago = <%= installed_days_ago %>;
|
||||
@@ -399,8 +400,11 @@
|
||||
'gaCampaignTip': __('For example, “Spring email”. [link]Read the guide.[/link]'),
|
||||
|
||||
'subscribersLimitNoticeTitle': __('Congratulations, you now have more than [subscribersLimit] subscribers!'),
|
||||
'subscribersLimitNoticeContent': __('Our free version is limited to [subscribersLimit] subscribers. You need to upgrade now to be able to continue using MailPoet.'),
|
||||
'upgradeNow': __('Upgrade Now')
|
||||
'freeVersionLimit': __('Our free version is limited to [subscribersLimit] subscribers.'),
|
||||
'yourPlanLimit': __('Your plan is limited to [subscribersLimit] subscribers.'),
|
||||
'youNeedToUpgrade': __('You need to upgrade now to be able to continue using MailPoet.'),
|
||||
'upgradeNow': __('Upgrade Now'),
|
||||
'refreshMySubscribers': __('I’ve upgraded my subscription, refresh subscriber limit'),
|
||||
}) %>
|
||||
<% include('mss_pitch_translations.html') %>
|
||||
<% endblock %>
|
||||
|
Reference in New Issue
Block a user