| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius for EDD Add-On |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class FS_Pricing extends FS_Entity { |
| 14 |
|
| 15 |
#region Properties |
| 16 |
|
| 17 |
/** |
| 18 |
* @var number |
| 19 |
*/ |
| 20 |
public $plan_id; |
| 21 |
/** |
| 22 |
* @var int |
| 23 |
*/ |
| 24 |
public $licenses; |
| 25 |
/** |
| 26 |
* @var null|float |
| 27 |
*/ |
| 28 |
public $monthly_price; |
| 29 |
/** |
| 30 |
* @var null|float |
| 31 |
*/ |
| 32 |
public $annual_price; |
| 33 |
/** |
| 34 |
* @var null|float |
| 35 |
*/ |
| 36 |
public $lifetime_price; |
| 37 |
/** |
| 38 |
* @author Leo Fajardo (@leorw) |
| 39 |
* @since 2.3.1 |
| 40 |
* |
| 41 |
* @var string One of the following: `usd`, `gbp`, `eur`. |
| 42 |
*/ |
| 43 |
public $currency; |
| 44 |
|
| 45 |
#endregion Properties |
| 46 |
|
| 47 |
/** |
| 48 |
* @param object|bool $pricing |
| 49 |
*/ |
| 50 |
function __construct( $pricing = false ) { |
| 51 |
parent::__construct( $pricing ); |
| 52 |
} |
| 53 |
|
| 54 |
static function get_type() { |
| 55 |
return 'pricing'; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @author Vova Feldman (@svovaf) |
| 60 |
* @since 1.1.8 |
| 61 |
* |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
function has_monthly() { |
| 65 |
return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* @author Vova Feldman (@svovaf) |
| 70 |
* @since 1.1.8 |
| 71 |
* |
| 72 |
* @return bool |
| 73 |
*/ |
| 74 |
function has_annual() { |
| 75 |
return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @author Vova Feldman (@svovaf) |
| 80 |
* @since 1.1.8 |
| 81 |
* |
| 82 |
* @return bool |
| 83 |
*/ |
| 84 |
function has_lifetime() { |
| 85 |
return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 ); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Check if unlimited licenses pricing. |
| 90 |
* |
| 91 |
* @author Vova Feldman (@svovaf) |
| 92 |
* @since 1.1.8 |
| 93 |
* |
| 94 |
* @return bool |
| 95 |
*/ |
| 96 |
function is_unlimited() { |
| 97 |
return is_null( $this->licenses ); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
/** |
| 102 |
* Check if pricing has more than one billing cycle. |
| 103 |
* |
| 104 |
* @author Vova Feldman (@svovaf) |
| 105 |
* @since 1.1.8 |
| 106 |
* |
| 107 |
* @return bool |
| 108 |
*/ |
| 109 |
function is_multi_cycle() { |
| 110 |
$cycles = 0; |
| 111 |
if ( $this->has_monthly() ) { |
| 112 |
$cycles ++; |
| 113 |
} |
| 114 |
if ( $this->has_annual() ) { |
| 115 |
$cycles ++; |
| 116 |
} |
| 117 |
if ( $this->has_lifetime() ) { |
| 118 |
$cycles ++; |
| 119 |
} |
| 120 |
|
| 121 |
return $cycles > 1; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Get annual over monthly discount. |
| 126 |
* |
| 127 |
* @author Vova Feldman (@svovaf) |
| 128 |
* @since 1.1.8 |
| 129 |
* |
| 130 |
* @return int |
| 131 |
*/ |
| 132 |
function annual_discount_percentage() { |
| 133 |
return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Get annual over monthly savings. |
| 138 |
* |
| 139 |
* @author Vova Feldman (@svovaf) |
| 140 |
* @since 1.1.8 |
| 141 |
* |
| 142 |
* @return float |
| 143 |
*/ |
| 144 |
function annual_savings() { |
| 145 |
return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses ); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* @author Leo Fajardo (@leorw) |
| 150 |
* @since 2.3.1 |
| 151 |
* |
| 152 |
* @return bool |
| 153 |
*/ |
| 154 |
function is_usd() { |
| 155 |
return ( 'usd' === $this->currency ); |
| 156 |
} |
| 157 |
} |