diff --git a/README.txt b/README.txt
index ea9dc3f2b..0e0e38f6e 100644
--- a/README.txt
+++ b/README.txt
@@ -110,6 +110,8 @@ Gravity PDF can be run on most modern shared web hosting without any issues. It
= 6.8.1 =
* Bug: Fix Form Editor saving problem for Gravity Forms v2.6.*
* Bug: Fix Drag and Drop Column layout issue when the GF Styles Pro plugin is enabled
+* Housekeeping: Exclude popular WordPress staging environments when activating Gravity PDF licenses
+* Housekeeping: Improve Gravity PDF license activation success and error messages
= 6.8.0 =
* Feature: Add PDF Download metabox to Gravity Flow Inbox for logged-in users with appropriate capability
diff --git a/src/Helper/Helper_Abstract_Addon.php b/src/Helper/Helper_Abstract_Addon.php
index ef162fc25..815c39ef5 100644
--- a/src/Helper/Helper_Abstract_Addon.php
+++ b/src/Helper/Helper_Abstract_Addon.php
@@ -649,10 +649,12 @@ public function schedule_license_check() {
'timeout' => 15,
'sslverify' => false,
'body' => [
- 'edd_action' => 'check_license',
- 'license' => $license_info['license'],
- 'item_name' => rawurlencode( $this->get_short_name() ),
- 'url' => home_url(),
+ 'edd_action' => 'check_license',
+ 'license' => $license_info['license'],
+ 'item_id' => $this->get_edd_download_id(),
+ 'item_name' => rawurlencode( $this->get_short_name() ),
+ 'url' => home_url(),
+ 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
],
]
);
@@ -687,13 +689,50 @@ public function schedule_license_check() {
$license_info['status'] = $license_check->license;
$license_info['message'] = $possible_responses[ $license_check->license ];
- /* Include the expiry date if license expired */
- if ( $license_check->license === 'expired' ) {
- $date_format = get_option( 'date_format' );
- $dt = new \DateTimeImmutable( $license_check->expires, wp_timezone() );
- $date = $dt === false ? gmdate( $date_format, false ) : $dt->format( $date_format );
-
- $license_info['message'] = sprintf( $license_info['message'], $date );
+ switch ( $license_check->license ) {
+ case 'expired':
+ $date_format = get_option( 'date_format' );
+ $dt = new \DateTimeImmutable( $license_check->expires, wp_timezone() );
+ $date = $dt === false ? gmdate( $date_format, false ) : $dt->format( $date_format );
+
+ $url = add_query_arg(
+ [
+ 'edd_license_key' => $license_info['license'],
+ 'download_id' => $this->get_edd_download_id(),
+ ],
+ 'https://gravitypdf.com/checkout/'
+ );
+
+ $license_info['message'] = sprintf( $license_info['message'], $date, $url );
+ break;
+
+ case 'revoked':
+ case 'disabled':
+ $url = add_query_arg(
+ [
+ 'edd_action' => 'add_to_cart',
+ 'download_id' => $this->get_edd_download_id(),
+ 'edd_options[price_id]' => $license_check->price_id,
+ ],
+ 'https://gravitypdf.com/checkout/'
+ );
+
+ $license_info['message'] = sprintf( $license_info['message'], $url );
+ break;
+
+ case 'no_activations_left':
+ $url = add_query_arg(
+ [
+ 'view' => 'upgrades',
+ 'action' => 'manage_licenses',
+ 'license_id' => $license_check->license_id,
+ 'payment_id' => $license_check->payment_id,
+ ],
+ 'https://gravitypdf.com/account/'
+ );
+
+ $license_info['message'] = sprintf( $license_info['message'], $url );
+ break;
}
$this->log->notice( 'License key no longer valid', $license_info );
diff --git a/src/Helper/Helper_Abstract_Options.php b/src/Helper/Helper_Abstract_Options.php
index 293135139..022daf239 100644
--- a/src/Helper/Helper_Abstract_Options.php
+++ b/src/Helper/Helper_Abstract_Options.php
@@ -1707,11 +1707,11 @@ public function license_callback( $args ) {
-
+
-
+
diff --git a/src/Helper/Helper_Data.php b/src/Helper/Helper_Data.php
index 3b47b0ac5..ec20cc597 100644
--- a/src/Helper/Helper_Data.php
+++ b/src/Helper/Helper_Data.php
@@ -166,17 +166,26 @@ public function add_addon( Helper_Abstract_Addon $class ) {
$this->addon[ $class->get_slug() ] = $class;
}
+ /**
+ * Get the various responses for license key activations
+ *
+ * @param string $addon_name
+ *
+ * @return array
+ */
public function addon_license_responses( $addon_name ) {
return [
- 'expired' => __( 'Your license key expired on %s.', 'gravity-forms-pdf-extended' ),
- 'revoked' => __( 'Your license key has been disabled', 'gravity-forms-pdf-extended' ),
- 'missing' => __( 'Invalid license key provided', 'gravity-forms-pdf-extended' ),
- 'invalid' => __( 'Your license is not active for this URL', 'gravity-forms-pdf-extended' ),
- 'site_inactive' => __( 'Your license is not active for this URL', 'gravity-forms-pdf-extended' ),
- 'item_name_mismatch' => sprintf( __( 'This appears to be an invalid license key for %s', 'gravity-forms-pdf-extended' ), $addon_name ),
- 'no_activations_left' => __( 'Your license key has reached its activation limit', 'gravity-forms-pdf-extended' ),
- 'default' => __( 'An error occurred, please try again', 'gravity-forms-pdf-extended' ),
- 'generic' => __( 'An error occurred during activation, please try again', 'gravity-forms-pdf-extended' ),
+ 'expired' => sprintf( __( 'This license key expired on %%s. %1$sPlease renew your license to continue receiving updates and support%2$s.', 'gravity-forms-pdf-extended' ), '', '' ),
+ 'revoked' => sprintf( __( 'This license key has been cancelled (most likely due to a refund request). %1$sPlease consider purchasing a new license%2$s.', 'gravity-forms-pdf-extended' ), '', '' ),
+ 'disabled' => sprintf( __( 'This license key has been cancelled (most likely due to a refund request). %1$sPlease consider purchasing a new license%2$s.', 'gravity-forms-pdf-extended' ), '', '' ),
+ 'missing' => __( 'This license key is invalid. Please check your key has been entered correctly.', 'gravity-forms-pdf-extended' ),
+ 'invalid' => __( 'The license key is invalid. Please check your key has been entered correctly.', 'gravity-forms-pdf-extended' ),
+ 'site_inactive' => __( 'Your license key is valid but does not match your current domain. This usually occurs if your domain URL changes. Please resave the settings to activate the license for this website.', 'gravity-forms-pdf-extended' ),
+ 'item_name_mismatch' => sprintf( __( 'This license key is not valid for %s. Please check your key is for this product.', 'gravity-forms-pdf-extended' ), $addon_name ),
+ 'invalid_item_id' => sprintf( __( 'This license key is not valid for %s. Please check your key is for this product.', 'gravity-forms-pdf-extended' ), $addon_name ),
+ 'no_activations_left' => sprintf( __( 'This license key has reached its activation limit. %1$sPlease upgrade your license to increase the site limit (you only pay the difference)%2$s.', 'gravity-forms-pdf-extended' ), '', '' ),
+ 'default' => __( 'An error occurred, please try again.', 'gravity-forms-pdf-extended' ),
+ 'generic' => __( 'An error occurred, please try again.', 'gravity-forms-pdf-extended' ),
];
}
diff --git a/src/Model/Model_Settings.php b/src/Model/Model_Settings.php
index 1c5d65347..2ef7139d4 100644
--- a/src/Model/Model_Settings.php
+++ b/src/Model/Model_Settings.php
@@ -334,10 +334,12 @@ protected function activate_license( Helper_Abstract_Addon $addon, $license_key
'timeout' => 15,
'sslverify' => false,
'body' => [
- 'edd_action' => 'activate_license',
- 'license' => $license_key,
- 'item_name' => rawurlencode( $addon->get_short_name() ), // the name of our product in EDD
- 'url' => home_url(),
+ 'edd_action' => 'activate_license',
+ 'license' => $license_key,
+ 'item_id' => $addon->get_edd_download_id(),
+ 'item_name' => rawurlencode( $addon->get_short_name() ), // the name of our product in EDD
+ 'url' => home_url(),
+ 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
],
]
);
@@ -356,7 +358,7 @@ protected function activate_license( Helper_Abstract_Addon $addon, $license_key
);
} else {
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
- $message = __( 'Your support license key has been successfully validated.', 'gravityforms' );
+ $message = __( 'Your support license key has been activated for this domain.', 'gravity-forms-pdf-extended' );
$status = 'active';
if ( ! isset( $license_data->success ) || false === $license_data->success ) {
@@ -367,13 +369,50 @@ protected function activate_license( Helper_Abstract_Addon $addon, $license_key
$message = $possible_responses[ $license_data->error ];
$status = $license_data->error;
- /* Include the expiry date if license expired */
- if ( $license_data->error === 'expired' ) {
- $date_format = get_option( 'date_format' );
- $dt = new \DateTimeImmutable( $license_data->expires, wp_timezone() );
- $date = $dt === false ? gmdate( $date_format, false ) : $dt->format( $date_format );
+ switch ( $license_data->error ) {
+ case 'expired':
+ $date_format = get_option( 'date_format' );
+ $dt = new \DateTimeImmutable( $license_data->expires, wp_timezone() );
+ $date = $dt === false ? gmdate( $date_format, false ) : $dt->format( $date_format );
+
+ $url = add_query_arg(
+ [
+ 'edd_license_key' => $license_key,
+ 'download_id' => $addon->get_edd_download_id(),
+ ],
+ 'https://gravitypdf.com/checkout/'
+ );
+
+ $message = sprintf( $message, $date, $url );
+ break;
+
+ case 'revoked':
+ case 'disabled':
+ $url = add_query_arg(
+ [
+ 'edd_action' => 'add_to_cart',
+ 'download_id' => $addon->get_edd_download_id(),
+ 'edd_options[price_id]' => $license_data->price_id,
+ ],
+ 'https://gravitypdf.com/checkout/'
+ );
+
+ $message = sprintf( $message, $url );
+ break;
- $message = sprintf( $message, $date );
+ case 'no_activations_left':
+ $url = add_query_arg(
+ [
+ 'view' => 'upgrades',
+ 'action' => 'manage_licenses',
+ 'license_id' => $license_data->license_id,
+ 'payment_id' => $license_data->payment_id,
+ ],
+ 'https://gravitypdf.com/account/'
+ );
+
+ $message = sprintf( $message, $url );
+ break;
}
}
@@ -473,10 +512,12 @@ public function deactivate_license_key( Helper_Abstract_Addon $addon, $license_k
'timeout' => 15,
'sslverify' => false,
'body' => [
- 'edd_action' => 'deactivate_license',
- 'license' => $license_key,
- 'item_name' => rawurlencode( $addon->get_short_name() ), // the name of our product in EDD
- 'url' => home_url(),
+ 'edd_action' => 'deactivate_license',
+ 'license' => $license_key,
+ 'item_id' => $addon->get_edd_download_id(),
+ 'item_name' => rawurlencode( $addon->get_short_name() ), // the name of our product in EDD
+ 'url' => home_url(),
+ 'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
],
]
);
diff --git a/tests/e2e/utilities/page-model/tabs/license.js b/tests/e2e/utilities/page-model/tabs/license.js
index 4d8b78008..60f4aa6ce 100644
--- a/tests/e2e/utilities/page-model/tabs/license.js
+++ b/tests/e2e/utilities/page-model/tabs/license.js
@@ -9,9 +9,9 @@ class License {
this.samplePluginInputBox = Selector('#gfpdf-fieldset-license_gravity-pdf-example-plugin').find('[id="gfpdf_settings[license_gravity-pdf-example-plugin]"]')
this.validLicenseKey = '987654321'
this.invalidLicenseKey = '123456789'
- this.invalidLicenseKeyMessage = Selector('.gforms_note_error').withText('Invalid license key provided')
+ this.invalidLicenseKeyMessage = Selector('.gforms_note_error').withText('This license key is invalid. Please check your key has been entered correctly.')
this.deactivateLinkMessage = Selector('button').withText('Deactivate License')
- this.successMessage = Selector('.gforms_note_success').withText('Your support license key has been successfully validated.')
+ this.successMessage = Selector('.gforms_note_success').withText('Your support license key has been activated for this domain.')
this.deactivateLink = Selector('.gfpdf-deactivate-license')
this.deactivatedMessage = Selector('.success').withText('License deactivated.')
diff --git a/tests/phpunit/unit-tests/test-addon.php b/tests/phpunit/unit-tests/test-addon.php
index c0ee18129..3f1fe3459 100644
--- a/tests/phpunit/unit-tests/test-addon.php
+++ b/tests/phpunit/unit-tests/test-addon.php
@@ -272,14 +272,14 @@ public function test_schedule_license_check() {
$api_response = function() {
return [
'response' => [ 'code' => 200 ],
- 'body' => json_encode( [ 'license' => 'revoked' ] ),
+ 'body' => json_encode( [ 'license' => 'revoked', 'price_id' => 1 ] ),
];
};
add_filter( 'pre_http_request', $api_response );
$this->assertTrue( $this->addon->schedule_license_check() );
- $this->assertEquals( 'Your license key has been disabled', $this->addon->get_license_message() );
+ $this->assertStringContainsString( 'This license key has been cancelled', $this->addon->get_license_message() );
remove_filter( 'pre_http_request', $api_response );
$this->addon->delete_license_info();
diff --git a/tests/phpunit/unit-tests/test-settings.php b/tests/phpunit/unit-tests/test-settings.php
index 1cf1e59da..3b4172b37 100644
--- a/tests/phpunit/unit-tests/test-settings.php
+++ b/tests/phpunit/unit-tests/test-settings.php
@@ -392,7 +392,7 @@ public function test_maybe_activate_licenses() {
]
);
- $this->assertEquals( 'Invalid license key provided', $results['license_other-plugin_message'] );
+ $this->assertStringContainsString( 'This license key is invalid.', $results['license_other-plugin_message'] );
$this->assertEquals( 'missing', $results['license_other-plugin_status'] );
/* Ensure add-on message and status are reset when license key is empty */
@@ -404,8 +404,8 @@ public function test_maybe_activate_licenses() {
]
);
- $this->assertEquals( '', $results['license_other-plugin_message'] );
- $this->assertEquals( '', $results['license_other-plugin_status'] );
+ $this->assertEmpty( $results['license_other-plugin_message'] );
+ $this->assertEmpty($results['license_other-plugin_status'] );
/* Check we don't do anything when the license is active */
$results = $this->model->maybe_active_licenses(
@@ -433,7 +433,7 @@ public function test_maybe_activate_licenses() {
]
);
- $this->assertEquals( 'Invalid license key provided', $results['license_other-plugin_message'] );
+ $this->assertStringContainsString( 'This license key is invalid.', $results['license_other-plugin_message'] );
$this->assertEquals( 'missing', $results['license_other-plugin_status'] );
/* Check that the hashed license reverts back to the unhashed version before saving */
@@ -482,7 +482,7 @@ public function test_activate_license( $expected, $api ) {
]
);
- $this->assertEquals( $expected, $results['license_my-custom-plugin_message'] );
+ $this->assertStringContainsString( $expected, $results['license_my-custom-plugin_message'] );
remove_filter( 'pre_http_request', $api_response );
$gfpdf->data->addon = [];
@@ -491,65 +491,61 @@ public function test_activate_license( $expected, $api ) {
/**
* @return array
*
- * @throws Exception
* @since 4.2
*/
public function providerActivateLicense() {
- $date_format = get_option( 'date_format' );
- $dt = new DateTimeImmutable( '', wp_timezone() );
- $date = $dt === false ? gmdate( $date_format, false ) : $dt->format( $date_format );
-
return [
[
- 'Your license key expired on ' . $date . '.',
+ 'This license key expired on',
[
- 'error' => 'expired',
- 'expires' => '',
+ 'error' => 'expired',
+ 'expires' => '',
+ 'price_id' => 1,
],
],
[
- 'Your license key has been disabled',
- [ 'error' => 'revoked' ],
+ 'This license key has been cancelled',
+ [ 'error' => 'revoked', 'price_id' => 1 ],
],
[
- 'Invalid license key provided',
- [ 'error' => 'missing' ],
+ 'This license key is invalid',
+ [ 'error' => 'missing', 'price_id' => 1 ],
],
[
- 'Your license is not active for this URL',
- [ 'error' => 'invalid' ],
+ 'The license key is invalid',
+ [ 'error' => 'invalid', 'price_id' => 1 ],
],
[
- 'Your license is not active for this URL',
- [ 'error' => 'site_inactive' ],
+ 'Your license key is valid but does not match your current domain',
+ [ 'error' => 'site_inactive', 'price_id' => 1 ],
],
[
- 'This appears to be an invalid license key for My Custom Plugin',
- [ 'error' => 'item_name_mismatch' ],
+ 'This license key is not valid for My Custom Plugin',
+ [ 'error' => 'item_name_mismatch', 'price_id' => 1 ],
],
[
- 'Your license key has reached its activation limit',
- [ 'error' => 'no_activations_left' ],
+ 'This license key has reached its activation limit',
+ [ 'error' => 'no_activations_left', 'license_id' => '', 'payment_id' => '' ],
],
[
'An error occurred, please try again',
- [ 'error' => 'default' ],
+ [ 'error' => 'default', 'price_id' => 1 ],
],
[
- 'An error occurred during activation, please try again',
- [ 'error' => 'generic' ],
+ 'An error occurred, please try again',
+ [ 'error' => 'generic', 'price_id' => 1 ],
],
[
- 'Your support license key has been successfully validated.',
+ 'Your support license key has been activated for this domain',
[ 'success' => 'true' ],
],
];