PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.48
Code Manager v1.0.48
1.0.48 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 / vendor / freemius / includes / entities / class-fs-payment.php
code-manager / vendor / freemius / includes / entities Last commit date
class-fs-affiliate-terms.php 5 days ago class-fs-affiliate.php 5 days ago class-fs-billing.php 5 days ago class-fs-entity.php 5 days ago class-fs-payment.php 5 days ago class-fs-plugin-info.php 5 days ago class-fs-plugin-license.php 5 days ago class-fs-plugin-plan.php 5 days ago class-fs-plugin-tag.php 5 days ago class-fs-plugin.php 5 days ago class-fs-pricing.php 5 days ago class-fs-scope-entity.php 5 days ago class-fs-site.php 5 days ago class-fs-subscription.php 5 days ago class-fs-user.php 5 days ago index.php 5 days ago
class-fs-payment.php
228 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2016, 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_Payment extends FS_Entity {
14
15 #region Properties
16
17 /**
18 * @var number
19 */
20 public $plugin_id;
21 /**
22 * @var number
23 */
24 public $user_id;
25 /**
26 * @var number
27 */
28 public $install_id;
29 /**
30 * @var number
31 */
32 public $subscription_id;
33 /**
34 * @var number
35 */
36 public $plan_id;
37 /**
38 * @var number
39 */
40 public $license_id;
41 /**
42 * @var float
43 */
44 public $gross;
45 /**
46 * @author Leo Fajardo (@leorw)
47 * @since 2.3.0
48 *
49 * @var string One of the following: `usd`, `gbp`, `eur`.
50 */
51 public $currency;
52 /**
53 * @var number
54 */
55 public $bound_payment_id;
56 /**
57 * @var string
58 */
59 public $external_id;
60 /**
61 * @var string
62 */
63 public $gateway;
64 /**
65 * @var string ISO 3166-1 alpha-2 - two-letter country code.
66 *
67 * @link http://www.wikiwand.com/en/ISO_3166-1_alpha-2
68 */
69 public $country_code;
70 /**
71 * @var string
72 */
73 public $vat_id;
74 /**
75 * @var float Actual Tax / VAT in $$$
76 */
77 public $vat;
78 /**
79 * @var int Payment source.
80 */
81 public $source = 0;
82
83 /**
84 * Presentment payment information for customer-facing currency display.
85 *
86 * @var object|null
87 */
88 public $presentment;
89
90 #endregion Properties
91
92 const CURRENCY_USD = 'usd';
93 const CURRENCY_GBP = 'gbp';
94 const CURRENCY_EUR = 'eur';
95 const CURRENCY_ILS = 'ils';
96 const CURRENCY_CAD = 'cad';
97 const CURRENCY_AUD = 'aud';
98 const CURRENCY_PLN = 'pln';
99
100 /**
101 * @param object|bool $payment
102 */
103 function __construct( $payment = false ) {
104 parent::__construct( $payment );
105 }
106
107 static function get_type() {
108 return 'payment';
109 }
110
111 /**
112 * @author Vova Feldman (@svovaf)
113 * @since 1.0.0
114 *
115 * @return bool
116 */
117 function is_refund() {
118 return ( parent::is_valid_id( $this->bound_payment_id ) && 0 > $this->gross );
119 }
120
121 /**
122 * Checks if the payment was migrated from another platform.
123 *
124 * @author Vova Feldman (@svovaf)
125 * @since 2.0.2
126 *
127 * @return bool
128 */
129 function is_migrated() {
130 return ( 0 != $this->source );
131 }
132
133 /**
134 * @return bool
135 */
136 private function has_presentment()
137 {
138 return is_object( $this->presentment );
139 }
140
141 /**
142 * @return float
143 */
144 private function get_display_gross()
145 {
146 return $this->has_presentment() ?
147 (float) $this->presentment->gross :
148 (float) $this->gross;
149 }
150
151 /**
152 * @return float
153 */
154 private function get_display_vat()
155 {
156 return $this->has_presentment() ?
157 (float) $this->presentment->vat :
158 (float) $this->vat;
159 }
160
161 /**
162 * @return string
163 */
164 private function get_display_currency()
165 {
166 return $this->has_presentment() ?
167 $this->presentment->currency :
168 $this->currency;
169 }
170
171 /**
172 * Returns the gross in this format:
173 * `{symbol}{amount | 2 decimal digits} {currency | uppercase}`
174 *
175 * Examples: £9.99 GBP, -£9.99 GBP.
176 *
177 * @author Leo Fajardo (@leorw)
178 * @since 2.3.0
179 *
180 * @return string
181 */
182 function formatted_gross()
183 {
184 $price = $this->get_display_gross() + $this->get_display_vat();
185
186 return (
187 ( $price < 0 ? '-' : '' ) .
188 $this->get_symbol() .
189 number_format( abs( $price ), 2, '.', ',' ) . ' ' .
190 strtoupper( $this->get_display_currency() )
191 );
192 }
193
194 /**
195 * A map between supported currencies with their symbols.
196 *
197 * @var array<string,string>
198 */
199 static $CURRENCY_2_SYMBOL;
200
201 /**
202 * @author Leo Fajardo (@leorw)
203 * @since 2.3.0
204 *
205 * @return string
206 */
207 private function get_symbol() {
208 if ( ! isset( self::$CURRENCY_2_SYMBOL ) ) {
209 // Lazy load.
210 self::$CURRENCY_2_SYMBOL = array(
211 self::CURRENCY_USD => '$',
212 self::CURRENCY_GBP => '&pound;',
213 self::CURRENCY_EUR => '&euro;',
214 self::CURRENCY_ILS => '',
215 self::CURRENCY_CAD => '$',
216 self::CURRENCY_AUD => '$',
217 self::CURRENCY_PLN => '',
218 );
219 }
220
221 $currency = $this->get_display_currency();
222
223 return isset( self::$CURRENCY_2_SYMBOL[ $currency ] )
224 ? self::$CURRENCY_2_SYMBOL[ $currency ]
225 : strtoupper( $currency ) . ' ';
226 }
227 }
228