Exemplo n.º 1
0
/**
 * Create a license key.
 *
 * @api
 *
 * @param array $args        {
 *
 * @type string $key         The license key to be used. If empty, one will be
 *       generated.
 * @type int    $transaction Transaction ID. If empty, one will be manually
 *       generated
 * @type int    $product     Product ID.
 * @type int    $customer    Customer ID.
 * @type string $status      The key's status. Accepts 'active', 'expired',
 *       'disabled'
 * @type float  $paid        If manually generating a transaction, the amount
 *       paid.
 * @type int    $limit       Activation limit.
 * @type string $expires     Expiration date. Pass null or empty string for
 *       forever.
 * @type string $date        When the transaction occurred. GMT.
 * }
 *
 * @return \ITELIC\Key|WP_Error
 */
function itelic_create_key($args)
{
    $defaults = array('key' => '', 'transaction' => '', 'product' => '', 'customer' => '', 'status' => '', 'paid' => '');
    $args = ITUtility::merge_defaults($args, $defaults);
    $product = itelic_get_product($args['product']);
    if (!$product->has_feature('licensing')) {
        return new WP_Error('invalid_product', __("Product does not have licensing enabled.", \ITELIC\Plugin::SLUG));
    }
    $customer = it_exchange_get_customer($args['customer']);
    if (!$customer) {
        return new WP_Error('invalid_customer', __("Invalid customer", \ITELIC\Plugin::SLUG));
    }
    $transaction = it_exchange_get_transaction($args['transaction']);
    if (!$args['transaction']) {
        if (!function_exists('it_exchange_manual_purchases_addon_transaction_uniqid')) {
            return new WP_Error('no_manual_purchases', __("Manual purchases add-on is not installed.", \ITELIC\Plugin::SLUG));
        }
        // Grab default currency
        $settings = it_exchange_get_option('settings_general');
        $currency = $settings['default-currency'];
        $description = array();
        $product_id = $product->ID;
        $itemized_data = apply_filters('it_exchange_add_itemized_data_to_cart_product', array(), $product_id);
        if (!is_serialized($itemized_data)) {
            $itemized_data = maybe_serialize($itemized_data);
        }
        $key = $product_id . '-' . md5($itemized_data);
        $products[$key]['product_base_price'] = $product->get_feature('base-price');
        $products[$key]['product_subtotal'] = $products[$key]['product_base_price'];
        //need to add count
        $products[$key]['product_name'] = get_the_title($product_id);
        $products[$key]['product_id'] = $product_id;
        $products[$key]['count'] = 1;
        $description[] = $products[$key]['product_name'];
        $description = apply_filters('it_exchange_get_cart_description', join(', ', $description), $description);
        // Package it up and send it to the transaction method add-on
        $total = empty($args['paid']) ? 0 : it_exchange_convert_to_database_number($args['paid']);
        $object = new stdClass();
        $object->total = number_format(it_exchange_convert_from_database_number($total), 2, '.', '');
        $object->currency = $currency;
        $object->description = $description;
        $object->products = $products;
        remove_action('it_exchange_add_transaction_success', 'ITELIC\\on_add_transaction_generate_license_keys');
        $uniquid = it_exchange_manual_purchases_addon_transaction_uniqid();
        $txn_args = array();
        if (isset($args['date'])) {
            $date = \ITELIC\make_date_time($args['date']);
            $txn_args['post_date'] = \ITELIC\convert_gmt_to_local($date)->format('Y-m-d H:i:s');
            $txn_args['post_date_gmt'] = $date->format('Y-m-d H:i:s');
        }
        $tid = it_exchange_add_transaction('manual-purchases', $uniquid, 'Completed', $customer->id, $object, $txn_args);
        add_action('it_exchange_add_transaction_success', 'ITELIC\\on_add_transaction_generate_license_keys');
        $transaction = it_exchange_get_transaction($tid);
    }
    $factory = new \ITELIC\Key\Factory($product, $customer, $transaction);
    $key = \ITELIC\generate_key_for_transaction_product($transaction, $product, $factory, $args['status'], $args['key']);
    if (isset($args['limit'])) {
        if (empty($args['limit']) || $args['limit'] == '-') {
            $limit = '';
        } else {
            $limit = $args['limit'];
        }
        $key->set_max($limit);
    }
    if (isset($args['expires'])) {
        if (is_string($args['expires'])) {
            $expires = \ITELIC\make_date_time($args['expires']);
        } else {
            $expires = $args['expires'];
        }
        if (!$expires instanceof DateTime) {
            $expires = null;
        }
        $key->set_expires($expires);
    }
    return $key;
}
Exemplo n.º 2
0
/**
 * Create a renewal transaction key.
 *
 * @api
 *
 * @param array $args {
 *
 * @type string $key  The license key to be used. If empty, one will be
 *       generated.
 * @type float  $paid If manually generating a transaction, the amount paid.
 * @tpye string $date When the transaction occurred. GMT.
 * }
 *
 * @return IT_Exchange_Transaction
 */
