/** * Apply the renewal discount. * * @since 1.0 * * @param string|float $db_base_price * @param array $product * @param bool $format * * @return string|float */ public function apply_renewal_discount($db_base_price, $product, $format) { try { $product = itelic_get_product($product['product_id']); } catch (\Exception $e) { return $db_base_price; } if (!$product->get_feature('licensing')) { return $db_base_price; } $session = $this->get_cache_data(); if (!isset($session["p" . $product->ID]) || $session["p" . $product->ID] === null) { return $db_base_price; } $key = $session["p" . $product->ID]; $key = itelic_get_key($key); $discount = new Discount($key); if (!$discount->is_discount_valid()) { return $db_base_price; } return $discount->get_discount_price($format); }
public function test_discount_is_invalid_if_now_is_after_discount_expiration() { $mock_product = $this->getMockBuilder('\\ITELIC\\Product')->disableOriginalConstructor()->getMock(); $mock_product->method('get_feature')->with('licensing-discount')->willReturn(array('expiry' => 30)); $mock_key = $this->getMockBuilder('\\ITELIC\\Key')->disableOriginalConstructor()->getMock(); $mock_key->method('get_product')->willReturn($mock_product); $mock_key->method('get_expires')->willReturn(\ITELIC\make_date_time('- 2 months')); $discount = new Discount($mock_key); $this->assertFalse($discount->is_discount_valid()); }