class-fs-billing.php
9 years ago
class-fs-entity.php
9 years ago
class-fs-payment.php
9 years ago
class-fs-plugin-info.php
9 years ago
class-fs-plugin-license.php
9 years ago
class-fs-plugin-plan.php
9 years ago
class-fs-plugin-tag.php
9 years ago
class-fs-plugin.php
9 years ago
class-fs-pricing.php
9 years ago
class-fs-scope-entity.php
9 years ago
class-fs-site.php
9 years ago
class-fs-subscription.php
9 years ago
class-fs-user.php
9 years ago
index.php
9 years ago
class-fs-pricing.php
141 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius for EDD Add-On |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 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 | #endregion Properties |
| 39 | |
| 40 | /** |
| 41 | * @param object|bool $pricing |
| 42 | */ |
| 43 | function __construct( $pricing = false ) { |
| 44 | parent::__construct( $pricing ); |
| 45 | } |
| 46 | |
| 47 | static function get_type() { |
| 48 | return 'pricing'; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @author Vova Feldman (@svovaf) |
| 53 | * @since 1.1.8 |
| 54 | * |
| 55 | * @return bool |
| 56 | */ |
| 57 | function has_monthly() { |
| 58 | return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @author Vova Feldman (@svovaf) |
| 63 | * @since 1.1.8 |
| 64 | * |
| 65 | * @return bool |
| 66 | */ |
| 67 | function has_annual() { |
| 68 | return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @author Vova Feldman (@svovaf) |
| 73 | * @since 1.1.8 |
| 74 | * |
| 75 | * @return bool |
| 76 | */ |
| 77 | function has_lifetime() { |
| 78 | return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Check if unlimited licenses pricing. |
| 83 | * |
| 84 | * @author Vova Feldman (@svovaf) |
| 85 | * @since 1.1.8 |
| 86 | * |
| 87 | * @return bool |
| 88 | */ |
| 89 | function is_unlimited() { |
| 90 | return is_null( $this->licenses ); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * Check if pricing has more than one billing cycle. |
| 96 | * |
| 97 | * @author Vova Feldman (@svovaf) |
| 98 | * @since 1.1.8 |
| 99 | * |
| 100 | * @return bool |
| 101 | */ |
| 102 | function is_multi_cycle() { |
| 103 | $cycles = 0; |
| 104 | if ( $this->has_monthly() ) { |
| 105 | $cycles ++; |
| 106 | } |
| 107 | if ( $this->has_annual() ) { |
| 108 | $cycles ++; |
| 109 | } |
| 110 | if ( $this->has_lifetime() ) { |
| 111 | $cycles ++; |
| 112 | } |
| 113 | |
| 114 | return $cycles > 1; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Get annual over monthly discount. |
| 119 | * |
| 120 | * @author Vova Feldman (@svovaf) |
| 121 | * @since 1.1.8 |
| 122 | * |
| 123 | * @return int |
| 124 | */ |
| 125 | function annual_discount_percentage() { |
| 126 | return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get annual over monthly savings. |
| 131 | * |
| 132 | * @author Vova Feldman (@svovaf) |
| 133 | * @since 1.1.8 |
| 134 | * |
| 135 | * @return float |
| 136 | */ |
| 137 | function annual_savings() { |
| 138 | return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses ); |
| 139 | } |
| 140 | |
| 141 | } |