コード例 #1
0
/**
 * Generate license keys for a transaction.
 *
 * @internal
 *
 * @since 1.0
 *
 * @param \IT_Exchange_Transaction $transaction
 * @param string                   $status Default ITELIC_Key::ACTIVE
 *
 * @return bool
 */
function generate_keys_for_transaction(\IT_Exchange_Transaction $transaction, $status = '')
{
    $result = false;
    foreach ($transaction->get_products() as $product) {
        if (isset($product['renewed_key']) && $product['renewed_key']) {
            continue;
            // this is a renewal purchase we shouldn't generate keys here.
        }
        $product = itelic_get_product($product['product_id']);
        if ($product->has_feature('licensing')) {
            $customer = it_exchange_get_transaction_customer($transaction);
            if (!$customer instanceof \IT_Exchange_Customer) {
                $customer = new \IT_Exchange_Customer($customer);
            }
            $factory = new Factory($product, $customer, $transaction);
            if (generate_key_for_transaction_product($transaction, $product, $factory, $status)) {
                $result = true;
            } else {
                $result = false;
            }
        }
    }
    return $result;
}
コード例 #2
0
/**
 * When a transaction is refunded, disable the key.
 *
 * @internal
 *
 * @since 1.0
 *
 * @param \IT_Exchange_Transaction $transaction
 * @param float                    $amount
 */
function disable_key_on_refund($transaction, $amount)
{
    if (!$transaction) {
        return;
    }
    if ($transaction->get_total() != 0) {
        return;
    }
    $keys = itelic_get_keys(array('transaction' => $transaction->ID));
    foreach ($keys as $key) {
        $key->set_status(Key::DISABLED);
    }
}
コード例 #3
0
 /**
  * Create a renewal record.
  *
  * @since 1.0
  *
  * @param Key                      $key
  * @param \IT_Exchange_Transaction $transaction
  * @param \DateTime                $expired
  * @param \DateTime                $renewal
  *
  * @return Renewal
  */
 public static function create(Key $key, \IT_Exchange_Transaction $transaction = null, \DateTime $expired, \DateTime $renewal = null)
 {
     if (empty($renewal)) {
         $renewal = make_date_time();
     }
     $revenue = '0.00';
     if ($transaction) {
         $tid = $transaction->ID;
         foreach ($transaction->get_products() as $product) {
             if ($product['product_id'] == $key->get_product()->ID) {
                 $revenue = $product['product_subtotal'];
                 break;
             }
         }
     } else {
         $tid = 0;
     }
     $data = array('lkey' => $key->get_key(), 'renewal_date' => $renewal->format("Y-m-d H:i:s"), 'key_expired_date' => $expired->format("Y-m-d H:i:s"), 'transaction_id' => $tid, 'revenue' => $revenue);
     $db = Manager::make_simple_query_object('itelic-renewals');
     $id = $db->insert($data);
     $renewal = self::get($id);
     if ($renewal) {
         /**
          * Fires when a renewal record is created.
          *
          * @since 1.0
          *
          * @param Renewal $renewal
          */
         do_action('itelic_create_renewal', $renewal);
         Cache::add($renewal);
     }
     return $renewal;
 }