/** * @param object|bool $plan */ function __construct($plan = false) { parent::__construct($plan); if (is_object($plan)) { $this->name = strtolower($plan->name); } }
function __construct($tag = false) { if (!$tag instanceof stdClass) { return; } parent::__construct($tag); $this->version = $tag->version; $this->url = $tag->url; }
/** * @param bool|stdClass $scope_entity */ function __construct($scope_entity = false) { if (!$scope_entity instanceof stdClass) { return; } parent::__construct($scope_entity); $this->public_key = $scope_entity->public_key; if (isset($scope_entity->secret_key)) { $this->secret_key = $scope_entity->secret_key; } }
/** * @param stdClass|bool $plan */ function __construct($plan = false) { if (!$plan instanceof stdClass) { return; } parent::__construct($plan); $this->title = $plan->title; $this->name = strtolower($plan->name); $this->trial_period = $plan->trial_period; $this->is_require_subscription = $plan->is_require_subscription; }
/** * @param stdClass|bool $license */ function __construct($license = false) { if (!$license instanceof stdClass) { return; } parent::__construct($license); $this->plan_id = $license->plan_id; $this->activated = $license->activated; $this->activated_local = $license->activated_local; $this->quota = $license->quota; $this->expiration = $license->expiration; $this->is_free_localhost = $license->is_free_localhost; $this->is_block_features = $license->is_block_features; }
/** * @param stdClass|bool $plugin_info */ function __construct($plugin_info = false) { if (!$plugin_info instanceof stdClass) { return; } parent::__construct($plugin_info); $this->plugin_id = $plugin_info->plugin_id; $this->description = $plugin_info->description; $this->short_description = $plugin_info->short_description; $this->banner_url = $plugin_info->banner_url; $this->card_banner_url = $plugin_info->card_banner_url; $this->selling_point_0 = $plugin_info->selling_point_0; $this->selling_point_1 = $plugin_info->selling_point_1; $this->selling_point_2 = $plugin_info->selling_point_2; $this->screenshots = $plugin_info->screenshots; }
/** * @param stdClass|bool $subscription */ function __construct($subscription = false) { if (!$subscription instanceof stdClass) { return; } parent::__construct($subscription); $this->user_id = $subscription->user_id; $this->install_id = $subscription->install_id; $this->plan_id = $subscription->plan_id; $this->license_id = $subscription->license_id; $this->amount_per_cycle = $subscription->amount_per_cycle; $this->billing_cycle = $subscription->billing_cycle; $this->outstanding_balance = $subscription->outstanding_balance; $this->failed_payments = $subscription->failed_payments; $this->gateway = $subscription->gateway; $this->trial_ends = $subscription->trial_ends; $this->next_payment = $subscription->next_payment; $this->vat_id = $subscription->vat_id; $this->country_code = $subscription->country_code; }
/** * @param object|bool $pricing */ function __construct($pricing = false) { parent::__construct($pricing); }
/** * Sync site's plugin plan. * * @author Vova Feldman (@svovaf) * @since 1.0.6 * @uses FS_Api * * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by * the admin. */ private function _sync_plugin_license($background = false) { $this->_logger->entrance(); // Sync site info. $site = $this->send_install_update(array(), true); $plan_change = 'none'; if ($this->is_api_error($site)) { $api = $this->get_api_site_scope(); // Try to ping API to see if not blocked. if (!$api->test()) { // Failed to ping API - blocked! $this->_admin_notices->add(sprintf(__fs('server-blocking-access', $this->_slug), $this->get_plugin_name(), '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>') . '<br> ' . __fs('server-error-message', $this->_slug) . var_export($site->error, true), __fs('oops', $this->_slug) . '...', 'error', $background); } else { // Authentication params are broken. $this->_admin_notices->add(__fs('wrong-authentication-param-message', $this->_slug), __fs('oops', $this->_slug) . '...', 'error'); } } else { $site = new FS_Site($site); // Sync licenses. $this->_sync_licenses(); // Sync plans. $this->_sync_plans(); // Check if plan / license changed. if (!FS_Entity::equals($site->plan, $this->_site->plan) || $site->trial_plan_id != $this->_site->trial_plan_id || $site->trial_ends != $this->_site->trial_ends || $site->license_id != $this->_site->license_id) { if ($site->is_trial() && !$this->_site->is_trial()) { // New trial started. $this->_site = $site; $plan_change = 'trial_started'; // Store trial plan information. $this->_enrich_site_trial_plan(true); } else { if ($this->_site->is_trial() && !$site->is_trial() && !is_numeric($site->license_id)) { // Was in trial, but now trial expired and no license ID. // New trial started. $this->_site = $site; $plan_change = 'trial_expired'; // Clear trial plan information. $this->_storage->trial_plan = null; } else { $is_free = $this->is_free_plan(); // Make sure license exist and not expired. $new_license = is_null($site->license_id) ? null : $this->_get_license_by_id($site->license_id); if ($is_free && (!is_object($new_license) || $new_license->is_expired())) { // The license is expired, so ignore upgrade method. } else { // License changed. $this->_site = $site; $this->_update_site_license($new_license); $this->_store_licenses(); $this->_enrich_site_plan(true); $plan_change = $is_free ? 'upgraded' : (is_object($new_license) ? 'changed' : 'downgraded'); } } } // Store updated site info. $this->_store_site(); } else { if (is_object($this->_license) && $this->_license->is_expired()) { if (!$this->has_features_enabled_license()) { $this->_deactivate_license(); $plan_change = 'downgraded'; } else { $plan_change = 'expired'; } } if (is_numeric($site->license_id) && is_object($this->_license)) { $this->_sync_site_subscription($this->_license); } } } switch ($plan_change) { case 'none': if (!$background && is_admin()) { $this->_admin_notices->add(sprintf(__fs('plan-did-not-change-message', $this->_slug) . ' ' . sprintf('<a href="%s">%s</a>', $this->contact_url('bug', sprintf(__fs('plan-did-not-change-email-message', $this->_slug), strtoupper($this->_site->plan->name))), __fs('contact-us-here', $this->_slug))), __fs('hmm', $this->_slug) . '...', 'error'); } break; case 'upgraded': $this->_admin_notices->add_sticky(sprintf(__fs('plan-upgraded-message', $this->_slug), '<i>' . $this->get_plugin_name() . '</i>') . ($this->is_premium() ? '' : ' ' . $this->_get_latest_download_link(sprintf(__fs('download-latest-x-version', $this->_slug), $this->_site->plan->title))), 'plan_upgraded', __fs('yee-haw', $this->_slug) . '!'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'changed': $this->_admin_notices->add_sticky(sprintf(__fs('plan-changed-to-x-message', $this->_slug), $this->_site->plan->title), 'plan_changed'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'downgraded': $this->_admin_notices->add_sticky(sprintf(__fs('license-expired-blocking-message', $this->_slug)), 'license_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'expired': $this->_admin_notices->add_sticky(sprintf(__fs('license-expired-non-blocking-message', $this->_slug), $this->_site->plan->title), 'license_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'trial_started': $this->_admin_notices->add_sticky(sprintf(__fs('trial-started-message', $this->_slug), '<i>' . $this->get_plugin_name() . '</i>') . ($this->is_premium() ? '' : ' ' . $this->_get_latest_download_link(sprintf(__fs('download-latest-x-version', $this->_slug), $this->_storage->trial_plan->title))), 'trial_started', __fs('yee-haw', $this->_slug) . '!'); $this->_admin_notices->remove_sticky(array('trial_promotion')); break; case 'trial_expired': $this->_admin_notices->add_sticky(__fs('trial-expired-message', $this->_slug), 'trial_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'plan_upgraded')); break; } if ('none' !== $plan_change) { $this->do_action('after_license_change', $plan_change, $this->_site->plan); } }
/** * @param object|bool $subscription */ function __construct($subscription = false) { parent::__construct($subscription); }
/** * @author Vova Feldman (@svovaf) * @since 1.0.0 * * @return bool */ function is_refund() { return parent::is_valid_id($this->bound_payment_id) && 0 > $this->gross; }
function __construct($tag = false) { parent::__construct($tag); }
/** * Sync site's plugin plan. * * @author Vova Feldman (@svovaf) * @since 1.0.6 * @uses FS_Api * * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin. */ private function _sync_plugin_license($background = false) { $this->_logger->entrance(); // Load site details. $site = $this->_fetch_site(true); $plan_change = 'none'; if (isset($site->error)) { $api = $this->get_api_site_scope(); // Try to ping API to see if not blocked. if (!$api->test()) { // Failed to ping API - blocked! $this->_admin_notices->add(sprintf(__('Your server is blocking the access to Freemius\' API, which is crucial for %1s license synchronization. Please contact your host to whitelist %2s', WP_FS__SLUG), $this->get_plugin_name(), '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>') . '<br> Error received from the server: ' . var_export($site->error, true), __('Oops...', WP_FS__SLUG), 'error', $background); } else { // Authentication params are broken. $this->_admin_notices->add(__('It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', WP_FS__SLUG), __('Oops...', WP_FS__SLUG), 'error'); } // Plan update failure, set update time to 24hours + 10min so it won't annoy the admin too much. $this->_site->updated = time() - WP_FS__TIME_24_HOURS_IN_SEC + WP_FS__TIME_10_MIN_IN_SEC; } else { // Sync licenses. $this->_sync_licenses(); // Check if plan / license changed. if (!FS_Entity::equals($site->plan, $this->_site->plan) || $site->trial_plan_id != $this->_site->trial_plan_id || $site->trial_ends != $this->_site->trial_ends || $site->license_id != $this->_site->license_id) { if ($site->is_trial() && !$this->_site->is_trial()) { // New trial started. $this->_site = $site; $plan_change = 'trial_started'; // Store trial plan information. $this->_enrich_site_trial_plan(true); } else { if ($this->_site->is_trial() && !$site->is_trial() && !is_numeric($site->license_id)) { // Was in trial, but now trial expired and no license ID. // New trial started. $this->_site = $site; $plan_change = 'trial_expired'; // Clear trial plan information. $this->_storage->trial_plan = null; } else { $is_free = $this->is_free_plan(); // Make sure license exist and not expired. $new_license = is_null($site->license_id) ? null : $this->_get_license_by_id($site->license_id); if ($is_free && (!is_object($new_license) || $new_license->is_expired())) { // The license is expired, so ignore upgrade method. } else { // License changed. $this->_site = $site; $this->_update_site_license($new_license); $this->_store_licenses(); $this->_enrich_site_plan(true); $plan_change = $is_free ? 'upgraded' : (is_object($new_license) ? 'changed' : 'downgraded'); } } } // Store updated site info. $this->_store_site(); } else { if (is_object($this->_license) && $this->_license->is_expired()) { if (!$this->has_features_enabled_license()) { $this->_deactivate_license(); $plan_change = 'downgraded'; } else { $plan_change = 'expired'; } } if (is_numeric($site->license_id) && is_object($this->_license)) { $this->_sync_site_subscription($this->_license); } } } switch ($plan_change) { case 'none': if (!$background && is_admin()) { $this->_admin_notices->add(sprintf(__('It looks like your plan did\'t change. If you did upgrade, it\'s probably an issue on our side - sorry. %1sPlease contact us here%2s', WP_FS__SLUG), '<a href="' . $this->contact_url('bug', sprintf(__('I have upgraded my account but when I try to Sync the License, the plan remains %s.', WP_FS__SLUG), strtoupper($this->_site->plan->name))) . '">', '</a>'), __('Hmm...', WP_FS__SLUG), 'error'); } break; case 'upgraded': $this->_admin_notices->add_sticky(sprintf(__('Your plan was successfully upgraded.', WP_FS__SLUG), '<i>' . $this->get_plugin_name() . '</i>') . ($this->is_premium() ? '' : ' ' . $this->_get_latest_download_link(sprintf(__('Download the latest %s version now', WP_FS__SLUG), $this->_site->plan->title))), 'plan_upgraded', __('Ye-ha!', WP_FS__SLUG)); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'changed': $this->_admin_notices->add_sticky(sprintf(__('Your plan was successfully changed to %s.', WP_FS__SLUG), $this->_site->plan->title), 'plan_changed'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'downgraded': $this->_admin_notices->add_sticky(sprintf(__('Your license has expired. You can still continue using the free plugin forever.', WP_FS__SLUG)), 'license_expired', __('Hmm...', WP_FS__SLUG)); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'expired': $this->_admin_notices->add_sticky(sprintf(__('Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', WP_FS__SLUG), $this->_site->plan->title), 'license_expired', __('Hmm...', WP_FS__SLUG)); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'trial_started': $this->_admin_notices->add_sticky(sprintf(__('Your trial has been successfully started.', WP_FS__SLUG), '<i>' . $this->get_plugin_name() . '</i>') . ($this->is_premium() ? '' : ' ' . $this->_get_latest_download_link(sprintf(__('Download the latest %s version now', WP_FS__SLUG), $this->_storage->trial_plan->title))), 'trial_started', __('Ye-ha!', WP_FS__SLUG)); $this->_admin_notices->remove_sticky(array('trial_promotion')); break; case 'trial_expired': $this->_admin_notices->add_sticky(__('Your trial has expired. You can still continue using all our free features.', WP_FS__SLUG), 'trial_expired', __('Hm...', WP_FS__SLUG)); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'plan_upgraded')); break; } if ('none' !== $plan_change) { $this->do_action('after_license_change', $plan_change, $this->_site->plan); } }
/** * @param stdClass|bool $license */ function __construct($license = false) { parent::__construct($license); }
/** * @param stdClass|bool $plugin_info */ function __construct($plugin_info = false) { parent::__construct($plugin_info); }
/** * Sync site's plugin plan. * * @author Vova Feldman (@svovaf) * @since 1.0.6 * @uses FS_Api * * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by * the admin. */ private function _sync_plugin_license($background = false) { $this->_logger->entrance(); /** * Sync site info. * * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version. */ $site = $this->send_install_update(array(), true); $plan_change = 'none'; if ($this->is_api_error($site)) { // Show API messages only if not background sync or if paying customer. if (!$background || $this->is_paying()) { // Try to ping API to see if not blocked. if (!FS_Api::test()) { /** * Failed to ping API - blocked! * * @author Vova Feldman (@svovaf) * @since 1.1.6 Only show message related to one of the Freemius powered plugins. Once it will be resolved it will fix the issue for all plugins anyways. There's no point to scare users with multiple error messages. */ $api = $this->get_api_site_scope(); if (!self::$_global_admin_notices->has_sticky('api_blocked')) { self::$_global_admin_notices->add(sprintf(__fs('server-blocking-access', $this->_slug), $this->get_plugin_name(), '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>') . '<br> ' . __fs('server-error-message', $this->_slug) . var_export($site->error, true), __fs('oops', $this->_slug) . '...', 'error', $background, false, 'api_blocked'); } } else { // Authentication params are broken. $this->_admin_notices->add(__fs('wrong-authentication-param-message', $this->_slug), __fs('oops', $this->_slug) . '...', 'error'); } } // No reason to continue with license sync while there are API issues. return; } // Remove sticky API connectivity message. self::$_global_admin_notices->remove_sticky('api_blocked'); $site = new FS_Site($site); // Sync plans. $this->_sync_plans(); if (!$this->has_paid_plan()) { $this->_site = $site; $this->_enrich_site_plan(true); $this->_store_site(); } else { /** * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license * associated with that ID is not included in the user's licenses collection. */ $this->_sync_licenses($site->license_id); // Check if plan / license changed. if (!FS_Entity::equals($site->plan, $this->_site->plan) || $site->trial_plan_id != $this->_site->trial_plan_id || $site->trial_ends != $this->_site->trial_ends || $site->license_id != $this->_site->license_id) { if ($site->is_trial() && (!$this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends)) { // New trial started. $this->_site = $site; $plan_change = 'trial_started'; // Store trial plan information. $this->_enrich_site_trial_plan(true); // For trial with subscription use-case. $new_license = is_null($site->license_id) ? null : $this->_get_license_by_id($site->license_id); if (is_object($new_license) && $new_license->is_valid()) { $this->_site = $site; $this->_update_site_license($new_license); $this->_store_licenses(); $this->_enrich_site_plan(true); $this->_sync_site_subscription($this->_license); } } else { if ($this->_site->is_trial() && !$site->is_trial() && !is_numeric($site->license_id)) { // Was in trial, but now trial expired and no license ID. // New trial started. $this->_site = $site; $plan_change = 'trial_expired'; // Clear trial plan information. $this->_storage->trial_plan = null; } else { $is_free = $this->is_free_plan(); // Make sure license exist and not expired. $new_license = is_null($site->license_id) ? null : $this->_get_license_by_id($site->license_id); if ($is_free && is_null($new_license) && $this->has_any_license() && $this->_license->is_cancelled) { // License cancelled. $this->_site = $site; $this->_update_site_license($new_license); $this->_store_licenses(); $this->_enrich_site_plan(true); $plan_change = 'cancelled'; } else { if ($is_free && (!is_object($new_license) || $new_license->is_expired())) { // The license is expired, so ignore upgrade method. } else { // License changed. $this->_site = $site; $this->_update_site_license($new_license); $this->_store_licenses(); $this->_enrich_site_plan(true); $plan_change = $is_free ? 'upgraded' : (is_object($new_license) ? 'changed' : 'downgraded'); } } } } // Store updated site info. $this->_store_site(); } else { if (is_object($this->_license) && $this->_license->is_expired()) { if (!$this->has_features_enabled_license()) { $this->_deactivate_license(); $plan_change = 'downgraded'; } else { $plan_change = 'expired'; } } if (is_numeric($site->license_id) && is_object($this->_license)) { $this->_sync_site_subscription($this->_license); } } } if ($this->has_paid_plan()) { switch ($plan_change) { case 'none': if (!$background && is_admin()) { $plan = $this->is_trial() ? $this->_storage->trial_plan : $this->_site->plan; $this->_admin_notices->add(sprintf(__fs('plan-did-not-change-message', $this->_slug), '<i><b>' . $plan->title . ($this->is_trial() ? ' ' . __fs('trial', $this->_slug) : '') . '</b></i>') . ' ' . sprintf('<a href="%s">%s</a>', $this->contact_url('bug', sprintf(__fs('plan-did-not-change-email-message', $this->_slug), strtoupper($plan->name))), __fs('contact-us-here', $this->_slug)), __fs('hmm', $this->_slug) . '...'); } break; case 'upgraded': $this->_admin_notices->add_sticky(sprintf(__fs('plan-upgraded-message', $this->_slug), '<i>' . $this->get_plugin_name() . '</i>') . $this->get_complete_upgrade_instructions(), 'plan_upgraded', __fs('yee-haw', $this->_slug) . '!'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'changed': $this->_admin_notices->add_sticky(sprintf(__fs('plan-changed-to-x-message', $this->_slug), $this->_site->plan->title), 'plan_changed'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'trial_expired', 'activation_complete')); break; case 'downgraded': $this->_admin_notices->add_sticky(sprintf(__fs('license-expired-blocking-message', $this->_slug)), 'license_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'cancelled': $this->_admin_notices->add(__fs('license-cancelled', $this->_slug) . ' ' . sprintf('<a href="%s">%s</a>', $this->contact_url('bug'), __fs('contact-us-here', $this->_slug)), __fs('hmm', $this->_slug) . '...', 'error'); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'expired': $this->_admin_notices->add_sticky(sprintf(__fs('license-expired-non-blocking-message', $this->_slug), $this->_site->plan->title), 'license_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky('plan_upgraded'); break; case 'trial_started': $this->_admin_notices->add_sticky(sprintf(__fs('trial-started-message', $this->_slug), '<i>' . $this->get_plugin_name() . '</i>') . $this->get_complete_upgrade_instructions($this->_storage->trial_plan->title), 'trial_started', __fs('yee-haw', $this->_slug) . '!'); $this->_admin_notices->remove_sticky(array('trial_promotion')); break; case 'trial_expired': $this->_admin_notices->add_sticky(__fs('trial-expired-message', $this->_slug), 'trial_expired', __fs('hmm', $this->_slug) . '...'); $this->_admin_notices->remove_sticky(array('trial_started', 'trial_promotion', 'plan_upgraded')); break; } } if ('none' !== $plan_change) { $this->do_action('after_license_change', $plan_change, $this->_site->plan); } }
/** * @param bool|stdClass $scope_entity */ function __construct($scope_entity = false) { parent::__construct($scope_entity); }