/** * Disable a license key. * * ## Options * * <key> * : License key * * @param $args * @param $assoc_args */ public function disable($args, $assoc_args) { list($key) = $args; if (substr($key, -3) == '...') { $key = substr($key, 0, strlen($key) - 3); if (strlen($key) < 3) { WP_CLI::error('At least the first three characters of the key must be provided to perform a partial match.'); } $keys = itelic_get_keys(array('key_like' => $key)); if (empty($keys)) { WP_CLI::error('No partial match found.'); } if (count($keys) > 1) { WP_CLI::line('Multiple keys found.'); $this->list_(array(), array('key_like' => $key)); return; } $object = reset($keys); } else { $object = $this->fetcher->get_check($key); } $object->set_status(\ITELIC\Key::DISABLED); WP_CLI::success("Key disabled."); }
/** * Enter the renewal process when the renew button is pressed on the super * widget. * * @since 1.0 */ public function enter_renewal_process_sw() { if (!isset($_GET['sw-product']) || !isset($_GET['nonce'])) { return; } $product = $_GET['sw-product']; if (!wp_verify_nonce($_GET['nonce'], "itelic-renew-{$product}")) { it_exchange_add_message('error', __("Something went wrong. Please refresh and try again.", Plugin::SLUG)); return; } it_exchange_add_product_to_shopping_cart($product, 1); $keys = itelic_get_keys(array('product' => $product, 'customer' => it_exchange_get_current_customer_id())); $keys = array_filter($keys, function (Key $key) { return $key->is_renewable(); }); if (count($keys) == 1) { $key = reset($keys); } else { $key = null; } $this->update_cache_data(array("p{$product}" => is_null($key) ? null : $key->get_key())); $this->persist(); die(1); }
/** * Delete a customer's license keys when the customer is deleted. * * @since 1.0 * * @param int $id */ function delete_keys_when_customer_deleted($id) { foreach (itelic_get_keys(array('customer' => $id)) as $key) { $key->delete(); } }
/** * Retrieve the licenses. * * @since 1.0 * * @return Key[] */ protected function get_licenses() { $args = array('customer' => it_exchange_get_current_customer_id()); return itelic_get_keys($args); }
/** * Get the current customers keys. * * @since 1.0 * * @return Key[] */ protected function get_keys() { return itelic_get_keys(array('customer' => $this->user->ID)); }
<?php /** * Template file for the renew product purchase requirement * * @author Iron Bound Designs * @since 1.0 */ $query = itelic_get_keys(array('customer' => it_exchange_get_current_customer_id(), 'product' => \ITELIC\get_current_product_id())); ?> <style type="text/css"> .renew-product-wrapper { background: #F6F6F6; padding: 1em; } #itelic-key-to-renew { display: block; max-width: 250px; white-space: nowrap; } </style> <div class="it-exchange-sw-processing it-exchange-sw-processing-renew-product"> <form method="POST" class="it-exchange-sw-renew-product"> <div class="renew-product-wrapper"> <label for="itelic-key-to-renew"><?php _e("Select Key to Renew", ITELIC\Plugin::SLUG);
/** * Get the license key for a particular transaction product. * * @internal * * @since 1.0 * * @param int $transaction_id * @param int $product_id * * @return Key */ function get_key_for_transaction_product($transaction_id, $product_id) { $data = itelic_get_keys(array('transaction' => absint($transaction_id), 'product' => absint($product_id), 'items_per_page' => 1, 'sql_calc_found_rows' => false)); if (empty($data)) { return null; } return reset($data); }
echo esc_attr($product); ?> "> <?php echo itelic_get_product($product)->post_title; ?> </label> <select id="itelic-renew-product-<?php echo esc_attr($product); ?> " name="itelic_key[<?php echo esc_attr($product); ?> ]"> <?php $keys = itelic_get_keys(array('customer' => it_exchange_get_current_customer_id(), 'product' => $product)); ?> <?php foreach ($keys as $key) { ?> <?php if ($key->get_expires() !== null) { ?> <option value="<?php echo esc_attr($key->get_key()); ?> "> <?php echo $key->get_key(); ?>
/** * Generate renewal records. * * ## Options * * <rate> * : Renewal rate as a percentage. Ex: 50 or 35 * * [--product=<product>] * : Only generate renewals for a certain product. * * @param $args * @param $assoc_args */ public function generate($args, $assoc_args) { list($rate) = $args; if ($rate < 1 || $rate > 100) { WP_CLI::error("Usage: 1 < <rate> <= 100"); } $query_args = array('status' => \ITELIC\Key::EXPIRED); if ($p = \WP_CLI\Utils\get_flag_value($assoc_args, 'product')) { $query_args['product'] = $p; } $keys = itelic_get_keys($query_args); $notify = \WP_CLI\Utils\make_progress_bar('Generating renewals.', count($keys)); foreach ($keys as $key) { if (rand(0, 100) <= $rate) { $min = $key->get_expires(); $min->sub(new DateInterval('P15D')); $max = $key->get_expires(); $max->add(new DateInterval('P30D')); $txn = itelic_create_renewal_transaction(array('key' => $key->get_key(), 'date' => $this->faker->dateTimeBetween($min, $max)->format('Y-m-d H:i:s'))); if (is_wp_error($txn)) { WP_CLI::error($txn); } $key->renew($txn); } $notify->tick(); } $notify->finish(); }