summaryrefslogtreecommitdiff
path: root/Postman/Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'Postman/Extensions')
-rw-r--r--Postman/Extensions/Admin/PostmanAdminView.php4
-rw-r--r--Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php2
-rw-r--r--Postman/Extensions/Core/Notifications/PostmanSlackNotify.php2
-rw-r--r--Postman/Extensions/License/PostmanLicenseHandler.php55
-rw-r--r--Postman/Extensions/License/PostmanLicenseManager.php4
5 files changed, 57 insertions, 10 deletions
diff --git a/Postman/Extensions/Admin/PostmanAdminView.php b/Postman/Extensions/Admin/PostmanAdminView.php
index af66fcb..428ee17 100644
--- a/Postman/Extensions/Admin/PostmanAdminView.php
+++ b/Postman/Extensions/Admin/PostmanAdminView.php
@@ -75,6 +75,10 @@
<button type="submit" name="post_smtp_extension[<?php echo $short_name; ?>_activate]" class="button button-primary">Activate</button>
<?php endif; ?>
+ <?php if ( $license_data->license === 'expired' ) : ?>
+ <a href="<?php echo $license_data->renew_url; ?>" target="_blank" class="button button-primary">Renew License</a>
+ <?php endif; ?>
+
<button type="submit" name="post_smtp_extension[<?php echo $short_name; ?>_deactivate]" class="button button-secondary">Deactivate</button>
</div>
</div>
diff --git a/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php b/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php
index c1f2661..bc1e95d 100644
--- a/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php
+++ b/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php
@@ -31,4 +31,4 @@ class PostmanPushoverNotify implements Postman_Notify {
error_log( __CLASS__ . ': ' . print_r( $body, true ) );
}
}
-}
+} \ No newline at end of file
diff --git a/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php b/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php
index 3e482a8..1da009a 100644
--- a/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php
+++ b/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php
@@ -37,4 +37,4 @@ class PostmanSlackNotify implements Postman_Notify {
error_log( __CLASS__ . ': ' . $message );
}
}
-} \ No newline at end of file
+}
diff --git a/Postman/Extensions/License/PostmanLicenseHandler.php b/Postman/Extensions/License/PostmanLicenseHandler.php
index b24aa14..e144951 100644
--- a/Postman/Extensions/License/PostmanLicenseHandler.php
+++ b/Postman/Extensions/License/PostmanLicenseHandler.php
@@ -7,6 +7,9 @@ if ( ! class_exists( 'PostmanLicenseHandler' ) ) :
class PostmanLicenseHandler {
+
+ const DAYS_TO_ALERT = array( 30, 14, 7, 1);
+
private $file;
private $license;
private $license_data;
@@ -81,7 +84,6 @@ class PostmanLicenseHandler {
add_action( 'init', array( $this, 'cron' ), 20 );
- // Check that license is valid once per week
add_action( 'admin_init', array( $this, 'validate_license' ) );
// Updater
@@ -241,9 +243,9 @@ class PostmanLicenseHandler {
set_site_transient( 'update_plugins', null );
// Decode license data
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
- update_option( $this->item_shortname . '_license_active', $license_data );
+ update_option( $this->item_shortname . '_license_active', $this->license_data );
update_option( $this->item_shortname . '_license_key', $license );
$slug = plugin_basename($this->file);
@@ -307,7 +309,7 @@ class PostmanLicenseHandler {
}
// Decode the license data
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
delete_option( $this->item_shortname . '_license_active' );
delete_option( $this->item_shortname . '_license_key' );
@@ -323,6 +325,39 @@ class PostmanLicenseHandler {
set_transient( $this->item_shortname . '_cron', true, rand( 12, 48 ) * HOUR_IN_SECONDS );
}
+
+ $license_data = $this->license_data;
+
+ $datetime1 = new DateTime();
+ $datetime2 = new DateTime( $license_data->expires );
+
+ foreach ( self::DAYS_TO_ALERT as $day_to_alert ) {
+
+ $interval = $datetime1->diff($datetime2);
+ if( $interval->days == $day_to_alert ){
+ add_action( 'admin_notices', function () use ( $day_to_alert, $license_data ) {
+ echo $this->item_name . ' is about to expire in ' . $day_to_alert . ' days: ' . $license_data->expires;
+ });
+
+ return;
+ }
+
+ if ( $interval->days == 0 ) {
+ add_action( 'admin_notices', function () use ( $license_data ) {
+ echo $this->item_name . ' license expire today at: ' . $license_data->expires;
+ });
+
+ return;
+ }
+ }
+
+ if ( $license_data->activations_left == 0 ) {
+ add_action( 'admin_notices', function () use ( $license_data ) {
+ echo $this->item_name . ' has no activations';
+ });
+
+ return;
+ }
}
@@ -357,10 +392,18 @@ class PostmanLicenseHandler {
return false;
}
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
+ return false;
+ }
+
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
- update_option( $this->item_shortname . '_license_active', $license_data );
+ update_option( $this->item_shortname . '_license_active', $this->license_data );
+
+ }
+ private function get_license_data() {
+ return get_option( $this->item_shortname . '_license_active' );
}
diff --git a/Postman/Extensions/License/PostmanLicenseManager.php b/Postman/Extensions/License/PostmanLicenseManager.php
index cb10852..a25f092 100644
--- a/Postman/Extensions/License/PostmanLicenseManager.php
+++ b/Postman/Extensions/License/PostmanLicenseManager.php
@@ -3,7 +3,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
class PostmanLicenseManager {
- const ENDPOINT = 'https://postmansmtp.com';
+ const ENDPOINT = 'https://postmansmtpcom-staging.dxpsites.net';
const CORE_EXTENSIONS = [ 'gmail_api', 'sendgrid_api', 'mandrill_api', 'mailgun_api' ];
@@ -97,4 +97,4 @@ class PostmanLicenseManager {
public function get_extensions() {
return $this->extensions;
}
-}
+} \ No newline at end of file