function itelic_create_renewal_transaction($args)
{
    $defaults = array('key' => '', 'paid' => '', 'date' => '');
    $args = ITUtility::merge_defaults($args, $defaults);
    $key = itelic_get_key($args['key']);
    if (!$key) {
        return new WP_Error('invalid_key', __("Invalid key", \ITELIC\Plugin::SLUG));
    }
    $product = $key->get_product();
    if (!function_exists('it_exchange_manual_purchases_addon_transaction_uniqid')) {
        return new WP_Error('no_manual_purchases', __("Manual purchases add-on is not installed.", \ITELIC\Plugin::SLUG));
    }
    // Grab default currency
    $settings = it_exchange_get_option('settings_general');
    $currency = $settings['default-currency'];
    $description = array();
    $product_id = $product->ID;
    $itemized_data = apply_filters('it_exchange_add_itemized_data_to_cart_product', array(), $product_id);
    if (!is_serialized($itemized_data)) {
        $itemized_data = maybe_serialize($itemized_data);
    }
    $i = $product_id . '-' . md5($itemized_data);
    $discounted = new \ITELIC\Renewal\Discount($key);
    $discounted = $discounted->get_discount_price();
    $products[$i]['product_base_price'] = $discounted;
    $products[$i]['product_subtotal'] = $products[$i]['product_base_price'];
    //need to add count
    $products[$i]['product_name'] = get_the_title($product_id);
    $products[$i]['product_id'] = $product_id;
    $products[$i]['count'] = 1;
    $description[] = $products[$i]['product_name'];
    $description = apply_filters('it_exchange_get_cart_description', join(', ', $description), $description);
    // Package it up and send it to the transaction method add-on
    $total = empty($args['paid']) ? $discounted : it_exchange_convert_to_database_number($args['paid']);
    $object = new stdClass();
    $object->total = number_format(it_exchange_convert_from_database_number($total), 2, '.', '');
    $object->currency = $currency;
    $object->description = $description;
    $object->products = $products;
    remove_action('it_exchange_add_transaction_success', 'ITELIC\\renew_key_on_renewal_purchase');
    $uniquid = it_exchange_manual_purchases_addon_transaction_uniqid();
    $txn_args = array();
    if (isset($args['date'])) {
        $date = \ITELIC\make_date_time($args['date']);
        $txn_args['post_date'] = \ITELIC\convert_gmt_to_local($date)->format('Y-m-d H:i:s');
        $txn_args['post_date_gmt'] = $date->format('Y-m-d H:i:s');
    }
    $customer = $key->get_customer()->id;
    $tid = it_exchange_add_transaction('manual-purchases', $uniquid, 'Completed', $customer, $object, $txn_args);
    add_action('it_exchange_add_transaction_success', 'ITELIC\\renew_key_on_renewal_purchase');
    return it_exchange_get_transaction($tid);
}
Exemplo n.º 3
0
    /**
     * Render the release view.
     */
    public function render()
    {
        if (!$this->release) {
            return;
        }
        $df = str_replace('F', 'M', get_option('date_format'));
        $tf = get_option('time_format');
        $dtf = "{$df} {$tf}";
        if ($this->release->get_status() == Release::STATUS_DRAFT) {
            $click_edit = ' title="' . __("Click to Edit", Plugin::SLUG) . '"';
        } else {
            $click_edit = '';
        }
        ?>

		<div id="release-details">
			<div class="spacing-wrapper bottom-border header-block">

				<div class="status status-<?php 
        echo esc_attr($this->release->get_status());
        ?>
">
					<span data-value="<?php 
        echo esc_attr($this->release->get_status());
        ?>
"<?php 
        echo $click_edit;
        ?>
>
						<?php 
        echo $this->release->get_status(true);
        ?>
					</span>
				</div>

				<div class="name-block">
					<h2 class="product-name"><?php 
        echo $this->release->get_product()->post_title;
        ?>
</h2>

					<h2 class="version-name"><?php 
        echo $this->release->get_version();
        ?>
</h2>
				</div>
			</div>

			<div class="spacing-wrapper bottom-border third-row misc-block">
				<div class="third type">
					<h4><?php 
        _e("Type", Plugin::SLUG);
        ?>
</h4>

					<h3 data-value="<?php 
        echo $this->release->get_type();
        ?>
"<?php 
        echo $click_edit;
        ?>
>
						<?php 
        echo $this->release->get_type(true);
        ?>
					</h3>
				</div>
				<div class="third release-date">
					<h4><?php 
        _e("Released", Plugin::SLUG);
        ?>
</h4>

					<h3>
						<?php 
        if (null === $this->release->get_start_date()) {
            ?>
							<?php 
            echo '&mdash;';
            ?>
						<?php 
        } else {
            ?>
							<?php 
            echo \ITELIC\convert_gmt_to_local($this->release->get_start_date())->format($df);
            ?>
						<?php 
        }
        ?>
					</h3>
				</div>
				<div class="third version">
					<h4><?php 
        _e("Version", Plugin::SLUG);
        ?>
</h4>

					<h3 data-value="<?php 
        echo $this->release->get_version();
        ?>
"<?php 
        echo $click_edit;
        ?>
>
						<?php 
        echo $this->release->get_version();
        ?>
					</h3>
				</div>
			</div>

			<?php 
        if (get_post_meta($this->release->get_product()->ID, '_itelic_first_release', true) == $this->release->get_pk()) {
            ?>

				<div class="spacing-wrapper">
					<p class="initial-release-notice">
						<?php 
            printf(__("Congratulations on releasing %s; there isn't any data to display for your first release, though.", Plugin::SLUG), $this->release->get_product()->post_title);
            ?>
					</p>
				</div>

				</div>

				<?php 
            return;
            ?>
			<?php 
        }
        ?>

			<?php 
        if ($this->release->get_status() == Release::STATUS_DRAFT) {
            ?>

				<?php 
            $this->render_replace_file_section();
            ?>

			<?php 
        }
        ?>

			<?php 
        $this->render_security_message();
        $this->render_upgrades_bar();
        $this->render_whats_changed();
        if ($this->release->get_status() != Release::STATUS_ARCHIVED) {
            $this->render_notification_editor();
        }
        $this->render_progress_line_chart();
        $this->render_versions_pie_chart();
        $this->render_notify_button_section();
        ?>
		</div>

		<?php 
        /**
         * Fires after the main single release screen.
         *
         * @since 1.0
         *
         * @param Release $release
         */
        do_action('itelic_single_release_screen_after', $this->release);
    }
