PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.35
Code Manager v1.0.35
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / includes / entities / class-fs-pricing.php
code-manager / freemius / includes / entities Last commit date
class-fs-affiliate-terms.php 2 years ago class-fs-affiliate.php 2 years ago class-fs-billing.php 2 years ago class-fs-entity.php 2 years ago class-fs-payment.php 2 years ago class-fs-plugin-info.php 2 years ago class-fs-plugin-license.php 2 years ago class-fs-plugin-plan.php 2 years ago class-fs-plugin-tag.php 2 years ago class-fs-plugin.php 2 years ago class-fs-pricing.php 2 years ago class-fs-scope-entity.php 2 years ago class-fs-site.php 2 years ago class-fs-subscription.php 2 years ago class-fs-user.php 2 years ago index.php 2 years ago
class-fs-pricing.php
157 lines
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 }