コード例 #1
0
 /**
  * Renew this license.
  *
  * @since 1.0
  *
  * @param \IT_Exchange_Transaction $transaction
  *
  * @return Renewal
  */
 public function renew(\IT_Exchange_Transaction $transaction = null)
 {
     if (!$this->is_renewable()) {
         throw new \UnexpectedValueException(__("You can't renew a license key that doesn't expire.", Plugin::SLUG));
     }
     if ($transaction === null) {
         $date = null;
     } else {
         $date = make_date_time($transaction->post_date_gmt);
     }
     $record = Renewal::create($this, $transaction, $this->get_expires(), $date);
     $this->extend();
     $now = make_date_time();
     if ($this->get_expires() > $now) {
         $this->set_status(self::ACTIVE);
     }
     /**
      * Fires when a license key is renewed.
      *
      * @since 1.0
      *
      * @param Key $this
      */
     do_action('itelic_renew_key', $this);
     return $record;
 }
コード例 #2
0
/**
 * Create a renewal record.
 *
 * @api
 *
 * @since 1.0
 *
 * @param array $args
 *
 * @return \ITELIC\Renewal|WP_Error
 */
function itelic_create_renewal($args)
{
    $defaults = array('key' => '', 'transaction' => '', 'expired' => '', 'renewal' => '');
    $args = ITUtility::merge_defaults($args, $defaults);
    if (is_string($args['key'])) {
        $key = itelic_get_key($args['key']);
    } else {
        $key = $args['key'];
    }
    if (!$key) {
        return new WP_Error('invalid_key', __("Invalid Key", \ITELIC\Plugin::SLUG));
    }
    if (!empty($args['transaction'])) {
        $transaction = it_exchange_get_transaction($args['transaction']);
        if (!$transaction) {
            return new WP_Error('invalid_transaction', __("Invalid transaction.", \ITELIC\Plugin::SLUG));
        }
    } else {
        $transaction = null;
    }
    $expired = is_string($args['expired']) ? \ITELIC\make_date_time($args['expired']) : $args['expired'];
    if (!$expired instanceof DateTime) {
        return new WP_Error('invalid_expiration', __("Invalid expiration date.", \ITELIC\Plugin::SLUG));
    }
    if (!empty($args['renewal'])) {
        $renewal = is_string($args['renewal']) ? \ITELIC\make_date_time($args['renewal']) : $args['renewal'];
        if (!$renewal instanceof DateTime) {
            return new WP_Error("invalid_renewal", __("Invalid renewal date.", \ITELIC\Plugin::SLUG));
        }
    } else {
        $renewal = null;
    }
    return \ITELIC\Renewal::create($key, $transaction, $expired, $renewal);
}
コード例 #3
0
 /**
  * Get data to display for a single object.
  *
  * @param \ITELIC\Renewal $object
  * @param bool            $raw
  *
  * @return array
  */
 protected function get_fields_for_object(\ITELIC\Renewal $object, $raw = false)
 {
     if ($object->get_transaction()) {
         $transaction = it_exchange_get_transaction_order_number($object->get_transaction());
     } else {
         $transaction = 'Manual';
     }
     return array('id' => $object->get_pk(), 'key' => $object->get_key()->get_key(), 'renewal_date' => $object->get_renewal_date()->format(DateTime::ISO8601), 'expired_date' => $object->get_key_expired_date()->format(DateTime::ISO8601), 'transaction' => $transaction, 'revenue' => $object->get_revenue(!$raw));
 }