Exemplo n.º 4
0
    /**
     * Get the activation row HTML.
     *
     * @since 1.0
     *
     * @param Activation $activation
     *
     * @return string
     */
    public function get_activation_row_html(Activation $activation)
    {
        $n_deactivate = wp_create_nonce('itelic-remote-deactivate-' . $activation->get_id());
        $n_delete = wp_create_nonce('itelic-remote-delete-' . $activation->get_id());
        ob_start();
        ?>

		<tr>
			<td data-title="<?php 
        _e("Location", Plugin::SLUG);
        ?>
">
				<?php 
        echo $activation->get_location();
        ?>
			</td>
			<td data-title="<?php 
        _e("Status", Plugin::SLUG);
        ?>
">
				<?php 
        echo $activation->get_status(true);
        ?>
			</td>
			<td data-title="<?php 
        _e("Activation", Plugin::SLUG);
        ?>
">
				<?php 
        echo \ITELIC\convert_gmt_to_local($activation->get_activation())->format($this->get_short_df());
        ?>
			</td>
			<td data-title="<?php 
        _e("Deactivation", Plugin::SLUG);
        ?>
">
				<?php 
        if (null === ($d = $activation->get_deactivation())) {
            ?>
					<a href="javascript:" data-id="<?php 
            echo esc_attr($activation->get_id());
            ?>
" data-nonce="<?php 
            echo $n_deactivate;
            ?>
" class="deactivate">
						<?php 
            _e("Deactivate", Plugin::SLUG);
            ?>
					</a>
				<?php 
        } else {
            ?>
					<?php 
            echo \ITELIC\convert_gmt_to_local($d)->format($this->get_short_df());
            ?>
				<?php 
        }
        ?>
			</td>
			<td data-title="<?php 
        _e("Version", Plugin::SLUG);
        ?>
">
				<?php 
        if (null === ($r = $activation->get_release())) {
            ?>
					<?php 
            _e("Unknown", Plugin::SLUG);
            ?>
				<?php 
        } else {
            ?>
					<?php 
            printf('v%s', $r->get_version());
            ?>
				<?php 
        }
        ?>
			</td>
			<td data-title="<?php 
        _e("Delete", Plugin::SLUG);
        ?>
">
				<button data-id="<?php 
        echo esc_attr($activation->get_id());
        ?>
" class="remove-item" data-nonce="<?php 
        echo $n_delete;
        ?>
">
					&times;
				</button>
			</td>
		</tr>

		<?php 
        return ob_get_clean();
    }
 /**
  * Retrieve the key's activation count.
  *
  * @since 1.0
  *
  * @param array $options
  *
  * @return string
  */
 public function expiration_date($options = array())
 {
     $defaults = array('format' => 'html', 'df' => str_replace('F', 'M', get_option('date_format')), 'label' => __('Expires', ITELIC\Plugin::SLUG));
     $options = ITUtility::merge_defaults($options, $defaults);
     if ($this->license) {
         if ($this->license->get_expires() === null) {
             $value = __("Never", ITELIC\Plugin::SLUG);
         } else {
             $value = \ITELIC\convert_gmt_to_local($this->license->get_expires())->format($options['df']);
         }
     } else {
         $value = '';
     }
     switch ($options['format']) {
         case 'html':
             return $value;
             break;
         case 'value':
             return $value;
             break;
         case 'label':
             return $options['label'];
             break;
         default:
             return $value;
             break;
     }
 }
