public function test_invalid_key_length_is_rejected() { $stub_txn = $this->getMockBuilder('\\IT_Exchange_Transaction')->disableOriginalConstructor()->getMock(); $stub_prod = $this->getMockBuilder('\\ITELIC\\Product')->disableOriginalConstructor()->getMock(); $stub_customer = $this->getMockBuilder('\\IT_Exchange_Customer')->disableOriginalConstructor()->getMock(); $this->setExpectedException('\\LengthException'); Key::create(str_repeat('-', 129), $stub_txn, $stub_prod, $stub_customer, 5); }
/** * Generate a key for a certain transaction product. * * @internal * * @since 1.0 * * @param \IT_Exchange_Transaction $transaction * @param Product $product * @param Factory $factory * @param string $status Optionally override the new key's status. Default active. * @param string $key Optionally specify the license key to be used. If empty, uses Factory. * * @return Key */ function generate_key_for_transaction_product(\IT_Exchange_Transaction $transaction, Product $product, Factory $factory, $status = '', $key = '') { $customer = it_exchange_get_transaction_customer($transaction); if (!$customer instanceof \IT_Exchange_Customer) { $customer = new \IT_Exchange_Customer($customer); } if (!$key) { $key = $factory->make(); } foreach ($transaction->get_products() as $tran_product) { if ($tran_product['product_id'] == $product->ID) { if (empty($tran_product['itemized_data'])) { continue; } if (is_string($tran_product['itemized_data'])) { $itemized = maybe_unserialize($tran_product['itemized_data']); } else { $itemized = $tran_product['itemized_data']; } if (isset($itemized['it_variant_combo_hash'])) { $hash = $itemized['it_variant_combo_hash']; $max = $product->get_feature('licensing', array('field' => 'limit', 'for_hash' => $hash)); } } } if (!isset($max)) { $max = $product->get_feature('licensing', array('field' => 'limit')); } if (!$product->has_feature('recurring-payments')) { $expires = null; } else { $type = $product->get_feature('recurring-payments', array('setting' => 'interval')); $count = $product->get_feature('recurring-payments', array('setting' => 'interval-count')); $interval = convert_rp_to_date_interval($type, $count); $expires = make_date_time($transaction->post_date_gmt); $expires->add($interval); } return Key::create($key, $transaction, $product, $customer, $max, $expires, $status); }