Exemplo n.º 6
0
 /**
  * Get the progress line chart.
  *
  * @since 1.0
  *
  * @param Release $release
  *
  * @return Chart\Base
  */
 private function get_progress_chart(Release $release)
 {
     if ($release->get_status() == Release::STATUS_DRAFT) {
         return null;
     }
     $raw = $release->get_first_14_days_of_upgrades();
     $now = new \DateTime();
     $diff = $release->get_start_date()->diff($now);
     $days = min(14, max($diff->days + 1, 1));
     $data = array();
     $day = \ITELIC\convert_gmt_to_local(clone $release->get_start_date());
     $sql_df = 'Y-m-d';
     for ($i = 0; $i < $days; $i++) {
         $key = $day->format($sql_df);
         if (isset($raw[$key])) {
             $data[$key] = $raw[$key];
         } else {
             $data[$key] = 0;
         }
         $day = $day->add(new \DateInterval('P1D'));
     }
     $df = 'M j';
     $labels = array_map(function ($day) use($df) {
         $day = new \DateTime($day);
         return $day->format($df);
     }, array_keys($data));
     $chart = new Chart\Line($labels, 698, 200, array('scaleIntegersOnly' => true, 'scaleBeginAtZero' => true, 'ibdLoadOn' => 'loadProgressChart', 'responsive' => true));
     $chart->add_data_set(array_values($data), '', array('fillColor' => "rgba(151,187,205,0.2)", 'strokeColor' => "rgba(151,187,205,1)", 'pointColor' => "rgba(151,187,205,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(151,187,205,1)"));
     return $chart;
 }