@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
15 | 15 | |
16 | 16 | /** |
17 | - * Which data store to load. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
17 | + * Which data store to load. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | 21 | protected $data_store_name = 'invoice'; |
22 | 22 | |
23 | 23 | /** |
24 | - * This is the name of this object type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
24 | + * This is the name of this object type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | protected $object_type = 'invoice'; |
29 | 29 | |
30 | 30 | /** |
31 | - * Item Data array. This is the core item data exposed in APIs. |
|
32 | - * |
|
33 | - * @since 1.0.19 |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $data = array( |
|
37 | - 'parent_id' => 0, |
|
38 | - 'status' => 'wpi-pending', |
|
39 | - 'version' => '', |
|
40 | - 'date_created' => null, |
|
31 | + * Item Data array. This is the core item data exposed in APIs. |
|
32 | + * |
|
33 | + * @since 1.0.19 |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $data = array( |
|
37 | + 'parent_id' => 0, |
|
38 | + 'status' => 'wpi-pending', |
|
39 | + 'version' => '', |
|
40 | + 'date_created' => null, |
|
41 | 41 | 'date_modified' => null, |
42 | 42 | 'due_date' => null, |
43 | 43 | 'completed_date' => null, |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | 'transaction_id' => '', |
80 | 80 | 'currency' => '', |
81 | 81 | 'disable_taxes' => false, |
82 | - 'subscription_id' => null, |
|
83 | - 'is_viewed' => false, |
|
84 | - 'email_cc' => '', |
|
85 | - 'template' => 'quantity', // hours, amount only |
|
82 | + 'subscription_id' => null, |
|
83 | + 'is_viewed' => false, |
|
84 | + 'email_cc' => '', |
|
85 | + 'template' => 'quantity', // hours, amount only |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | /** |
89 | - * Stores meta in cache for future reads. |
|
90 | - * |
|
91 | - * A group must be set to to enable caching. |
|
92 | - * |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - protected $cache_group = 'getpaid_invoices'; |
|
89 | + * Stores meta in cache for future reads. |
|
90 | + * |
|
91 | + * A group must be set to to enable caching. |
|
92 | + * |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + protected $cache_group = 'getpaid_invoices'; |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Stores a reference to the original WP_Post object |
@@ -106,104 +106,104 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @var int |
108 | 108 | */ |
109 | - protected $recurring_item = null; |
|
109 | + protected $recurring_item = null; |
|
110 | 110 | |
111 | - /** |
|
111 | + /** |
|
112 | 112 | * Stores an array of item totals. |
113 | - * |
|
114 | - * e.g $totals['discount'] = array( |
|
115 | - * 'initial' => 10, |
|
116 | - * 'recurring' => 10, |
|
117 | - * ) |
|
113 | + * |
|
114 | + * e.g $totals['discount'] = array( |
|
115 | + * 'initial' => 10, |
|
116 | + * 'recurring' => 10, |
|
117 | + * ) |
|
118 | 118 | * |
119 | 119 | * @var array |
120 | 120 | */ |
121 | - protected $totals = array(); |
|
121 | + protected $totals = array(); |
|
122 | 122 | |
123 | - /** |
|
124 | - * Stores the status transition information. |
|
125 | - * |
|
126 | - * @since 1.0.19 |
|
127 | - * @var bool |
|
128 | - */ |
|
129 | - protected $status_transition = false; |
|
123 | + /** |
|
124 | + * Stores the status transition information. |
|
125 | + * |
|
126 | + * @since 1.0.19 |
|
127 | + * @var bool |
|
128 | + */ |
|
129 | + protected $status_transition = false; |
|
130 | 130 | |
131 | 131 | /** |
132 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
133 | - * |
|
134 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
135 | - */ |
|
132 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
133 | + * |
|
134 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
135 | + */ |
|
136 | 136 | public function __construct( $invoice = false ) { |
137 | 137 | |
138 | 138 | parent::__construct( $invoice ); |
139 | 139 | |
140 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
141 | - $this->set_id( $invoice ); |
|
142 | - } elseif ( $invoice instanceof self ) { |
|
143 | - $this->set_id( $invoice->get_id() ); |
|
144 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
145 | - $this->set_id( $invoice->ID ); |
|
146 | - } elseif ( is_array( $invoice ) ) { |
|
147 | - $this->set_props( $invoice ); |
|
148 | - |
|
149 | - if ( isset( $invoice['ID'] ) ) { |
|
150 | - $this->set_id( $invoice['ID'] ); |
|
151 | - } |
|
152 | - |
|
153 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
154 | - $this->set_id( $invoice_id ); |
|
155 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
156 | - $this->set_id( $invoice_id ); |
|
157 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
158 | - $this->set_id( $invoice_id ); |
|
159 | - }else { |
|
160 | - $this->set_object_read( true ); |
|
161 | - } |
|
140 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
141 | + $this->set_id( $invoice ); |
|
142 | + } elseif ( $invoice instanceof self ) { |
|
143 | + $this->set_id( $invoice->get_id() ); |
|
144 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
145 | + $this->set_id( $invoice->ID ); |
|
146 | + } elseif ( is_array( $invoice ) ) { |
|
147 | + $this->set_props( $invoice ); |
|
148 | + |
|
149 | + if ( isset( $invoice['ID'] ) ) { |
|
150 | + $this->set_id( $invoice['ID'] ); |
|
151 | + } |
|
152 | + |
|
153 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
154 | + $this->set_id( $invoice_id ); |
|
155 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
156 | + $this->set_id( $invoice_id ); |
|
157 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
158 | + $this->set_id( $invoice_id ); |
|
159 | + }else { |
|
160 | + $this->set_object_read( true ); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | // Load the datastore. |
164 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
164 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
165 | 165 | |
166 | - if ( $this->get_id() > 0 ) { |
|
166 | + if ( $this->get_id() > 0 ) { |
|
167 | 167 | $this->post = get_post( $this->get_id() ); |
168 | 168 | $this->ID = $this->get_id(); |
169 | - $this->data_store->read( $this ); |
|
169 | + $this->data_store->read( $this ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
175 | - * Given an invoice key/number, it returns its id. |
|
176 | - * |
|
177 | - * |
|
178 | - * @static |
|
179 | - * @param string $value The invoice key or number |
|
180 | - * @param string $field Either key, transaction_id or number. |
|
181 | - * @since 1.0.15 |
|
182 | - * @return int |
|
183 | - */ |
|
184 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
175 | + * Given an invoice key/number, it returns its id. |
|
176 | + * |
|
177 | + * |
|
178 | + * @static |
|
179 | + * @param string $value The invoice key or number |
|
180 | + * @param string $field Either key, transaction_id or number. |
|
181 | + * @since 1.0.15 |
|
182 | + * @return int |
|
183 | + */ |
|
184 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
185 | 185 | global $wpdb; |
186 | 186 | |
187 | - // Trim the value. |
|
188 | - $value = trim( $value ); |
|
187 | + // Trim the value. |
|
188 | + $value = trim( $value ); |
|
189 | 189 | |
190 | - if ( empty( $value ) ) { |
|
191 | - return 0; |
|
192 | - } |
|
190 | + if ( empty( $value ) ) { |
|
191 | + return 0; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | // Valid fields. |
195 | 195 | $fields = array( 'key', 'number', 'transaction_id' ); |
196 | 196 | |
197 | - // Ensure a field has been passed. |
|
198 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
199 | - return 0; |
|
200 | - } |
|
197 | + // Ensure a field has been passed. |
|
198 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
199 | + return 0; |
|
200 | + } |
|
201 | 201 | |
202 | - // Maybe retrieve from the cache. |
|
203 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
204 | - if ( false !== $invoice_id ) { |
|
205 | - return $invoice_id; |
|
206 | - } |
|
202 | + // Maybe retrieve from the cache. |
|
203 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
204 | + if ( false !== $invoice_id ) { |
|
205 | + return $invoice_id; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | // Fetch from the db. |
209 | 209 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
212 | 212 | ); |
213 | 213 | |
214 | - // Update the cache with our data |
|
215 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
214 | + // Update the cache with our data |
|
215 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | 216 | |
217 | - return $invoice_id; |
|
217 | + return $invoice_id; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -240,80 +240,80 @@ discard block |
||
240 | 240 | */ |
241 | 241 | |
242 | 242 | /** |
243 | - * Get parent invoice ID. |
|
244 | - * |
|
245 | - * @since 1.0.19 |
|
246 | - * @param string $context View or edit context. |
|
247 | - * @return int |
|
248 | - */ |
|
249 | - public function get_parent_id( $context = 'view' ) { |
|
250 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
243 | + * Get parent invoice ID. |
|
244 | + * |
|
245 | + * @since 1.0.19 |
|
246 | + * @param string $context View or edit context. |
|
247 | + * @return int |
|
248 | + */ |
|
249 | + public function get_parent_id( $context = 'view' ) { |
|
250 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | - * Get parent invoice. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @return WPInv_Invoice |
|
258 | - */ |
|
254 | + * Get parent invoice. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @return WPInv_Invoice |
|
258 | + */ |
|
259 | 259 | public function get_parent_payment() { |
260 | 260 | return new WPInv_Invoice( $this->get_parent_id() ); |
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
264 | - * Alias for self::get_parent_payment(). |
|
265 | - * |
|
266 | - * @since 1.0.19 |
|
267 | - * @return WPInv_Invoice |
|
268 | - */ |
|
264 | + * Alias for self::get_parent_payment(). |
|
265 | + * |
|
266 | + * @since 1.0.19 |
|
267 | + * @return WPInv_Invoice |
|
268 | + */ |
|
269 | 269 | public function get_parent() { |
270 | 270 | return $this->get_parent_payment(); |
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | - * Get invoice status. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function get_status( $context = 'view' ) { |
|
281 | - return $this->get_prop( 'status', $context ); |
|
282 | - } |
|
274 | + * Get invoice status. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function get_status( $context = 'view' ) { |
|
281 | + return $this->get_prop( 'status', $context ); |
|
282 | + } |
|
283 | 283 | |
284 | - /** |
|
285 | - * Retrieves an array of possible invoice statuses. |
|
286 | - * |
|
287 | - * @since 1.0.19 |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function get_all_statuses() { |
|
291 | - |
|
292 | - $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
293 | - |
|
294 | - // For backwards compatibility. |
|
295 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
284 | + /** |
|
285 | + * Retrieves an array of possible invoice statuses. |
|
286 | + * |
|
287 | + * @since 1.0.19 |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function get_all_statuses() { |
|
291 | + |
|
292 | + $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
293 | + |
|
294 | + // For backwards compatibility. |
|
295 | + if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
296 | 296 | $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - return $statuses; |
|
299 | + return $statuses; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | - * Get invoice status nice name. |
|
304 | - * |
|
305 | - * @since 1.0.19 |
|
306 | - * @return string |
|
307 | - */ |
|
303 | + * Get invoice status nice name. |
|
304 | + * |
|
305 | + * @since 1.0.19 |
|
306 | + * @return string |
|
307 | + */ |
|
308 | 308 | public function get_status_nicename() { |
309 | - $statuses = $this->get_all_statuses(); |
|
309 | + $statuses = $this->get_all_statuses(); |
|
310 | 310 | |
311 | 311 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
312 | 312 | |
313 | 313 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
314 | 314 | } |
315 | 315 | |
316 | - /** |
|
316 | + /** |
|
317 | 317 | * Retrieves the invoice status label html |
318 | 318 | * |
319 | 319 | * @since 1.0.0 |
@@ -321,27 +321,27 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function get_status_label_html() { |
323 | 323 | |
324 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
325 | - $status = sanitize_html_class( $this->get_status() ); |
|
324 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
325 | + $status = sanitize_html_class( $this->get_status() ); |
|
326 | 326 | |
327 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
328 | - } |
|
327 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
328 | + } |
|
329 | 329 | |
330 | 330 | /** |
331 | - * Get plugin version when the invoice was created. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - public function get_version( $context = 'view' ) { |
|
338 | - return $this->get_prop( 'version', $context ); |
|
339 | - } |
|
331 | + * Get plugin version when the invoice was created. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return string |
|
336 | + */ |
|
337 | + public function get_version( $context = 'view' ) { |
|
338 | + return $this->get_prop( 'version', $context ); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * @deprecated |
|
343 | - */ |
|
344 | - public function get_invoice_date( $formatted = true ) { |
|
341 | + /** |
|
342 | + * @deprecated |
|
343 | + */ |
|
344 | + public function get_invoice_date( $formatted = true ) { |
|
345 | 345 | $date_completed = $this->get_date_completed(); |
346 | 346 | $invoice_date = $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
347 | 347 | |
@@ -358,187 +358,187 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
361 | - * Get date when the invoice was created. |
|
362 | - * |
|
363 | - * @since 1.0.19 |
|
364 | - * @param string $context View or edit context. |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_date_created( $context = 'view' ) { |
|
368 | - return $this->get_prop( 'date_created', $context ); |
|
369 | - } |
|
361 | + * Get date when the invoice was created. |
|
362 | + * |
|
363 | + * @since 1.0.19 |
|
364 | + * @param string $context View or edit context. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_date_created( $context = 'view' ) { |
|
368 | + return $this->get_prop( 'date_created', $context ); |
|
369 | + } |
|
370 | 370 | |
371 | - /** |
|
372 | - * Alias for self::get_date_created(). |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @param string $context View or edit context. |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function get_created_date( $context = 'view' ) { |
|
379 | - return $this->get_date_created( $context ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Get GMT date when the invoice was created. |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - * @param string $context View or edit context. |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_date_created_gmt( $context = 'view' ) { |
|
371 | + /** |
|
372 | + * Alias for self::get_date_created(). |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @param string $context View or edit context. |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function get_created_date( $context = 'view' ) { |
|
379 | + return $this->get_date_created( $context ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Get GMT date when the invoice was created. |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + * @param string $context View or edit context. |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_date_created_gmt( $context = 'view' ) { |
|
390 | 390 | $date = $this->get_date_created( $context ); |
391 | 391 | |
392 | 392 | if ( $date ) { |
393 | 393 | $date = get_gmt_from_date( $date ); |
394 | 394 | } |
395 | - return $date; |
|
395 | + return $date; |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Get date when the invoice was last modified. |
|
400 | - * |
|
401 | - * @since 1.0.19 |
|
402 | - * @param string $context View or edit context. |
|
403 | - * @return string |
|
404 | - */ |
|
405 | - public function get_date_modified( $context = 'view' ) { |
|
406 | - return $this->get_prop( 'date_modified', $context ); |
|
407 | - } |
|
399 | + * Get date when the invoice was last modified. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $context View or edit context. |
|
403 | + * @return string |
|
404 | + */ |
|
405 | + public function get_date_modified( $context = 'view' ) { |
|
406 | + return $this->get_prop( 'date_modified', $context ); |
|
407 | + } |
|
408 | 408 | |
409 | - /** |
|
410 | - * Alias for self::get_date_modified(). |
|
411 | - * |
|
412 | - * @since 1.0.19 |
|
413 | - * @param string $context View or edit context. |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function get_modified_date( $context = 'view' ) { |
|
417 | - return $this->get_date_modified( $context ); |
|
409 | + /** |
|
410 | + * Alias for self::get_date_modified(). |
|
411 | + * |
|
412 | + * @since 1.0.19 |
|
413 | + * @param string $context View or edit context. |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function get_modified_date( $context = 'view' ) { |
|
417 | + return $this->get_date_modified( $context ); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
421 | - * Get GMT date when the invoice was last modified. |
|
422 | - * |
|
423 | - * @since 1.0.19 |
|
424 | - * @param string $context View or edit context. |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
421 | + * Get GMT date when the invoice was last modified. |
|
422 | + * |
|
423 | + * @since 1.0.19 |
|
424 | + * @param string $context View or edit context. |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
428 | 428 | $date = $this->get_date_modified( $context ); |
429 | 429 | |
430 | 430 | if ( $date ) { |
431 | 431 | $date = get_gmt_from_date( $date ); |
432 | 432 | } |
433 | - return $date; |
|
433 | + return $date; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
437 | - * Get the invoice due date. |
|
438 | - * |
|
439 | - * @since 1.0.19 |
|
440 | - * @param string $context View or edit context. |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - public function get_due_date( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'due_date', $context ); |
|
437 | + * Get the invoice due date. |
|
438 | + * |
|
439 | + * @since 1.0.19 |
|
440 | + * @param string $context View or edit context. |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + public function get_due_date( $context = 'view' ) { |
|
444 | + return $this->get_prop( 'due_date', $context ); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
448 | - * Alias for self::get_due_date(). |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param string $context View or edit context. |
|
452 | - * @return string |
|
453 | - */ |
|
454 | - public function get_date_due( $context = 'view' ) { |
|
455 | - return $this->get_due_date( $context ); |
|
448 | + * Alias for self::get_due_date(). |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param string $context View or edit context. |
|
452 | + * @return string |
|
453 | + */ |
|
454 | + public function get_date_due( $context = 'view' ) { |
|
455 | + return $this->get_due_date( $context ); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
459 | - * Get the invoice GMT due date. |
|
460 | - * |
|
461 | - * @since 1.0.19 |
|
462 | - * @param string $context View or edit context. |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function get_due_date_gmt( $context = 'view' ) { |
|
459 | + * Get the invoice GMT due date. |
|
460 | + * |
|
461 | + * @since 1.0.19 |
|
462 | + * @param string $context View or edit context. |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function get_due_date_gmt( $context = 'view' ) { |
|
466 | 466 | $date = $this->get_due_date( $context ); |
467 | 467 | |
468 | 468 | if ( $date ) { |
469 | 469 | $date = get_gmt_from_date( $date ); |
470 | 470 | } |
471 | - return $date; |
|
471 | + return $date; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | - * Alias for self::get_due_date_gmt(). |
|
476 | - * |
|
477 | - * @since 1.0.19 |
|
478 | - * @param string $context View or edit context. |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_gmt_date_due( $context = 'view' ) { |
|
482 | - return $this->get_due_date_gmt( $context ); |
|
475 | + * Alias for self::get_due_date_gmt(). |
|
476 | + * |
|
477 | + * @since 1.0.19 |
|
478 | + * @param string $context View or edit context. |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_gmt_date_due( $context = 'view' ) { |
|
482 | + return $this->get_due_date_gmt( $context ); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
486 | - * Get date when the invoice was completed. |
|
487 | - * |
|
488 | - * @since 1.0.19 |
|
489 | - * @param string $context View or edit context. |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - public function get_completed_date( $context = 'view' ) { |
|
493 | - return $this->get_prop( 'completed_date', $context ); |
|
486 | + * Get date when the invoice was completed. |
|
487 | + * |
|
488 | + * @since 1.0.19 |
|
489 | + * @param string $context View or edit context. |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + public function get_completed_date( $context = 'view' ) { |
|
493 | + return $this->get_prop( 'completed_date', $context ); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
497 | - * Alias for self::get_completed_date(). |
|
498 | - * |
|
499 | - * @since 1.0.19 |
|
500 | - * @param string $context View or edit context. |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_date_completed( $context = 'view' ) { |
|
504 | - return $this->get_completed_date( $context ); |
|
497 | + * Alias for self::get_completed_date(). |
|
498 | + * |
|
499 | + * @since 1.0.19 |
|
500 | + * @param string $context View or edit context. |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_date_completed( $context = 'view' ) { |
|
504 | + return $this->get_completed_date( $context ); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Get GMT date when the invoice was was completed. |
|
509 | - * |
|
510 | - * @since 1.0.19 |
|
511 | - * @param string $context View or edit context. |
|
512 | - * @return string |
|
513 | - */ |
|
514 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
508 | + * Get GMT date when the invoice was was completed. |
|
509 | + * |
|
510 | + * @since 1.0.19 |
|
511 | + * @param string $context View or edit context. |
|
512 | + * @return string |
|
513 | + */ |
|
514 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
515 | 515 | $date = $this->get_completed_date( $context ); |
516 | 516 | |
517 | 517 | if ( $date ) { |
518 | 518 | $date = get_gmt_from_date( $date ); |
519 | 519 | } |
520 | - return $date; |
|
520 | + return $date; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
524 | - * Alias for self::get_completed_date_gmt(). |
|
525 | - * |
|
526 | - * @since 1.0.19 |
|
527 | - * @param string $context View or edit context. |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
531 | - return $this->get_completed_date_gmt( $context ); |
|
524 | + * Alias for self::get_completed_date_gmt(). |
|
525 | + * |
|
526 | + * @since 1.0.19 |
|
527 | + * @param string $context View or edit context. |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
531 | + return $this->get_completed_date_gmt( $context ); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
535 | - * Get the invoice number. |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param string $context View or edit context. |
|
539 | - * @return string |
|
540 | - */ |
|
541 | - public function get_number( $context = 'view' ) { |
|
535 | + * Get the invoice number. |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param string $context View or edit context. |
|
539 | + * @return string |
|
540 | + */ |
|
541 | + public function get_number( $context = 'view' ) { |
|
542 | 542 | $number = $this->get_prop( 'number', $context ); |
543 | 543 | |
544 | 544 | if ( empty( $number ) ) { |
@@ -546,17 +546,17 @@ discard block |
||
546 | 546 | $this->set_number( $number ); |
547 | 547 | } |
548 | 548 | |
549 | - return $number; |
|
549 | + return $number; |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
553 | - * Get the invoice key. |
|
554 | - * |
|
555 | - * @since 1.0.19 |
|
556 | - * @param string $context View or edit context. |
|
557 | - * @return string |
|
558 | - */ |
|
559 | - public function get_key( $context = 'view' ) { |
|
553 | + * Get the invoice key. |
|
554 | + * |
|
555 | + * @since 1.0.19 |
|
556 | + * @param string $context View or edit context. |
|
557 | + * @return string |
|
558 | + */ |
|
559 | + public function get_key( $context = 'view' ) { |
|
560 | 560 | $key = $this->get_prop( 'key', $context ); |
561 | 561 | |
562 | 562 | if ( empty( $key ) ) { |
@@ -564,24 +564,24 @@ discard block |
||
564 | 564 | $this->set_key( $key ); |
565 | 565 | } |
566 | 566 | |
567 | - return $key; |
|
567 | + return $key; |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | - * Get the invoice type. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - * @param string $context View or edit context. |
|
575 | - * @return string |
|
576 | - */ |
|
577 | - public function get_type( $context = 'view' ) { |
|
571 | + * Get the invoice type. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + * @param string $context View or edit context. |
|
575 | + * @return string |
|
576 | + */ |
|
577 | + public function get_type( $context = 'view' ) { |
|
578 | 578 | return $this->get_prop( 'type', $context ); |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - /** |
|
582 | - * @deprecated |
|
583 | - */ |
|
584 | - public function get_invoice_quote_type( $post_id ) { |
|
581 | + /** |
|
582 | + * @deprecated |
|
583 | + */ |
|
584 | + public function get_invoice_quote_type( $post_id ) { |
|
585 | 585 | if ( empty( $post_id ) ) { |
586 | 586 | return ''; |
587 | 587 | } |
@@ -598,35 +598,35 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
601 | - * Get the invoice post type. |
|
602 | - * |
|
603 | - * @since 1.0.19 |
|
604 | - * @param string $context View or edit context. |
|
605 | - * @return string |
|
606 | - */ |
|
607 | - public function get_post_type( $context = 'view' ) { |
|
601 | + * Get the invoice post type. |
|
602 | + * |
|
603 | + * @since 1.0.19 |
|
604 | + * @param string $context View or edit context. |
|
605 | + * @return string |
|
606 | + */ |
|
607 | + public function get_post_type( $context = 'view' ) { |
|
608 | 608 | return $this->get_prop( 'post_type', $context ); |
609 | 609 | } |
610 | 610 | |
611 | 611 | /** |
612 | - * Get the invoice mode. |
|
613 | - * |
|
614 | - * @since 1.0.19 |
|
615 | - * @param string $context View or edit context. |
|
616 | - * @return string |
|
617 | - */ |
|
618 | - public function get_mode( $context = 'view' ) { |
|
612 | + * Get the invoice mode. |
|
613 | + * |
|
614 | + * @since 1.0.19 |
|
615 | + * @param string $context View or edit context. |
|
616 | + * @return string |
|
617 | + */ |
|
618 | + public function get_mode( $context = 'view' ) { |
|
619 | 619 | return $this->get_prop( 'mode', $context ); |
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
623 | - * Get the invoice path. |
|
624 | - * |
|
625 | - * @since 1.0.19 |
|
626 | - * @param string $context View or edit context. |
|
627 | - * @return string |
|
628 | - */ |
|
629 | - public function get_path( $context = 'view' ) { |
|
623 | + * Get the invoice path. |
|
624 | + * |
|
625 | + * @since 1.0.19 |
|
626 | + * @param string $context View or edit context. |
|
627 | + * @return string |
|
628 | + */ |
|
629 | + public function get_path( $context = 'view' ) { |
|
630 | 630 | $path = $this->get_prop( 'path', $context ); |
631 | 631 | |
632 | 632 | if ( empty( $path ) ) { |
@@ -634,71 +634,71 @@ discard block |
||
634 | 634 | $path = sanitize_title( $prefix . $this->get_id() ); |
635 | 635 | } |
636 | 636 | |
637 | - return $path; |
|
637 | + return $path; |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
641 | - * Get the invoice name/title. |
|
642 | - * |
|
643 | - * @since 1.0.19 |
|
644 | - * @param string $context View or edit context. |
|
645 | - * @return string |
|
646 | - */ |
|
647 | - public function get_name( $context = 'view' ) { |
|
641 | + * Get the invoice name/title. |
|
642 | + * |
|
643 | + * @since 1.0.19 |
|
644 | + * @param string $context View or edit context. |
|
645 | + * @return string |
|
646 | + */ |
|
647 | + public function get_name( $context = 'view' ) { |
|
648 | 648 | return $this->get_prop( 'title', $context ); |
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
652 | - * Alias of self::get_name(). |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @param string $context View or edit context. |
|
656 | - * @return string |
|
657 | - */ |
|
658 | - public function get_title( $context = 'view' ) { |
|
659 | - return $this->get_name( $context ); |
|
652 | + * Alias of self::get_name(). |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @param string $context View or edit context. |
|
656 | + * @return string |
|
657 | + */ |
|
658 | + public function get_title( $context = 'view' ) { |
|
659 | + return $this->get_name( $context ); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | /** |
663 | - * Get the invoice description. |
|
664 | - * |
|
665 | - * @since 1.0.19 |
|
666 | - * @param string $context View or edit context. |
|
667 | - * @return string |
|
668 | - */ |
|
669 | - public function get_description( $context = 'view' ) { |
|
670 | - return $this->get_prop( 'description', $context ); |
|
663 | + * Get the invoice description. |
|
664 | + * |
|
665 | + * @since 1.0.19 |
|
666 | + * @param string $context View or edit context. |
|
667 | + * @return string |
|
668 | + */ |
|
669 | + public function get_description( $context = 'view' ) { |
|
670 | + return $this->get_prop( 'description', $context ); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
674 | - * Alias of self::get_description(). |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $context View or edit context. |
|
678 | - * @return string |
|
679 | - */ |
|
680 | - public function get_excerpt( $context = 'view' ) { |
|
681 | - return $this->get_description( $context ); |
|
674 | + * Alias of self::get_description(). |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @param string $context View or edit context. |
|
678 | + * @return string |
|
679 | + */ |
|
680 | + public function get_excerpt( $context = 'view' ) { |
|
681 | + return $this->get_description( $context ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
685 | - * Alias of self::get_description(). |
|
686 | - * |
|
687 | - * @since 1.0.19 |
|
688 | - * @param string $context View or edit context. |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - public function get_summary( $context = 'view' ) { |
|
692 | - return $this->get_description( $context ); |
|
685 | + * Alias of self::get_description(). |
|
686 | + * |
|
687 | + * @since 1.0.19 |
|
688 | + * @param string $context View or edit context. |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + public function get_summary( $context = 'view' ) { |
|
692 | + return $this->get_description( $context ); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
696 | - * Returns the user info. |
|
697 | - * |
|
698 | - * @since 1.0.19 |
|
696 | + * Returns the user info. |
|
697 | + * |
|
698 | + * @since 1.0.19 |
|
699 | 699 | * @param string $context View or edit context. |
700 | - * @return array |
|
701 | - */ |
|
700 | + * @return array |
|
701 | + */ |
|
702 | 702 | public function get_user_info( $context = 'view' ) { |
703 | 703 | |
704 | 704 | $user_info = array( |
@@ -715,605 +715,605 @@ discard block |
||
715 | 715 | 'company' => $this->get_company( $context ), |
716 | 716 | 'vat_number' => $this->get_vat_number( $context ), |
717 | 717 | 'discount' => $this->get_discount_code( $context ), |
718 | - ); |
|
718 | + ); |
|
719 | 719 | |
720 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
720 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
721 | 721 | |
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
725 | - * Get the customer id. |
|
726 | - * |
|
727 | - * @since 1.0.19 |
|
728 | - * @param string $context View or edit context. |
|
729 | - * @return int |
|
730 | - */ |
|
731 | - public function get_author( $context = 'view' ) { |
|
732 | - return (int) $this->get_prop( 'author', $context ); |
|
725 | + * Get the customer id. |
|
726 | + * |
|
727 | + * @since 1.0.19 |
|
728 | + * @param string $context View or edit context. |
|
729 | + * @return int |
|
730 | + */ |
|
731 | + public function get_author( $context = 'view' ) { |
|
732 | + return (int) $this->get_prop( 'author', $context ); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
736 | - * Alias of self::get_author(). |
|
737 | - * |
|
738 | - * @since 1.0.19 |
|
739 | - * @param string $context View or edit context. |
|
740 | - * @return int |
|
741 | - */ |
|
742 | - public function get_user_id( $context = 'view' ) { |
|
743 | - return $this->get_author( $context ); |
|
736 | + * Alias of self::get_author(). |
|
737 | + * |
|
738 | + * @since 1.0.19 |
|
739 | + * @param string $context View or edit context. |
|
740 | + * @return int |
|
741 | + */ |
|
742 | + public function get_user_id( $context = 'view' ) { |
|
743 | + return $this->get_author( $context ); |
|
744 | 744 | } |
745 | 745 | |
746 | - /** |
|
747 | - * Alias of self::get_author(). |
|
748 | - * |
|
749 | - * @since 1.0.19 |
|
750 | - * @param string $context View or edit context. |
|
751 | - * @return int |
|
752 | - */ |
|
753 | - public function get_customer_id( $context = 'view' ) { |
|
754 | - return $this->get_author( $context ); |
|
746 | + /** |
|
747 | + * Alias of self::get_author(). |
|
748 | + * |
|
749 | + * @since 1.0.19 |
|
750 | + * @param string $context View or edit context. |
|
751 | + * @return int |
|
752 | + */ |
|
753 | + public function get_customer_id( $context = 'view' ) { |
|
754 | + return $this->get_author( $context ); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Get the customer's ip. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - * @param string $context View or edit context. |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public function get_ip( $context = 'view' ) { |
|
765 | - return $this->get_prop( 'user_ip', $context ); |
|
758 | + * Get the customer's ip. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + * @param string $context View or edit context. |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public function get_ip( $context = 'view' ) { |
|
765 | + return $this->get_prop( 'user_ip', $context ); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | /** |
769 | - * Alias of self::get_ip(). |
|
770 | - * |
|
771 | - * @since 1.0.19 |
|
772 | - * @param string $context View or edit context. |
|
773 | - * @return string |
|
774 | - */ |
|
775 | - public function get_user_ip( $context = 'view' ) { |
|
776 | - return $this->get_ip( $context ); |
|
769 | + * Alias of self::get_ip(). |
|
770 | + * |
|
771 | + * @since 1.0.19 |
|
772 | + * @param string $context View or edit context. |
|
773 | + * @return string |
|
774 | + */ |
|
775 | + public function get_user_ip( $context = 'view' ) { |
|
776 | + return $this->get_ip( $context ); |
|
777 | 777 | } |
778 | 778 | |
779 | - /** |
|
780 | - * Alias of self::get_ip(). |
|
781 | - * |
|
782 | - * @since 1.0.19 |
|
783 | - * @param string $context View or edit context. |
|
784 | - * @return string |
|
785 | - */ |
|
786 | - public function get_customer_ip( $context = 'view' ) { |
|
787 | - return $this->get_ip( $context ); |
|
779 | + /** |
|
780 | + * Alias of self::get_ip(). |
|
781 | + * |
|
782 | + * @since 1.0.19 |
|
783 | + * @param string $context View or edit context. |
|
784 | + * @return string |
|
785 | + */ |
|
786 | + public function get_customer_ip( $context = 'view' ) { |
|
787 | + return $this->get_ip( $context ); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | /** |
791 | - * Get the customer's first name. |
|
792 | - * |
|
793 | - * @since 1.0.19 |
|
794 | - * @param string $context View or edit context. |
|
795 | - * @return string |
|
796 | - */ |
|
797 | - public function get_first_name( $context = 'view' ) { |
|
798 | - return $this->get_prop( 'first_name', $context ); |
|
791 | + * Get the customer's first name. |
|
792 | + * |
|
793 | + * @since 1.0.19 |
|
794 | + * @param string $context View or edit context. |
|
795 | + * @return string |
|
796 | + */ |
|
797 | + public function get_first_name( $context = 'view' ) { |
|
798 | + return $this->get_prop( 'first_name', $context ); |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
802 | - * Alias of self::get_first_name(). |
|
803 | - * |
|
804 | - * @since 1.0.19 |
|
805 | - * @param string $context View or edit context. |
|
806 | - * @return int |
|
807 | - */ |
|
808 | - public function get_user_first_name( $context = 'view' ) { |
|
809 | - return $this->get_first_name( $context ); |
|
802 | + * Alias of self::get_first_name(). |
|
803 | + * |
|
804 | + * @since 1.0.19 |
|
805 | + * @param string $context View or edit context. |
|
806 | + * @return int |
|
807 | + */ |
|
808 | + public function get_user_first_name( $context = 'view' ) { |
|
809 | + return $this->get_first_name( $context ); |
|
810 | 810 | } |
811 | 811 | |
812 | - /** |
|
813 | - * Alias of self::get_first_name(). |
|
814 | - * |
|
815 | - * @since 1.0.19 |
|
816 | - * @param string $context View or edit context. |
|
817 | - * @return int |
|
818 | - */ |
|
819 | - public function get_customer_first_name( $context = 'view' ) { |
|
820 | - return $this->get_first_name( $context ); |
|
812 | + /** |
|
813 | + * Alias of self::get_first_name(). |
|
814 | + * |
|
815 | + * @since 1.0.19 |
|
816 | + * @param string $context View or edit context. |
|
817 | + * @return int |
|
818 | + */ |
|
819 | + public function get_customer_first_name( $context = 'view' ) { |
|
820 | + return $this->get_first_name( $context ); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
824 | - * Get the customer's last name. |
|
825 | - * |
|
826 | - * @since 1.0.19 |
|
827 | - * @param string $context View or edit context. |
|
828 | - * @return string |
|
829 | - */ |
|
830 | - public function get_last_name( $context = 'view' ) { |
|
831 | - return $this->get_prop( 'last_name', $context ); |
|
824 | + * Get the customer's last name. |
|
825 | + * |
|
826 | + * @since 1.0.19 |
|
827 | + * @param string $context View or edit context. |
|
828 | + * @return string |
|
829 | + */ |
|
830 | + public function get_last_name( $context = 'view' ) { |
|
831 | + return $this->get_prop( 'last_name', $context ); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | /** |
835 | - * Alias of self::get_last_name(). |
|
836 | - * |
|
837 | - * @since 1.0.19 |
|
838 | - * @param string $context View or edit context. |
|
839 | - * @return int |
|
840 | - */ |
|
841 | - public function get_user_last_name( $context = 'view' ) { |
|
842 | - return $this->get_last_name( $context ); |
|
835 | + * Alias of self::get_last_name(). |
|
836 | + * |
|
837 | + * @since 1.0.19 |
|
838 | + * @param string $context View or edit context. |
|
839 | + * @return int |
|
840 | + */ |
|
841 | + public function get_user_last_name( $context = 'view' ) { |
|
842 | + return $this->get_last_name( $context ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Alias of self::get_last_name(). |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $context View or edit context. |
|
850 | - * @return int |
|
851 | - */ |
|
852 | - public function get_customer_last_name( $context = 'view' ) { |
|
853 | - return $this->get_last_name( $context ); |
|
846 | + * Alias of self::get_last_name(). |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $context View or edit context. |
|
850 | + * @return int |
|
851 | + */ |
|
852 | + public function get_customer_last_name( $context = 'view' ) { |
|
853 | + return $this->get_last_name( $context ); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
857 | - * Get the customer's full name. |
|
858 | - * |
|
859 | - * @since 1.0.19 |
|
860 | - * @param string $context View or edit context. |
|
861 | - * @return string |
|
862 | - */ |
|
863 | - public function get_full_name( $context = 'view' ) { |
|
864 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
857 | + * Get the customer's full name. |
|
858 | + * |
|
859 | + * @since 1.0.19 |
|
860 | + * @param string $context View or edit context. |
|
861 | + * @return string |
|
862 | + */ |
|
863 | + public function get_full_name( $context = 'view' ) { |
|
864 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
868 | - * Alias of self::get_full_name(). |
|
869 | - * |
|
870 | - * @since 1.0.19 |
|
871 | - * @param string $context View or edit context. |
|
872 | - * @return int |
|
873 | - */ |
|
874 | - public function get_user_full_name( $context = 'view' ) { |
|
875 | - return $this->get_full_name( $context ); |
|
868 | + * Alias of self::get_full_name(). |
|
869 | + * |
|
870 | + * @since 1.0.19 |
|
871 | + * @param string $context View or edit context. |
|
872 | + * @return int |
|
873 | + */ |
|
874 | + public function get_user_full_name( $context = 'view' ) { |
|
875 | + return $this->get_full_name( $context ); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | /** |
879 | - * Alias of self::get_full_name(). |
|
880 | - * |
|
881 | - * @since 1.0.19 |
|
882 | - * @param string $context View or edit context. |
|
883 | - * @return int |
|
884 | - */ |
|
885 | - public function get_customer_full_name( $context = 'view' ) { |
|
886 | - return $this->get_full_name( $context ); |
|
879 | + * Alias of self::get_full_name(). |
|
880 | + * |
|
881 | + * @since 1.0.19 |
|
882 | + * @param string $context View or edit context. |
|
883 | + * @return int |
|
884 | + */ |
|
885 | + public function get_customer_full_name( $context = 'view' ) { |
|
886 | + return $this->get_full_name( $context ); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | /** |
890 | - * Get the customer's phone number. |
|
891 | - * |
|
892 | - * @since 1.0.19 |
|
893 | - * @param string $context View or edit context. |
|
894 | - * @return string |
|
895 | - */ |
|
896 | - public function get_phone( $context = 'view' ) { |
|
897 | - return $this->get_prop( 'phone', $context ); |
|
890 | + * Get the customer's phone number. |
|
891 | + * |
|
892 | + * @since 1.0.19 |
|
893 | + * @param string $context View or edit context. |
|
894 | + * @return string |
|
895 | + */ |
|
896 | + public function get_phone( $context = 'view' ) { |
|
897 | + return $this->get_prop( 'phone', $context ); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
901 | - * Alias of self::get_phone(). |
|
902 | - * |
|
903 | - * @since 1.0.19 |
|
904 | - * @param string $context View or edit context. |
|
905 | - * @return int |
|
906 | - */ |
|
907 | - public function get_phone_number( $context = 'view' ) { |
|
908 | - return $this->get_phone( $context ); |
|
901 | + * Alias of self::get_phone(). |
|
902 | + * |
|
903 | + * @since 1.0.19 |
|
904 | + * @param string $context View or edit context. |
|
905 | + * @return int |
|
906 | + */ |
|
907 | + public function get_phone_number( $context = 'view' ) { |
|
908 | + return $this->get_phone( $context ); |
|
909 | 909 | } |
910 | 910 | |
911 | 911 | /** |
912 | - * Alias of self::get_phone(). |
|
913 | - * |
|
914 | - * @since 1.0.19 |
|
915 | - * @param string $context View or edit context. |
|
916 | - * @return int |
|
917 | - */ |
|
918 | - public function get_user_phone( $context = 'view' ) { |
|
919 | - return $this->get_phone( $context ); |
|
912 | + * Alias of self::get_phone(). |
|
913 | + * |
|
914 | + * @since 1.0.19 |
|
915 | + * @param string $context View or edit context. |
|
916 | + * @return int |
|
917 | + */ |
|
918 | + public function get_user_phone( $context = 'view' ) { |
|
919 | + return $this->get_phone( $context ); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | /** |
923 | - * Alias of self::get_phone(). |
|
924 | - * |
|
925 | - * @since 1.0.19 |
|
926 | - * @param string $context View or edit context. |
|
927 | - * @return int |
|
928 | - */ |
|
929 | - public function get_customer_phone( $context = 'view' ) { |
|
930 | - return $this->get_phone( $context ); |
|
923 | + * Alias of self::get_phone(). |
|
924 | + * |
|
925 | + * @since 1.0.19 |
|
926 | + * @param string $context View or edit context. |
|
927 | + * @return int |
|
928 | + */ |
|
929 | + public function get_customer_phone( $context = 'view' ) { |
|
930 | + return $this->get_phone( $context ); |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
934 | - * Get the customer's email address. |
|
935 | - * |
|
936 | - * @since 1.0.19 |
|
937 | - * @param string $context View or edit context. |
|
938 | - * @return string |
|
939 | - */ |
|
940 | - public function get_email( $context = 'view' ) { |
|
941 | - return $this->get_prop( 'email', $context ); |
|
934 | + * Get the customer's email address. |
|
935 | + * |
|
936 | + * @since 1.0.19 |
|
937 | + * @param string $context View or edit context. |
|
938 | + * @return string |
|
939 | + */ |
|
940 | + public function get_email( $context = 'view' ) { |
|
941 | + return $this->get_prop( 'email', $context ); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | /** |
945 | - * Alias of self::get_email(). |
|
946 | - * |
|
947 | - * @since 1.0.19 |
|
948 | - * @param string $context View or edit context. |
|
949 | - * @return string |
|
950 | - */ |
|
951 | - public function get_email_address( $context = 'view' ) { |
|
952 | - return $this->get_email( $context ); |
|
945 | + * Alias of self::get_email(). |
|
946 | + * |
|
947 | + * @since 1.0.19 |
|
948 | + * @param string $context View or edit context. |
|
949 | + * @return string |
|
950 | + */ |
|
951 | + public function get_email_address( $context = 'view' ) { |
|
952 | + return $this->get_email( $context ); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | /** |
956 | - * Alias of self::get_email(). |
|
957 | - * |
|
958 | - * @since 1.0.19 |
|
959 | - * @param string $context View or edit context. |
|
960 | - * @return int |
|
961 | - */ |
|
962 | - public function get_user_email( $context = 'view' ) { |
|
963 | - return $this->get_email( $context ); |
|
956 | + * Alias of self::get_email(). |
|
957 | + * |
|
958 | + * @since 1.0.19 |
|
959 | + * @param string $context View or edit context. |
|
960 | + * @return int |
|
961 | + */ |
|
962 | + public function get_user_email( $context = 'view' ) { |
|
963 | + return $this->get_email( $context ); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | /** |
967 | - * Alias of self::get_email(). |
|
968 | - * |
|
969 | - * @since 1.0.19 |
|
970 | - * @param string $context View or edit context. |
|
971 | - * @return int |
|
972 | - */ |
|
973 | - public function get_customer_email( $context = 'view' ) { |
|
974 | - return $this->get_email( $context ); |
|
967 | + * Alias of self::get_email(). |
|
968 | + * |
|
969 | + * @since 1.0.19 |
|
970 | + * @param string $context View or edit context. |
|
971 | + * @return int |
|
972 | + */ |
|
973 | + public function get_customer_email( $context = 'view' ) { |
|
974 | + return $this->get_email( $context ); |
|
975 | 975 | } |
976 | 976 | |
977 | 977 | /** |
978 | - * Get the customer's country. |
|
979 | - * |
|
980 | - * @since 1.0.19 |
|
981 | - * @param string $context View or edit context. |
|
982 | - * @return string |
|
983 | - */ |
|
984 | - public function get_country( $context = 'view' ) { |
|
985 | - $country = $this->get_prop( 'country', $context ); |
|
986 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
978 | + * Get the customer's country. |
|
979 | + * |
|
980 | + * @since 1.0.19 |
|
981 | + * @param string $context View or edit context. |
|
982 | + * @return string |
|
983 | + */ |
|
984 | + public function get_country( $context = 'view' ) { |
|
985 | + $country = $this->get_prop( 'country', $context ); |
|
986 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | /** |
990 | - * Alias of self::get_country(). |
|
991 | - * |
|
992 | - * @since 1.0.19 |
|
993 | - * @param string $context View or edit context. |
|
994 | - * @return int |
|
995 | - */ |
|
996 | - public function get_user_country( $context = 'view' ) { |
|
997 | - return $this->get_country( $context ); |
|
990 | + * Alias of self::get_country(). |
|
991 | + * |
|
992 | + * @since 1.0.19 |
|
993 | + * @param string $context View or edit context. |
|
994 | + * @return int |
|
995 | + */ |
|
996 | + public function get_user_country( $context = 'view' ) { |
|
997 | + return $this->get_country( $context ); |
|
998 | 998 | } |
999 | 999 | |
1000 | 1000 | /** |
1001 | - * Alias of self::get_country(). |
|
1002 | - * |
|
1003 | - * @since 1.0.19 |
|
1004 | - * @param string $context View or edit context. |
|
1005 | - * @return int |
|
1006 | - */ |
|
1007 | - public function get_customer_country( $context = 'view' ) { |
|
1008 | - return $this->get_country( $context ); |
|
1001 | + * Alias of self::get_country(). |
|
1002 | + * |
|
1003 | + * @since 1.0.19 |
|
1004 | + * @param string $context View or edit context. |
|
1005 | + * @return int |
|
1006 | + */ |
|
1007 | + public function get_customer_country( $context = 'view' ) { |
|
1008 | + return $this->get_country( $context ); |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
1012 | - * Get the customer's state. |
|
1013 | - * |
|
1014 | - * @since 1.0.19 |
|
1015 | - * @param string $context View or edit context. |
|
1016 | - * @return string |
|
1017 | - */ |
|
1018 | - public function get_state( $context = 'view' ) { |
|
1019 | - $state = $this->get_prop( 'state', $context ); |
|
1020 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1012 | + * Get the customer's state. |
|
1013 | + * |
|
1014 | + * @since 1.0.19 |
|
1015 | + * @param string $context View or edit context. |
|
1016 | + * @return string |
|
1017 | + */ |
|
1018 | + public function get_state( $context = 'view' ) { |
|
1019 | + $state = $this->get_prop( 'state', $context ); |
|
1020 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
1024 | - * Alias of self::get_state(). |
|
1025 | - * |
|
1026 | - * @since 1.0.19 |
|
1027 | - * @param string $context View or edit context. |
|
1028 | - * @return int |
|
1029 | - */ |
|
1030 | - public function get_user_state( $context = 'view' ) { |
|
1031 | - return $this->get_state( $context ); |
|
1032 | - } |
|
1033 | - |
|
1024 | + * Alias of self::get_state(). |
|
1025 | + * |
|
1026 | + * @since 1.0.19 |
|
1027 | + * @param string $context View or edit context. |
|
1028 | + * @return int |
|
1029 | + */ |
|
1030 | + public function get_user_state( $context = 'view' ) { |
|
1031 | + return $this->get_state( $context ); |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * Alias of self::get_state(). |
|
1036 | + * |
|
1037 | + * @since 1.0.19 |
|
1038 | + * @param string $context View or edit context. |
|
1039 | + * @return int |
|
1040 | + */ |
|
1041 | + public function get_customer_state( $context = 'view' ) { |
|
1042 | + return $this->get_state( $context ); |
|
1043 | + } |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Get the customer's city. |
|
1047 | + * |
|
1048 | + * @since 1.0.19 |
|
1049 | + * @param string $context View or edit context. |
|
1050 | + * @return string |
|
1051 | + */ |
|
1052 | + public function get_city( $context = 'view' ) { |
|
1053 | + return $this->get_prop( 'city', $context ); |
|
1054 | + } |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * Alias of self::get_city(). |
|
1058 | + * |
|
1059 | + * @since 1.0.19 |
|
1060 | + * @param string $context View or edit context. |
|
1061 | + * @return string |
|
1062 | + */ |
|
1063 | + public function get_user_city( $context = 'view' ) { |
|
1064 | + return $this->get_city( $context ); |
|
1065 | + } |
|
1066 | + |
|
1034 | 1067 | /** |
1035 | - * Alias of self::get_state(). |
|
1036 | - * |
|
1037 | - * @since 1.0.19 |
|
1038 | - * @param string $context View or edit context. |
|
1039 | - * @return int |
|
1040 | - */ |
|
1041 | - public function get_customer_state( $context = 'view' ) { |
|
1042 | - return $this->get_state( $context ); |
|
1068 | + * Alias of self::get_city(). |
|
1069 | + * |
|
1070 | + * @since 1.0.19 |
|
1071 | + * @param string $context View or edit context. |
|
1072 | + * @return string |
|
1073 | + */ |
|
1074 | + public function get_customer_city( $context = 'view' ) { |
|
1075 | + return $this->get_city( $context ); |
|
1043 | 1076 | } |
1044 | 1077 | |
1045 | 1078 | /** |
1046 | - * Get the customer's city. |
|
1047 | - * |
|
1048 | - * @since 1.0.19 |
|
1049 | - * @param string $context View or edit context. |
|
1050 | - * @return string |
|
1051 | - */ |
|
1052 | - public function get_city( $context = 'view' ) { |
|
1053 | - return $this->get_prop( 'city', $context ); |
|
1079 | + * Get the customer's zip. |
|
1080 | + * |
|
1081 | + * @since 1.0.19 |
|
1082 | + * @param string $context View or edit context. |
|
1083 | + * @return string |
|
1084 | + */ |
|
1085 | + public function get_zip( $context = 'view' ) { |
|
1086 | + return $this->get_prop( 'zip', $context ); |
|
1054 | 1087 | } |
1055 | 1088 | |
1056 | 1089 | /** |
1057 | - * Alias of self::get_city(). |
|
1058 | - * |
|
1059 | - * @since 1.0.19 |
|
1060 | - * @param string $context View or edit context. |
|
1061 | - * @return string |
|
1062 | - */ |
|
1063 | - public function get_user_city( $context = 'view' ) { |
|
1064 | - return $this->get_city( $context ); |
|
1090 | + * Alias of self::get_zip(). |
|
1091 | + * |
|
1092 | + * @since 1.0.19 |
|
1093 | + * @param string $context View or edit context. |
|
1094 | + * @return string |
|
1095 | + */ |
|
1096 | + public function get_user_zip( $context = 'view' ) { |
|
1097 | + return $this->get_zip( $context ); |
|
1065 | 1098 | } |
1066 | 1099 | |
1067 | 1100 | /** |
1068 | - * Alias of self::get_city(). |
|
1069 | - * |
|
1070 | - * @since 1.0.19 |
|
1071 | - * @param string $context View or edit context. |
|
1072 | - * @return string |
|
1073 | - */ |
|
1074 | - public function get_customer_city( $context = 'view' ) { |
|
1075 | - return $this->get_city( $context ); |
|
1101 | + * Alias of self::get_zip(). |
|
1102 | + * |
|
1103 | + * @since 1.0.19 |
|
1104 | + * @param string $context View or edit context. |
|
1105 | + * @return string |
|
1106 | + */ |
|
1107 | + public function get_customer_zip( $context = 'view' ) { |
|
1108 | + return $this->get_zip( $context ); |
|
1076 | 1109 | } |
1077 | 1110 | |
1078 | 1111 | /** |
1079 | - * Get the customer's zip. |
|
1080 | - * |
|
1081 | - * @since 1.0.19 |
|
1082 | - * @param string $context View or edit context. |
|
1083 | - * @return string |
|
1084 | - */ |
|
1085 | - public function get_zip( $context = 'view' ) { |
|
1086 | - return $this->get_prop( 'zip', $context ); |
|
1112 | + * Get the customer's company. |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @param string $context View or edit context. |
|
1116 | + * @return string |
|
1117 | + */ |
|
1118 | + public function get_company( $context = 'view' ) { |
|
1119 | + return $this->get_prop( 'company', $context ); |
|
1087 | 1120 | } |
1088 | 1121 | |
1089 | 1122 | /** |
1090 | - * Alias of self::get_zip(). |
|
1091 | - * |
|
1092 | - * @since 1.0.19 |
|
1093 | - * @param string $context View or edit context. |
|
1094 | - * @return string |
|
1095 | - */ |
|
1096 | - public function get_user_zip( $context = 'view' ) { |
|
1097 | - return $this->get_zip( $context ); |
|
1123 | + * Alias of self::get_company(). |
|
1124 | + * |
|
1125 | + * @since 1.0.19 |
|
1126 | + * @param string $context View or edit context. |
|
1127 | + * @return string |
|
1128 | + */ |
|
1129 | + public function get_user_company( $context = 'view' ) { |
|
1130 | + return $this->get_company( $context ); |
|
1098 | 1131 | } |
1099 | 1132 | |
1100 | 1133 | /** |
1101 | - * Alias of self::get_zip(). |
|
1102 | - * |
|
1103 | - * @since 1.0.19 |
|
1104 | - * @param string $context View or edit context. |
|
1105 | - * @return string |
|
1106 | - */ |
|
1107 | - public function get_customer_zip( $context = 'view' ) { |
|
1108 | - return $this->get_zip( $context ); |
|
1134 | + * Alias of self::get_company(). |
|
1135 | + * |
|
1136 | + * @since 1.0.19 |
|
1137 | + * @param string $context View or edit context. |
|
1138 | + * @return string |
|
1139 | + */ |
|
1140 | + public function get_customer_company( $context = 'view' ) { |
|
1141 | + return $this->get_company( $context ); |
|
1109 | 1142 | } |
1110 | 1143 | |
1111 | 1144 | /** |
1112 | - * Get the customer's company. |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @param string $context View or edit context. |
|
1116 | - * @return string |
|
1117 | - */ |
|
1118 | - public function get_company( $context = 'view' ) { |
|
1119 | - return $this->get_prop( 'company', $context ); |
|
1145 | + * Get the customer's vat number. |
|
1146 | + * |
|
1147 | + * @since 1.0.19 |
|
1148 | + * @param string $context View or edit context. |
|
1149 | + * @return string |
|
1150 | + */ |
|
1151 | + public function get_vat_number( $context = 'view' ) { |
|
1152 | + return $this->get_prop( 'vat_number', $context ); |
|
1120 | 1153 | } |
1121 | 1154 | |
1122 | 1155 | /** |
1123 | - * Alias of self::get_company(). |
|
1124 | - * |
|
1125 | - * @since 1.0.19 |
|
1126 | - * @param string $context View or edit context. |
|
1127 | - * @return string |
|
1128 | - */ |
|
1129 | - public function get_user_company( $context = 'view' ) { |
|
1130 | - return $this->get_company( $context ); |
|
1156 | + * Alias of self::get_vat_number(). |
|
1157 | + * |
|
1158 | + * @since 1.0.19 |
|
1159 | + * @param string $context View or edit context. |
|
1160 | + * @return string |
|
1161 | + */ |
|
1162 | + public function get_user_vat_number( $context = 'view' ) { |
|
1163 | + return $this->get_vat_number( $context ); |
|
1131 | 1164 | } |
1132 | 1165 | |
1133 | 1166 | /** |
1134 | - * Alias of self::get_company(). |
|
1135 | - * |
|
1136 | - * @since 1.0.19 |
|
1137 | - * @param string $context View or edit context. |
|
1138 | - * @return string |
|
1139 | - */ |
|
1140 | - public function get_customer_company( $context = 'view' ) { |
|
1141 | - return $this->get_company( $context ); |
|
1167 | + * Alias of self::get_vat_number(). |
|
1168 | + * |
|
1169 | + * @since 1.0.19 |
|
1170 | + * @param string $context View or edit context. |
|
1171 | + * @return string |
|
1172 | + */ |
|
1173 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1174 | + return $this->get_vat_number( $context ); |
|
1142 | 1175 | } |
1143 | 1176 | |
1144 | 1177 | /** |
1145 | - * Get the customer's vat number. |
|
1146 | - * |
|
1147 | - * @since 1.0.19 |
|
1148 | - * @param string $context View or edit context. |
|
1149 | - * @return string |
|
1150 | - */ |
|
1151 | - public function get_vat_number( $context = 'view' ) { |
|
1152 | - return $this->get_prop( 'vat_number', $context ); |
|
1178 | + * Get the customer's vat rate. |
|
1179 | + * |
|
1180 | + * @since 1.0.19 |
|
1181 | + * @param string $context View or edit context. |
|
1182 | + * @return string |
|
1183 | + */ |
|
1184 | + public function get_vat_rate( $context = 'view' ) { |
|
1185 | + return $this->get_prop( 'vat_rate', $context ); |
|
1153 | 1186 | } |
1154 | 1187 | |
1155 | 1188 | /** |
1156 | - * Alias of self::get_vat_number(). |
|
1157 | - * |
|
1158 | - * @since 1.0.19 |
|
1159 | - * @param string $context View or edit context. |
|
1160 | - * @return string |
|
1161 | - */ |
|
1162 | - public function get_user_vat_number( $context = 'view' ) { |
|
1163 | - return $this->get_vat_number( $context ); |
|
1189 | + * Alias of self::get_vat_rate(). |
|
1190 | + * |
|
1191 | + * @since 1.0.19 |
|
1192 | + * @param string $context View or edit context. |
|
1193 | + * @return string |
|
1194 | + */ |
|
1195 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1196 | + return $this->get_vat_rate( $context ); |
|
1164 | 1197 | } |
1165 | 1198 | |
1166 | 1199 | /** |
1167 | - * Alias of self::get_vat_number(). |
|
1168 | - * |
|
1169 | - * @since 1.0.19 |
|
1170 | - * @param string $context View or edit context. |
|
1171 | - * @return string |
|
1172 | - */ |
|
1173 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1174 | - return $this->get_vat_number( $context ); |
|
1200 | + * Alias of self::get_vat_rate(). |
|
1201 | + * |
|
1202 | + * @since 1.0.19 |
|
1203 | + * @param string $context View or edit context. |
|
1204 | + * @return string |
|
1205 | + */ |
|
1206 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1207 | + return $this->get_vat_rate( $context ); |
|
1175 | 1208 | } |
1176 | 1209 | |
1177 | 1210 | /** |
1178 | - * Get the customer's vat rate. |
|
1179 | - * |
|
1180 | - * @since 1.0.19 |
|
1181 | - * @param string $context View or edit context. |
|
1182 | - * @return string |
|
1183 | - */ |
|
1184 | - public function get_vat_rate( $context = 'view' ) { |
|
1185 | - return $this->get_prop( 'vat_rate', $context ); |
|
1211 | + * Get the customer's address. |
|
1212 | + * |
|
1213 | + * @since 1.0.19 |
|
1214 | + * @param string $context View or edit context. |
|
1215 | + * @return string |
|
1216 | + */ |
|
1217 | + public function get_address( $context = 'view' ) { |
|
1218 | + return $this->get_prop( 'address', $context ); |
|
1186 | 1219 | } |
1187 | 1220 | |
1188 | 1221 | /** |
1189 | - * Alias of self::get_vat_rate(). |
|
1190 | - * |
|
1191 | - * @since 1.0.19 |
|
1192 | - * @param string $context View or edit context. |
|
1193 | - * @return string |
|
1194 | - */ |
|
1195 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1196 | - return $this->get_vat_rate( $context ); |
|
1222 | + * Alias of self::get_address(). |
|
1223 | + * |
|
1224 | + * @since 1.0.19 |
|
1225 | + * @param string $context View or edit context. |
|
1226 | + * @return string |
|
1227 | + */ |
|
1228 | + public function get_user_address( $context = 'view' ) { |
|
1229 | + return $this->get_address( $context ); |
|
1197 | 1230 | } |
1198 | 1231 | |
1199 | 1232 | /** |
1200 | - * Alias of self::get_vat_rate(). |
|
1201 | - * |
|
1202 | - * @since 1.0.19 |
|
1203 | - * @param string $context View or edit context. |
|
1204 | - * @return string |
|
1205 | - */ |
|
1206 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1207 | - return $this->get_vat_rate( $context ); |
|
1233 | + * Alias of self::get_address(). |
|
1234 | + * |
|
1235 | + * @since 1.0.19 |
|
1236 | + * @param string $context View or edit context. |
|
1237 | + * @return string |
|
1238 | + */ |
|
1239 | + public function get_customer_address( $context = 'view' ) { |
|
1240 | + return $this->get_address( $context ); |
|
1208 | 1241 | } |
1209 | 1242 | |
1210 | 1243 | /** |
1211 | - * Get the customer's address. |
|
1212 | - * |
|
1213 | - * @since 1.0.19 |
|
1214 | - * @param string $context View or edit context. |
|
1215 | - * @return string |
|
1216 | - */ |
|
1217 | - public function get_address( $context = 'view' ) { |
|
1218 | - return $this->get_prop( 'address', $context ); |
|
1219 | - } |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * Alias of self::get_address(). |
|
1223 | - * |
|
1224 | - * @since 1.0.19 |
|
1225 | - * @param string $context View or edit context. |
|
1226 | - * @return string |
|
1227 | - */ |
|
1228 | - public function get_user_address( $context = 'view' ) { |
|
1229 | - return $this->get_address( $context ); |
|
1230 | - } |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * Alias of self::get_address(). |
|
1234 | - * |
|
1235 | - * @since 1.0.19 |
|
1236 | - * @param string $context View or edit context. |
|
1237 | - * @return string |
|
1238 | - */ |
|
1239 | - public function get_customer_address( $context = 'view' ) { |
|
1240 | - return $this->get_address( $context ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Get whether the customer has viewed the invoice or not. |
|
1245 | - * |
|
1246 | - * @since 1.0.19 |
|
1247 | - * @param string $context View or edit context. |
|
1248 | - * @return bool |
|
1249 | - */ |
|
1250 | - public function get_is_viewed( $context = 'view' ) { |
|
1251 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * Get other recipients for invoice communications. |
|
1256 | - * |
|
1257 | - * @since 1.0.19 |
|
1258 | - * @param string $context View or edit context. |
|
1259 | - * @return bool |
|
1260 | - */ |
|
1261 | - public function get_email_cc( $context = 'view' ) { |
|
1262 | - return $this->get_prop( 'email_cc', $context ); |
|
1263 | - } |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * Get invoice template. |
|
1267 | - * |
|
1268 | - * @since 1.0.19 |
|
1269 | - * @param string $context View or edit context. |
|
1270 | - * @return bool |
|
1271 | - */ |
|
1272 | - public function get_template( $context = 'view' ) { |
|
1273 | - return $this->get_prop( 'template', $context ); |
|
1274 | - } |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * Get whether the customer has confirmed their address. |
|
1278 | - * |
|
1279 | - * @since 1.0.19 |
|
1280 | - * @param string $context View or edit context. |
|
1281 | - * @return bool |
|
1282 | - */ |
|
1283 | - public function get_address_confirmed( $context = 'view' ) { |
|
1284 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1285 | - } |
|
1286 | - |
|
1287 | - /** |
|
1288 | - * Alias of self::get_address_confirmed(). |
|
1289 | - * |
|
1290 | - * @since 1.0.19 |
|
1291 | - * @param string $context View or edit context. |
|
1292 | - * @return bool |
|
1293 | - */ |
|
1294 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1295 | - return $this->get_address_confirmed( $context ); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Alias of self::get_address(). |
|
1300 | - * |
|
1301 | - * @since 1.0.19 |
|
1302 | - * @param string $context View or edit context. |
|
1303 | - * @return bool |
|
1304 | - */ |
|
1305 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1306 | - return $this->get_address_confirmed( $context ); |
|
1307 | - } |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * Get the invoice subtotal. |
|
1311 | - * |
|
1312 | - * @since 1.0.19 |
|
1313 | - * @param string $context View or edit context. |
|
1314 | - * @return float |
|
1315 | - */ |
|
1316 | - public function get_subtotal( $context = 'view' ) { |
|
1244 | + * Get whether the customer has viewed the invoice or not. |
|
1245 | + * |
|
1246 | + * @since 1.0.19 |
|
1247 | + * @param string $context View or edit context. |
|
1248 | + * @return bool |
|
1249 | + */ |
|
1250 | + public function get_is_viewed( $context = 'view' ) { |
|
1251 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * Get other recipients for invoice communications. |
|
1256 | + * |
|
1257 | + * @since 1.0.19 |
|
1258 | + * @param string $context View or edit context. |
|
1259 | + * @return bool |
|
1260 | + */ |
|
1261 | + public function get_email_cc( $context = 'view' ) { |
|
1262 | + return $this->get_prop( 'email_cc', $context ); |
|
1263 | + } |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * Get invoice template. |
|
1267 | + * |
|
1268 | + * @since 1.0.19 |
|
1269 | + * @param string $context View or edit context. |
|
1270 | + * @return bool |
|
1271 | + */ |
|
1272 | + public function get_template( $context = 'view' ) { |
|
1273 | + return $this->get_prop( 'template', $context ); |
|
1274 | + } |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * Get whether the customer has confirmed their address. |
|
1278 | + * |
|
1279 | + * @since 1.0.19 |
|
1280 | + * @param string $context View or edit context. |
|
1281 | + * @return bool |
|
1282 | + */ |
|
1283 | + public function get_address_confirmed( $context = 'view' ) { |
|
1284 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1285 | + } |
|
1286 | + |
|
1287 | + /** |
|
1288 | + * Alias of self::get_address_confirmed(). |
|
1289 | + * |
|
1290 | + * @since 1.0.19 |
|
1291 | + * @param string $context View or edit context. |
|
1292 | + * @return bool |
|
1293 | + */ |
|
1294 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1295 | + return $this->get_address_confirmed( $context ); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Alias of self::get_address(). |
|
1300 | + * |
|
1301 | + * @since 1.0.19 |
|
1302 | + * @param string $context View or edit context. |
|
1303 | + * @return bool |
|
1304 | + */ |
|
1305 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1306 | + return $this->get_address_confirmed( $context ); |
|
1307 | + } |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * Get the invoice subtotal. |
|
1311 | + * |
|
1312 | + * @since 1.0.19 |
|
1313 | + * @param string $context View or edit context. |
|
1314 | + * @return float |
|
1315 | + */ |
|
1316 | + public function get_subtotal( $context = 'view' ) { |
|
1317 | 1317 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1318 | 1318 | |
1319 | 1319 | // Backwards compatibility. |
@@ -1325,165 +1325,165 @@ discard block |
||
1325 | 1325 | } |
1326 | 1326 | |
1327 | 1327 | /** |
1328 | - * Get the invoice discount total. |
|
1329 | - * |
|
1330 | - * @since 1.0.19 |
|
1331 | - * @param string $context View or edit context. |
|
1332 | - * @return float |
|
1333 | - */ |
|
1334 | - public function get_total_discount( $context = 'view' ) { |
|
1335 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1328 | + * Get the invoice discount total. |
|
1329 | + * |
|
1330 | + * @since 1.0.19 |
|
1331 | + * @param string $context View or edit context. |
|
1332 | + * @return float |
|
1333 | + */ |
|
1334 | + public function get_total_discount( $context = 'view' ) { |
|
1335 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | /** |
1339 | - * Get the invoice tax total. |
|
1340 | - * |
|
1341 | - * @since 1.0.19 |
|
1342 | - * @param string $context View or edit context. |
|
1343 | - * @return float |
|
1344 | - */ |
|
1345 | - public function get_total_tax( $context = 'view' ) { |
|
1346 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1347 | - } |
|
1339 | + * Get the invoice tax total. |
|
1340 | + * |
|
1341 | + * @since 1.0.19 |
|
1342 | + * @param string $context View or edit context. |
|
1343 | + * @return float |
|
1344 | + */ |
|
1345 | + public function get_total_tax( $context = 'view' ) { |
|
1346 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
1347 | + } |
|
1348 | 1348 | |
1349 | - /** |
|
1350 | - * @deprecated |
|
1351 | - */ |
|
1352 | - public function get_final_tax( $currency = false ) { |
|
1353 | - $tax = $this->get_total_tax(); |
|
1349 | + /** |
|
1350 | + * @deprecated |
|
1351 | + */ |
|
1352 | + public function get_final_tax( $currency = false ) { |
|
1353 | + $tax = $this->get_total_tax(); |
|
1354 | 1354 | |
1355 | 1355 | if ( $currency ) { |
1356 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1356 | + return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | return $tax; |
1360 | 1360 | } |
1361 | 1361 | |
1362 | 1362 | /** |
1363 | - * Get the invoice fees total. |
|
1364 | - * |
|
1365 | - * @since 1.0.19 |
|
1366 | - * @param string $context View or edit context. |
|
1367 | - * @return float |
|
1368 | - */ |
|
1369 | - public function get_total_fees( $context = 'view' ) { |
|
1370 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1363 | + * Get the invoice fees total. |
|
1364 | + * |
|
1365 | + * @since 1.0.19 |
|
1366 | + * @param string $context View or edit context. |
|
1367 | + * @return float |
|
1368 | + */ |
|
1369 | + public function get_total_fees( $context = 'view' ) { |
|
1370 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | /** |
1374 | - * Alias for self::get_total_fees(). |
|
1375 | - * |
|
1376 | - * @since 1.0.19 |
|
1377 | - * @param string $context View or edit context. |
|
1378 | - * @return float |
|
1379 | - */ |
|
1380 | - public function get_fees_total( $context = 'view' ) { |
|
1381 | - return $this->get_total_fees( $context ); |
|
1374 | + * Alias for self::get_total_fees(). |
|
1375 | + * |
|
1376 | + * @since 1.0.19 |
|
1377 | + * @param string $context View or edit context. |
|
1378 | + * @return float |
|
1379 | + */ |
|
1380 | + public function get_fees_total( $context = 'view' ) { |
|
1381 | + return $this->get_total_fees( $context ); |
|
1382 | 1382 | } |
1383 | 1383 | |
1384 | 1384 | /** |
1385 | - * Get the invoice total. |
|
1386 | - * |
|
1387 | - * @since 1.0.19 |
|
1385 | + * Get the invoice total. |
|
1386 | + * |
|
1387 | + * @since 1.0.19 |
|
1388 | 1388 | * @return float |
1389 | - */ |
|
1390 | - public function get_total() { |
|
1391 | - $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1392 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1393 | - } |
|
1389 | + */ |
|
1390 | + public function get_total() { |
|
1391 | + $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1392 | + return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1393 | + } |
|
1394 | 1394 | |
1395 | - /** |
|
1396 | - * Get the invoice totals. |
|
1397 | - * |
|
1398 | - * @since 1.0.19 |
|
1395 | + /** |
|
1396 | + * Get the invoice totals. |
|
1397 | + * |
|
1398 | + * @since 1.0.19 |
|
1399 | 1399 | * @return float |
1400 | - */ |
|
1401 | - public function get_totals() { |
|
1402 | - return $this->totals; |
|
1400 | + */ |
|
1401 | + public function get_totals() { |
|
1402 | + return $this->totals; |
|
1403 | 1403 | } |
1404 | 1404 | |
1405 | 1405 | /** |
1406 | - * Get the initial invoice total. |
|
1407 | - * |
|
1408 | - * @since 1.0.19 |
|
1406 | + * Get the initial invoice total. |
|
1407 | + * |
|
1408 | + * @since 1.0.19 |
|
1409 | 1409 | * @param string $context View or edit context. |
1410 | 1410 | * @return float |
1411 | - */ |
|
1411 | + */ |
|
1412 | 1412 | public function get_initial_total() { |
1413 | 1413 | |
1414 | - if ( empty( $this->totals ) ) { |
|
1415 | - $this->recalculate_total(); |
|
1416 | - } |
|
1414 | + if ( empty( $this->totals ) ) { |
|
1415 | + $this->recalculate_total(); |
|
1416 | + } |
|
1417 | 1417 | |
1418 | - $tax = $this->totals['tax']['initial']; |
|
1419 | - $fee = $this->totals['fee']['initial']; |
|
1420 | - $discount = $this->totals['discount']['initial']; |
|
1421 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1422 | - $total = $tax + $fee - $discount + $subtotal; |
|
1418 | + $tax = $this->totals['tax']['initial']; |
|
1419 | + $fee = $this->totals['fee']['initial']; |
|
1420 | + $discount = $this->totals['discount']['initial']; |
|
1421 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1422 | + $total = $tax + $fee - $discount + $subtotal; |
|
1423 | 1423 | |
1424 | - if ( 0 > $total ) { |
|
1425 | - $total = 0; |
|
1426 | - } |
|
1424 | + if ( 0 > $total ) { |
|
1425 | + $total = 0; |
|
1426 | + } |
|
1427 | 1427 | |
1428 | 1428 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1429 | - } |
|
1429 | + } |
|
1430 | 1430 | |
1431 | - /** |
|
1432 | - * Get the recurring invoice total. |
|
1433 | - * |
|
1434 | - * @since 1.0.19 |
|
1431 | + /** |
|
1432 | + * Get the recurring invoice total. |
|
1433 | + * |
|
1434 | + * @since 1.0.19 |
|
1435 | 1435 | * @param string $context View or edit context. |
1436 | 1436 | * @return float |
1437 | - */ |
|
1437 | + */ |
|
1438 | 1438 | public function get_recurring_total() { |
1439 | 1439 | |
1440 | - if ( empty( $this->totals ) ) { |
|
1441 | - $this->recalculate_total(); |
|
1442 | - } |
|
1440 | + if ( empty( $this->totals ) ) { |
|
1441 | + $this->recalculate_total(); |
|
1442 | + } |
|
1443 | 1443 | |
1444 | - $tax = $this->totals['tax']['recurring']; |
|
1445 | - $fee = $this->totals['fee']['recurring']; |
|
1446 | - $discount = $this->totals['discount']['recurring']; |
|
1447 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1448 | - $total = $tax + $fee - $discount + $subtotal; |
|
1444 | + $tax = $this->totals['tax']['recurring']; |
|
1445 | + $fee = $this->totals['fee']['recurring']; |
|
1446 | + $discount = $this->totals['discount']['recurring']; |
|
1447 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1448 | + $total = $tax + $fee - $discount + $subtotal; |
|
1449 | 1449 | |
1450 | - if ( 0 > $total ) { |
|
1451 | - $total = 0; |
|
1452 | - } |
|
1450 | + if ( 0 > $total ) { |
|
1451 | + $total = 0; |
|
1452 | + } |
|
1453 | 1453 | |
1454 | 1454 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1455 | - } |
|
1455 | + } |
|
1456 | 1456 | |
1457 | - /** |
|
1458 | - * Returns recurring payment details. |
|
1459 | - * |
|
1460 | - * @since 1.0.19 |
|
1457 | + /** |
|
1458 | + * Returns recurring payment details. |
|
1459 | + * |
|
1460 | + * @since 1.0.19 |
|
1461 | 1461 | * @param string $field Optionally provide a field to return. |
1462 | - * @param string $currency Whether to include the currency. |
|
1462 | + * @param string $currency Whether to include the currency. |
|
1463 | 1463 | * @return float |
1464 | - */ |
|
1464 | + */ |
|
1465 | 1465 | public function get_recurring_details( $field = '', $currency = false ) { |
1466 | 1466 | |
1467 | - // Maybe recalculate totals. |
|
1468 | - if ( empty( $this->totals ) ) { |
|
1469 | - $this->recalculate_total(); |
|
1470 | - } |
|
1467 | + // Maybe recalculate totals. |
|
1468 | + if ( empty( $this->totals ) ) { |
|
1469 | + $this->recalculate_total(); |
|
1470 | + } |
|
1471 | 1471 | |
1472 | - // Prepare recurring totals. |
|
1472 | + // Prepare recurring totals. |
|
1473 | 1473 | $data = apply_filters( |
1474 | - 'wpinv_get_invoice_recurring_details', |
|
1475 | - array( |
|
1476 | - 'cart_details' => $this->get_cart_details(), |
|
1477 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1478 | - 'discount' => $this->totals['discount']['recurring'], |
|
1479 | - 'tax' => $this->totals['tax']['recurring'], |
|
1480 | - 'fee' => $this->totals['fee']['recurring'], |
|
1481 | - 'total' => $this->get_recurring_total(), |
|
1482 | - ), |
|
1483 | - $this, |
|
1484 | - $field, |
|
1485 | - $currency |
|
1486 | - ); |
|
1474 | + 'wpinv_get_invoice_recurring_details', |
|
1475 | + array( |
|
1476 | + 'cart_details' => $this->get_cart_details(), |
|
1477 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1478 | + 'discount' => $this->totals['discount']['recurring'], |
|
1479 | + 'tax' => $this->totals['tax']['recurring'], |
|
1480 | + 'fee' => $this->totals['fee']['recurring'], |
|
1481 | + 'total' => $this->get_recurring_total(), |
|
1482 | + ), |
|
1483 | + $this, |
|
1484 | + $field, |
|
1485 | + $currency |
|
1486 | + ); |
|
1487 | 1487 | |
1488 | 1488 | if ( isset( $data[$field] ) ) { |
1489 | 1489 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1493,145 +1493,145 @@ discard block |
||
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | /** |
1496 | - * Get the invoice fees. |
|
1497 | - * |
|
1498 | - * @since 1.0.19 |
|
1499 | - * @param string $context View or edit context. |
|
1500 | - * @return array |
|
1501 | - */ |
|
1502 | - public function get_fees( $context = 'view' ) { |
|
1503 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1496 | + * Get the invoice fees. |
|
1497 | + * |
|
1498 | + * @since 1.0.19 |
|
1499 | + * @param string $context View or edit context. |
|
1500 | + * @return array |
|
1501 | + */ |
|
1502 | + public function get_fees( $context = 'view' ) { |
|
1503 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | /** |
1507 | - * Get the invoice discounts. |
|
1508 | - * |
|
1509 | - * @since 1.0.19 |
|
1510 | - * @param string $context View or edit context. |
|
1511 | - * @return array |
|
1512 | - */ |
|
1513 | - public function get_discounts( $context = 'view' ) { |
|
1514 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1507 | + * Get the invoice discounts. |
|
1508 | + * |
|
1509 | + * @since 1.0.19 |
|
1510 | + * @param string $context View or edit context. |
|
1511 | + * @return array |
|
1512 | + */ |
|
1513 | + public function get_discounts( $context = 'view' ) { |
|
1514 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | 1517 | /** |
1518 | - * Get the invoice taxes. |
|
1519 | - * |
|
1520 | - * @since 1.0.19 |
|
1521 | - * @param string $context View or edit context. |
|
1522 | - * @return array |
|
1523 | - */ |
|
1524 | - public function get_taxes( $context = 'view' ) { |
|
1525 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1518 | + * Get the invoice taxes. |
|
1519 | + * |
|
1520 | + * @since 1.0.19 |
|
1521 | + * @param string $context View or edit context. |
|
1522 | + * @return array |
|
1523 | + */ |
|
1524 | + public function get_taxes( $context = 'view' ) { |
|
1525 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | /** |
1529 | - * Get the invoice items. |
|
1530 | - * |
|
1531 | - * @since 1.0.19 |
|
1532 | - * @param string $context View or edit context. |
|
1533 | - * @return GetPaid_Form_Item[] |
|
1534 | - */ |
|
1535 | - public function get_items( $context = 'view' ) { |
|
1529 | + * Get the invoice items. |
|
1530 | + * |
|
1531 | + * @since 1.0.19 |
|
1532 | + * @param string $context View or edit context. |
|
1533 | + * @return GetPaid_Form_Item[] |
|
1534 | + */ |
|
1535 | + public function get_items( $context = 'view' ) { |
|
1536 | 1536 | return $this->get_prop( 'items', $context ); |
1537 | 1537 | } |
1538 | 1538 | |
1539 | 1539 | /** |
1540 | - * Get the invoice's payment form. |
|
1541 | - * |
|
1542 | - * @since 1.0.19 |
|
1543 | - * @param string $context View or edit context. |
|
1544 | - * @return int |
|
1545 | - */ |
|
1546 | - public function get_payment_form( $context = 'view' ) { |
|
1547 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1540 | + * Get the invoice's payment form. |
|
1541 | + * |
|
1542 | + * @since 1.0.19 |
|
1543 | + * @param string $context View or edit context. |
|
1544 | + * @return int |
|
1545 | + */ |
|
1546 | + public function get_payment_form( $context = 'view' ) { |
|
1547 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | /** |
1551 | - * Get the invoice's submission id. |
|
1552 | - * |
|
1553 | - * @since 1.0.19 |
|
1554 | - * @param string $context View or edit context. |
|
1555 | - * @return string |
|
1556 | - */ |
|
1557 | - public function get_submission_id( $context = 'view' ) { |
|
1558 | - return $this->get_prop( 'submission_id', $context ); |
|
1551 | + * Get the invoice's submission id. |
|
1552 | + * |
|
1553 | + * @since 1.0.19 |
|
1554 | + * @param string $context View or edit context. |
|
1555 | + * @return string |
|
1556 | + */ |
|
1557 | + public function get_submission_id( $context = 'view' ) { |
|
1558 | + return $this->get_prop( 'submission_id', $context ); |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | 1561 | /** |
1562 | - * Get the invoice's discount code. |
|
1563 | - * |
|
1564 | - * @since 1.0.19 |
|
1565 | - * @param string $context View or edit context. |
|
1566 | - * @return string |
|
1567 | - */ |
|
1568 | - public function get_discount_code( $context = 'view' ) { |
|
1569 | - return $this->get_prop( 'discount_code', $context ); |
|
1562 | + * Get the invoice's discount code. |
|
1563 | + * |
|
1564 | + * @since 1.0.19 |
|
1565 | + * @param string $context View or edit context. |
|
1566 | + * @return string |
|
1567 | + */ |
|
1568 | + public function get_discount_code( $context = 'view' ) { |
|
1569 | + return $this->get_prop( 'discount_code', $context ); |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | /** |
1573 | - * Get the invoice's gateway. |
|
1574 | - * |
|
1575 | - * @since 1.0.19 |
|
1576 | - * @param string $context View or edit context. |
|
1577 | - * @return string |
|
1578 | - */ |
|
1579 | - public function get_gateway( $context = 'view' ) { |
|
1580 | - return $this->get_prop( 'gateway', $context ); |
|
1573 | + * Get the invoice's gateway. |
|
1574 | + * |
|
1575 | + * @since 1.0.19 |
|
1576 | + * @param string $context View or edit context. |
|
1577 | + * @return string |
|
1578 | + */ |
|
1579 | + public function get_gateway( $context = 'view' ) { |
|
1580 | + return $this->get_prop( 'gateway', $context ); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | /** |
1584 | - * Get the invoice's gateway display title. |
|
1585 | - * |
|
1586 | - * @since 1.0.19 |
|
1587 | - * @return string |
|
1588 | - */ |
|
1584 | + * Get the invoice's gateway display title. |
|
1585 | + * |
|
1586 | + * @since 1.0.19 |
|
1587 | + * @return string |
|
1588 | + */ |
|
1589 | 1589 | public function get_gateway_title() { |
1590 | 1590 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1591 | 1591 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1592 | 1592 | } |
1593 | 1593 | |
1594 | 1594 | /** |
1595 | - * Get the invoice's transaction id. |
|
1596 | - * |
|
1597 | - * @since 1.0.19 |
|
1598 | - * @param string $context View or edit context. |
|
1599 | - * @return string |
|
1600 | - */ |
|
1601 | - public function get_transaction_id( $context = 'view' ) { |
|
1602 | - return $this->get_prop( 'transaction_id', $context ); |
|
1595 | + * Get the invoice's transaction id. |
|
1596 | + * |
|
1597 | + * @since 1.0.19 |
|
1598 | + * @param string $context View or edit context. |
|
1599 | + * @return string |
|
1600 | + */ |
|
1601 | + public function get_transaction_id( $context = 'view' ) { |
|
1602 | + return $this->get_prop( 'transaction_id', $context ); |
|
1603 | 1603 | } |
1604 | 1604 | |
1605 | 1605 | /** |
1606 | - * Get the invoice's currency. |
|
1607 | - * |
|
1608 | - * @since 1.0.19 |
|
1609 | - * @param string $context View or edit context. |
|
1610 | - * @return string |
|
1611 | - */ |
|
1612 | - public function get_currency( $context = 'view' ) { |
|
1606 | + * Get the invoice's currency. |
|
1607 | + * |
|
1608 | + * @since 1.0.19 |
|
1609 | + * @param string $context View or edit context. |
|
1610 | + * @return string |
|
1611 | + */ |
|
1612 | + public function get_currency( $context = 'view' ) { |
|
1613 | 1613 | $currency = $this->get_prop( 'currency', $context ); |
1614 | 1614 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1615 | 1615 | } |
1616 | 1616 | |
1617 | 1617 | /** |
1618 | - * Checks if we are charging taxes for this invoice. |
|
1619 | - * |
|
1620 | - * @since 1.0.19 |
|
1621 | - * @param string $context View or edit context. |
|
1622 | - * @return bool |
|
1623 | - */ |
|
1624 | - public function get_disable_taxes( $context = 'view' ) { |
|
1618 | + * Checks if we are charging taxes for this invoice. |
|
1619 | + * |
|
1620 | + * @since 1.0.19 |
|
1621 | + * @param string $context View or edit context. |
|
1622 | + * @return bool |
|
1623 | + */ |
|
1624 | + public function get_disable_taxes( $context = 'view' ) { |
|
1625 | 1625 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1626 | 1626 | } |
1627 | 1627 | |
1628 | 1628 | /** |
1629 | - * Retrieves the remote subscription id for an invoice. |
|
1630 | - * |
|
1631 | - * @since 1.0.19 |
|
1632 | - * @param string $context View or edit context. |
|
1633 | - * @return int |
|
1634 | - */ |
|
1629 | + * Retrieves the remote subscription id for an invoice. |
|
1630 | + * |
|
1631 | + * @since 1.0.19 |
|
1632 | + * @param string $context View or edit context. |
|
1633 | + * @return int |
|
1634 | + */ |
|
1635 | 1635 | public function get_subscription_id( $context = 'view' ) { |
1636 | 1636 | $subscription_id = $this->get_prop( 'subscription_id', $context ); |
1637 | 1637 | |
@@ -1644,12 +1644,12 @@ discard block |
||
1644 | 1644 | } |
1645 | 1645 | |
1646 | 1646 | /** |
1647 | - * Retrieves the payment meta for an invoice. |
|
1648 | - * |
|
1649 | - * @since 1.0.19 |
|
1650 | - * @param string $context View or edit context. |
|
1651 | - * @return array |
|
1652 | - */ |
|
1647 | + * Retrieves the payment meta for an invoice. |
|
1648 | + * |
|
1649 | + * @since 1.0.19 |
|
1650 | + * @param string $context View or edit context. |
|
1651 | + * @return array |
|
1652 | + */ |
|
1653 | 1653 | public function get_payment_meta( $context = 'view' ) { |
1654 | 1654 | |
1655 | 1655 | return array( |
@@ -1669,11 +1669,11 @@ discard block |
||
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | /** |
1672 | - * Retrieves the cart details for an invoice. |
|
1673 | - * |
|
1674 | - * @since 1.0.19 |
|
1675 | - * @return array |
|
1676 | - */ |
|
1672 | + * Retrieves the cart details for an invoice. |
|
1673 | + * |
|
1674 | + * @since 1.0.19 |
|
1675 | + * @return array |
|
1676 | + */ |
|
1677 | 1677 | public function get_cart_details() { |
1678 | 1678 | $items = $this->get_items(); |
1679 | 1679 | $cart_details = array(); |
@@ -1683,16 +1683,16 @@ discard block |
||
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | return $cart_details; |
1686 | - } |
|
1686 | + } |
|
1687 | 1687 | |
1688 | - /** |
|
1689 | - * Retrieves the recurring item. |
|
1690 | - * |
|
1691 | - * @return null|GetPaid_Form_Item|int |
|
1692 | - */ |
|
1693 | - public function get_recurring( $object = false ) { |
|
1688 | + /** |
|
1689 | + * Retrieves the recurring item. |
|
1690 | + * |
|
1691 | + * @return null|GetPaid_Form_Item|int |
|
1692 | + */ |
|
1693 | + public function get_recurring( $object = false ) { |
|
1694 | 1694 | |
1695 | - // Are we returning an object? |
|
1695 | + // Are we returning an object? |
|
1696 | 1696 | if ( $object ) { |
1697 | 1697 | return $this->get_item( $this->recurring_item ); |
1698 | 1698 | } |
@@ -1700,100 +1700,100 @@ discard block |
||
1700 | 1700 | return $this->recurring_item; |
1701 | 1701 | } |
1702 | 1702 | |
1703 | - /** |
|
1704 | - * Retrieves the subscription name. |
|
1705 | - * |
|
1706 | - * @since 1.0.19 |
|
1707 | - * @return string |
|
1708 | - */ |
|
1709 | - public function get_subscription_name() { |
|
1703 | + /** |
|
1704 | + * Retrieves the subscription name. |
|
1705 | + * |
|
1706 | + * @since 1.0.19 |
|
1707 | + * @return string |
|
1708 | + */ |
|
1709 | + public function get_subscription_name() { |
|
1710 | 1710 | |
1711 | - // Retrieve the recurring name |
|
1711 | + // Retrieve the recurring name |
|
1712 | 1712 | $item = $this->get_recurring( true ); |
1713 | 1713 | |
1714 | - // Abort if it does not exist. |
|
1714 | + // Abort if it does not exist. |
|
1715 | 1715 | if ( empty( $item ) ) { |
1716 | 1716 | return ''; |
1717 | 1717 | } |
1718 | 1718 | |
1719 | - // Return the item name. |
|
1719 | + // Return the item name. |
|
1720 | 1720 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1721 | - } |
|
1722 | - |
|
1723 | - /** |
|
1724 | - * Retrieves the view url. |
|
1725 | - * |
|
1726 | - * @since 1.0.19 |
|
1727 | - * @return string |
|
1728 | - */ |
|
1729 | - public function get_view_url() { |
|
1721 | + } |
|
1722 | + |
|
1723 | + /** |
|
1724 | + * Retrieves the view url. |
|
1725 | + * |
|
1726 | + * @since 1.0.19 |
|
1727 | + * @return string |
|
1728 | + */ |
|
1729 | + public function get_view_url() { |
|
1730 | 1730 | $invoice_url = get_permalink( $this->get_id() ); |
1731 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1731 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1732 | 1732 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1733 | - } |
|
1733 | + } |
|
1734 | 1734 | |
1735 | - /** |
|
1736 | - * Retrieves the payment url. |
|
1737 | - * |
|
1738 | - * @since 1.0.19 |
|
1739 | - * @return string |
|
1740 | - */ |
|
1741 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1735 | + /** |
|
1736 | + * Retrieves the payment url. |
|
1737 | + * |
|
1738 | + * @since 1.0.19 |
|
1739 | + * @return string |
|
1740 | + */ |
|
1741 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1742 | 1742 | |
1743 | - // Retrieve the checkout url. |
|
1743 | + // Retrieve the checkout url. |
|
1744 | 1744 | $pay_url = wpinv_get_checkout_uri(); |
1745 | 1745 | |
1746 | - // Maybe force ssl. |
|
1746 | + // Maybe force ssl. |
|
1747 | 1747 | if ( is_ssl() ) { |
1748 | 1748 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1749 | 1749 | } |
1750 | 1750 | |
1751 | - // Add the invoice key. |
|
1752 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1751 | + // Add the invoice key. |
|
1752 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1753 | 1753 | |
1754 | - // (Maybe?) add a secret |
|
1754 | + // (Maybe?) add a secret |
|
1755 | 1755 | if ( $secret ) { |
1756 | 1756 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1757 | 1757 | } |
1758 | 1758 | |
1759 | 1759 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1760 | - } |
|
1760 | + } |
|
1761 | 1761 | |
1762 | - /** |
|
1763 | - * Retrieves the receipt url. |
|
1764 | - * |
|
1765 | - * @since 1.0.19 |
|
1766 | - * @return string |
|
1767 | - */ |
|
1768 | - public function get_receipt_url() { |
|
1769 | - |
|
1770 | - // Retrieve the checkout url. |
|
1762 | + /** |
|
1763 | + * Retrieves the receipt url. |
|
1764 | + * |
|
1765 | + * @since 1.0.19 |
|
1766 | + * @return string |
|
1767 | + */ |
|
1768 | + public function get_receipt_url() { |
|
1769 | + |
|
1770 | + // Retrieve the checkout url. |
|
1771 | 1771 | $receipt_url = wpinv_get_success_page_uri(); |
1772 | 1772 | |
1773 | - // Maybe force ssl. |
|
1773 | + // Maybe force ssl. |
|
1774 | 1774 | if ( is_ssl() ) { |
1775 | 1775 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
1776 | 1776 | } |
1777 | 1777 | |
1778 | - // Add the invoice key. |
|
1779 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1778 | + // Add the invoice key. |
|
1779 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1780 | 1780 | |
1781 | 1781 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | /** |
1785 | - * Magic method for accessing invoice properties. |
|
1786 | - * |
|
1787 | - * @since 1.0.15 |
|
1788 | - * @access public |
|
1789 | - * |
|
1790 | - * @param string $key Discount data to retrieve |
|
1791 | - * @param string $context View or edit context. |
|
1792 | - * @return mixed Value of the given invoice property (if set). |
|
1793 | - */ |
|
1794 | - public function get( $key, $context = 'view' ) { |
|
1785 | + * Magic method for accessing invoice properties. |
|
1786 | + * |
|
1787 | + * @since 1.0.15 |
|
1788 | + * @access public |
|
1789 | + * |
|
1790 | + * @param string $key Discount data to retrieve |
|
1791 | + * @param string $context View or edit context. |
|
1792 | + * @return mixed Value of the given invoice property (if set). |
|
1793 | + */ |
|
1794 | + public function get( $key, $context = 'view' ) { |
|
1795 | 1795 | return $this->get_prop( $key, $context ); |
1796 | - } |
|
1796 | + } |
|
1797 | 1797 | |
1798 | 1798 | /* |
1799 | 1799 | |-------------------------------------------------------------------------- |
@@ -1806,130 +1806,130 @@ discard block |
||
1806 | 1806 | */ |
1807 | 1807 | |
1808 | 1808 | /** |
1809 | - * Magic method for setting invoice properties. |
|
1810 | - * |
|
1811 | - * @since 1.0.19 |
|
1812 | - * @access public |
|
1813 | - * |
|
1814 | - * @param string $key Discount data to retrieve |
|
1815 | - * @param mixed $value new value. |
|
1816 | - * @return mixed Value of the given invoice property (if set). |
|
1817 | - */ |
|
1818 | - public function set( $key, $value ) { |
|
1809 | + * Magic method for setting invoice properties. |
|
1810 | + * |
|
1811 | + * @since 1.0.19 |
|
1812 | + * @access public |
|
1813 | + * |
|
1814 | + * @param string $key Discount data to retrieve |
|
1815 | + * @param mixed $value new value. |
|
1816 | + * @return mixed Value of the given invoice property (if set). |
|
1817 | + */ |
|
1818 | + public function set( $key, $value ) { |
|
1819 | 1819 | |
1820 | 1820 | $setter = "set_$key"; |
1821 | 1821 | if ( is_callable( array( $this, $setter ) ) ) { |
1822 | 1822 | $this->{$setter}( $value ); |
1823 | 1823 | } |
1824 | 1824 | |
1825 | - } |
|
1825 | + } |
|
1826 | 1826 | |
1827 | - /** |
|
1828 | - * Sets item status. |
|
1829 | - * |
|
1830 | - * @since 1.0.19 |
|
1831 | - * @param string $new_status New status. |
|
1832 | - * @param string $note Optional note to add. |
|
1833 | - * @param bool $manual_update Is this a manual status change?. |
|
1834 | - * @return array details of change. |
|
1835 | - */ |
|
1836 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1837 | - $old_status = $this->get_status(); |
|
1827 | + /** |
|
1828 | + * Sets item status. |
|
1829 | + * |
|
1830 | + * @since 1.0.19 |
|
1831 | + * @param string $new_status New status. |
|
1832 | + * @param string $note Optional note to add. |
|
1833 | + * @param bool $manual_update Is this a manual status change?. |
|
1834 | + * @return array details of change. |
|
1835 | + */ |
|
1836 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1837 | + $old_status = $this->get_status(); |
|
1838 | 1838 | |
1839 | - $statuses = $this->get_all_statuses(); |
|
1839 | + $statuses = $this->get_all_statuses(); |
|
1840 | 1840 | |
1841 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
1842 | - unset( $statuses[ 'draft' ] ); |
|
1843 | - } |
|
1841 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
1842 | + unset( $statuses[ 'draft' ] ); |
|
1843 | + } |
|
1844 | 1844 | |
1845 | - $this->set_prop( 'status', $new_status ); |
|
1845 | + $this->set_prop( 'status', $new_status ); |
|
1846 | 1846 | |
1847 | - // If setting the status, ensure it's set to a valid status. |
|
1848 | - if ( true === $this->object_read ) { |
|
1847 | + // If setting the status, ensure it's set to a valid status. |
|
1848 | + if ( true === $this->object_read ) { |
|
1849 | 1849 | |
1850 | - // Only allow valid new status. |
|
1851 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
1852 | - $new_status = 'wpi-pending'; |
|
1853 | - } |
|
1850 | + // Only allow valid new status. |
|
1851 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
1852 | + $new_status = 'wpi-pending'; |
|
1853 | + } |
|
1854 | 1854 | |
1855 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1856 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
1857 | - $old_status = 'wpi-pending'; |
|
1858 | - } |
|
1855 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1856 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
1857 | + $old_status = 'wpi-pending'; |
|
1858 | + } |
|
1859 | 1859 | |
1860 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
1861 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
1862 | - $old_status = 'wpi-pending'; |
|
1863 | - } |
|
1860 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
1861 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
1862 | + $old_status = 'wpi-pending'; |
|
1863 | + } |
|
1864 | 1864 | |
1865 | - } |
|
1865 | + } |
|
1866 | 1866 | |
1867 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1868 | - $this->status_transition = array( |
|
1869 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1870 | - 'to' => $new_status, |
|
1871 | - 'note' => $note, |
|
1872 | - 'manual' => (bool) $manual_update, |
|
1873 | - ); |
|
1867 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1868 | + $this->status_transition = array( |
|
1869 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1870 | + 'to' => $new_status, |
|
1871 | + 'note' => $note, |
|
1872 | + 'manual' => (bool) $manual_update, |
|
1873 | + ); |
|
1874 | 1874 | |
1875 | - if ( $manual_update ) { |
|
1876 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1877 | - } |
|
1875 | + if ( $manual_update ) { |
|
1876 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1877 | + } |
|
1878 | 1878 | |
1879 | - $this->maybe_set_date_paid(); |
|
1879 | + $this->maybe_set_date_paid(); |
|
1880 | 1880 | |
1881 | - } |
|
1881 | + } |
|
1882 | 1882 | |
1883 | - return array( |
|
1884 | - 'from' => $old_status, |
|
1885 | - 'to' => $new_status, |
|
1886 | - ); |
|
1887 | - } |
|
1883 | + return array( |
|
1884 | + 'from' => $old_status, |
|
1885 | + 'to' => $new_status, |
|
1886 | + ); |
|
1887 | + } |
|
1888 | 1888 | |
1889 | - /** |
|
1890 | - * Maybe set date paid. |
|
1891 | - * |
|
1892 | - * Sets the date paid variable when transitioning to the payment complete |
|
1893 | - * order status. |
|
1894 | - * |
|
1895 | - * @since 1.0.19 |
|
1896 | - */ |
|
1897 | - public function maybe_set_date_paid() { |
|
1889 | + /** |
|
1890 | + * Maybe set date paid. |
|
1891 | + * |
|
1892 | + * Sets the date paid variable when transitioning to the payment complete |
|
1893 | + * order status. |
|
1894 | + * |
|
1895 | + * @since 1.0.19 |
|
1896 | + */ |
|
1897 | + public function maybe_set_date_paid() { |
|
1898 | 1898 | |
1899 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1900 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
1901 | - } |
|
1902 | - } |
|
1899 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1900 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
1901 | + } |
|
1902 | + } |
|
1903 | 1903 | |
1904 | 1904 | /** |
1905 | - * Set parent invoice ID. |
|
1906 | - * |
|
1907 | - * @since 1.0.19 |
|
1908 | - */ |
|
1909 | - public function set_parent_id( $value ) { |
|
1910 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
1911 | - return; |
|
1912 | - } |
|
1913 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
1905 | + * Set parent invoice ID. |
|
1906 | + * |
|
1907 | + * @since 1.0.19 |
|
1908 | + */ |
|
1909 | + public function set_parent_id( $value ) { |
|
1910 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
1911 | + return; |
|
1912 | + } |
|
1913 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
1914 | 1914 | } |
1915 | 1915 | |
1916 | 1916 | /** |
1917 | - * Set plugin version when the invoice was created. |
|
1918 | - * |
|
1919 | - * @since 1.0.19 |
|
1920 | - */ |
|
1921 | - public function set_version( $value ) { |
|
1922 | - $this->set_prop( 'version', $value ); |
|
1917 | + * Set plugin version when the invoice was created. |
|
1918 | + * |
|
1919 | + * @since 1.0.19 |
|
1920 | + */ |
|
1921 | + public function set_version( $value ) { |
|
1922 | + $this->set_prop( 'version', $value ); |
|
1923 | 1923 | } |
1924 | - |
|
1925 | - /** |
|
1926 | - * Set date when the invoice was created. |
|
1927 | - * |
|
1928 | - * @since 1.0.19 |
|
1929 | - * @param string $value Value to set. |
|
1924 | + |
|
1925 | + /** |
|
1926 | + * Set date when the invoice was created. |
|
1927 | + * |
|
1928 | + * @since 1.0.19 |
|
1929 | + * @param string $value Value to set. |
|
1930 | 1930 | * @return bool Whether or not the date was set. |
1931 | - */ |
|
1932 | - public function set_date_created( $value ) { |
|
1931 | + */ |
|
1932 | + public function set_date_created( $value ) { |
|
1933 | 1933 | $date = strtotime( $value ); |
1934 | 1934 | |
1935 | 1935 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1942,13 +1942,13 @@ discard block |
||
1942 | 1942 | } |
1943 | 1943 | |
1944 | 1944 | /** |
1945 | - * Set date invoice due date. |
|
1946 | - * |
|
1947 | - * @since 1.0.19 |
|
1948 | - * @param string $value Value to set. |
|
1945 | + * Set date invoice due date. |
|
1946 | + * |
|
1947 | + * @since 1.0.19 |
|
1948 | + * @param string $value Value to set. |
|
1949 | 1949 | * @return bool Whether or not the date was set. |
1950 | - */ |
|
1951 | - public function set_due_date( $value ) { |
|
1950 | + */ |
|
1951 | + public function set_due_date( $value ) { |
|
1952 | 1952 | $date = strtotime( $value ); |
1953 | 1953 | |
1954 | 1954 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1956,29 +1956,29 @@ discard block |
||
1956 | 1956 | return true; |
1957 | 1957 | } |
1958 | 1958 | |
1959 | - $this->set_prop( 'due_date', '' ); |
|
1959 | + $this->set_prop( 'due_date', '' ); |
|
1960 | 1960 | return false; |
1961 | 1961 | |
1962 | 1962 | } |
1963 | 1963 | |
1964 | 1964 | /** |
1965 | - * Alias of self::set_due_date(). |
|
1966 | - * |
|
1967 | - * @since 1.0.19 |
|
1968 | - * @param string $value New name. |
|
1969 | - */ |
|
1970 | - public function set_date_due( $value ) { |
|
1971 | - $this->set_due_date( $value ); |
|
1965 | + * Alias of self::set_due_date(). |
|
1966 | + * |
|
1967 | + * @since 1.0.19 |
|
1968 | + * @param string $value New name. |
|
1969 | + */ |
|
1970 | + public function set_date_due( $value ) { |
|
1971 | + $this->set_due_date( $value ); |
|
1972 | 1972 | } |
1973 | 1973 | |
1974 | 1974 | /** |
1975 | - * Set date invoice was completed. |
|
1976 | - * |
|
1977 | - * @since 1.0.19 |
|
1978 | - * @param string $value Value to set. |
|
1975 | + * Set date invoice was completed. |
|
1976 | + * |
|
1977 | + * @since 1.0.19 |
|
1978 | + * @param string $value Value to set. |
|
1979 | 1979 | * @return bool Whether or not the date was set. |
1980 | - */ |
|
1981 | - public function set_completed_date( $value ) { |
|
1980 | + */ |
|
1981 | + public function set_completed_date( $value ) { |
|
1982 | 1982 | $date = strtotime( $value ); |
1983 | 1983 | |
1984 | 1984 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1986,29 +1986,29 @@ discard block |
||
1986 | 1986 | return true; |
1987 | 1987 | } |
1988 | 1988 | |
1989 | - $this->set_prop( 'completed_date', '' ); |
|
1989 | + $this->set_prop( 'completed_date', '' ); |
|
1990 | 1990 | return false; |
1991 | 1991 | |
1992 | 1992 | } |
1993 | 1993 | |
1994 | 1994 | /** |
1995 | - * Alias of self::set_completed_date(). |
|
1996 | - * |
|
1997 | - * @since 1.0.19 |
|
1998 | - * @param string $value New name. |
|
1999 | - */ |
|
2000 | - public function set_date_completed( $value ) { |
|
2001 | - $this->set_completed_date( $value ); |
|
1995 | + * Alias of self::set_completed_date(). |
|
1996 | + * |
|
1997 | + * @since 1.0.19 |
|
1998 | + * @param string $value New name. |
|
1999 | + */ |
|
2000 | + public function set_date_completed( $value ) { |
|
2001 | + $this->set_completed_date( $value ); |
|
2002 | 2002 | } |
2003 | 2003 | |
2004 | 2004 | /** |
2005 | - * Set date when the invoice was last modified. |
|
2006 | - * |
|
2007 | - * @since 1.0.19 |
|
2008 | - * @param string $value Value to set. |
|
2005 | + * Set date when the invoice was last modified. |
|
2006 | + * |
|
2007 | + * @since 1.0.19 |
|
2008 | + * @param string $value Value to set. |
|
2009 | 2009 | * @return bool Whether or not the date was set. |
2010 | - */ |
|
2011 | - public function set_date_modified( $value ) { |
|
2010 | + */ |
|
2011 | + public function set_date_modified( $value ) { |
|
2012 | 2012 | $date = strtotime( $value ); |
2013 | 2013 | |
2014 | 2014 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2016,706 +2016,706 @@ discard block |
||
2016 | 2016 | return true; |
2017 | 2017 | } |
2018 | 2018 | |
2019 | - $this->set_prop( 'date_modified', '' ); |
|
2019 | + $this->set_prop( 'date_modified', '' ); |
|
2020 | 2020 | return false; |
2021 | 2021 | |
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | /** |
2025 | - * Set the invoice number. |
|
2026 | - * |
|
2027 | - * @since 1.0.19 |
|
2028 | - * @param string $value New number. |
|
2029 | - */ |
|
2030 | - public function set_number( $value ) { |
|
2025 | + * Set the invoice number. |
|
2026 | + * |
|
2027 | + * @since 1.0.19 |
|
2028 | + * @param string $value New number. |
|
2029 | + */ |
|
2030 | + public function set_number( $value ) { |
|
2031 | 2031 | $number = sanitize_text_field( $value ); |
2032 | - $this->set_prop( 'number', $number ); |
|
2032 | + $this->set_prop( 'number', $number ); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | /** |
2036 | - * Set the invoice type. |
|
2037 | - * |
|
2038 | - * @since 1.0.19 |
|
2039 | - * @param string $value Type. |
|
2040 | - */ |
|
2041 | - public function set_type( $value ) { |
|
2036 | + * Set the invoice type. |
|
2037 | + * |
|
2038 | + * @since 1.0.19 |
|
2039 | + * @param string $value Type. |
|
2040 | + */ |
|
2041 | + public function set_type( $value ) { |
|
2042 | 2042 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2043 | - $this->set_prop( 'type', $type ); |
|
2044 | - } |
|
2043 | + $this->set_prop( 'type', $type ); |
|
2044 | + } |
|
2045 | 2045 | |
2046 | 2046 | /** |
2047 | - * Set the invoice post type. |
|
2048 | - * |
|
2049 | - * @since 1.0.19 |
|
2050 | - * @param string $value Post type. |
|
2051 | - */ |
|
2052 | - public function set_post_type( $value ) { |
|
2047 | + * Set the invoice post type. |
|
2048 | + * |
|
2049 | + * @since 1.0.19 |
|
2050 | + * @param string $value Post type. |
|
2051 | + */ |
|
2052 | + public function set_post_type( $value ) { |
|
2053 | 2053 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2054 | - $this->set_type( $value ); |
|
2054 | + $this->set_type( $value ); |
|
2055 | 2055 | $this->set_prop( 'post_type', $value ); |
2056 | 2056 | } |
2057 | 2057 | } |
2058 | 2058 | |
2059 | 2059 | /** |
2060 | - * Set the invoice key. |
|
2061 | - * |
|
2062 | - * @since 1.0.19 |
|
2063 | - * @param string $value New key. |
|
2064 | - */ |
|
2065 | - public function set_key( $value ) { |
|
2060 | + * Set the invoice key. |
|
2061 | + * |
|
2062 | + * @since 1.0.19 |
|
2063 | + * @param string $value New key. |
|
2064 | + */ |
|
2065 | + public function set_key( $value ) { |
|
2066 | 2066 | $key = sanitize_text_field( $value ); |
2067 | - $this->set_prop( 'key', $key ); |
|
2067 | + $this->set_prop( 'key', $key ); |
|
2068 | 2068 | } |
2069 | 2069 | |
2070 | 2070 | /** |
2071 | - * Set the invoice mode. |
|
2072 | - * |
|
2073 | - * @since 1.0.19 |
|
2074 | - * @param string $value mode. |
|
2075 | - */ |
|
2076 | - public function set_mode( $value ) { |
|
2071 | + * Set the invoice mode. |
|
2072 | + * |
|
2073 | + * @since 1.0.19 |
|
2074 | + * @param string $value mode. |
|
2075 | + */ |
|
2076 | + public function set_mode( $value ) { |
|
2077 | 2077 | if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
2078 | 2078 | $this->set_prop( 'value', $value ); |
2079 | 2079 | } |
2080 | 2080 | } |
2081 | 2081 | |
2082 | 2082 | /** |
2083 | - * Set the invoice path. |
|
2084 | - * |
|
2085 | - * @since 1.0.19 |
|
2086 | - * @param string $value path. |
|
2087 | - */ |
|
2088 | - public function set_path( $value ) { |
|
2083 | + * Set the invoice path. |
|
2084 | + * |
|
2085 | + * @since 1.0.19 |
|
2086 | + * @param string $value path. |
|
2087 | + */ |
|
2088 | + public function set_path( $value ) { |
|
2089 | 2089 | $this->set_prop( 'path', $value ); |
2090 | 2090 | } |
2091 | 2091 | |
2092 | 2092 | /** |
2093 | - * Set the invoice name. |
|
2094 | - * |
|
2095 | - * @since 1.0.19 |
|
2096 | - * @param string $value New name. |
|
2097 | - */ |
|
2098 | - public function set_name( $value ) { |
|
2093 | + * Set the invoice name. |
|
2094 | + * |
|
2095 | + * @since 1.0.19 |
|
2096 | + * @param string $value New name. |
|
2097 | + */ |
|
2098 | + public function set_name( $value ) { |
|
2099 | 2099 | $name = sanitize_text_field( $value ); |
2100 | - $this->set_prop( 'name', $name ); |
|
2100 | + $this->set_prop( 'name', $name ); |
|
2101 | 2101 | } |
2102 | 2102 | |
2103 | 2103 | /** |
2104 | - * Alias of self::set_name(). |
|
2105 | - * |
|
2106 | - * @since 1.0.19 |
|
2107 | - * @param string $value New name. |
|
2108 | - */ |
|
2109 | - public function set_title( $value ) { |
|
2110 | - $this->set_name( $value ); |
|
2104 | + * Alias of self::set_name(). |
|
2105 | + * |
|
2106 | + * @since 1.0.19 |
|
2107 | + * @param string $value New name. |
|
2108 | + */ |
|
2109 | + public function set_title( $value ) { |
|
2110 | + $this->set_name( $value ); |
|
2111 | 2111 | } |
2112 | 2112 | |
2113 | 2113 | /** |
2114 | - * Set the invoice description. |
|
2115 | - * |
|
2116 | - * @since 1.0.19 |
|
2117 | - * @param string $value New description. |
|
2118 | - */ |
|
2119 | - public function set_description( $value ) { |
|
2114 | + * Set the invoice description. |
|
2115 | + * |
|
2116 | + * @since 1.0.19 |
|
2117 | + * @param string $value New description. |
|
2118 | + */ |
|
2119 | + public function set_description( $value ) { |
|
2120 | 2120 | $description = wp_kses_post( $value ); |
2121 | - return $this->set_prop( 'description', $description ); |
|
2121 | + return $this->set_prop( 'description', $description ); |
|
2122 | 2122 | } |
2123 | 2123 | |
2124 | 2124 | /** |
2125 | - * Alias of self::set_description(). |
|
2126 | - * |
|
2127 | - * @since 1.0.19 |
|
2128 | - * @param string $value New description. |
|
2129 | - */ |
|
2130 | - public function set_excerpt( $value ) { |
|
2131 | - $this->set_description( $value ); |
|
2125 | + * Alias of self::set_description(). |
|
2126 | + * |
|
2127 | + * @since 1.0.19 |
|
2128 | + * @param string $value New description. |
|
2129 | + */ |
|
2130 | + public function set_excerpt( $value ) { |
|
2131 | + $this->set_description( $value ); |
|
2132 | 2132 | } |
2133 | 2133 | |
2134 | 2134 | /** |
2135 | - * Alias of self::set_description(). |
|
2136 | - * |
|
2137 | - * @since 1.0.19 |
|
2138 | - * @param string $value New description. |
|
2139 | - */ |
|
2140 | - public function set_summary( $value ) { |
|
2141 | - $this->set_description( $value ); |
|
2135 | + * Alias of self::set_description(). |
|
2136 | + * |
|
2137 | + * @since 1.0.19 |
|
2138 | + * @param string $value New description. |
|
2139 | + */ |
|
2140 | + public function set_summary( $value ) { |
|
2141 | + $this->set_description( $value ); |
|
2142 | 2142 | } |
2143 | 2143 | |
2144 | 2144 | /** |
2145 | - * Set the receiver of the invoice. |
|
2146 | - * |
|
2147 | - * @since 1.0.19 |
|
2148 | - * @param int $value New author. |
|
2149 | - */ |
|
2150 | - public function set_author( $value ) { |
|
2151 | - $user = get_user_by( 'id', (int) $value ); |
|
2145 | + * Set the receiver of the invoice. |
|
2146 | + * |
|
2147 | + * @since 1.0.19 |
|
2148 | + * @param int $value New author. |
|
2149 | + */ |
|
2150 | + public function set_author( $value ) { |
|
2151 | + $user = get_user_by( 'id', (int) $value ); |
|
2152 | 2152 | |
2153 | - if ( $user && $user->ID ) { |
|
2154 | - $this->set_prop( 'author', $user->ID ); |
|
2155 | - $this->set_prop( 'email', $user->user_email ); |
|
2156 | - } |
|
2153 | + if ( $user && $user->ID ) { |
|
2154 | + $this->set_prop( 'author', $user->ID ); |
|
2155 | + $this->set_prop( 'email', $user->user_email ); |
|
2156 | + } |
|
2157 | 2157 | |
2158 | 2158 | } |
2159 | 2159 | |
2160 | 2160 | /** |
2161 | - * Alias of self::set_author(). |
|
2162 | - * |
|
2163 | - * @since 1.0.19 |
|
2164 | - * @param int $value New user id. |
|
2165 | - */ |
|
2166 | - public function set_user_id( $value ) { |
|
2167 | - $this->set_author( $value ); |
|
2161 | + * Alias of self::set_author(). |
|
2162 | + * |
|
2163 | + * @since 1.0.19 |
|
2164 | + * @param int $value New user id. |
|
2165 | + */ |
|
2166 | + public function set_user_id( $value ) { |
|
2167 | + $this->set_author( $value ); |
|
2168 | 2168 | } |
2169 | 2169 | |
2170 | 2170 | /** |
2171 | - * Alias of self::set_author(). |
|
2172 | - * |
|
2173 | - * @since 1.0.19 |
|
2174 | - * @param int $value New user id. |
|
2175 | - */ |
|
2176 | - public function set_customer_id( $value ) { |
|
2177 | - $this->set_author( $value ); |
|
2171 | + * Alias of self::set_author(). |
|
2172 | + * |
|
2173 | + * @since 1.0.19 |
|
2174 | + * @param int $value New user id. |
|
2175 | + */ |
|
2176 | + public function set_customer_id( $value ) { |
|
2177 | + $this->set_author( $value ); |
|
2178 | 2178 | } |
2179 | 2179 | |
2180 | 2180 | /** |
2181 | - * Set the customer's ip. |
|
2182 | - * |
|
2183 | - * @since 1.0.19 |
|
2184 | - * @param string $value ip address. |
|
2185 | - */ |
|
2186 | - public function set_ip( $value ) { |
|
2187 | - $this->set_prop( 'ip', $value ); |
|
2181 | + * Set the customer's ip. |
|
2182 | + * |
|
2183 | + * @since 1.0.19 |
|
2184 | + * @param string $value ip address. |
|
2185 | + */ |
|
2186 | + public function set_ip( $value ) { |
|
2187 | + $this->set_prop( 'ip', $value ); |
|
2188 | 2188 | } |
2189 | 2189 | |
2190 | 2190 | /** |
2191 | - * Alias of self::set_ip(). |
|
2192 | - * |
|
2193 | - * @since 1.0.19 |
|
2194 | - * @param string $value ip address. |
|
2195 | - */ |
|
2196 | - public function set_user_ip( $value ) { |
|
2197 | - $this->set_ip( $value ); |
|
2191 | + * Alias of self::set_ip(). |
|
2192 | + * |
|
2193 | + * @since 1.0.19 |
|
2194 | + * @param string $value ip address. |
|
2195 | + */ |
|
2196 | + public function set_user_ip( $value ) { |
|
2197 | + $this->set_ip( $value ); |
|
2198 | 2198 | } |
2199 | 2199 | |
2200 | 2200 | /** |
2201 | - * Set the customer's first name. |
|
2202 | - * |
|
2203 | - * @since 1.0.19 |
|
2204 | - * @param string $value first name. |
|
2205 | - */ |
|
2206 | - public function set_first_name( $value ) { |
|
2207 | - $this->set_prop( 'first_name', $value ); |
|
2201 | + * Set the customer's first name. |
|
2202 | + * |
|
2203 | + * @since 1.0.19 |
|
2204 | + * @param string $value first name. |
|
2205 | + */ |
|
2206 | + public function set_first_name( $value ) { |
|
2207 | + $this->set_prop( 'first_name', $value ); |
|
2208 | 2208 | } |
2209 | 2209 | |
2210 | 2210 | /** |
2211 | - * Alias of self::set_first_name(). |
|
2212 | - * |
|
2213 | - * @since 1.0.19 |
|
2214 | - * @param string $value first name. |
|
2215 | - */ |
|
2216 | - public function set_user_first_name( $value ) { |
|
2217 | - $this->set_first_name( $value ); |
|
2211 | + * Alias of self::set_first_name(). |
|
2212 | + * |
|
2213 | + * @since 1.0.19 |
|
2214 | + * @param string $value first name. |
|
2215 | + */ |
|
2216 | + public function set_user_first_name( $value ) { |
|
2217 | + $this->set_first_name( $value ); |
|
2218 | 2218 | } |
2219 | 2219 | |
2220 | 2220 | /** |
2221 | - * Alias of self::set_first_name(). |
|
2222 | - * |
|
2223 | - * @since 1.0.19 |
|
2224 | - * @param string $value first name. |
|
2225 | - */ |
|
2226 | - public function set_customer_first_name( $value ) { |
|
2227 | - $this->set_first_name( $value ); |
|
2221 | + * Alias of self::set_first_name(). |
|
2222 | + * |
|
2223 | + * @since 1.0.19 |
|
2224 | + * @param string $value first name. |
|
2225 | + */ |
|
2226 | + public function set_customer_first_name( $value ) { |
|
2227 | + $this->set_first_name( $value ); |
|
2228 | 2228 | } |
2229 | 2229 | |
2230 | 2230 | /** |
2231 | - * Set the customer's last name. |
|
2232 | - * |
|
2233 | - * @since 1.0.19 |
|
2234 | - * @param string $value last name. |
|
2235 | - */ |
|
2236 | - public function set_last_name( $value ) { |
|
2237 | - $this->set_prop( 'last_name', $value ); |
|
2231 | + * Set the customer's last name. |
|
2232 | + * |
|
2233 | + * @since 1.0.19 |
|
2234 | + * @param string $value last name. |
|
2235 | + */ |
|
2236 | + public function set_last_name( $value ) { |
|
2237 | + $this->set_prop( 'last_name', $value ); |
|
2238 | 2238 | } |
2239 | 2239 | |
2240 | 2240 | /** |
2241 | - * Alias of self::set_last_name(). |
|
2242 | - * |
|
2243 | - * @since 1.0.19 |
|
2244 | - * @param string $value last name. |
|
2245 | - */ |
|
2246 | - public function set_user_last_name( $value ) { |
|
2247 | - $this->set_last_name( $value ); |
|
2241 | + * Alias of self::set_last_name(). |
|
2242 | + * |
|
2243 | + * @since 1.0.19 |
|
2244 | + * @param string $value last name. |
|
2245 | + */ |
|
2246 | + public function set_user_last_name( $value ) { |
|
2247 | + $this->set_last_name( $value ); |
|
2248 | 2248 | } |
2249 | 2249 | |
2250 | 2250 | /** |
2251 | - * Alias of self::set_last_name(). |
|
2252 | - * |
|
2253 | - * @since 1.0.19 |
|
2254 | - * @param string $value last name. |
|
2255 | - */ |
|
2256 | - public function set_customer_last_name( $value ) { |
|
2257 | - $this->set_last_name( $value ); |
|
2251 | + * Alias of self::set_last_name(). |
|
2252 | + * |
|
2253 | + * @since 1.0.19 |
|
2254 | + * @param string $value last name. |
|
2255 | + */ |
|
2256 | + public function set_customer_last_name( $value ) { |
|
2257 | + $this->set_last_name( $value ); |
|
2258 | 2258 | } |
2259 | 2259 | |
2260 | 2260 | /** |
2261 | - * Set the customer's phone number. |
|
2262 | - * |
|
2263 | - * @since 1.0.19 |
|
2264 | - * @param string $value phone. |
|
2265 | - */ |
|
2266 | - public function set_phone( $value ) { |
|
2267 | - $this->set_prop( 'phone', $value ); |
|
2261 | + * Set the customer's phone number. |
|
2262 | + * |
|
2263 | + * @since 1.0.19 |
|
2264 | + * @param string $value phone. |
|
2265 | + */ |
|
2266 | + public function set_phone( $value ) { |
|
2267 | + $this->set_prop( 'phone', $value ); |
|
2268 | 2268 | } |
2269 | 2269 | |
2270 | 2270 | /** |
2271 | - * Alias of self::set_phone(). |
|
2272 | - * |
|
2273 | - * @since 1.0.19 |
|
2274 | - * @param string $value phone. |
|
2275 | - */ |
|
2276 | - public function set_user_phone( $value ) { |
|
2277 | - $this->set_phone( $value ); |
|
2271 | + * Alias of self::set_phone(). |
|
2272 | + * |
|
2273 | + * @since 1.0.19 |
|
2274 | + * @param string $value phone. |
|
2275 | + */ |
|
2276 | + public function set_user_phone( $value ) { |
|
2277 | + $this->set_phone( $value ); |
|
2278 | + } |
|
2279 | + |
|
2280 | + /** |
|
2281 | + * Alias of self::set_phone(). |
|
2282 | + * |
|
2283 | + * @since 1.0.19 |
|
2284 | + * @param string $value phone. |
|
2285 | + */ |
|
2286 | + public function set_customer_phone( $value ) { |
|
2287 | + $this->set_phone( $value ); |
|
2288 | + } |
|
2289 | + |
|
2290 | + /** |
|
2291 | + * Alias of self::set_phone(). |
|
2292 | + * |
|
2293 | + * @since 1.0.19 |
|
2294 | + * @param string $value phone. |
|
2295 | + */ |
|
2296 | + public function set_phone_number( $value ) { |
|
2297 | + $this->set_phone( $value ); |
|
2278 | 2298 | } |
2279 | 2299 | |
2280 | 2300 | /** |
2281 | - * Alias of self::set_phone(). |
|
2282 | - * |
|
2283 | - * @since 1.0.19 |
|
2284 | - * @param string $value phone. |
|
2285 | - */ |
|
2286 | - public function set_customer_phone( $value ) { |
|
2287 | - $this->set_phone( $value ); |
|
2301 | + * Set the customer's email address. |
|
2302 | + * |
|
2303 | + * @since 1.0.19 |
|
2304 | + * @param string $value email address. |
|
2305 | + */ |
|
2306 | + public function set_email( $value ) { |
|
2307 | + $this->set_prop( 'email', $value ); |
|
2288 | 2308 | } |
2289 | 2309 | |
2290 | 2310 | /** |
2291 | - * Alias of self::set_phone(). |
|
2292 | - * |
|
2293 | - * @since 1.0.19 |
|
2294 | - * @param string $value phone. |
|
2295 | - */ |
|
2296 | - public function set_phone_number( $value ) { |
|
2297 | - $this->set_phone( $value ); |
|
2311 | + * Alias of self::set_email(). |
|
2312 | + * |
|
2313 | + * @since 1.0.19 |
|
2314 | + * @param string $value email address. |
|
2315 | + */ |
|
2316 | + public function set_user_email( $value ) { |
|
2317 | + $this->set_email( $value ); |
|
2298 | 2318 | } |
2299 | 2319 | |
2300 | 2320 | /** |
2301 | - * Set the customer's email address. |
|
2302 | - * |
|
2303 | - * @since 1.0.19 |
|
2304 | - * @param string $value email address. |
|
2305 | - */ |
|
2306 | - public function set_email( $value ) { |
|
2307 | - $this->set_prop( 'email', $value ); |
|
2321 | + * Alias of self::set_email(). |
|
2322 | + * |
|
2323 | + * @since 1.0.19 |
|
2324 | + * @param string $value email address. |
|
2325 | + */ |
|
2326 | + public function set_email_address( $value ) { |
|
2327 | + $this->set_email( $value ); |
|
2328 | + } |
|
2329 | + |
|
2330 | + /** |
|
2331 | + * Alias of self::set_email(). |
|
2332 | + * |
|
2333 | + * @since 1.0.19 |
|
2334 | + * @param string $value email address. |
|
2335 | + */ |
|
2336 | + public function set_customer_email( $value ) { |
|
2337 | + $this->set_email( $value ); |
|
2308 | 2338 | } |
2309 | 2339 | |
2310 | 2340 | /** |
2311 | - * Alias of self::set_email(). |
|
2312 | - * |
|
2313 | - * @since 1.0.19 |
|
2314 | - * @param string $value email address. |
|
2315 | - */ |
|
2316 | - public function set_user_email( $value ) { |
|
2317 | - $this->set_email( $value ); |
|
2341 | + * Set the customer's country. |
|
2342 | + * |
|
2343 | + * @since 1.0.19 |
|
2344 | + * @param string $value country. |
|
2345 | + */ |
|
2346 | + public function set_country( $value ) { |
|
2347 | + $this->set_prop( 'country', $value ); |
|
2318 | 2348 | } |
2319 | 2349 | |
2320 | 2350 | /** |
2321 | - * Alias of self::set_email(). |
|
2322 | - * |
|
2323 | - * @since 1.0.19 |
|
2324 | - * @param string $value email address. |
|
2325 | - */ |
|
2326 | - public function set_email_address( $value ) { |
|
2327 | - $this->set_email( $value ); |
|
2351 | + * Alias of self::set_country(). |
|
2352 | + * |
|
2353 | + * @since 1.0.19 |
|
2354 | + * @param string $value country. |
|
2355 | + */ |
|
2356 | + public function set_user_country( $value ) { |
|
2357 | + $this->set_country( $value ); |
|
2328 | 2358 | } |
2329 | 2359 | |
2330 | 2360 | /** |
2331 | - * Alias of self::set_email(). |
|
2332 | - * |
|
2333 | - * @since 1.0.19 |
|
2334 | - * @param string $value email address. |
|
2335 | - */ |
|
2336 | - public function set_customer_email( $value ) { |
|
2337 | - $this->set_email( $value ); |
|
2361 | + * Alias of self::set_country(). |
|
2362 | + * |
|
2363 | + * @since 1.0.19 |
|
2364 | + * @param string $value country. |
|
2365 | + */ |
|
2366 | + public function set_customer_country( $value ) { |
|
2367 | + $this->set_country( $value ); |
|
2338 | 2368 | } |
2339 | 2369 | |
2340 | 2370 | /** |
2341 | - * Set the customer's country. |
|
2342 | - * |
|
2343 | - * @since 1.0.19 |
|
2344 | - * @param string $value country. |
|
2345 | - */ |
|
2346 | - public function set_country( $value ) { |
|
2347 | - $this->set_prop( 'country', $value ); |
|
2371 | + * Set the customer's state. |
|
2372 | + * |
|
2373 | + * @since 1.0.19 |
|
2374 | + * @param string $value state. |
|
2375 | + */ |
|
2376 | + public function set_state( $value ) { |
|
2377 | + $this->set_prop( 'state', $value ); |
|
2348 | 2378 | } |
2349 | 2379 | |
2350 | 2380 | /** |
2351 | - * Alias of self::set_country(). |
|
2352 | - * |
|
2353 | - * @since 1.0.19 |
|
2354 | - * @param string $value country. |
|
2355 | - */ |
|
2356 | - public function set_user_country( $value ) { |
|
2357 | - $this->set_country( $value ); |
|
2381 | + * Alias of self::set_state(). |
|
2382 | + * |
|
2383 | + * @since 1.0.19 |
|
2384 | + * @param string $value state. |
|
2385 | + */ |
|
2386 | + public function set_user_state( $value ) { |
|
2387 | + $this->set_state( $value ); |
|
2358 | 2388 | } |
2359 | 2389 | |
2360 | 2390 | /** |
2361 | - * Alias of self::set_country(). |
|
2362 | - * |
|
2363 | - * @since 1.0.19 |
|
2364 | - * @param string $value country. |
|
2365 | - */ |
|
2366 | - public function set_customer_country( $value ) { |
|
2367 | - $this->set_country( $value ); |
|
2391 | + * Alias of self::set_state(). |
|
2392 | + * |
|
2393 | + * @since 1.0.19 |
|
2394 | + * @param string $value state. |
|
2395 | + */ |
|
2396 | + public function set_customer_state( $value ) { |
|
2397 | + $this->set_state( $value ); |
|
2368 | 2398 | } |
2369 | 2399 | |
2370 | 2400 | /** |
2371 | - * Set the customer's state. |
|
2372 | - * |
|
2373 | - * @since 1.0.19 |
|
2374 | - * @param string $value state. |
|
2375 | - */ |
|
2376 | - public function set_state( $value ) { |
|
2377 | - $this->set_prop( 'state', $value ); |
|
2401 | + * Set the customer's city. |
|
2402 | + * |
|
2403 | + * @since 1.0.19 |
|
2404 | + * @param string $value city. |
|
2405 | + */ |
|
2406 | + public function set_city( $value ) { |
|
2407 | + $this->set_prop( 'city', $value ); |
|
2378 | 2408 | } |
2379 | 2409 | |
2380 | 2410 | /** |
2381 | - * Alias of self::set_state(). |
|
2382 | - * |
|
2383 | - * @since 1.0.19 |
|
2384 | - * @param string $value state. |
|
2385 | - */ |
|
2386 | - public function set_user_state( $value ) { |
|
2387 | - $this->set_state( $value ); |
|
2411 | + * Alias of self::set_city(). |
|
2412 | + * |
|
2413 | + * @since 1.0.19 |
|
2414 | + * @param string $value city. |
|
2415 | + */ |
|
2416 | + public function set_user_city( $value ) { |
|
2417 | + $this->set_city( $value ); |
|
2388 | 2418 | } |
2389 | 2419 | |
2390 | 2420 | /** |
2391 | - * Alias of self::set_state(). |
|
2392 | - * |
|
2393 | - * @since 1.0.19 |
|
2394 | - * @param string $value state. |
|
2395 | - */ |
|
2396 | - public function set_customer_state( $value ) { |
|
2397 | - $this->set_state( $value ); |
|
2421 | + * Alias of self::set_city(). |
|
2422 | + * |
|
2423 | + * @since 1.0.19 |
|
2424 | + * @param string $value city. |
|
2425 | + */ |
|
2426 | + public function set_customer_city( $value ) { |
|
2427 | + $this->set_city( $value ); |
|
2398 | 2428 | } |
2399 | 2429 | |
2400 | 2430 | /** |
2401 | - * Set the customer's city. |
|
2402 | - * |
|
2403 | - * @since 1.0.19 |
|
2404 | - * @param string $value city. |
|
2405 | - */ |
|
2406 | - public function set_city( $value ) { |
|
2407 | - $this->set_prop( 'city', $value ); |
|
2431 | + * Set the customer's zip code. |
|
2432 | + * |
|
2433 | + * @since 1.0.19 |
|
2434 | + * @param string $value zip. |
|
2435 | + */ |
|
2436 | + public function set_zip( $value ) { |
|
2437 | + $this->set_prop( 'zip', $value ); |
|
2408 | 2438 | } |
2409 | 2439 | |
2410 | 2440 | /** |
2411 | - * Alias of self::set_city(). |
|
2412 | - * |
|
2413 | - * @since 1.0.19 |
|
2414 | - * @param string $value city. |
|
2415 | - */ |
|
2416 | - public function set_user_city( $value ) { |
|
2417 | - $this->set_city( $value ); |
|
2441 | + * Alias of self::set_zip(). |
|
2442 | + * |
|
2443 | + * @since 1.0.19 |
|
2444 | + * @param string $value zip. |
|
2445 | + */ |
|
2446 | + public function set_user_zip( $value ) { |
|
2447 | + $this->set_zip( $value ); |
|
2418 | 2448 | } |
2419 | 2449 | |
2420 | 2450 | /** |
2421 | - * Alias of self::set_city(). |
|
2422 | - * |
|
2423 | - * @since 1.0.19 |
|
2424 | - * @param string $value city. |
|
2425 | - */ |
|
2426 | - public function set_customer_city( $value ) { |
|
2427 | - $this->set_city( $value ); |
|
2451 | + * Alias of self::set_zip(). |
|
2452 | + * |
|
2453 | + * @since 1.0.19 |
|
2454 | + * @param string $value zip. |
|
2455 | + */ |
|
2456 | + public function set_customer_zip( $value ) { |
|
2457 | + $this->set_zip( $value ); |
|
2428 | 2458 | } |
2429 | 2459 | |
2430 | 2460 | /** |
2431 | - * Set the customer's zip code. |
|
2432 | - * |
|
2433 | - * @since 1.0.19 |
|
2434 | - * @param string $value zip. |
|
2435 | - */ |
|
2436 | - public function set_zip( $value ) { |
|
2437 | - $this->set_prop( 'zip', $value ); |
|
2461 | + * Set the customer's company. |
|
2462 | + * |
|
2463 | + * @since 1.0.19 |
|
2464 | + * @param string $value company. |
|
2465 | + */ |
|
2466 | + public function set_company( $value ) { |
|
2467 | + $this->set_prop( 'company', $value ); |
|
2438 | 2468 | } |
2439 | 2469 | |
2440 | 2470 | /** |
2441 | - * Alias of self::set_zip(). |
|
2442 | - * |
|
2443 | - * @since 1.0.19 |
|
2444 | - * @param string $value zip. |
|
2445 | - */ |
|
2446 | - public function set_user_zip( $value ) { |
|
2447 | - $this->set_zip( $value ); |
|
2471 | + * Alias of self::set_company(). |
|
2472 | + * |
|
2473 | + * @since 1.0.19 |
|
2474 | + * @param string $value company. |
|
2475 | + */ |
|
2476 | + public function set_user_company( $value ) { |
|
2477 | + $this->set_company( $value ); |
|
2448 | 2478 | } |
2449 | 2479 | |
2450 | 2480 | /** |
2451 | - * Alias of self::set_zip(). |
|
2452 | - * |
|
2453 | - * @since 1.0.19 |
|
2454 | - * @param string $value zip. |
|
2455 | - */ |
|
2456 | - public function set_customer_zip( $value ) { |
|
2457 | - $this->set_zip( $value ); |
|
2481 | + * Alias of self::set_company(). |
|
2482 | + * |
|
2483 | + * @since 1.0.19 |
|
2484 | + * @param string $value company. |
|
2485 | + */ |
|
2486 | + public function set_customer_company( $value ) { |
|
2487 | + $this->set_company( $value ); |
|
2458 | 2488 | } |
2459 | 2489 | |
2460 | 2490 | /** |
2461 | - * Set the customer's company. |
|
2462 | - * |
|
2463 | - * @since 1.0.19 |
|
2464 | - * @param string $value company. |
|
2465 | - */ |
|
2466 | - public function set_company( $value ) { |
|
2467 | - $this->set_prop( 'company', $value ); |
|
2491 | + * Set the customer's var number. |
|
2492 | + * |
|
2493 | + * @since 1.0.19 |
|
2494 | + * @param string $value var number. |
|
2495 | + */ |
|
2496 | + public function set_vat_number( $value ) { |
|
2497 | + $this->set_prop( 'vat_number', $value ); |
|
2468 | 2498 | } |
2469 | 2499 | |
2470 | 2500 | /** |
2471 | - * Alias of self::set_company(). |
|
2472 | - * |
|
2473 | - * @since 1.0.19 |
|
2474 | - * @param string $value company. |
|
2475 | - */ |
|
2476 | - public function set_user_company( $value ) { |
|
2477 | - $this->set_company( $value ); |
|
2501 | + * Alias of self::set_vat_number(). |
|
2502 | + * |
|
2503 | + * @since 1.0.19 |
|
2504 | + * @param string $value var number. |
|
2505 | + */ |
|
2506 | + public function set_user_vat_number( $value ) { |
|
2507 | + $this->set_vat_number( $value ); |
|
2478 | 2508 | } |
2479 | 2509 | |
2480 | 2510 | /** |
2481 | - * Alias of self::set_company(). |
|
2482 | - * |
|
2483 | - * @since 1.0.19 |
|
2484 | - * @param string $value company. |
|
2485 | - */ |
|
2486 | - public function set_customer_company( $value ) { |
|
2487 | - $this->set_company( $value ); |
|
2511 | + * Alias of self::set_vat_number(). |
|
2512 | + * |
|
2513 | + * @since 1.0.19 |
|
2514 | + * @param string $value var number. |
|
2515 | + */ |
|
2516 | + public function set_customer_vat_number( $value ) { |
|
2517 | + $this->set_vat_number( $value ); |
|
2488 | 2518 | } |
2489 | 2519 | |
2490 | 2520 | /** |
2491 | - * Set the customer's var number. |
|
2492 | - * |
|
2493 | - * @since 1.0.19 |
|
2494 | - * @param string $value var number. |
|
2495 | - */ |
|
2496 | - public function set_vat_number( $value ) { |
|
2497 | - $this->set_prop( 'vat_number', $value ); |
|
2521 | + * Set the customer's vat rate. |
|
2522 | + * |
|
2523 | + * @since 1.0.19 |
|
2524 | + * @param string $value var rate. |
|
2525 | + */ |
|
2526 | + public function set_vat_rate( $value ) { |
|
2527 | + $this->set_prop( 'vat_rate', $value ); |
|
2498 | 2528 | } |
2499 | 2529 | |
2500 | 2530 | /** |
2501 | - * Alias of self::set_vat_number(). |
|
2502 | - * |
|
2503 | - * @since 1.0.19 |
|
2504 | - * @param string $value var number. |
|
2505 | - */ |
|
2506 | - public function set_user_vat_number( $value ) { |
|
2507 | - $this->set_vat_number( $value ); |
|
2531 | + * Alias of self::set_vat_rate(). |
|
2532 | + * |
|
2533 | + * @since 1.0.19 |
|
2534 | + * @param string $value var number. |
|
2535 | + */ |
|
2536 | + public function set_user_vat_rate( $value ) { |
|
2537 | + $this->set_vat_rate( $value ); |
|
2508 | 2538 | } |
2509 | 2539 | |
2510 | 2540 | /** |
2511 | - * Alias of self::set_vat_number(). |
|
2512 | - * |
|
2513 | - * @since 1.0.19 |
|
2514 | - * @param string $value var number. |
|
2515 | - */ |
|
2516 | - public function set_customer_vat_number( $value ) { |
|
2517 | - $this->set_vat_number( $value ); |
|
2541 | + * Alias of self::set_vat_rate(). |
|
2542 | + * |
|
2543 | + * @since 1.0.19 |
|
2544 | + * @param string $value var number. |
|
2545 | + */ |
|
2546 | + public function set_customer_vat_rate( $value ) { |
|
2547 | + $this->set_vat_rate( $value ); |
|
2518 | 2548 | } |
2519 | 2549 | |
2520 | 2550 | /** |
2521 | - * Set the customer's vat rate. |
|
2522 | - * |
|
2523 | - * @since 1.0.19 |
|
2524 | - * @param string $value var rate. |
|
2525 | - */ |
|
2526 | - public function set_vat_rate( $value ) { |
|
2527 | - $this->set_prop( 'vat_rate', $value ); |
|
2551 | + * Set the customer's address. |
|
2552 | + * |
|
2553 | + * @since 1.0.19 |
|
2554 | + * @param string $value address. |
|
2555 | + */ |
|
2556 | + public function set_address( $value ) { |
|
2557 | + $this->set_prop( 'address', $value ); |
|
2528 | 2558 | } |
2529 | 2559 | |
2530 | 2560 | /** |
2531 | - * Alias of self::set_vat_rate(). |
|
2532 | - * |
|
2533 | - * @since 1.0.19 |
|
2534 | - * @param string $value var number. |
|
2535 | - */ |
|
2536 | - public function set_user_vat_rate( $value ) { |
|
2537 | - $this->set_vat_rate( $value ); |
|
2561 | + * Alias of self::set_address(). |
|
2562 | + * |
|
2563 | + * @since 1.0.19 |
|
2564 | + * @param string $value address. |
|
2565 | + */ |
|
2566 | + public function set_user_address( $value ) { |
|
2567 | + $this->set_address( $value ); |
|
2538 | 2568 | } |
2539 | 2569 | |
2540 | 2570 | /** |
2541 | - * Alias of self::set_vat_rate(). |
|
2542 | - * |
|
2543 | - * @since 1.0.19 |
|
2544 | - * @param string $value var number. |
|
2545 | - */ |
|
2546 | - public function set_customer_vat_rate( $value ) { |
|
2547 | - $this->set_vat_rate( $value ); |
|
2571 | + * Alias of self::set_address(). |
|
2572 | + * |
|
2573 | + * @since 1.0.19 |
|
2574 | + * @param string $value address. |
|
2575 | + */ |
|
2576 | + public function set_customer_address( $value ) { |
|
2577 | + $this->set_address( $value ); |
|
2548 | 2578 | } |
2549 | 2579 | |
2550 | 2580 | /** |
2551 | - * Set the customer's address. |
|
2552 | - * |
|
2553 | - * @since 1.0.19 |
|
2554 | - * @param string $value address. |
|
2555 | - */ |
|
2556 | - public function set_address( $value ) { |
|
2557 | - $this->set_prop( 'address', $value ); |
|
2581 | + * Set whether the customer has viewed the invoice or not. |
|
2582 | + * |
|
2583 | + * @since 1.0.19 |
|
2584 | + * @param int|bool $value confirmed. |
|
2585 | + */ |
|
2586 | + public function set_is_viewed( $value ) { |
|
2587 | + $this->set_prop( 'is_viewed', $value ); |
|
2558 | 2588 | } |
2559 | 2589 | |
2560 | 2590 | /** |
2561 | - * Alias of self::set_address(). |
|
2562 | - * |
|
2563 | - * @since 1.0.19 |
|
2564 | - * @param string $value address. |
|
2565 | - */ |
|
2566 | - public function set_user_address( $value ) { |
|
2567 | - $this->set_address( $value ); |
|
2591 | + * Set extra email recipients. |
|
2592 | + * |
|
2593 | + * @since 1.0.19 |
|
2594 | + * @param string $value email recipients. |
|
2595 | + */ |
|
2596 | + public function set_email_cc( $value ) { |
|
2597 | + $this->set_prop( 'email_cc', $value ); |
|
2568 | 2598 | } |
2569 | 2599 | |
2570 | 2600 | /** |
2571 | - * Alias of self::set_address(). |
|
2572 | - * |
|
2573 | - * @since 1.0.19 |
|
2574 | - * @param string $value address. |
|
2575 | - */ |
|
2576 | - public function set_customer_address( $value ) { |
|
2577 | - $this->set_address( $value ); |
|
2601 | + * Set the invoice template. |
|
2602 | + * |
|
2603 | + * @since 1.0.19 |
|
2604 | + * @param string $value email recipients. |
|
2605 | + */ |
|
2606 | + public function set_template( $value ) { |
|
2607 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2608 | + $this->set_prop( 'template', $value ); |
|
2609 | + } |
|
2578 | 2610 | } |
2579 | 2611 | |
2580 | 2612 | /** |
2581 | - * Set whether the customer has viewed the invoice or not. |
|
2582 | - * |
|
2583 | - * @since 1.0.19 |
|
2584 | - * @param int|bool $value confirmed. |
|
2585 | - */ |
|
2586 | - public function set_is_viewed( $value ) { |
|
2587 | - $this->set_prop( 'is_viewed', $value ); |
|
2588 | - } |
|
2589 | - |
|
2590 | - /** |
|
2591 | - * Set extra email recipients. |
|
2592 | - * |
|
2593 | - * @since 1.0.19 |
|
2594 | - * @param string $value email recipients. |
|
2595 | - */ |
|
2596 | - public function set_email_cc( $value ) { |
|
2597 | - $this->set_prop( 'email_cc', $value ); |
|
2598 | - } |
|
2599 | - |
|
2600 | - /** |
|
2601 | - * Set the invoice template. |
|
2602 | - * |
|
2603 | - * @since 1.0.19 |
|
2604 | - * @param string $value email recipients. |
|
2605 | - */ |
|
2606 | - public function set_template( $value ) { |
|
2607 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2608 | - $this->set_prop( 'template', $value ); |
|
2609 | - } |
|
2610 | - } |
|
2611 | - |
|
2612 | - /** |
|
2613 | - * Set the customer's address confirmed status. |
|
2614 | - * |
|
2615 | - * @since 1.0.19 |
|
2616 | - * @param int|bool $value confirmed. |
|
2617 | - */ |
|
2618 | - public function set_address_confirmed( $value ) { |
|
2619 | - $this->set_prop( 'address_confirmed', $value ); |
|
2613 | + * Set the customer's address confirmed status. |
|
2614 | + * |
|
2615 | + * @since 1.0.19 |
|
2616 | + * @param int|bool $value confirmed. |
|
2617 | + */ |
|
2618 | + public function set_address_confirmed( $value ) { |
|
2619 | + $this->set_prop( 'address_confirmed', $value ); |
|
2620 | 2620 | } |
2621 | 2621 | |
2622 | 2622 | /** |
2623 | - * Alias of self::set_address_confirmed(). |
|
2624 | - * |
|
2625 | - * @since 1.0.19 |
|
2626 | - * @param int|bool $value confirmed. |
|
2627 | - */ |
|
2628 | - public function set_user_address_confirmed( $value ) { |
|
2629 | - $this->set_address_confirmed( $value ); |
|
2623 | + * Alias of self::set_address_confirmed(). |
|
2624 | + * |
|
2625 | + * @since 1.0.19 |
|
2626 | + * @param int|bool $value confirmed. |
|
2627 | + */ |
|
2628 | + public function set_user_address_confirmed( $value ) { |
|
2629 | + $this->set_address_confirmed( $value ); |
|
2630 | 2630 | } |
2631 | 2631 | |
2632 | 2632 | /** |
2633 | - * Alias of self::set_address_confirmed(). |
|
2634 | - * |
|
2635 | - * @since 1.0.19 |
|
2636 | - * @param int|bool $value confirmed. |
|
2637 | - */ |
|
2638 | - public function set_customer_address_confirmed( $value ) { |
|
2639 | - $this->set_address_confirmed( $value ); |
|
2633 | + * Alias of self::set_address_confirmed(). |
|
2634 | + * |
|
2635 | + * @since 1.0.19 |
|
2636 | + * @param int|bool $value confirmed. |
|
2637 | + */ |
|
2638 | + public function set_customer_address_confirmed( $value ) { |
|
2639 | + $this->set_address_confirmed( $value ); |
|
2640 | 2640 | } |
2641 | 2641 | |
2642 | 2642 | /** |
2643 | - * Set the invoice sub total. |
|
2644 | - * |
|
2645 | - * @since 1.0.19 |
|
2646 | - * @param float $value sub total. |
|
2647 | - */ |
|
2648 | - public function set_subtotal( $value ) { |
|
2649 | - $this->set_prop( 'subtotal', $value ); |
|
2643 | + * Set the invoice sub total. |
|
2644 | + * |
|
2645 | + * @since 1.0.19 |
|
2646 | + * @param float $value sub total. |
|
2647 | + */ |
|
2648 | + public function set_subtotal( $value ) { |
|
2649 | + $this->set_prop( 'subtotal', $value ); |
|
2650 | 2650 | } |
2651 | 2651 | |
2652 | 2652 | /** |
2653 | - * Set the invoice discount amount. |
|
2654 | - * |
|
2655 | - * @since 1.0.19 |
|
2656 | - * @param float $value discount total. |
|
2657 | - */ |
|
2658 | - public function set_total_discount( $value ) { |
|
2659 | - $this->set_prop( 'total_discount', $value ); |
|
2653 | + * Set the invoice discount amount. |
|
2654 | + * |
|
2655 | + * @since 1.0.19 |
|
2656 | + * @param float $value discount total. |
|
2657 | + */ |
|
2658 | + public function set_total_discount( $value ) { |
|
2659 | + $this->set_prop( 'total_discount', $value ); |
|
2660 | 2660 | } |
2661 | 2661 | |
2662 | 2662 | /** |
2663 | - * Alias of self::set_total_discount(). |
|
2664 | - * |
|
2665 | - * @since 1.0.19 |
|
2666 | - * @param float $value discount total. |
|
2667 | - */ |
|
2668 | - public function set_discount( $value ) { |
|
2669 | - $this->set_total_discount( $value ); |
|
2663 | + * Alias of self::set_total_discount(). |
|
2664 | + * |
|
2665 | + * @since 1.0.19 |
|
2666 | + * @param float $value discount total. |
|
2667 | + */ |
|
2668 | + public function set_discount( $value ) { |
|
2669 | + $this->set_total_discount( $value ); |
|
2670 | 2670 | } |
2671 | 2671 | |
2672 | 2672 | /** |
2673 | - * Set the invoice tax amount. |
|
2674 | - * |
|
2675 | - * @since 1.0.19 |
|
2676 | - * @param float $value tax total. |
|
2677 | - */ |
|
2678 | - public function set_total_tax( $value ) { |
|
2679 | - $this->set_prop( 'total_tax', $value ); |
|
2673 | + * Set the invoice tax amount. |
|
2674 | + * |
|
2675 | + * @since 1.0.19 |
|
2676 | + * @param float $value tax total. |
|
2677 | + */ |
|
2678 | + public function set_total_tax( $value ) { |
|
2679 | + $this->set_prop( 'total_tax', $value ); |
|
2680 | 2680 | } |
2681 | 2681 | |
2682 | 2682 | /** |
2683 | - * Alias of self::set_total_tax(). |
|
2684 | - * |
|
2685 | - * @since 1.0.19 |
|
2686 | - * @param float $value tax total. |
|
2687 | - */ |
|
2688 | - public function set_tax_total( $value ) { |
|
2689 | - $this->set_total_tax( $value ); |
|
2683 | + * Alias of self::set_total_tax(). |
|
2684 | + * |
|
2685 | + * @since 1.0.19 |
|
2686 | + * @param float $value tax total. |
|
2687 | + */ |
|
2688 | + public function set_tax_total( $value ) { |
|
2689 | + $this->set_total_tax( $value ); |
|
2690 | 2690 | } |
2691 | 2691 | |
2692 | 2692 | /** |
2693 | - * Set the invoice fees amount. |
|
2694 | - * |
|
2695 | - * @since 1.0.19 |
|
2696 | - * @param float $value fees total. |
|
2697 | - */ |
|
2698 | - public function set_total_fees( $value ) { |
|
2699 | - $this->set_prop( 'total_fees', $value ); |
|
2693 | + * Set the invoice fees amount. |
|
2694 | + * |
|
2695 | + * @since 1.0.19 |
|
2696 | + * @param float $value fees total. |
|
2697 | + */ |
|
2698 | + public function set_total_fees( $value ) { |
|
2699 | + $this->set_prop( 'total_fees', $value ); |
|
2700 | 2700 | } |
2701 | 2701 | |
2702 | 2702 | /** |
2703 | - * Alias of self::set_total_fees(). |
|
2704 | - * |
|
2705 | - * @since 1.0.19 |
|
2706 | - * @param float $value fees total. |
|
2707 | - */ |
|
2708 | - public function set_fees_total( $value ) { |
|
2709 | - $this->set_total_fees( $value ); |
|
2703 | + * Alias of self::set_total_fees(). |
|
2704 | + * |
|
2705 | + * @since 1.0.19 |
|
2706 | + * @param float $value fees total. |
|
2707 | + */ |
|
2708 | + public function set_fees_total( $value ) { |
|
2709 | + $this->set_total_fees( $value ); |
|
2710 | 2710 | } |
2711 | 2711 | |
2712 | 2712 | /** |
2713 | - * Set the invoice fees. |
|
2714 | - * |
|
2715 | - * @since 1.0.19 |
|
2716 | - * @param array $value fees. |
|
2717 | - */ |
|
2718 | - public function set_fees( $value ) { |
|
2713 | + * Set the invoice fees. |
|
2714 | + * |
|
2715 | + * @since 1.0.19 |
|
2716 | + * @param array $value fees. |
|
2717 | + */ |
|
2718 | + public function set_fees( $value ) { |
|
2719 | 2719 | |
2720 | 2720 | $this->set_prop( 'fees', array() ); |
2721 | 2721 | |
@@ -2733,23 +2733,23 @@ discard block |
||
2733 | 2733 | } |
2734 | 2734 | |
2735 | 2735 | /** |
2736 | - * Set the invoice taxes. |
|
2737 | - * |
|
2738 | - * @since 1.0.19 |
|
2739 | - * @param array $value taxes. |
|
2740 | - */ |
|
2741 | - public function set_taxes( $value ) { |
|
2742 | - $this->set_prop( 'taxes', $value ); |
|
2736 | + * Set the invoice taxes. |
|
2737 | + * |
|
2738 | + * @since 1.0.19 |
|
2739 | + * @param array $value taxes. |
|
2740 | + */ |
|
2741 | + public function set_taxes( $value ) { |
|
2742 | + $this->set_prop( 'taxes', $value ); |
|
2743 | 2743 | } |
2744 | 2744 | |
2745 | 2745 | /** |
2746 | - * Set the invoice discounts. |
|
2747 | - * |
|
2748 | - * @since 1.0.19 |
|
2749 | - * @param array $value discounts. |
|
2750 | - */ |
|
2751 | - public function set_discounts( $value ) { |
|
2752 | - $this->set_prop( 'discounts', array() ); |
|
2746 | + * Set the invoice discounts. |
|
2747 | + * |
|
2748 | + * @since 1.0.19 |
|
2749 | + * @param array $value discounts. |
|
2750 | + */ |
|
2751 | + public function set_discounts( $value ) { |
|
2752 | + $this->set_prop( 'discounts', array() ); |
|
2753 | 2753 | |
2754 | 2754 | // Ensure that we have an array. |
2755 | 2755 | if ( ! is_array( $value ) ) { |
@@ -2764,12 +2764,12 @@ discard block |
||
2764 | 2764 | } |
2765 | 2765 | |
2766 | 2766 | /** |
2767 | - * Set the invoice items. |
|
2768 | - * |
|
2769 | - * @since 1.0.19 |
|
2770 | - * @param GetPaid_Form_Item[] $value items. |
|
2771 | - */ |
|
2772 | - public function set_items( $value ) { |
|
2767 | + * Set the invoice items. |
|
2768 | + * |
|
2769 | + * @since 1.0.19 |
|
2770 | + * @param GetPaid_Form_Item[] $value items. |
|
2771 | + */ |
|
2772 | + public function set_items( $value ) { |
|
2773 | 2773 | |
2774 | 2774 | // Remove existing items. |
2775 | 2775 | $this->set_prop( 'items', array() ); |
@@ -2786,85 +2786,85 @@ discard block |
||
2786 | 2786 | } |
2787 | 2787 | |
2788 | 2788 | /** |
2789 | - * Set the payment form. |
|
2790 | - * |
|
2791 | - * @since 1.0.19 |
|
2792 | - * @param int $value payment form. |
|
2793 | - */ |
|
2794 | - public function set_payment_form( $value ) { |
|
2795 | - $this->set_prop( 'payment_form', $value ); |
|
2789 | + * Set the payment form. |
|
2790 | + * |
|
2791 | + * @since 1.0.19 |
|
2792 | + * @param int $value payment form. |
|
2793 | + */ |
|
2794 | + public function set_payment_form( $value ) { |
|
2795 | + $this->set_prop( 'payment_form', $value ); |
|
2796 | 2796 | } |
2797 | 2797 | |
2798 | 2798 | /** |
2799 | - * Set the submission id. |
|
2800 | - * |
|
2801 | - * @since 1.0.19 |
|
2802 | - * @param string $value submission id. |
|
2803 | - */ |
|
2804 | - public function set_submission_id( $value ) { |
|
2805 | - $this->set_prop( 'submission_id', $value ); |
|
2799 | + * Set the submission id. |
|
2800 | + * |
|
2801 | + * @since 1.0.19 |
|
2802 | + * @param string $value submission id. |
|
2803 | + */ |
|
2804 | + public function set_submission_id( $value ) { |
|
2805 | + $this->set_prop( 'submission_id', $value ); |
|
2806 | 2806 | } |
2807 | 2807 | |
2808 | 2808 | /** |
2809 | - * Set the discount code. |
|
2810 | - * |
|
2811 | - * @since 1.0.19 |
|
2812 | - * @param string $value discount code. |
|
2813 | - */ |
|
2814 | - public function set_discount_code( $value ) { |
|
2815 | - $this->set_prop( 'discount_code', $value ); |
|
2809 | + * Set the discount code. |
|
2810 | + * |
|
2811 | + * @since 1.0.19 |
|
2812 | + * @param string $value discount code. |
|
2813 | + */ |
|
2814 | + public function set_discount_code( $value ) { |
|
2815 | + $this->set_prop( 'discount_code', $value ); |
|
2816 | 2816 | } |
2817 | 2817 | |
2818 | 2818 | /** |
2819 | - * Set the gateway. |
|
2820 | - * |
|
2821 | - * @since 1.0.19 |
|
2822 | - * @param string $value gateway. |
|
2823 | - */ |
|
2824 | - public function set_gateway( $value ) { |
|
2825 | - $this->set_prop( 'gateway', $value ); |
|
2819 | + * Set the gateway. |
|
2820 | + * |
|
2821 | + * @since 1.0.19 |
|
2822 | + * @param string $value gateway. |
|
2823 | + */ |
|
2824 | + public function set_gateway( $value ) { |
|
2825 | + $this->set_prop( 'gateway', $value ); |
|
2826 | 2826 | } |
2827 | 2827 | |
2828 | 2828 | /** |
2829 | - * Set the transaction id. |
|
2830 | - * |
|
2831 | - * @since 1.0.19 |
|
2832 | - * @param string $value transaction id. |
|
2833 | - */ |
|
2834 | - public function set_transaction_id( $value ) { |
|
2835 | - if ( ! empty( $value ) ) { |
|
2836 | - $this->set_prop( 'transaction_id', $value ); |
|
2837 | - } |
|
2829 | + * Set the transaction id. |
|
2830 | + * |
|
2831 | + * @since 1.0.19 |
|
2832 | + * @param string $value transaction id. |
|
2833 | + */ |
|
2834 | + public function set_transaction_id( $value ) { |
|
2835 | + if ( ! empty( $value ) ) { |
|
2836 | + $this->set_prop( 'transaction_id', $value ); |
|
2837 | + } |
|
2838 | 2838 | } |
2839 | 2839 | |
2840 | 2840 | /** |
2841 | - * Set the currency id. |
|
2842 | - * |
|
2843 | - * @since 1.0.19 |
|
2844 | - * @param string $value currency id. |
|
2845 | - */ |
|
2846 | - public function set_currency( $value ) { |
|
2847 | - $this->set_prop( 'currency', $value ); |
|
2841 | + * Set the currency id. |
|
2842 | + * |
|
2843 | + * @since 1.0.19 |
|
2844 | + * @param string $value currency id. |
|
2845 | + */ |
|
2846 | + public function set_currency( $value ) { |
|
2847 | + $this->set_prop( 'currency', $value ); |
|
2848 | 2848 | } |
2849 | 2849 | |
2850 | - /** |
|
2851 | - * Set whether to disable taxes. |
|
2852 | - * |
|
2853 | - * @since 1.0.19 |
|
2854 | - * @param bool $value value. |
|
2855 | - */ |
|
2856 | - public function set_disable_taxes( $value ) { |
|
2857 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2858 | - } |
|
2850 | + /** |
|
2851 | + * Set whether to disable taxes. |
|
2852 | + * |
|
2853 | + * @since 1.0.19 |
|
2854 | + * @param bool $value value. |
|
2855 | + */ |
|
2856 | + public function set_disable_taxes( $value ) { |
|
2857 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2858 | + } |
|
2859 | 2859 | |
2860 | 2860 | /** |
2861 | - * Set the subscription id. |
|
2862 | - * |
|
2863 | - * @since 1.0.19 |
|
2864 | - * @param string $value subscription id. |
|
2865 | - */ |
|
2866 | - public function set_subscription_id( $value ) { |
|
2867 | - $this->set_prop( 'subscription_id', $value ); |
|
2861 | + * Set the subscription id. |
|
2862 | + * |
|
2863 | + * @since 1.0.19 |
|
2864 | + * @param string $value subscription id. |
|
2865 | + */ |
|
2866 | + public function set_subscription_id( $value ) { |
|
2867 | + $this->set_prop( 'subscription_id', $value ); |
|
2868 | 2868 | } |
2869 | 2869 | |
2870 | 2870 | /* |
@@ -2903,12 +2903,12 @@ discard block |
||
2903 | 2903 | */ |
2904 | 2904 | public function is_taxable() { |
2905 | 2905 | return ! $this->get_disable_taxes(); |
2906 | - } |
|
2906 | + } |
|
2907 | 2907 | |
2908 | - /** |
|
2909 | - * @deprecated |
|
2910 | - */ |
|
2911 | - public function has_vat() { |
|
2908 | + /** |
|
2909 | + * @deprecated |
|
2910 | + */ |
|
2911 | + public function has_vat() { |
|
2912 | 2912 | global $wpinv_euvat, $wpi_country; |
2913 | 2913 | |
2914 | 2914 | $requires_vat = false; |
@@ -2919,17 +2919,17 @@ discard block |
||
2919 | 2919 | } |
2920 | 2920 | |
2921 | 2921 | return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
2922 | - } |
|
2922 | + } |
|
2923 | 2923 | |
2924 | - /** |
|
2925 | - * Checks to see if the invoice requires payment. |
|
2926 | - */ |
|
2927 | - public function is_free() { |
|
2924 | + /** |
|
2925 | + * Checks to see if the invoice requires payment. |
|
2926 | + */ |
|
2927 | + public function is_free() { |
|
2928 | 2928 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
2929 | 2929 | |
2930 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
2931 | - $is_free = false; |
|
2932 | - } |
|
2930 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
2931 | + $is_free = false; |
|
2932 | + } |
|
2933 | 2933 | |
2934 | 2934 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
2935 | 2935 | } |
@@ -2940,46 +2940,46 @@ discard block |
||
2940 | 2940 | public function is_paid() { |
2941 | 2941 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
2942 | 2942 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
2943 | - } |
|
2943 | + } |
|
2944 | 2944 | |
2945 | - /** |
|
2945 | + /** |
|
2946 | 2946 | * Checks if the invoice needs payment. |
2947 | 2947 | */ |
2948 | - public function needs_payment() { |
|
2949 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
2948 | + public function needs_payment() { |
|
2949 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
2950 | 2950 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
2951 | 2951 | } |
2952 | 2952 | |
2953 | - /** |
|
2953 | + /** |
|
2954 | 2954 | * Checks if the invoice is refunded. |
2955 | 2955 | */ |
2956 | - public function is_refunded() { |
|
2956 | + public function is_refunded() { |
|
2957 | 2957 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
2958 | 2958 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
2959 | - } |
|
2959 | + } |
|
2960 | 2960 | |
2961 | - /** |
|
2961 | + /** |
|
2962 | 2962 | * Checks if the invoice is held. |
2963 | 2963 | */ |
2964 | - public function is_held() { |
|
2964 | + public function is_held() { |
|
2965 | 2965 | $is_held = $this->has_status( 'wpi-onhold' ); |
2966 | 2966 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
2967 | - } |
|
2967 | + } |
|
2968 | 2968 | |
2969 | - /** |
|
2969 | + /** |
|
2970 | 2970 | * Checks if the invoice is due. |
2971 | 2971 | */ |
2972 | - public function is_due() { |
|
2973 | - $due_date = $this->get_due_date(); |
|
2974 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
2975 | - } |
|
2972 | + public function is_due() { |
|
2973 | + $due_date = $this->get_due_date(); |
|
2974 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
2975 | + } |
|
2976 | 2976 | |
2977 | - /** |
|
2977 | + /** |
|
2978 | 2978 | * Checks if the invoice is draft. |
2979 | 2979 | */ |
2980 | - public function is_draft() { |
|
2980 | + public function is_draft() { |
|
2981 | 2981 | return $this->has_status( 'draft, auto-draft' ); |
2982 | - } |
|
2982 | + } |
|
2983 | 2983 | |
2984 | 2984 | /** |
2985 | 2985 | * Checks if the invoice has a given status. |
@@ -2987,9 +2987,9 @@ discard block |
||
2987 | 2987 | public function has_status( $status ) { |
2988 | 2988 | $status = wpinv_parse_list( $status ); |
2989 | 2989 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
2990 | - } |
|
2990 | + } |
|
2991 | 2991 | |
2992 | - /** |
|
2992 | + /** |
|
2993 | 2993 | * Checks if the invoice is of a given type. |
2994 | 2994 | */ |
2995 | 2995 | public function is_type( $type ) { |
@@ -3012,25 +3012,25 @@ discard block |
||
3012 | 3012 | */ |
3013 | 3013 | public function has_free_trial() { |
3014 | 3014 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3015 | - } |
|
3015 | + } |
|
3016 | 3016 | |
3017 | - /** |
|
3017 | + /** |
|
3018 | 3018 | * @deprecated |
3019 | 3019 | */ |
3020 | 3020 | public function is_free_trial() { |
3021 | 3021 | $this->has_free_trial(); |
3022 | 3022 | } |
3023 | 3023 | |
3024 | - /** |
|
3024 | + /** |
|
3025 | 3025 | * Check if the initial payment if 0. |
3026 | 3026 | * |
3027 | 3027 | */ |
3028 | - public function is_initial_free() { |
|
3028 | + public function is_initial_free() { |
|
3029 | 3029 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3030 | 3030 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3031 | 3031 | } |
3032 | 3032 | |
3033 | - /** |
|
3033 | + /** |
|
3034 | 3034 | * Check if the recurring item has a free trial. |
3035 | 3035 | * |
3036 | 3036 | */ |
@@ -3043,21 +3043,21 @@ discard block |
||
3043 | 3043 | |
3044 | 3044 | $item = $this->get_recurring( true ); |
3045 | 3045 | return $item->has_free_trial(); |
3046 | - } |
|
3046 | + } |
|
3047 | 3047 | |
3048 | - /** |
|
3048 | + /** |
|
3049 | 3049 | * Check if the free trial is a result of a discount. |
3050 | 3050 | */ |
3051 | 3051 | public function is_free_trial_from_discount() { |
3052 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3053 | - } |
|
3052 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3053 | + } |
|
3054 | 3054 | |
3055 | - /** |
|
3055 | + /** |
|
3056 | 3056 | * @deprecated |
3057 | 3057 | */ |
3058 | 3058 | public function discount_first_payment_only() { |
3059 | 3059 | |
3060 | - $discount_code = $this->get_discount_code(); |
|
3060 | + $discount_code = $this->get_discount_code(); |
|
3061 | 3061 | if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
3062 | 3062 | return true; |
3063 | 3063 | } |
@@ -3088,28 +3088,28 @@ discard block |
||
3088 | 3088 | */ |
3089 | 3089 | public function add_item( $item ) { |
3090 | 3090 | |
3091 | - if ( is_array( $item ) ) { |
|
3092 | - $item = $this->process_array_item( $item ); |
|
3093 | - } |
|
3091 | + if ( is_array( $item ) ) { |
|
3092 | + $item = $this->process_array_item( $item ); |
|
3093 | + } |
|
3094 | 3094 | |
3095 | - if ( is_numeric( $item ) ) { |
|
3096 | - $item = new GetPaid_Form_Item( $item ); |
|
3097 | - } |
|
3095 | + if ( is_numeric( $item ) ) { |
|
3096 | + $item = new GetPaid_Form_Item( $item ); |
|
3097 | + } |
|
3098 | 3098 | |
3099 | 3099 | // Make sure that it is available for purchase. |
3100 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3101 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3100 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3101 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3102 | 3102 | } |
3103 | 3103 | |
3104 | 3104 | // Do we have a recurring item? |
3105 | - if ( $item->is_recurring() ) { |
|
3105 | + if ( $item->is_recurring() ) { |
|
3106 | 3106 | |
3107 | - // An invoice can only contain one recurring item. |
|
3108 | - if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
3109 | - return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
3110 | - } |
|
3107 | + // An invoice can only contain one recurring item. |
|
3108 | + if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
3109 | + return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
3110 | + } |
|
3111 | 3111 | |
3112 | - $this->recurring_item = $item->get_id(); |
|
3112 | + $this->recurring_item = $item->get_id(); |
|
3113 | 3113 | } |
3114 | 3114 | |
3115 | 3115 | // Invoice id. |
@@ -3120,60 +3120,60 @@ discard block |
||
3120 | 3120 | $items[ (int) $item->get_id() ] = $item; |
3121 | 3121 | |
3122 | 3122 | $this->set_prop( 'items', $items ); |
3123 | - return true; |
|
3124 | - } |
|
3123 | + return true; |
|
3124 | + } |
|
3125 | 3125 | |
3126 | - /** |
|
3127 | - * Converts an array to an item. |
|
3128 | - * |
|
3129 | - * @since 1.0.19 |
|
3130 | - * @return GetPaid_Form_Item |
|
3131 | - */ |
|
3132 | - protected function process_array_item( $array ) { |
|
3133 | - |
|
3134 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3135 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3136 | - |
|
3137 | - // Set item data. |
|
3138 | - foreach( array( 'name', 'price', 'description' ) as $key ) { |
|
3139 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3140 | - $method = "set_$key"; |
|
3141 | - $item->$method( $array[ "item_$key" ] ); |
|
3142 | - } |
|
3143 | - } |
|
3144 | - |
|
3145 | - if ( isset( $array['quantity'] ) ) { |
|
3146 | - $item->set_quantity( $array['quantity'] ); |
|
3147 | - } |
|
3148 | - |
|
3149 | - // Set item meta. |
|
3150 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3151 | - $item->set_item_meta( $array['meta'] ); |
|
3152 | - } |
|
3153 | - |
|
3154 | - return $item; |
|
3155 | - |
|
3156 | - } |
|
3157 | - |
|
3158 | - /** |
|
3159 | - * Retrieves a specific item. |
|
3160 | - * |
|
3161 | - * @since 1.0.19 |
|
3162 | - */ |
|
3163 | - public function get_item( $item_id ) { |
|
3164 | - $items = $this->get_items(); |
|
3165 | - $item_id = (int) $item_id; |
|
3166 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3167 | - } |
|
3168 | - |
|
3169 | - /** |
|
3170 | - * Removes a specific item. |
|
3171 | - * |
|
3172 | - * @since 1.0.19 |
|
3173 | - */ |
|
3174 | - public function remove_item( $item_id ) { |
|
3175 | - $items = $this->get_items(); |
|
3176 | - $item_id = (int) $item_id; |
|
3126 | + /** |
|
3127 | + * Converts an array to an item. |
|
3128 | + * |
|
3129 | + * @since 1.0.19 |
|
3130 | + * @return GetPaid_Form_Item |
|
3131 | + */ |
|
3132 | + protected function process_array_item( $array ) { |
|
3133 | + |
|
3134 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3135 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3136 | + |
|
3137 | + // Set item data. |
|
3138 | + foreach( array( 'name', 'price', 'description' ) as $key ) { |
|
3139 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3140 | + $method = "set_$key"; |
|
3141 | + $item->$method( $array[ "item_$key" ] ); |
|
3142 | + } |
|
3143 | + } |
|
3144 | + |
|
3145 | + if ( isset( $array['quantity'] ) ) { |
|
3146 | + $item->set_quantity( $array['quantity'] ); |
|
3147 | + } |
|
3148 | + |
|
3149 | + // Set item meta. |
|
3150 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3151 | + $item->set_item_meta( $array['meta'] ); |
|
3152 | + } |
|
3153 | + |
|
3154 | + return $item; |
|
3155 | + |
|
3156 | + } |
|
3157 | + |
|
3158 | + /** |
|
3159 | + * Retrieves a specific item. |
|
3160 | + * |
|
3161 | + * @since 1.0.19 |
|
3162 | + */ |
|
3163 | + public function get_item( $item_id ) { |
|
3164 | + $items = $this->get_items(); |
|
3165 | + $item_id = (int) $item_id; |
|
3166 | + return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3167 | + } |
|
3168 | + |
|
3169 | + /** |
|
3170 | + * Removes a specific item. |
|
3171 | + * |
|
3172 | + * @since 1.0.19 |
|
3173 | + */ |
|
3174 | + public function remove_item( $item_id ) { |
|
3175 | + $items = $this->get_items(); |
|
3176 | + $item_id = (int) $item_id; |
|
3177 | 3177 | |
3178 | 3178 | if ( $item_id == $this->recurring_item ) { |
3179 | 3179 | $this->recurring_item = null; |
@@ -3200,38 +3200,38 @@ discard block |
||
3200 | 3200 | if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) { |
3201 | 3201 | |
3202 | 3202 | $amount = $fees[ $fee ]['amount'] += $amount; |
3203 | - $fees[ $fee ] = array( |
|
3204 | - 'amount' => $amount, |
|
3203 | + $fees[ $fee ] = array( |
|
3204 | + 'amount' => $amount, |
|
3205 | 3205 | 'recurring' => (bool) $recurring, |
3206 | 3206 | ); |
3207 | 3207 | |
3208 | - } else { |
|
3209 | - $fees[ $fee ] = array( |
|
3208 | + } else { |
|
3209 | + $fees[ $fee ] = array( |
|
3210 | 3210 | 'amount' => $amount, |
3211 | 3211 | 'recurring' => (bool) $recurring, |
3212 | 3212 | ); |
3213 | - } |
|
3213 | + } |
|
3214 | 3214 | |
3215 | 3215 | $this->set_prop( 'fees', $fee ); |
3216 | 3216 | |
3217 | 3217 | } |
3218 | 3218 | |
3219 | 3219 | /** |
3220 | - * Retrieves a specific fee. |
|
3221 | - * |
|
3222 | - * @since 1.0.19 |
|
3223 | - */ |
|
3224 | - public function get_fee( $fee ) { |
|
3220 | + * Retrieves a specific fee. |
|
3221 | + * |
|
3222 | + * @since 1.0.19 |
|
3223 | + */ |
|
3224 | + public function get_fee( $fee ) { |
|
3225 | 3225 | $fees = $this->get_fees(); |
3226 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3226 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3227 | 3227 | } |
3228 | 3228 | |
3229 | 3229 | /** |
3230 | - * Removes a specific fee. |
|
3231 | - * |
|
3232 | - * @since 1.0.19 |
|
3233 | - */ |
|
3234 | - public function remove_fee( $fee ) { |
|
3230 | + * Removes a specific fee. |
|
3231 | + * |
|
3232 | + * @since 1.0.19 |
|
3233 | + */ |
|
3234 | + public function remove_fee( $fee ) { |
|
3235 | 3235 | $fees = $this->get_fees(); |
3236 | 3236 | if ( isset( $fees[ $fee ] ) ) { |
3237 | 3237 | unset( $fees[ $fee ] ); |
@@ -3254,44 +3254,44 @@ discard block |
||
3254 | 3254 | if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) { |
3255 | 3255 | |
3256 | 3256 | $amount = $discounts[ $discount ]['amount'] += $amount; |
3257 | - $discounts[ $discount ] = array( |
|
3257 | + $discounts[ $discount ] = array( |
|
3258 | 3258 | 'amount' => $amount, |
3259 | 3259 | 'recurring' => (bool) $recurring, |
3260 | 3260 | ); |
3261 | 3261 | |
3262 | - } else { |
|
3263 | - $discounts[ $discount ] = array( |
|
3262 | + } else { |
|
3263 | + $discounts[ $discount ] = array( |
|
3264 | 3264 | 'amount' => $amount, |
3265 | 3265 | 'recurring' => (bool) $recurring, |
3266 | 3266 | ); |
3267 | - } |
|
3267 | + } |
|
3268 | 3268 | |
3269 | 3269 | $this->set_prop( 'discounts', $discount ); |
3270 | 3270 | |
3271 | 3271 | } |
3272 | 3272 | |
3273 | 3273 | /** |
3274 | - * Retrieves a specific discount. |
|
3275 | - * |
|
3276 | - * @since 1.0.19 |
|
3277 | - */ |
|
3278 | - public function get_discount( $discount = false ) { |
|
3274 | + * Retrieves a specific discount. |
|
3275 | + * |
|
3276 | + * @since 1.0.19 |
|
3277 | + */ |
|
3278 | + public function get_discount( $discount = false ) { |
|
3279 | 3279 | |
3280 | - // Backwards compatibilty. |
|
3281 | - if ( empty( $discount ) ) { |
|
3282 | - return $this->get_total_discount(); |
|
3283 | - } |
|
3280 | + // Backwards compatibilty. |
|
3281 | + if ( empty( $discount ) ) { |
|
3282 | + return $this->get_total_discount(); |
|
3283 | + } |
|
3284 | 3284 | |
3285 | 3285 | $discounts = $this->get_discounts(); |
3286 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3286 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3287 | 3287 | } |
3288 | 3288 | |
3289 | 3289 | /** |
3290 | - * Removes a specific discount. |
|
3291 | - * |
|
3292 | - * @since 1.0.19 |
|
3293 | - */ |
|
3294 | - public function remove_discount( $discount ) { |
|
3290 | + * Removes a specific discount. |
|
3291 | + * |
|
3292 | + * @since 1.0.19 |
|
3293 | + */ |
|
3294 | + public function remove_discount( $discount ) { |
|
3295 | 3295 | $discounts = $this->get_discounts(); |
3296 | 3296 | if ( isset( $discounts[ $discount ] ) ) { |
3297 | 3297 | unset( $discounts[ $discount ] ); |
@@ -3317,44 +3317,44 @@ discard block |
||
3317 | 3317 | if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) { |
3318 | 3318 | |
3319 | 3319 | $amount = $taxes[ $tax ]['amount'] += $amount; |
3320 | - $taxes[ $tax ] = array( |
|
3320 | + $taxes[ $tax ] = array( |
|
3321 | 3321 | 'amount' => $amount, |
3322 | 3322 | 'recurring' => (bool) $recurring, |
3323 | 3323 | ); |
3324 | 3324 | |
3325 | - } else { |
|
3326 | - $taxes[ $tax ] = array( |
|
3325 | + } else { |
|
3326 | + $taxes[ $tax ] = array( |
|
3327 | 3327 | 'amount' => $amount, |
3328 | 3328 | 'recurring' => (bool) $recurring, |
3329 | 3329 | ); |
3330 | - } |
|
3330 | + } |
|
3331 | 3331 | |
3332 | 3332 | $this->set_prop( 'taxes', $tax ); |
3333 | 3333 | |
3334 | 3334 | } |
3335 | 3335 | |
3336 | 3336 | /** |
3337 | - * Retrieves a specific tax. |
|
3338 | - * |
|
3339 | - * @since 1.0.19 |
|
3340 | - */ |
|
3341 | - public function get_tax( $tax = null ) { |
|
3337 | + * Retrieves a specific tax. |
|
3338 | + * |
|
3339 | + * @since 1.0.19 |
|
3340 | + */ |
|
3341 | + public function get_tax( $tax = null ) { |
|
3342 | 3342 | |
3343 | - // Backwards compatility. |
|
3344 | - if ( empty( $tax ) ) { |
|
3345 | - return $this->get_total_tax(); |
|
3346 | - } |
|
3343 | + // Backwards compatility. |
|
3344 | + if ( empty( $tax ) ) { |
|
3345 | + return $this->get_total_tax(); |
|
3346 | + } |
|
3347 | 3347 | |
3348 | 3348 | $taxes = $this->get_taxes(); |
3349 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3349 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3350 | 3350 | } |
3351 | 3351 | |
3352 | 3352 | /** |
3353 | - * Removes a specific tax. |
|
3354 | - * |
|
3355 | - * @since 1.0.19 |
|
3356 | - */ |
|
3357 | - public function remove_tax( $tax ) { |
|
3353 | + * Removes a specific tax. |
|
3354 | + * |
|
3355 | + * @since 1.0.19 |
|
3356 | + */ |
|
3357 | + public function remove_tax( $tax ) { |
|
3358 | 3358 | $taxes = $this->get_discounts(); |
3359 | 3359 | if ( isset( $taxes[ $tax ] ) ) { |
3360 | 3360 | unset( $taxes[ $tax ] ); |
@@ -3363,160 +3363,160 @@ discard block |
||
3363 | 3363 | } |
3364 | 3364 | |
3365 | 3365 | /** |
3366 | - * Recalculates the invoice subtotal. |
|
3367 | - * |
|
3368 | - * @since 1.0.19 |
|
3369 | - * @return float The recalculated subtotal |
|
3370 | - */ |
|
3371 | - public function recalculate_subtotal() { |
|
3366 | + * Recalculates the invoice subtotal. |
|
3367 | + * |
|
3368 | + * @since 1.0.19 |
|
3369 | + * @return float The recalculated subtotal |
|
3370 | + */ |
|
3371 | + public function recalculate_subtotal() { |
|
3372 | 3372 | $items = $this->get_items(); |
3373 | - $subtotal = 0; |
|
3374 | - $recurring = 0; |
|
3373 | + $subtotal = 0; |
|
3374 | + $recurring = 0; |
|
3375 | 3375 | |
3376 | 3376 | foreach ( $items as $item ) { |
3377 | - $subtotal += $item->get_sub_total(); |
|
3378 | - $recurring += $item->get_recurring_sub_total(); |
|
3377 | + $subtotal += $item->get_sub_total(); |
|
3378 | + $recurring += $item->get_recurring_sub_total(); |
|
3379 | 3379 | } |
3380 | 3380 | |
3381 | - if ( $this->is_renewal() ) { |
|
3382 | - $this->set_subtotal( $recurring ); |
|
3383 | - } else { |
|
3384 | - $this->set_subtotal( $subtotal ); |
|
3385 | - } |
|
3381 | + if ( $this->is_renewal() ) { |
|
3382 | + $this->set_subtotal( $recurring ); |
|
3383 | + } else { |
|
3384 | + $this->set_subtotal( $subtotal ); |
|
3385 | + } |
|
3386 | 3386 | |
3387 | - $this->totals['subtotal'] = array( |
|
3388 | - 'initial' => $subtotal, |
|
3389 | - 'recurring' => $recurring, |
|
3390 | - ); |
|
3387 | + $this->totals['subtotal'] = array( |
|
3388 | + 'initial' => $subtotal, |
|
3389 | + 'recurring' => $recurring, |
|
3390 | + ); |
|
3391 | 3391 | |
3392 | 3392 | return $this->is_renewal() ? $recurring : $subtotal; |
3393 | 3393 | } |
3394 | 3394 | |
3395 | 3395 | /** |
3396 | - * Recalculates the invoice discount total. |
|
3397 | - * |
|
3398 | - * @since 1.0.19 |
|
3399 | - * @return float The recalculated discount |
|
3400 | - */ |
|
3401 | - public function recalculate_total_discount() { |
|
3396 | + * Recalculates the invoice discount total. |
|
3397 | + * |
|
3398 | + * @since 1.0.19 |
|
3399 | + * @return float The recalculated discount |
|
3400 | + */ |
|
3401 | + public function recalculate_total_discount() { |
|
3402 | 3402 | $discounts = $this->get_discounts(); |
3403 | - $discount = 0; |
|
3404 | - $recurring = 0; |
|
3403 | + $discount = 0; |
|
3404 | + $recurring = 0; |
|
3405 | 3405 | |
3406 | 3406 | foreach ( $discounts as $data ) { |
3407 | 3407 | |
3408 | - if ( $data['recurring'] ) { |
|
3409 | - $recurring += $data['amount']; |
|
3410 | - } else { |
|
3411 | - $discount += $data['amount']; |
|
3412 | - } |
|
3408 | + if ( $data['recurring'] ) { |
|
3409 | + $recurring += $data['amount']; |
|
3410 | + } else { |
|
3411 | + $discount += $data['amount']; |
|
3412 | + } |
|
3413 | 3413 | |
3414 | - } |
|
3414 | + } |
|
3415 | 3415 | |
3416 | - if ( $this->is_renewal() ) { |
|
3417 | - $this->set_total_discount( $recurring ); |
|
3418 | - } else { |
|
3419 | - $this->set_total_discount( $discount ); |
|
3420 | - } |
|
3416 | + if ( $this->is_renewal() ) { |
|
3417 | + $this->set_total_discount( $recurring ); |
|
3418 | + } else { |
|
3419 | + $this->set_total_discount( $discount ); |
|
3420 | + } |
|
3421 | 3421 | |
3422 | - $this->totals['discount'] = array( |
|
3423 | - 'initial' => $discount, |
|
3424 | - 'recurring' => $recurring, |
|
3425 | - ); |
|
3422 | + $this->totals['discount'] = array( |
|
3423 | + 'initial' => $discount, |
|
3424 | + 'recurring' => $recurring, |
|
3425 | + ); |
|
3426 | 3426 | |
3427 | - return $this->is_renewal() ? $recurring : $discount; |
|
3427 | + return $this->is_renewal() ? $recurring : $discount; |
|
3428 | 3428 | |
3429 | 3429 | } |
3430 | 3430 | |
3431 | 3431 | /** |
3432 | - * Recalculates the invoice tax total. |
|
3433 | - * |
|
3434 | - * @since 1.0.19 |
|
3435 | - * @return float The recalculated tax |
|
3436 | - */ |
|
3437 | - public function recalculate_total_tax() { |
|
3432 | + * Recalculates the invoice tax total. |
|
3433 | + * |
|
3434 | + * @since 1.0.19 |
|
3435 | + * @return float The recalculated tax |
|
3436 | + */ |
|
3437 | + public function recalculate_total_tax() { |
|
3438 | 3438 | $taxes = $this->get_taxes(); |
3439 | - $tax = 0; |
|
3440 | - $recurring = 0; |
|
3439 | + $tax = 0; |
|
3440 | + $recurring = 0; |
|
3441 | 3441 | |
3442 | 3442 | foreach ( $taxes as $data ) { |
3443 | 3443 | |
3444 | - if ( $data['recurring'] ) { |
|
3445 | - $recurring += $data['amount']; |
|
3446 | - } else { |
|
3447 | - $tax += $data['amount']; |
|
3448 | - } |
|
3444 | + if ( $data['recurring'] ) { |
|
3445 | + $recurring += $data['amount']; |
|
3446 | + } else { |
|
3447 | + $tax += $data['amount']; |
|
3448 | + } |
|
3449 | 3449 | |
3450 | - } |
|
3450 | + } |
|
3451 | 3451 | |
3452 | - if ( $this->is_renewal() ) { |
|
3453 | - $this->set_total_tax( $recurring ); |
|
3454 | - } else { |
|
3455 | - $this->set_total_tax( $tax ); |
|
3456 | - } |
|
3452 | + if ( $this->is_renewal() ) { |
|
3453 | + $this->set_total_tax( $recurring ); |
|
3454 | + } else { |
|
3455 | + $this->set_total_tax( $tax ); |
|
3456 | + } |
|
3457 | 3457 | |
3458 | - $this->totals['tax'] = array( |
|
3459 | - 'initial' => $tax, |
|
3460 | - 'recurring' => $recurring, |
|
3461 | - ); |
|
3458 | + $this->totals['tax'] = array( |
|
3459 | + 'initial' => $tax, |
|
3460 | + 'recurring' => $recurring, |
|
3461 | + ); |
|
3462 | 3462 | |
3463 | - return $this->is_renewal() ? $recurring : $tax; |
|
3463 | + return $this->is_renewal() ? $recurring : $tax; |
|
3464 | 3464 | |
3465 | 3465 | } |
3466 | 3466 | |
3467 | 3467 | /** |
3468 | - * Recalculates the invoice fees total. |
|
3469 | - * |
|
3470 | - * @since 1.0.19 |
|
3471 | - * @return float The recalculated fee |
|
3472 | - */ |
|
3473 | - public function recalculate_total_fees() { |
|
3474 | - $fees = $this->get_fees(); |
|
3475 | - $fee = 0; |
|
3476 | - $recurring = 0; |
|
3468 | + * Recalculates the invoice fees total. |
|
3469 | + * |
|
3470 | + * @since 1.0.19 |
|
3471 | + * @return float The recalculated fee |
|
3472 | + */ |
|
3473 | + public function recalculate_total_fees() { |
|
3474 | + $fees = $this->get_fees(); |
|
3475 | + $fee = 0; |
|
3476 | + $recurring = 0; |
|
3477 | 3477 | |
3478 | 3478 | foreach ( $fees as $data ) { |
3479 | 3479 | |
3480 | - if ( $data['recurring'] ) { |
|
3481 | - $recurring += $data['amount']; |
|
3482 | - } else { |
|
3483 | - $fee += $data['amount']; |
|
3484 | - } |
|
3480 | + if ( $data['recurring'] ) { |
|
3481 | + $recurring += $data['amount']; |
|
3482 | + } else { |
|
3483 | + $fee += $data['amount']; |
|
3484 | + } |
|
3485 | 3485 | |
3486 | - } |
|
3486 | + } |
|
3487 | 3487 | |
3488 | 3488 | if ( $this->is_renewal() ) { |
3489 | - $this->set_total_fees( $recurring ); |
|
3490 | - } else { |
|
3491 | - $this->set_total_fees( $fee ); |
|
3492 | - } |
|
3489 | + $this->set_total_fees( $recurring ); |
|
3490 | + } else { |
|
3491 | + $this->set_total_fees( $fee ); |
|
3492 | + } |
|
3493 | 3493 | |
3494 | - $this->totals['fee'] = array( |
|
3495 | - 'initial' => $fee, |
|
3496 | - 'recurring' => $recurring, |
|
3497 | - ); |
|
3494 | + $this->totals['fee'] = array( |
|
3495 | + 'initial' => $fee, |
|
3496 | + 'recurring' => $recurring, |
|
3497 | + ); |
|
3498 | 3498 | |
3499 | 3499 | $this->set_total_fees( $fee ); |
3500 | 3500 | return $this->is_renewal() ? $recurring : $fee; |
3501 | 3501 | } |
3502 | 3502 | |
3503 | 3503 | /** |
3504 | - * Recalculates the invoice total. |
|
3505 | - * |
|
3506 | - * @since 1.0.19 |
|
3504 | + * Recalculates the invoice total. |
|
3505 | + * |
|
3506 | + * @since 1.0.19 |
|
3507 | 3507 | * @return float The invoice total |
3508 | - */ |
|
3509 | - public function recalculate_total() { |
|
3508 | + */ |
|
3509 | + public function recalculate_total() { |
|
3510 | 3510 | $this->recalculate_subtotal(); |
3511 | 3511 | $this->recalculate_total_fees(); |
3512 | 3512 | $this->recalculate_total_discount(); |
3513 | 3513 | $this->recalculate_total_tax(); |
3514 | - return $this->get_total(); |
|
3515 | - } |
|
3514 | + return $this->get_total(); |
|
3515 | + } |
|
3516 | 3516 | |
3517 | - /** |
|
3518 | - * @deprecated |
|
3519 | - */ |
|
3517 | + /** |
|
3518 | + * @deprecated |
|
3519 | + */ |
|
3520 | 3520 | public function recalculate_totals( $temp = false ) { |
3521 | 3521 | $this->update_items( $temp ); |
3522 | 3522 | $this->save( true ); |
@@ -3534,7 +3534,7 @@ discard block |
||
3534 | 3534 | * Adds a note to an invoice. |
3535 | 3535 | * |
3536 | 3536 | * @param string $note The note being added. |
3537 | - * @return int|false The new note's ID on success, false on failure. |
|
3537 | + * @return int|false The new note's ID on success, false on failure. |
|
3538 | 3538 | * |
3539 | 3539 | */ |
3540 | 3540 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3544,23 +3544,23 @@ discard block |
||
3544 | 3544 | return false; |
3545 | 3545 | } |
3546 | 3546 | |
3547 | - // If this is an admin comment or it has been added by the user. |
|
3548 | - if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) { |
|
3549 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3547 | + // If this is an admin comment or it has been added by the user. |
|
3548 | + if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) { |
|
3549 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3550 | 3550 | $author = $user->display_name; |
3551 | 3551 | $author_email = $user->user_email; |
3552 | - } |
|
3552 | + } |
|
3553 | 3553 | |
3554 | - if ( $system ) { |
|
3555 | - $author = 'System'; |
|
3554 | + if ( $system ) { |
|
3555 | + $author = 'System'; |
|
3556 | 3556 | $author_email = '[email protected]'; |
3557 | - } |
|
3557 | + } |
|
3558 | 3558 | |
3559 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3559 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3560 | 3560 | |
3561 | - } |
|
3561 | + } |
|
3562 | 3562 | |
3563 | - /** |
|
3563 | + /** |
|
3564 | 3564 | * Generates a unique key for the invoice. |
3565 | 3565 | */ |
3566 | 3566 | public function generate_key( $string = '' ) { |
@@ -3580,106 +3580,106 @@ discard block |
||
3580 | 3580 | $number = wpinv_get_next_invoice_number( $this->post_type ); |
3581 | 3581 | } |
3582 | 3582 | |
3583 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3583 | + $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3584 | 3584 | |
3585 | - return $number; |
|
3586 | - } |
|
3585 | + return $number; |
|
3586 | + } |
|
3587 | 3587 | |
3588 | - /** |
|
3589 | - * Handle the status transition. |
|
3590 | - */ |
|
3591 | - protected function status_transition() { |
|
3592 | - $status_transition = $this->status_transition; |
|
3588 | + /** |
|
3589 | + * Handle the status transition. |
|
3590 | + */ |
|
3591 | + protected function status_transition() { |
|
3592 | + $status_transition = $this->status_transition; |
|
3593 | 3593 | |
3594 | - // Reset status transition variable. |
|
3595 | - $this->status_transition = false; |
|
3594 | + // Reset status transition variable. |
|
3595 | + $this->status_transition = false; |
|
3596 | 3596 | |
3597 | - if ( $status_transition ) { |
|
3598 | - try { |
|
3597 | + if ( $status_transition ) { |
|
3598 | + try { |
|
3599 | 3599 | |
3600 | - // Fire a hook for the status change. |
|
3601 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
3600 | + // Fire a hook for the status change. |
|
3601 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
3602 | 3602 | |
3603 | - // @deprecated this is deprecated and will be removed in the future. |
|
3604 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3603 | + // @deprecated this is deprecated and will be removed in the future. |
|
3604 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3605 | 3605 | |
3606 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3606 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3607 | 3607 | |
3608 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3609 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3608 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3609 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3610 | 3610 | |
3611 | - // Fire another hook. |
|
3612 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
3613 | - do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
3611 | + // Fire another hook. |
|
3612 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
3613 | + do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
3614 | 3614 | |
3615 | - // @deprecated this is deprecated and will be removed in the future. |
|
3616 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3615 | + // @deprecated this is deprecated and will be removed in the future. |
|
3616 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3617 | 3617 | |
3618 | - // Note the transition occurred. |
|
3619 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3618 | + // Note the transition occurred. |
|
3619 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3620 | 3620 | |
3621 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3622 | - if ( |
|
3623 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true ) |
|
3624 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3625 | - ) { |
|
3626 | - do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
3627 | - } |
|
3628 | - } else { |
|
3629 | - /* translators: %s: new invoice status */ |
|
3630 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3621 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3622 | + if ( |
|
3623 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true ) |
|
3624 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3625 | + ) { |
|
3626 | + do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
3627 | + } |
|
3628 | + } else { |
|
3629 | + /* translators: %s: new invoice status */ |
|
3630 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3631 | 3631 | |
3632 | - // Note the transition occurred. |
|
3633 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3632 | + // Note the transition occurred. |
|
3633 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3634 | 3634 | |
3635 | - } |
|
3636 | - } catch ( Exception $e ) { |
|
3637 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3638 | - } |
|
3639 | - } |
|
3640 | - } |
|
3635 | + } |
|
3636 | + } catch ( Exception $e ) { |
|
3637 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3638 | + } |
|
3639 | + } |
|
3640 | + } |
|
3641 | 3641 | |
3642 | - /** |
|
3643 | - * Updates an invoice status. |
|
3644 | - */ |
|
3645 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3642 | + /** |
|
3643 | + * Updates an invoice status. |
|
3644 | + */ |
|
3645 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3646 | 3646 | |
3647 | - // Fires before updating a status. |
|
3648 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3647 | + // Fires before updating a status. |
|
3648 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3649 | 3649 | |
3650 | - // Update the status. |
|
3651 | - $this->set_status( $new_status, $note, $manual ); |
|
3650 | + // Update the status. |
|
3651 | + $this->set_status( $new_status, $note, $manual ); |
|
3652 | 3652 | |
3653 | - // Save the order. |
|
3654 | - return $this->save(); |
|
3653 | + // Save the order. |
|
3654 | + return $this->save(); |
|
3655 | 3655 | |
3656 | - } |
|
3656 | + } |
|
3657 | 3657 | |
3658 | - /** |
|
3659 | - * @deprecated |
|
3660 | - */ |
|
3661 | - public function refresh_item_ids() { |
|
3658 | + /** |
|
3659 | + * @deprecated |
|
3660 | + */ |
|
3661 | + public function refresh_item_ids() { |
|
3662 | 3662 | $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
3663 | 3663 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3664 | - } |
|
3664 | + } |
|
3665 | 3665 | |
3666 | - /** |
|
3667 | - * @deprecated |
|
3668 | - */ |
|
3669 | - public function update_items( $temp = false ) { |
|
3666 | + /** |
|
3667 | + * @deprecated |
|
3668 | + */ |
|
3669 | + public function update_items( $temp = false ) { |
|
3670 | 3670 | |
3671 | - $this->set_items( $this->get_items() ); |
|
3671 | + $this->set_items( $this->get_items() ); |
|
3672 | 3672 | |
3673 | - if ( ! $temp ) { |
|
3674 | - $this->save(); |
|
3675 | - } |
|
3673 | + if ( ! $temp ) { |
|
3674 | + $this->save(); |
|
3675 | + } |
|
3676 | 3676 | |
3677 | 3677 | return $this; |
3678 | - } |
|
3678 | + } |
|
3679 | 3679 | |
3680 | - /** |
|
3681 | - * @deprecated |
|
3682 | - */ |
|
3680 | + /** |
|
3681 | + * @deprecated |
|
3682 | + */ |
|
3683 | 3683 | public function validate_discount() { |
3684 | 3684 | |
3685 | 3685 | $discount_code = $this->get_discount_code(); |
@@ -3695,86 +3695,86 @@ discard block |
||
3695 | 3695 | |
3696 | 3696 | } |
3697 | 3697 | |
3698 | - /** |
|
3699 | - * Refunds an invoice. |
|
3700 | - */ |
|
3698 | + /** |
|
3699 | + * Refunds an invoice. |
|
3700 | + */ |
|
3701 | 3701 | public function refund() { |
3702 | - $this->set_status( 'wpi-refunded' ); |
|
3702 | + $this->set_status( 'wpi-refunded' ); |
|
3703 | 3703 | $this->save(); |
3704 | - } |
|
3704 | + } |
|
3705 | 3705 | |
3706 | - /** |
|
3707 | - * Marks an invoice as paid. |
|
3708 | - * |
|
3709 | - * @param string $transaction_id |
|
3710 | - */ |
|
3706 | + /** |
|
3707 | + * Marks an invoice as paid. |
|
3708 | + * |
|
3709 | + * @param string $transaction_id |
|
3710 | + */ |
|
3711 | 3711 | public function mark_paid( $transaction_id = null, $note = '' ) { |
3712 | 3712 | |
3713 | - // Set the transaction id. |
|
3714 | - if ( empty( $transaction_id ) ) { |
|
3715 | - $transaction_id = $this->generate_key('trans_'); |
|
3716 | - } |
|
3713 | + // Set the transaction id. |
|
3714 | + if ( empty( $transaction_id ) ) { |
|
3715 | + $transaction_id = $this->generate_key('trans_'); |
|
3716 | + } |
|
3717 | 3717 | |
3718 | - if ( ! $this->get_transaction_id() ) { |
|
3719 | - $this->set_transaction_id( $transaction_id ); |
|
3720 | - } |
|
3718 | + if ( ! $this->get_transaction_id() ) { |
|
3719 | + $this->set_transaction_id( $transaction_id ); |
|
3720 | + } |
|
3721 | 3721 | |
3722 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3723 | - return $this->save(); |
|
3724 | - } |
|
3722 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3723 | + return $this->save(); |
|
3724 | + } |
|
3725 | 3725 | |
3726 | - // Set the completed date. |
|
3727 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
3726 | + // Set the completed date. |
|
3727 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
3728 | 3728 | |
3729 | - // Set the new status. |
|
3730 | - if ( $this->is_renewal() ) { |
|
3729 | + // Set the new status. |
|
3730 | + if ( $this->is_renewal() ) { |
|
3731 | 3731 | |
3732 | - $_note = sprintf( |
|
3733 | - __( 'Renewed via %s', 'invoicing' ), |
|
3734 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3735 | - ); |
|
3732 | + $_note = sprintf( |
|
3733 | + __( 'Renewed via %s', 'invoicing' ), |
|
3734 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3735 | + ); |
|
3736 | 3736 | |
3737 | - if ( 'none' == $this->get_gateway() ) { |
|
3738 | - $_note = $note; |
|
3739 | - } |
|
3737 | + if ( 'none' == $this->get_gateway() ) { |
|
3738 | + $_note = $note; |
|
3739 | + } |
|
3740 | 3740 | |
3741 | - $this->set_status( 'wpi-renewal', $_note ); |
|
3741 | + $this->set_status( 'wpi-renewal', $_note ); |
|
3742 | 3742 | |
3743 | - } else { |
|
3743 | + } else { |
|
3744 | 3744 | |
3745 | - $_note = sprintf( |
|
3746 | - __( 'Paid via %s', 'invoicing' ), |
|
3747 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3748 | - ); |
|
3745 | + $_note = sprintf( |
|
3746 | + __( 'Paid via %s', 'invoicing' ), |
|
3747 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3748 | + ); |
|
3749 | 3749 | |
3750 | - if ( 'none' == $this->get_gateway() ) { |
|
3751 | - $_note = $note; |
|
3752 | - } |
|
3750 | + if ( 'none' == $this->get_gateway() ) { |
|
3751 | + $_note = $note; |
|
3752 | + } |
|
3753 | 3753 | |
3754 | - $this->set_status( 'publish',$_note ); |
|
3754 | + $this->set_status( 'publish',$_note ); |
|
3755 | 3755 | |
3756 | - } |
|
3756 | + } |
|
3757 | 3757 | |
3758 | - // Set checkout mode. |
|
3759 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3760 | - $this->set_mode( $mode ); |
|
3758 | + // Set checkout mode. |
|
3759 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3760 | + $this->set_mode( $mode ); |
|
3761 | 3761 | |
3762 | - // Save the invoice. |
|
3762 | + // Save the invoice. |
|
3763 | 3763 | $this->save(); |
3764 | - } |
|
3765 | - |
|
3766 | - |
|
3767 | - /** |
|
3768 | - * Save data to the database. |
|
3769 | - * |
|
3770 | - * @since 1.0.19 |
|
3771 | - * @return int invoice ID |
|
3772 | - */ |
|
3773 | - public function save() { |
|
3774 | - $this->maybe_set_date_paid(); |
|
3775 | - parent::save(); |
|
3776 | - $this->status_transition(); |
|
3777 | - return $this->get_id(); |
|
3778 | - } |
|
3764 | + } |
|
3765 | + |
|
3766 | + |
|
3767 | + /** |
|
3768 | + * Save data to the database. |
|
3769 | + * |
|
3770 | + * @since 1.0.19 |
|
3771 | + * @return int invoice ID |
|
3772 | + */ |
|
3773 | + public function save() { |
|
3774 | + $this->maybe_set_date_paid(); |
|
3775 | + parent::save(); |
|
3776 | + $this->status_transition(); |
|
3777 | + return $this->get_id(); |
|
3778 | + } |
|
3779 | 3779 | |
3780 | 3780 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,190 +15,190 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Subscription_Data_Store { |
17 | 17 | |
18 | - /** |
|
19 | - * A map of database fields to data types. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $database_fields_to_data_type = array( |
|
25 | - 'id' => '%d', |
|
26 | - 'customer_id' => '%d', |
|
27 | - 'frequency' => '%d', |
|
28 | - 'period' => '%s', |
|
29 | - 'initial_amount' => '%s', |
|
30 | - 'recurring_amount' => '%s', |
|
31 | - 'bill_times' => '%d', |
|
32 | - 'transaction_id' => '%s', |
|
33 | - 'parent_payment_id' => '%d', |
|
34 | - 'product_id' => '%d', |
|
35 | - 'created' => '%s', |
|
36 | - 'expiration' => '%s', |
|
37 | - 'trial_period' => '%s', |
|
38 | - 'status' => '%s', |
|
39 | - 'profile_id' => '%s', |
|
40 | - ); |
|
41 | - |
|
42 | - /* |
|
18 | + /** |
|
19 | + * A map of database fields to data types. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $database_fields_to_data_type = array( |
|
25 | + 'id' => '%d', |
|
26 | + 'customer_id' => '%d', |
|
27 | + 'frequency' => '%d', |
|
28 | + 'period' => '%s', |
|
29 | + 'initial_amount' => '%s', |
|
30 | + 'recurring_amount' => '%s', |
|
31 | + 'bill_times' => '%d', |
|
32 | + 'transaction_id' => '%s', |
|
33 | + 'parent_payment_id' => '%d', |
|
34 | + 'product_id' => '%d', |
|
35 | + 'created' => '%s', |
|
36 | + 'expiration' => '%s', |
|
37 | + 'trial_period' => '%s', |
|
38 | + 'status' => '%s', |
|
39 | + 'profile_id' => '%s', |
|
40 | + ); |
|
41 | + |
|
42 | + /* |
|
43 | 43 | |-------------------------------------------------------------------------- |
44 | 44 | | CRUD Methods |
45 | 45 | |-------------------------------------------------------------------------- |
46 | 46 | */ |
47 | 47 | |
48 | - /** |
|
49 | - * Method to create a new subscription in the database. |
|
50 | - * |
|
51 | - * @param WPInv_Subscription $subscription Subscription object. |
|
52 | - */ |
|
53 | - public function create( &$subscription ) { |
|
54 | - global $wpdb; |
|
55 | - |
|
56 | - $values = array(); |
|
57 | - $formats = array(); |
|
58 | - |
|
59 | - $fields = $this->database_fields_to_data_type; |
|
60 | - unset( $fields['id'] ); |
|
61 | - |
|
62 | - foreach ( $fields as $key => $format ) { |
|
63 | - $method = "get_$key"; |
|
64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
65 | - $formats[] = $format; |
|
66 | - } |
|
67 | - |
|
68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats ); |
|
69 | - |
|
70 | - if ( $result ) { |
|
71 | - $subscription->set_id( $wpdb->insert_id ); |
|
72 | - $subscription->apply_changes(); |
|
73 | - $subscription->clear_cache(); |
|
74 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
75 | - return true; |
|
76 | - } |
|
77 | - |
|
78 | - return false; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Method to read a subscription from the database. |
|
83 | - * |
|
84 | - * @param WPInv_Subscription $subscription Subscription object. |
|
85 | - * |
|
86 | - */ |
|
87 | - public function read( &$subscription ) { |
|
88 | - global $wpdb; |
|
89 | - |
|
90 | - $subscription->set_defaults(); |
|
91 | - |
|
92 | - if ( ! $subscription->get_id() ) { |
|
93 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
94 | - $subscription->set_id( 0 ); |
|
95 | - return false; |
|
96 | - } |
|
97 | - |
|
98 | - // Maybe retrieve from the cache. |
|
99 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
100 | - |
|
101 | - // If not found, retrieve from the db. |
|
102 | - if ( false === $raw_subscription ) { |
|
103 | - |
|
104 | - $raw_subscription = $wpdb->get_row( |
|
105 | - $wpdb->prepare( |
|
106 | - "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
107 | - $subscription->get_id() |
|
108 | - ) |
|
109 | - ); |
|
110 | - |
|
111 | - // Update the cache with our data |
|
112 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - if ( ! $raw_subscription ) { |
|
117 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
122 | - $method = "set_$key"; |
|
123 | - $subscription->$method( $raw_subscription->$key ); |
|
124 | - } |
|
125 | - |
|
126 | - $subscription->set_object_read( true ); |
|
127 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Method to update a subscription in the database. |
|
133 | - * |
|
134 | - * @param WPInv_Subscription $subscription Subscription object. |
|
135 | - */ |
|
136 | - public function update( &$subscription ) { |
|
137 | - global $wpdb; |
|
138 | - |
|
139 | - $changes = $subscription->get_changes(); |
|
140 | - $values = array(); |
|
141 | - $format = array(); |
|
142 | - |
|
143 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
144 | - if ( array_key_exists( $key, $changes ) ) { |
|
145 | - $method = "get_$key"; |
|
146 | - $values[$key] = $subscription->$method( 'edit' ); |
|
147 | - $formats[] = $format; |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - if ( empty( $values ) ) { |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $wpdb->update( |
|
156 | - $wpdb->prefix . 'wpinv_subscriptions', |
|
157 | - $values, |
|
158 | - array( |
|
159 | - 'id' => $subscription->get_id(), |
|
160 | - ), |
|
161 | - $formats, |
|
162 | - '%d' |
|
163 | - ); |
|
164 | - |
|
165 | - // Apply the changes. |
|
166 | - $subscription->apply_changes(); |
|
167 | - |
|
168 | - // Delete cache. |
|
169 | - $subscription->clear_cache(); |
|
170 | - |
|
171 | - // Fire a hook. |
|
172 | - do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription ); |
|
173 | - |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Method to delete a subscription from the database. |
|
178 | - * |
|
179 | - * @param WPInv_Subscription $subscription |
|
180 | - */ |
|
181 | - public function delete( &$subscription ) { |
|
182 | - global $wpdb; |
|
183 | - |
|
184 | - $wpdb->query( |
|
185 | - $wpdb->prepare( |
|
186 | - "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
48 | + /** |
|
49 | + * Method to create a new subscription in the database. |
|
50 | + * |
|
51 | + * @param WPInv_Subscription $subscription Subscription object. |
|
52 | + */ |
|
53 | + public function create( &$subscription ) { |
|
54 | + global $wpdb; |
|
55 | + |
|
56 | + $values = array(); |
|
57 | + $formats = array(); |
|
58 | + |
|
59 | + $fields = $this->database_fields_to_data_type; |
|
60 | + unset( $fields['id'] ); |
|
61 | + |
|
62 | + foreach ( $fields as $key => $format ) { |
|
63 | + $method = "get_$key"; |
|
64 | + $values[$key] = $subscription->$method( 'edit' ); |
|
65 | + $formats[] = $format; |
|
66 | + } |
|
67 | + |
|
68 | + $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats ); |
|
69 | + |
|
70 | + if ( $result ) { |
|
71 | + $subscription->set_id( $wpdb->insert_id ); |
|
72 | + $subscription->apply_changes(); |
|
73 | + $subscription->clear_cache(); |
|
74 | + do_action( 'getpaid_new_subscription', $subscription ); |
|
75 | + return true; |
|
76 | + } |
|
77 | + |
|
78 | + return false; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Method to read a subscription from the database. |
|
83 | + * |
|
84 | + * @param WPInv_Subscription $subscription Subscription object. |
|
85 | + * |
|
86 | + */ |
|
87 | + public function read( &$subscription ) { |
|
88 | + global $wpdb; |
|
89 | + |
|
90 | + $subscription->set_defaults(); |
|
91 | + |
|
92 | + if ( ! $subscription->get_id() ) { |
|
93 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
94 | + $subscription->set_id( 0 ); |
|
95 | + return false; |
|
96 | + } |
|
97 | + |
|
98 | + // Maybe retrieve from the cache. |
|
99 | + $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
100 | + |
|
101 | + // If not found, retrieve from the db. |
|
102 | + if ( false === $raw_subscription ) { |
|
103 | + |
|
104 | + $raw_subscription = $wpdb->get_row( |
|
105 | + $wpdb->prepare( |
|
106 | + "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
107 | + $subscription->get_id() |
|
108 | + ) |
|
109 | + ); |
|
110 | + |
|
111 | + // Update the cache with our data |
|
112 | + wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + if ( ! $raw_subscription ) { |
|
117 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
122 | + $method = "set_$key"; |
|
123 | + $subscription->$method( $raw_subscription->$key ); |
|
124 | + } |
|
125 | + |
|
126 | + $subscription->set_object_read( true ); |
|
127 | + do_action( 'getpaid_read_subscription', $subscription ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Method to update a subscription in the database. |
|
133 | + * |
|
134 | + * @param WPInv_Subscription $subscription Subscription object. |
|
135 | + */ |
|
136 | + public function update( &$subscription ) { |
|
137 | + global $wpdb; |
|
138 | + |
|
139 | + $changes = $subscription->get_changes(); |
|
140 | + $values = array(); |
|
141 | + $format = array(); |
|
142 | + |
|
143 | + foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
144 | + if ( array_key_exists( $key, $changes ) ) { |
|
145 | + $method = "get_$key"; |
|
146 | + $values[$key] = $subscription->$method( 'edit' ); |
|
147 | + $formats[] = $format; |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + if ( empty( $values ) ) { |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $wpdb->update( |
|
156 | + $wpdb->prefix . 'wpinv_subscriptions', |
|
157 | + $values, |
|
158 | + array( |
|
159 | + 'id' => $subscription->get_id(), |
|
160 | + ), |
|
161 | + $formats, |
|
162 | + '%d' |
|
163 | + ); |
|
164 | + |
|
165 | + // Apply the changes. |
|
166 | + $subscription->apply_changes(); |
|
167 | + |
|
168 | + // Delete cache. |
|
169 | + $subscription->clear_cache(); |
|
170 | + |
|
171 | + // Fire a hook. |
|
172 | + do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription ); |
|
173 | + |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Method to delete a subscription from the database. |
|
178 | + * |
|
179 | + * @param WPInv_Subscription $subscription |
|
180 | + */ |
|
181 | + public function delete( &$subscription ) { |
|
182 | + global $wpdb; |
|
183 | + |
|
184 | + $wpdb->query( |
|
185 | + $wpdb->prepare( |
|
186 | + "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
187 | 187 | WHERE id = %d", |
188 | - $subscription->get_id() |
|
189 | - ) |
|
190 | - ); |
|
188 | + $subscription->get_id() |
|
189 | + ) |
|
190 | + ); |
|
191 | 191 | |
192 | - // Delete cache. |
|
193 | - $subscription->clear_cache(); |
|
192 | + // Delete cache. |
|
193 | + $subscription->clear_cache(); |
|
194 | 194 | |
195 | - // Fire a hook. |
|
196 | - do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription ); |
|
195 | + // Fire a hook. |
|
196 | + do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription ); |
|
197 | 197 | |
198 | - $subscription->set_id( 0 ); |
|
199 | - } |
|
198 | + $subscription->set_id( 0 ); |
|
199 | + } |
|
200 | 200 | |
201 | - /* |
|
201 | + /* |
|
202 | 202 | |-------------------------------------------------------------------------- |
203 | 203 | | Additional Methods |
204 | 204 | |-------------------------------------------------------------------------- |
@@ -13,449 +13,449 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | - |
|
142 | - // Register gateway. |
|
143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | - |
|
145 | - // Enable Subscriptions. |
|
146 | - if ( $this->supports( 'subscription' ) ) { |
|
147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | - } |
|
149 | - |
|
150 | - // Enable sandbox. |
|
151 | - if ( $this->supports( 'sandbox' ) ) { |
|
152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | - } |
|
154 | - |
|
155 | - // Gateway settings. |
|
156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | + |
|
142 | + // Register gateway. |
|
143 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | + |
|
145 | + // Enable Subscriptions. |
|
146 | + if ( $this->supports( 'subscription' ) ) { |
|
147 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | + } |
|
149 | + |
|
150 | + // Enable sandbox. |
|
151 | + if ( $this->supports( 'sandbox' ) ) { |
|
152 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | + } |
|
154 | + |
|
155 | + // Gateway settings. |
|
156 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
157 | 157 | |
158 | 158 | |
159 | - // Gateway checkout fiellds. |
|
160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | - |
|
162 | - // Process payment. |
|
163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
159 | + // Gateway checkout fiellds. |
|
160 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | + |
|
162 | + // Process payment. |
|
163 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
164 | + |
|
165 | + // Change the checkout button text. |
|
166 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + } |
|
169 | + |
|
170 | + // Check if a gateway is valid for a given currency. |
|
171 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | + |
|
173 | + // Generate the transaction url. |
|
174 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | + |
|
176 | + // Generate the subscription url. |
|
177 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | + |
|
179 | + // Confirm payments. |
|
180 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | + |
|
182 | + // Verify IPNs. |
|
183 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Checks if this gateway is a given gateway. |
|
189 | + * |
|
190 | + * @since 1.0.19 |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function is( $gateway ) { |
|
194 | + return $gateway == $this->id; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns a users saved tokens for this gateway. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function get_tokens( $sandbox = null ) { |
|
204 | + |
|
205 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
206 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + |
|
208 | + if ( is_array( $tokens ) ) { |
|
209 | + $this->tokens = $tokens; |
|
210 | + } |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + if ( ! is_bool( $sandbox ) ) { |
|
215 | + return $this->tokens; |
|
216 | + } |
|
217 | + |
|
218 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
219 | + return wp_list_filter( $this->tokens, $args ); |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Saves a token for this gateway. |
|
225 | + * |
|
226 | + * @since 1.0.19 |
|
227 | + */ |
|
228 | + public function save_token( $token ) { |
|
164 | 229 | |
165 | - // Change the checkout button text. |
|
166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | - } |
|
169 | - |
|
170 | - // Check if a gateway is valid for a given currency. |
|
171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | - |
|
173 | - // Generate the transaction url. |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | - |
|
176 | - // Generate the subscription url. |
|
177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | - |
|
179 | - // Confirm payments. |
|
180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | - |
|
182 | - // Verify IPNs. |
|
183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Checks if this gateway is a given gateway. |
|
189 | - * |
|
190 | - * @since 1.0.19 |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function is( $gateway ) { |
|
194 | - return $gateway == $this->id; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns a users saved tokens for this gateway. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function get_tokens( $sandbox = null ) { |
|
204 | - |
|
205 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
206 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | - |
|
208 | - if ( is_array( $tokens ) ) { |
|
209 | - $this->tokens = $tokens; |
|
210 | - } |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | - return $this->tokens; |
|
216 | - } |
|
217 | - |
|
218 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
219 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | - |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Saves a token for this gateway. |
|
225 | - * |
|
226 | - * @since 1.0.19 |
|
227 | - */ |
|
228 | - public function save_token( $token ) { |
|
229 | - |
|
230 | - $tokens = $this->get_tokens(); |
|
231 | - $tokens[] = $token; |
|
232 | - |
|
233 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
234 | - |
|
235 | - $this->tokens = $tokens; |
|
236 | - |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Return the title for admin screens. |
|
241 | - * |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function get_method_title() { |
|
245 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Return the description for admin screens. |
|
250 | - * |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function get_method_description() { |
|
254 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Get the success url. |
|
259 | - * |
|
260 | - * @param WPInv_Invoice $invoice Invoice object. |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function get_return_url( $invoice ) { |
|
264 | - |
|
265 | - // Payment success url |
|
266 | - $return_url = add_query_arg( |
|
267 | - array( |
|
268 | - 'payment-confirm' => $this->id, |
|
269 | - 'invoice_key' => $invoice->get_key(), |
|
270 | - 'utm_nooverride' => 1 |
|
271 | - ), |
|
272 | - wpinv_get_success_page_uri() |
|
273 | - ); |
|
274 | - |
|
275 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Confirms payments when rendering the success page. |
|
280 | - * |
|
281 | - * @param string $content Success page content. |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function get_confirm_payment( $content ) { |
|
230 | + $tokens = $this->get_tokens(); |
|
231 | + $tokens[] = $token; |
|
232 | + |
|
233 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
234 | + |
|
235 | + $this->tokens = $tokens; |
|
236 | + |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Return the title for admin screens. |
|
241 | + * |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function get_method_title() { |
|
245 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Return the description for admin screens. |
|
250 | + * |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function get_method_description() { |
|
254 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Get the success url. |
|
259 | + * |
|
260 | + * @param WPInv_Invoice $invoice Invoice object. |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function get_return_url( $invoice ) { |
|
264 | + |
|
265 | + // Payment success url |
|
266 | + $return_url = add_query_arg( |
|
267 | + array( |
|
268 | + 'payment-confirm' => $this->id, |
|
269 | + 'invoice_key' => $invoice->get_key(), |
|
270 | + 'utm_nooverride' => 1 |
|
271 | + ), |
|
272 | + wpinv_get_success_page_uri() |
|
273 | + ); |
|
274 | + |
|
275 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Confirms payments when rendering the success page. |
|
280 | + * |
|
281 | + * @param string $content Success page content. |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function get_confirm_payment( $content ) { |
|
285 | 285 | |
286 | - // Retrieve the invoice. |
|
287 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
286 | + // Retrieve the invoice. |
|
287 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
288 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | 289 | |
290 | - // Ensure that it exists and that it is pending payment. |
|
291 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
292 | - return $content; |
|
293 | - } |
|
290 | + // Ensure that it exists and that it is pending payment. |
|
291 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
292 | + return $content; |
|
293 | + } |
|
294 | 294 | |
295 | - // Can the user view this invoice?? |
|
296 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
297 | - return $content; |
|
298 | - } |
|
295 | + // Can the user view this invoice?? |
|
296 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
297 | + return $content; |
|
298 | + } |
|
299 | 299 | |
300 | - // Show payment processing indicator. |
|
301 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Processes ipns and marks payments as complete. |
|
306 | - * |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - public function verify_ipn() {} |
|
310 | - |
|
311 | - /** |
|
312 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
313 | - * |
|
314 | - * @param string $transaction_url transaction url. |
|
315 | - * @param WPInv_Invoice $invoice Invoice object. |
|
316 | - * @return string transaction URL, or empty string. |
|
317 | - */ |
|
318 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
319 | - |
|
320 | - $transaction_id = $invoice->get_transaction_id(); |
|
321 | - |
|
322 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
323 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
324 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
325 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
326 | - } |
|
327 | - |
|
328 | - return $transaction_url; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
333 | - * |
|
334 | - * @param string $subscription_url transaction url. |
|
335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
336 | - * @return string subscription URL, or empty string. |
|
337 | - */ |
|
338 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
339 | - |
|
340 | - $profile_id = $invoice->get_subscription_id(); |
|
341 | - |
|
342 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
343 | - |
|
344 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
345 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
346 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
347 | - |
|
348 | - } |
|
349 | - |
|
350 | - return $subscription_url; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Check if the gateway is available for use. |
|
355 | - * |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - public function is_available() { |
|
359 | - return ! empty( $this->enabled ); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Return the gateway's title. |
|
364 | - * |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_title() { |
|
368 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Return the gateway's description. |
|
373 | - * |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function get_description() { |
|
377 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Process Payment. |
|
382 | - * |
|
383 | - * |
|
384 | - * @param WPInv_Invoice $invoice Invoice. |
|
385 | - * @param array $submission_data Posted checkout fields. |
|
386 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
387 | - * @return void |
|
388 | - */ |
|
389 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
390 | - // Process the payment then either redirect to the success page or the gateway. |
|
391 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Process refund. |
|
396 | - * |
|
397 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
398 | - * a passed in amount. |
|
399 | - * |
|
400 | - * @param WPInv_Invoice $invoice Invoice. |
|
401 | - * @param float $amount Refund amount. |
|
402 | - * @param string $reason Refund reason. |
|
403 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
404 | - */ |
|
405 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
406 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Displays the payment fields, credit cards etc. |
|
411 | - * |
|
412 | - * @param int $invoice_id 0 or invoice id. |
|
413 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
414 | - */ |
|
415 | - public function payment_fields( $invoice_id, $form ) { |
|
416 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Filters the gateway settings. |
|
421 | - * |
|
422 | - * @param array $admin_settings |
|
423 | - */ |
|
424 | - public function admin_settings( $admin_settings ) { |
|
425 | - return $admin_settings; |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Retrieves the value of a gateway setting. |
|
430 | - * |
|
431 | - * @param string $option |
|
432 | - */ |
|
433 | - public function get_option( $option, $default = false ) { |
|
434 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Check if a gateway supports a given feature. |
|
439 | - * |
|
440 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
441 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
442 | - * |
|
443 | - * @param string $feature string The name of a feature to test support for. |
|
444 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
445 | - * @since 1.0.19 |
|
446 | - */ |
|
447 | - public function supports( $feature ) { |
|
448 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Returns the credit card form html. |
|
453 | - * |
|
454 | - * @param bool $save whether or not to display the save button. |
|
455 | - */ |
|
300 | + // Show payment processing indicator. |
|
301 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Processes ipns and marks payments as complete. |
|
306 | + * |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + public function verify_ipn() {} |
|
310 | + |
|
311 | + /** |
|
312 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
313 | + * |
|
314 | + * @param string $transaction_url transaction url. |
|
315 | + * @param WPInv_Invoice $invoice Invoice object. |
|
316 | + * @return string transaction URL, or empty string. |
|
317 | + */ |
|
318 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
319 | + |
|
320 | + $transaction_id = $invoice->get_transaction_id(); |
|
321 | + |
|
322 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
323 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
324 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
325 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
326 | + } |
|
327 | + |
|
328 | + return $transaction_url; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
333 | + * |
|
334 | + * @param string $subscription_url transaction url. |
|
335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
336 | + * @return string subscription URL, or empty string. |
|
337 | + */ |
|
338 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
339 | + |
|
340 | + $profile_id = $invoice->get_subscription_id(); |
|
341 | + |
|
342 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
343 | + |
|
344 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
345 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
346 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
347 | + |
|
348 | + } |
|
349 | + |
|
350 | + return $subscription_url; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Check if the gateway is available for use. |
|
355 | + * |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + public function is_available() { |
|
359 | + return ! empty( $this->enabled ); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Return the gateway's title. |
|
364 | + * |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_title() { |
|
368 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Return the gateway's description. |
|
373 | + * |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function get_description() { |
|
377 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Process Payment. |
|
382 | + * |
|
383 | + * |
|
384 | + * @param WPInv_Invoice $invoice Invoice. |
|
385 | + * @param array $submission_data Posted checkout fields. |
|
386 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
387 | + * @return void |
|
388 | + */ |
|
389 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
390 | + // Process the payment then either redirect to the success page or the gateway. |
|
391 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Process refund. |
|
396 | + * |
|
397 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
398 | + * a passed in amount. |
|
399 | + * |
|
400 | + * @param WPInv_Invoice $invoice Invoice. |
|
401 | + * @param float $amount Refund amount. |
|
402 | + * @param string $reason Refund reason. |
|
403 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
404 | + */ |
|
405 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
406 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Displays the payment fields, credit cards etc. |
|
411 | + * |
|
412 | + * @param int $invoice_id 0 or invoice id. |
|
413 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
414 | + */ |
|
415 | + public function payment_fields( $invoice_id, $form ) { |
|
416 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Filters the gateway settings. |
|
421 | + * |
|
422 | + * @param array $admin_settings |
|
423 | + */ |
|
424 | + public function admin_settings( $admin_settings ) { |
|
425 | + return $admin_settings; |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Retrieves the value of a gateway setting. |
|
430 | + * |
|
431 | + * @param string $option |
|
432 | + */ |
|
433 | + public function get_option( $option, $default = false ) { |
|
434 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Check if a gateway supports a given feature. |
|
439 | + * |
|
440 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
441 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
442 | + * |
|
443 | + * @param string $feature string The name of a feature to test support for. |
|
444 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
445 | + * @since 1.0.19 |
|
446 | + */ |
|
447 | + public function supports( $feature ) { |
|
448 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Returns the credit card form html. |
|
453 | + * |
|
454 | + * @param bool $save whether or not to display the save button. |
|
455 | + */ |
|
456 | 456 | public function get_cc_form( $save = false ) { |
457 | 457 | |
458 | - ob_start(); |
|
458 | + ob_start(); |
|
459 | 459 | |
460 | 460 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
461 | 461 | |
@@ -561,175 +561,175 @@ discard block |
||
561 | 561 | |
562 | 562 | <?php |
563 | 563 | |
564 | - if ( $save ) { |
|
565 | - echo $this->save_payment_method_checkbox(); |
|
566 | - } |
|
564 | + if ( $save ) { |
|
565 | + echo $this->save_payment_method_checkbox(); |
|
566 | + } |
|
567 | 567 | |
568 | - ?> |
|
568 | + ?> |
|
569 | 569 | </div> |
570 | 570 | |
571 | 571 | </div> |
572 | 572 | <?php |
573 | 573 | |
574 | - return ob_get_clean(); |
|
574 | + return ob_get_clean(); |
|
575 | + |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Displays a new payment method entry form. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + */ |
|
583 | + public function new_payment_method_entry( $form ) { |
|
584 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Grab and display our saved payment methods. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + */ |
|
592 | + public function saved_payment_methods() { |
|
593 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
594 | + |
|
595 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
596 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
597 | + } |
|
575 | 598 | |
599 | + $html .= $this->get_new_payment_method_option_html(); |
|
600 | + $html .= '</ul>'; |
|
601 | + |
|
602 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
576 | 603 | } |
577 | 604 | |
578 | - /** |
|
579 | - * Displays a new payment method entry form. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - */ |
|
583 | - public function new_payment_method_entry( $form ) { |
|
584 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Grab and display our saved payment methods. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - */ |
|
592 | - public function saved_payment_methods() { |
|
593 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
594 | - |
|
595 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
596 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
597 | - } |
|
598 | - |
|
599 | - $html .= $this->get_new_payment_method_option_html(); |
|
600 | - $html .= '</ul>'; |
|
601 | - |
|
602 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Gets saved payment method HTML from a token. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param array $token Payment Token. |
|
610 | - * @return string Generated payment method HTML |
|
611 | - */ |
|
612 | - public function get_saved_payment_method_option_html( $token ) { |
|
613 | - |
|
614 | - return sprintf( |
|
615 | - '<li class="getpaid-payment-method form-group"> |
|
605 | + /** |
|
606 | + * Gets saved payment method HTML from a token. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param array $token Payment Token. |
|
610 | + * @return string Generated payment method HTML |
|
611 | + */ |
|
612 | + public function get_saved_payment_method_option_html( $token ) { |
|
613 | + |
|
614 | + return sprintf( |
|
615 | + '<li class="getpaid-payment-method form-group"> |
|
616 | 616 | <label> |
617 | 617 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
618 | 618 | <span>%3$s</span> |
619 | 619 | </label> |
620 | 620 | </li>', |
621 | - esc_attr( $this->id ), |
|
622 | - esc_attr( $token['id'] ), |
|
623 | - esc_html( $token['name'] ), |
|
624 | - checked( empty( $token['default'] ), false, false ) |
|
625 | - ); |
|
621 | + esc_attr( $this->id ), |
|
622 | + esc_attr( $token['id'] ), |
|
623 | + esc_html( $token['name'] ), |
|
624 | + checked( empty( $token['default'] ), false, false ) |
|
625 | + ); |
|
626 | 626 | |
627 | - } |
|
627 | + } |
|
628 | 628 | |
629 | - /** |
|
630 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
631 | - * |
|
632 | - * @since 1.0.19 |
|
633 | - */ |
|
634 | - public function get_new_payment_method_option_html() { |
|
629 | + /** |
|
630 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
631 | + * |
|
632 | + * @since 1.0.19 |
|
633 | + */ |
|
634 | + public function get_new_payment_method_option_html() { |
|
635 | 635 | |
636 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
636 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
637 | 637 | |
638 | - return sprintf( |
|
639 | - '<li class="getpaid-new-payment-method"> |
|
638 | + return sprintf( |
|
639 | + '<li class="getpaid-new-payment-method"> |
|
640 | 640 | <label> |
641 | 641 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
642 | 642 | <span>%2$s</span> |
643 | 643 | </label> |
644 | 644 | </li>', |
645 | - esc_attr( $this->id ), |
|
646 | - esc_html( $label ) |
|
647 | - ); |
|
645 | + esc_attr( $this->id ), |
|
646 | + esc_html( $label ) |
|
647 | + ); |
|
648 | 648 | |
649 | - } |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
652 | - * Outputs a checkbox for saving a new payment method to the database. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - */ |
|
656 | - public function save_payment_method_checkbox() { |
|
651 | + /** |
|
652 | + * Outputs a checkbox for saving a new payment method to the database. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + */ |
|
656 | + public function save_payment_method_checkbox() { |
|
657 | 657 | |
658 | - return sprintf( |
|
659 | - '<p class="form-group getpaid-save-payment-method"> |
|
658 | + return sprintf( |
|
659 | + '<p class="form-group getpaid-save-payment-method"> |
|
660 | 660 | <label> |
661 | 661 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
662 | 662 | <span>%2$s</span> |
663 | 663 | </label> |
664 | 664 | </p>', |
665 | - esc_attr( $this->id ), |
|
666 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
667 | - ); |
|
665 | + esc_attr( $this->id ), |
|
666 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
667 | + ); |
|
668 | 668 | |
669 | - } |
|
669 | + } |
|
670 | 670 | |
671 | - /** |
|
672 | - * Registers the gateway. |
|
673 | - * |
|
674 | - * @return array |
|
675 | - */ |
|
676 | - public function register_gateway( $gateways ) { |
|
671 | + /** |
|
672 | + * Registers the gateway. |
|
673 | + * |
|
674 | + * @return array |
|
675 | + */ |
|
676 | + public function register_gateway( $gateways ) { |
|
677 | 677 | |
678 | - $gateways[ $this->id ] = array( |
|
678 | + $gateways[ $this->id ] = array( |
|
679 | 679 | |
680 | - 'admin_label' => $this->method_title, |
|
680 | + 'admin_label' => $this->method_title, |
|
681 | 681 | 'checkout_label' => $this->title, |
682 | - 'ordering' => $this->order, |
|
683 | - |
|
684 | - ); |
|
685 | - |
|
686 | - return $gateways; |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Checks whether or not this is a sandbox request. |
|
692 | - * |
|
693 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
694 | - * @return bool |
|
695 | - */ |
|
696 | - public function is_sandbox( $invoice = null ) { |
|
697 | - |
|
698 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
699 | - return $invoice->get_mode() == 'test'; |
|
700 | - } |
|
701 | - |
|
702 | - return wpinv_is_test_mode( $this->id ); |
|
703 | - |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Renames the checkout button |
|
708 | - * |
|
709 | - * @return string |
|
710 | - */ |
|
711 | - public function rename_checkout_button() { |
|
712 | - return $this->checkout_button_text; |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Validate gateway currency |
|
717 | - * |
|
718 | - * @return bool |
|
719 | - */ |
|
720 | - public function validate_currency( $validation, $currency ) { |
|
721 | - |
|
722 | - // Required currencies. |
|
723 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
724 | - return false; |
|
725 | - } |
|
726 | - |
|
727 | - // Excluded currencies. |
|
728 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
729 | - return false; |
|
730 | - } |
|
731 | - |
|
732 | - return $validation; |
|
733 | - } |
|
682 | + 'ordering' => $this->order, |
|
683 | + |
|
684 | + ); |
|
685 | + |
|
686 | + return $gateways; |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Checks whether or not this is a sandbox request. |
|
692 | + * |
|
693 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
694 | + * @return bool |
|
695 | + */ |
|
696 | + public function is_sandbox( $invoice = null ) { |
|
697 | + |
|
698 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
699 | + return $invoice->get_mode() == 'test'; |
|
700 | + } |
|
701 | + |
|
702 | + return wpinv_is_test_mode( $this->id ); |
|
703 | + |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * Renames the checkout button |
|
708 | + * |
|
709 | + * @return string |
|
710 | + */ |
|
711 | + public function rename_checkout_button() { |
|
712 | + return $this->checkout_button_text; |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Validate gateway currency |
|
717 | + * |
|
718 | + * @return bool |
|
719 | + */ |
|
720 | + public function validate_currency( $validation, $currency ) { |
|
721 | + |
|
722 | + // Required currencies. |
|
723 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
724 | + return false; |
|
725 | + } |
|
726 | + |
|
727 | + // Excluded currencies. |
|
728 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
729 | + return false; |
|
730 | + } |
|
731 | + |
|
732 | + return $validation; |
|
733 | + } |
|
734 | 734 | |
735 | 735 | } |
@@ -14,508 +14,508 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
94 | - $this->tax = new WPInv_EUVat(); |
|
95 | - $this->tax->init(); |
|
96 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
97 | - |
|
98 | - // Init other objects. |
|
99 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
100 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
101 | - $this->set( 'notes', new WPInv_Notes() ); |
|
102 | - $this->set( 'api', new WPInv_API() ); |
|
103 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
104 | - $this->set( 'template', new GetPaid_Template() ); |
|
105 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Define plugin constants. |
|
110 | - */ |
|
111 | - public function define_constants() { |
|
112 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
113 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
114 | - $this->version = WPINV_VERSION; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Hook into actions and filters. |
|
119 | - * |
|
120 | - * @since 1.0.19 |
|
121 | - */ |
|
122 | - protected function init_hooks() { |
|
123 | - /* Internationalize the text strings used. */ |
|
124 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
125 | - |
|
126 | - // Init the plugin after WordPress inits. |
|
127 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
128 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
129 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
130 | - |
|
131 | - if ( class_exists( 'BuddyPress' ) ) { |
|
132 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
133 | - } |
|
134 | - |
|
135 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
136 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
137 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
138 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
139 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
140 | - |
|
141 | - // Fires after registering actions. |
|
142 | - do_action( 'wpinv_actions', $this ); |
|
143 | - do_action( 'getpaid_actions', $this ); |
|
144 | - |
|
145 | - } |
|
146 | - |
|
147 | - public function plugins_loaded() { |
|
148 | - /* Internationalize the text strings used. */ |
|
149 | - $this->load_textdomain(); |
|
150 | - |
|
151 | - do_action( 'wpinv_loaded' ); |
|
152 | - |
|
153 | - // Fix oxygen page builder conflict |
|
154 | - if ( function_exists( 'ct_css_output' ) ) { |
|
155 | - wpinv_oxygen_fix_conflict(); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Load the translation of the plugin. |
|
161 | - * |
|
162 | - * @since 1.0 |
|
163 | - */ |
|
164 | - public function load_textdomain( $locale = NULL ) { |
|
165 | - if ( empty( $locale ) ) { |
|
166 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
167 | - } |
|
168 | - |
|
169 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
170 | - |
|
171 | - unload_textdomain( 'invoicing' ); |
|
172 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
173 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
174 | - |
|
175 | - /** |
|
176 | - * Define language constants. |
|
177 | - */ |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Include required core files used in admin and on the frontend. |
|
183 | - */ |
|
184 | - public function includes() { |
|
185 | - |
|
186 | - // Start with the settings. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
188 | - |
|
189 | - // Packages/libraries. |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
193 | - |
|
194 | - // Load functions. |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
209 | - |
|
210 | - // Register autoloader. |
|
211 | - try { |
|
212 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
213 | - } catch ( Exception $e ) { |
|
214 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
215 | - } |
|
216 | - |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
240 | - |
|
241 | - /** |
|
242 | - * Load the tax class. |
|
243 | - */ |
|
244 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
245 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
246 | - } |
|
247 | - |
|
248 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
249 | - if ( !empty( $gateways ) ) { |
|
250 | - foreach ( $gateways as $gateway ) { |
|
251 | - if ( $gateway == 'manual' ) { |
|
252 | - continue; |
|
253 | - } |
|
254 | - |
|
255 | - $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
256 | - |
|
257 | - if ( file_exists( $gateway_file ) ) { |
|
258 | - require_once( $gateway_file ); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
264 | - GetPaid_Post_Types_Admin::init(); |
|
265 | - |
|
266 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
267 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
268 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
269 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
270 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
271 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
273 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
274 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
275 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
276 | - // load the user class only on the users.php page |
|
277 | - global $pagenow; |
|
278 | - if($pagenow=='users.php'){ |
|
279 | - new WPInv_Admin_Users(); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - // Register cli commands |
|
284 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
285 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
286 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
287 | - } |
|
288 | - |
|
289 | - // include css inliner |
|
290 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
291 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
292 | - } |
|
293 | - |
|
294 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Class autoloader |
|
299 | - * |
|
300 | - * @param string $class_name The name of the class to load. |
|
301 | - * @access public |
|
302 | - * @since 1.0.19 |
|
303 | - * @return void |
|
304 | - */ |
|
305 | - public function autoload( $class_name ) { |
|
306 | - |
|
307 | - // Normalize the class name... |
|
308 | - $class_name = strtolower( $class_name ); |
|
309 | - |
|
310 | - // ... and make sure it is our class. |
|
311 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
312 | - return; |
|
313 | - } |
|
314 | - |
|
315 | - // Next, prepare the file name from the class. |
|
316 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
317 | - |
|
318 | - // Base path of the classes. |
|
319 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
320 | - |
|
321 | - // And an array of possible locations in order of importance. |
|
322 | - $locations = array( |
|
323 | - "$plugin_path/includes", |
|
324 | - "$plugin_path/includes/data-stores", |
|
325 | - "$plugin_path/includes/gateways", |
|
326 | - "$plugin_path/includes/api", |
|
327 | - "$plugin_path/includes/admin", |
|
328 | - "$plugin_path/includes/admin/meta-boxes", |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
332 | - |
|
333 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
334 | - include trailingslashit( $location ) . $file_name; |
|
335 | - break; |
|
336 | - } |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Inits hooks etc. |
|
344 | - */ |
|
345 | - public function init() { |
|
346 | - |
|
347 | - // Fires before getpaid inits. |
|
348 | - do_action( 'before_getpaid_init', $this ); |
|
349 | - |
|
350 | - // Load default gateways. |
|
351 | - $gateways = apply_filters( |
|
352 | - 'getpaid_default_gateways', |
|
353 | - array( |
|
354 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
355 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
356 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
357 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
358 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
359 | - ) |
|
360 | - ); |
|
361 | - |
|
362 | - foreach ( $gateways as $id => $class ) { |
|
363 | - $this->gateways[ $id ] = new $class(); |
|
364 | - } |
|
365 | - |
|
366 | - // Fires after getpaid inits. |
|
367 | - do_action( 'getpaid_init', $this ); |
|
368 | - |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Checks if this is an IPN request and processes it. |
|
373 | - */ |
|
374 | - public function maybe_process_ipn() { |
|
375 | - |
|
376 | - // Ensure that this is an IPN request. |
|
377 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
378 | - return; |
|
379 | - } |
|
380 | - |
|
381 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
382 | - |
|
383 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
384 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
385 | - exit; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - public function enqueue_scripts() { |
|
390 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
391 | - |
|
392 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
393 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
394 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
395 | - |
|
396 | - // Register scripts |
|
397 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
398 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
399 | - |
|
400 | - $localize = array(); |
|
401 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
402 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
403 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
404 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
405 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
406 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
407 | - $localize['decimals'] = wpinv_decimals(); |
|
408 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
409 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
410 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
411 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
412 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
413 | - |
|
414 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
415 | - |
|
416 | - wp_enqueue_script( 'jquery-blockui' ); |
|
417 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
418 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
419 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
420 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
421 | - wp_dequeue_script( 'google-maps-api' ); |
|
422 | - } |
|
423 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
424 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
425 | - } |
|
426 | - |
|
427 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
428 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
429 | - |
|
430 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
431 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
432 | - |
|
433 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
434 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
435 | - } |
|
436 | - |
|
437 | - public function wpinv_actions() { |
|
438 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
439 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - public function pre_get_posts( $wp_query ) { |
|
444 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
445 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
446 | - } |
|
447 | - |
|
448 | - return $wp_query; |
|
449 | - } |
|
450 | - |
|
451 | - public function bp_invoicing_init() { |
|
452 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Register widgets |
|
457 | - * |
|
458 | - */ |
|
459 | - public function register_widgets() { |
|
460 | - $widgets = apply_filters( |
|
461 | - 'getpaid_widget_classes', |
|
462 | - array( |
|
463 | - 'WPInv_Checkout_Widget', |
|
464 | - 'WPInv_History_Widget', |
|
465 | - 'WPInv_Receipt_Widget', |
|
466 | - 'WPInv_Subscriptions_Widget', |
|
467 | - 'WPInv_Buy_Item_Widget', |
|
468 | - 'WPInv_Messages_Widget', |
|
469 | - 'WPInv_GetPaid_Widget' |
|
470 | - ) |
|
471 | - ); |
|
472 | - |
|
473 | - foreach ( $widgets as $widget ) { |
|
474 | - register_widget( $widget ); |
|
475 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
94 | + $this->tax = new WPInv_EUVat(); |
|
95 | + $this->tax->init(); |
|
96 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
97 | + |
|
98 | + // Init other objects. |
|
99 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
100 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
101 | + $this->set( 'notes', new WPInv_Notes() ); |
|
102 | + $this->set( 'api', new WPInv_API() ); |
|
103 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
104 | + $this->set( 'template', new GetPaid_Template() ); |
|
105 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Define plugin constants. |
|
110 | + */ |
|
111 | + public function define_constants() { |
|
112 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
113 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
114 | + $this->version = WPINV_VERSION; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Hook into actions and filters. |
|
119 | + * |
|
120 | + * @since 1.0.19 |
|
121 | + */ |
|
122 | + protected function init_hooks() { |
|
123 | + /* Internationalize the text strings used. */ |
|
124 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
125 | + |
|
126 | + // Init the plugin after WordPress inits. |
|
127 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
128 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
129 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
130 | + |
|
131 | + if ( class_exists( 'BuddyPress' ) ) { |
|
132 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
133 | + } |
|
134 | + |
|
135 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
136 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
137 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
138 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
139 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
140 | + |
|
141 | + // Fires after registering actions. |
|
142 | + do_action( 'wpinv_actions', $this ); |
|
143 | + do_action( 'getpaid_actions', $this ); |
|
144 | + |
|
145 | + } |
|
146 | + |
|
147 | + public function plugins_loaded() { |
|
148 | + /* Internationalize the text strings used. */ |
|
149 | + $this->load_textdomain(); |
|
150 | + |
|
151 | + do_action( 'wpinv_loaded' ); |
|
152 | + |
|
153 | + // Fix oxygen page builder conflict |
|
154 | + if ( function_exists( 'ct_css_output' ) ) { |
|
155 | + wpinv_oxygen_fix_conflict(); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Load the translation of the plugin. |
|
161 | + * |
|
162 | + * @since 1.0 |
|
163 | + */ |
|
164 | + public function load_textdomain( $locale = NULL ) { |
|
165 | + if ( empty( $locale ) ) { |
|
166 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
167 | + } |
|
168 | + |
|
169 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
170 | + |
|
171 | + unload_textdomain( 'invoicing' ); |
|
172 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
173 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
174 | + |
|
175 | + /** |
|
176 | + * Define language constants. |
|
177 | + */ |
|
178 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Include required core files used in admin and on the frontend. |
|
183 | + */ |
|
184 | + public function includes() { |
|
185 | + |
|
186 | + // Start with the settings. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
188 | + |
|
189 | + // Packages/libraries. |
|
190 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
193 | + |
|
194 | + // Load functions. |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
209 | + |
|
210 | + // Register autoloader. |
|
211 | + try { |
|
212 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
213 | + } catch ( Exception $e ) { |
|
214 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
215 | + } |
|
216 | + |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
240 | + |
|
241 | + /** |
|
242 | + * Load the tax class. |
|
243 | + */ |
|
244 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
245 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
246 | + } |
|
247 | + |
|
248 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
249 | + if ( !empty( $gateways ) ) { |
|
250 | + foreach ( $gateways as $gateway ) { |
|
251 | + if ( $gateway == 'manual' ) { |
|
252 | + continue; |
|
253 | + } |
|
254 | + |
|
255 | + $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
256 | + |
|
257 | + if ( file_exists( $gateway_file ) ) { |
|
258 | + require_once( $gateway_file ); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
264 | + GetPaid_Post_Types_Admin::init(); |
|
265 | + |
|
266 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
267 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
268 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
269 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
270 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
271 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
273 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
274 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
275 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
276 | + // load the user class only on the users.php page |
|
277 | + global $pagenow; |
|
278 | + if($pagenow=='users.php'){ |
|
279 | + new WPInv_Admin_Users(); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + // Register cli commands |
|
284 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
285 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
286 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
287 | + } |
|
288 | + |
|
289 | + // include css inliner |
|
290 | + if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
291 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
292 | + } |
|
293 | + |
|
294 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Class autoloader |
|
299 | + * |
|
300 | + * @param string $class_name The name of the class to load. |
|
301 | + * @access public |
|
302 | + * @since 1.0.19 |
|
303 | + * @return void |
|
304 | + */ |
|
305 | + public function autoload( $class_name ) { |
|
306 | + |
|
307 | + // Normalize the class name... |
|
308 | + $class_name = strtolower( $class_name ); |
|
309 | + |
|
310 | + // ... and make sure it is our class. |
|
311 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
312 | + return; |
|
313 | + } |
|
314 | + |
|
315 | + // Next, prepare the file name from the class. |
|
316 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
317 | + |
|
318 | + // Base path of the classes. |
|
319 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
320 | + |
|
321 | + // And an array of possible locations in order of importance. |
|
322 | + $locations = array( |
|
323 | + "$plugin_path/includes", |
|
324 | + "$plugin_path/includes/data-stores", |
|
325 | + "$plugin_path/includes/gateways", |
|
326 | + "$plugin_path/includes/api", |
|
327 | + "$plugin_path/includes/admin", |
|
328 | + "$plugin_path/includes/admin/meta-boxes", |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
332 | + |
|
333 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
334 | + include trailingslashit( $location ) . $file_name; |
|
335 | + break; |
|
336 | + } |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Inits hooks etc. |
|
344 | + */ |
|
345 | + public function init() { |
|
346 | + |
|
347 | + // Fires before getpaid inits. |
|
348 | + do_action( 'before_getpaid_init', $this ); |
|
349 | + |
|
350 | + // Load default gateways. |
|
351 | + $gateways = apply_filters( |
|
352 | + 'getpaid_default_gateways', |
|
353 | + array( |
|
354 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
355 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
356 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
357 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
358 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
359 | + ) |
|
360 | + ); |
|
361 | + |
|
362 | + foreach ( $gateways as $id => $class ) { |
|
363 | + $this->gateways[ $id ] = new $class(); |
|
364 | + } |
|
365 | + |
|
366 | + // Fires after getpaid inits. |
|
367 | + do_action( 'getpaid_init', $this ); |
|
368 | + |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Checks if this is an IPN request and processes it. |
|
373 | + */ |
|
374 | + public function maybe_process_ipn() { |
|
375 | + |
|
376 | + // Ensure that this is an IPN request. |
|
377 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
378 | + return; |
|
379 | + } |
|
380 | + |
|
381 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
382 | + |
|
383 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
384 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
385 | + exit; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + public function enqueue_scripts() { |
|
390 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
391 | + |
|
392 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
393 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
394 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
395 | + |
|
396 | + // Register scripts |
|
397 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
398 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
399 | + |
|
400 | + $localize = array(); |
|
401 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
402 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
403 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
404 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
405 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
406 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
407 | + $localize['decimals'] = wpinv_decimals(); |
|
408 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
409 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
410 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
411 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
412 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
413 | + |
|
414 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
415 | + |
|
416 | + wp_enqueue_script( 'jquery-blockui' ); |
|
417 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
418 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
419 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
420 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
421 | + wp_dequeue_script( 'google-maps-api' ); |
|
422 | + } |
|
423 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
424 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
425 | + } |
|
426 | + |
|
427 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
428 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
429 | + |
|
430 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
431 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
432 | + |
|
433 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
434 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
435 | + } |
|
436 | + |
|
437 | + public function wpinv_actions() { |
|
438 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
439 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + public function pre_get_posts( $wp_query ) { |
|
444 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
445 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
446 | + } |
|
447 | + |
|
448 | + return $wp_query; |
|
449 | + } |
|
450 | + |
|
451 | + public function bp_invoicing_init() { |
|
452 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Register widgets |
|
457 | + * |
|
458 | + */ |
|
459 | + public function register_widgets() { |
|
460 | + $widgets = apply_filters( |
|
461 | + 'getpaid_widget_classes', |
|
462 | + array( |
|
463 | + 'WPInv_Checkout_Widget', |
|
464 | + 'WPInv_History_Widget', |
|
465 | + 'WPInv_Receipt_Widget', |
|
466 | + 'WPInv_Subscriptions_Widget', |
|
467 | + 'WPInv_Buy_Item_Widget', |
|
468 | + 'WPInv_Messages_Widget', |
|
469 | + 'WPInv_GetPaid_Widget' |
|
470 | + ) |
|
471 | + ); |
|
472 | + |
|
473 | + foreach ( $widgets as $widget ) { |
|
474 | + register_widget( $widget ); |
|
475 | + } |
|
476 | 476 | |
477 | - } |
|
477 | + } |
|
478 | 478 | |
479 | - /** |
|
480 | - * Remove our pages from yoast sitemaps. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - * @param int[] $excluded_posts_ids |
|
484 | - */ |
|
485 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
479 | + /** |
|
480 | + * Remove our pages from yoast sitemaps. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + * @param int[] $excluded_posts_ids |
|
484 | + */ |
|
485 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
486 | 486 | |
487 | - // Ensure that we have an array. |
|
488 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
489 | - $excluded_posts_ids = array(); |
|
490 | - } |
|
487 | + // Ensure that we have an array. |
|
488 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
489 | + $excluded_posts_ids = array(); |
|
490 | + } |
|
491 | 491 | |
492 | - // Prepare our pages. |
|
493 | - $our_pages = array(); |
|
492 | + // Prepare our pages. |
|
493 | + $our_pages = array(); |
|
494 | 494 | |
495 | - // Checkout page. |
|
496 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
495 | + // Checkout page. |
|
496 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
497 | 497 | |
498 | - // Success page. |
|
499 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
498 | + // Success page. |
|
499 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
500 | 500 | |
501 | - // Failure page. |
|
502 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
501 | + // Failure page. |
|
502 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
503 | 503 | |
504 | - // History page. |
|
505 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
504 | + // History page. |
|
505 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
506 | 506 | |
507 | - // Subscriptions page. |
|
508 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
507 | + // Subscriptions page. |
|
508 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
509 | 509 | |
510 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
510 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
511 | 511 | |
512 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
513 | - return array_unique( $excluded_posts_ids ); |
|
512 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
513 | + return array_unique( $excluded_posts_ids ); |
|
514 | 514 | |
515 | - } |
|
515 | + } |
|
516 | 516 | |
517 | - public function wp_footer() { |
|
518 | - echo ' |
|
517 | + public function wp_footer() { |
|
518 | + echo ' |
|
519 | 519 | <div class="bsui"> |
520 | 520 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
521 | 521 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -526,6 +526,6 @@ discard block |
||
526 | 526 | </div> |
527 | 527 | </div> |
528 | 528 | '; |
529 | - } |
|
529 | + } |
|
530 | 530 | |
531 | 531 | } |
@@ -15,127 +15,127 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => null, |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - private $subs_db; |
|
66 | - |
|
67 | - /** |
|
68 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
69 | - * |
|
70 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
71 | - * @param bool $deprecated |
|
72 | - */ |
|
73 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
74 | - |
|
75 | - parent::__construct( $subscription ); |
|
76 | - |
|
77 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
78 | - $this->set_id( $subscription ); |
|
79 | - } elseif ( $subscription instanceof self ) { |
|
80 | - $this->set_id( $subscription->get_id() ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
84 | - $this->set_id( $subscription_id ); |
|
85 | - } else { |
|
86 | - $this->set_object_read( true ); |
|
87 | - } |
|
88 | - |
|
89 | - // Load the datastore. |
|
90 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
91 | - |
|
92 | - if ( $this->get_id() > 0 ) { |
|
93 | - $this->data_store->read( $this ); |
|
94 | - } |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
100 | - * |
|
101 | - * |
|
102 | - * @static |
|
103 | - * @param string $value |
|
104 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
105 | - * @since 1.0.19 |
|
106 | - * @return int |
|
107 | - */ |
|
108 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => null, |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + private $subs_db; |
|
66 | + |
|
67 | + /** |
|
68 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
69 | + * |
|
70 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
71 | + * @param bool $deprecated |
|
72 | + */ |
|
73 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
74 | + |
|
75 | + parent::__construct( $subscription ); |
|
76 | + |
|
77 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
78 | + $this->set_id( $subscription ); |
|
79 | + } elseif ( $subscription instanceof self ) { |
|
80 | + $this->set_id( $subscription->get_id() ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
84 | + $this->set_id( $subscription_id ); |
|
85 | + } else { |
|
86 | + $this->set_object_read( true ); |
|
87 | + } |
|
88 | + |
|
89 | + // Load the datastore. |
|
90 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
91 | + |
|
92 | + if ( $this->get_id() > 0 ) { |
|
93 | + $this->data_store->read( $this ); |
|
94 | + } |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
100 | + * |
|
101 | + * |
|
102 | + * @static |
|
103 | + * @param string $value |
|
104 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
105 | + * @since 1.0.19 |
|
106 | + * @return int |
|
107 | + */ |
|
108 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
109 | 109 | global $wpdb; |
110 | 110 | |
111 | - // Trim the value. |
|
112 | - $value = trim( $value ); |
|
111 | + // Trim the value. |
|
112 | + $value = trim( $value ); |
|
113 | 113 | |
114 | - if ( empty( $value ) ) { |
|
115 | - return 0; |
|
116 | - } |
|
114 | + if ( empty( $value ) ) { |
|
115 | + return 0; |
|
116 | + } |
|
117 | 117 | |
118 | - if ( 'invoice_id' == $field ) { |
|
119 | - $field = 'parent_payment_id'; |
|
120 | - } |
|
118 | + if ( 'invoice_id' == $field ) { |
|
119 | + $field = 'parent_payment_id'; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | // Valid fields. |
123 | 123 | $fields = array( |
124 | - 'parent_payment_id', |
|
125 | - 'transaction_id', |
|
126 | - 'profile_id' |
|
127 | - ); |
|
128 | - |
|
129 | - // Ensure a field has been passed. |
|
130 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
131 | - return 0; |
|
132 | - } |
|
133 | - |
|
134 | - // Maybe retrieve from the cache. |
|
135 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
136 | - if ( ! empty( $subscription_id ) ) { |
|
137 | - return $subscription_id; |
|
138 | - } |
|
124 | + 'parent_payment_id', |
|
125 | + 'transaction_id', |
|
126 | + 'profile_id' |
|
127 | + ); |
|
128 | + |
|
129 | + // Ensure a field has been passed. |
|
130 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
131 | + return 0; |
|
132 | + } |
|
133 | + |
|
134 | + // Maybe retrieve from the cache. |
|
135 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
136 | + if ( ! empty( $subscription_id ) ) { |
|
137 | + return $subscription_id; |
|
138 | + } |
|
139 | 139 | |
140 | 140 | // Fetch from the db. |
141 | 141 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -143,34 +143,34 @@ discard block |
||
143 | 143 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
144 | 144 | ); |
145 | 145 | |
146 | - if ( empty( $subscription_id ) ) { |
|
147 | - return 0; |
|
148 | - } |
|
146 | + if ( empty( $subscription_id ) ) { |
|
147 | + return 0; |
|
148 | + } |
|
149 | 149 | |
150 | - // Update the cache with our data. |
|
151 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | + // Update the cache with our data. |
|
151 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
152 | 152 | |
153 | - return $subscription_id; |
|
154 | - } |
|
153 | + return $subscription_id; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
156 | + /** |
|
157 | 157 | * Clears the subscription's cache. |
158 | 158 | */ |
159 | 159 | public function clear_cache() { |
160 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
162 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
163 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
164 | - } |
|
160 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
161 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
162 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
163 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
166 | + /** |
|
167 | 167 | * Checks if a subscription key is set. |
168 | 168 | */ |
169 | 169 | public function _isset( $key ) { |
170 | 170 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | - /* |
|
173 | + /* |
|
174 | 174 | |-------------------------------------------------------------------------- |
175 | 175 | | CRUD methods |
176 | 176 | |-------------------------------------------------------------------------- |
@@ -179,57 +179,57 @@ discard block |
||
179 | 179 | | |
180 | 180 | */ |
181 | 181 | |
182 | - /* |
|
182 | + /* |
|
183 | 183 | |-------------------------------------------------------------------------- |
184 | 184 | | Getters |
185 | 185 | |-------------------------------------------------------------------------- |
186 | 186 | */ |
187 | 187 | |
188 | - /** |
|
189 | - * Get customer id. |
|
190 | - * |
|
191 | - * @since 1.0.19 |
|
192 | - * @param string $context View or edit context. |
|
193 | - * @return int |
|
194 | - */ |
|
195 | - public function get_customer_id( $context = 'view' ) { |
|
196 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Get customer information. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @param string $context View or edit context. |
|
204 | - * @return WP_User|false WP_User object on success, false on failure. |
|
205 | - */ |
|
206 | - public function get_customer( $context = 'view' ) { |
|
207 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Get parent invoice id. |
|
212 | - * |
|
213 | - * @since 1.0.19 |
|
214 | - * @param string $context View or edit context. |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
218 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Alias for self::get_parent_invoice_id(). |
|
223 | - * |
|
224 | - * @since 1.0.19 |
|
225 | - * @param string $context View or edit context. |
|
226 | - * @return int |
|
227 | - */ |
|
188 | + /** |
|
189 | + * Get customer id. |
|
190 | + * |
|
191 | + * @since 1.0.19 |
|
192 | + * @param string $context View or edit context. |
|
193 | + * @return int |
|
194 | + */ |
|
195 | + public function get_customer_id( $context = 'view' ) { |
|
196 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Get customer information. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @param string $context View or edit context. |
|
204 | + * @return WP_User|false WP_User object on success, false on failure. |
|
205 | + */ |
|
206 | + public function get_customer( $context = 'view' ) { |
|
207 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Get parent invoice id. |
|
212 | + * |
|
213 | + * @since 1.0.19 |
|
214 | + * @param string $context View or edit context. |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
218 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Alias for self::get_parent_invoice_id(). |
|
223 | + * |
|
224 | + * @since 1.0.19 |
|
225 | + * @param string $context View or edit context. |
|
226 | + * @return int |
|
227 | + */ |
|
228 | 228 | public function get_parent_payment_id( $context = 'view' ) { |
229 | 229 | return $this->get_parent_invoice_id( $context ); |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
232 | + /** |
|
233 | 233 | * Alias for self::get_parent_invoice_id(). |
234 | 234 | * |
235 | 235 | * @since 1.0.0 |
@@ -239,390 +239,390 @@ discard block |
||
239 | 239 | return $this->get_parent_invoice_id( $context ); |
240 | 240 | } |
241 | 241 | |
242 | - /** |
|
243 | - * Get parent invoice. |
|
244 | - * |
|
245 | - * @since 1.0.19 |
|
246 | - * @param string $context View or edit context. |
|
247 | - * @return WPInv_Invoice |
|
248 | - */ |
|
249 | - public function get_parent_invoice( $context = 'view' ) { |
|
250 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Alias for self::get_parent_invoice(). |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @param string $context View or edit context. |
|
258 | - * @return WPInv_Invoice |
|
259 | - */ |
|
242 | + /** |
|
243 | + * Get parent invoice. |
|
244 | + * |
|
245 | + * @since 1.0.19 |
|
246 | + * @param string $context View or edit context. |
|
247 | + * @return WPInv_Invoice |
|
248 | + */ |
|
249 | + public function get_parent_invoice( $context = 'view' ) { |
|
250 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Alias for self::get_parent_invoice(). |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @param string $context View or edit context. |
|
258 | + * @return WPInv_Invoice |
|
259 | + */ |
|
260 | 260 | public function get_parent_payment( $context = 'view' ) { |
261 | 261 | return $this->get_parent_invoice( $context ); |
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Get subscription's product id. |
|
266 | - * |
|
267 | - * @since 1.0.19 |
|
268 | - * @param string $context View or edit context. |
|
269 | - * @return int |
|
270 | - */ |
|
271 | - public function get_product_id( $context = 'view' ) { |
|
272 | - return (int) $this->get_prop( 'product_id', $context ); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Get the subscription product. |
|
277 | - * |
|
278 | - * @since 1.0.19 |
|
279 | - * @param string $context View or edit context. |
|
280 | - * @return WPInv_Item |
|
281 | - */ |
|
282 | - public function get_product( $context = 'view' ) { |
|
283 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Get parent invoice's gateway. |
|
288 | - * |
|
289 | - * Here for backwards compatibility. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return string |
|
294 | - */ |
|
295 | - public function get_gateway( $context = 'view' ) { |
|
296 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Get the period of a renewal. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return string |
|
305 | - */ |
|
306 | - public function get_period( $context = 'view' ) { |
|
307 | - return $this->get_prop( 'period', $context ); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get number of periods each renewal is valid for. |
|
312 | - * |
|
313 | - * @since 1.0.19 |
|
314 | - * @param string $context View or edit context. |
|
315 | - * @return int |
|
316 | - */ |
|
317 | - public function get_frequency( $context = 'view' ) { |
|
318 | - return (int) $this->get_prop( 'frequency', $context ); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Get the initial amount for the subscription. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @param string $context View or edit context. |
|
326 | - * @return float |
|
327 | - */ |
|
328 | - public function get_initial_amount( $context = 'view' ) { |
|
329 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Get the recurring amount for the subscription. |
|
334 | - * |
|
335 | - * @since 1.0.19 |
|
336 | - * @param string $context View or edit context. |
|
337 | - * @return float |
|
338 | - */ |
|
339 | - public function get_recurring_amount( $context = 'view' ) { |
|
340 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Get number of times that this subscription can be renewed. |
|
345 | - * |
|
346 | - * @since 1.0.19 |
|
347 | - * @param string $context View or edit context. |
|
348 | - * @return int |
|
349 | - */ |
|
350 | - public function get_bill_times( $context = 'view' ) { |
|
351 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Get transaction id of this subscription's parent invoice. |
|
356 | - * |
|
357 | - * @since 1.0.19 |
|
358 | - * @param string $context View or edit context. |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public function get_transaction_id( $context = 'view' ) { |
|
362 | - return $this->get_prop( 'transaction_id', $context ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Get the date that the subscription was created. |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @param string $context View or edit context. |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - public function get_created( $context = 'view' ) { |
|
373 | - return $this->get_prop( 'created', $context ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Alias for self::get_created(). |
|
378 | - * |
|
379 | - * @since 1.0.19 |
|
380 | - * @param string $context View or edit context. |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - public function get_date_created( $context = 'view' ) { |
|
384 | - return $this->get_created( $context ); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Retrieves the creation date in a timestamp |
|
389 | - * |
|
390 | - * @since 1.0.0 |
|
391 | - * @return int |
|
392 | - */ |
|
393 | - public function get_time_created() { |
|
394 | - $created = $this->get_date_created(); |
|
395 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Get GMT date when the subscription was created. |
|
400 | - * |
|
401 | - * @since 1.0.19 |
|
402 | - * @param string $context View or edit context. |
|
403 | - * @return string |
|
404 | - */ |
|
405 | - public function get_date_created_gmt( $context = 'view' ) { |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Get subscription's product id. |
|
266 | + * |
|
267 | + * @since 1.0.19 |
|
268 | + * @param string $context View or edit context. |
|
269 | + * @return int |
|
270 | + */ |
|
271 | + public function get_product_id( $context = 'view' ) { |
|
272 | + return (int) $this->get_prop( 'product_id', $context ); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Get the subscription product. |
|
277 | + * |
|
278 | + * @since 1.0.19 |
|
279 | + * @param string $context View or edit context. |
|
280 | + * @return WPInv_Item |
|
281 | + */ |
|
282 | + public function get_product( $context = 'view' ) { |
|
283 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Get parent invoice's gateway. |
|
288 | + * |
|
289 | + * Here for backwards compatibility. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return string |
|
294 | + */ |
|
295 | + public function get_gateway( $context = 'view' ) { |
|
296 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Get the period of a renewal. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + public function get_period( $context = 'view' ) { |
|
307 | + return $this->get_prop( 'period', $context ); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get number of periods each renewal is valid for. |
|
312 | + * |
|
313 | + * @since 1.0.19 |
|
314 | + * @param string $context View or edit context. |
|
315 | + * @return int |
|
316 | + */ |
|
317 | + public function get_frequency( $context = 'view' ) { |
|
318 | + return (int) $this->get_prop( 'frequency', $context ); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get the initial amount for the subscription. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @param string $context View or edit context. |
|
326 | + * @return float |
|
327 | + */ |
|
328 | + public function get_initial_amount( $context = 'view' ) { |
|
329 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Get the recurring amount for the subscription. |
|
334 | + * |
|
335 | + * @since 1.0.19 |
|
336 | + * @param string $context View or edit context. |
|
337 | + * @return float |
|
338 | + */ |
|
339 | + public function get_recurring_amount( $context = 'view' ) { |
|
340 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Get number of times that this subscription can be renewed. |
|
345 | + * |
|
346 | + * @since 1.0.19 |
|
347 | + * @param string $context View or edit context. |
|
348 | + * @return int |
|
349 | + */ |
|
350 | + public function get_bill_times( $context = 'view' ) { |
|
351 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Get transaction id of this subscription's parent invoice. |
|
356 | + * |
|
357 | + * @since 1.0.19 |
|
358 | + * @param string $context View or edit context. |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public function get_transaction_id( $context = 'view' ) { |
|
362 | + return $this->get_prop( 'transaction_id', $context ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Get the date that the subscription was created. |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @param string $context View or edit context. |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + public function get_created( $context = 'view' ) { |
|
373 | + return $this->get_prop( 'created', $context ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Alias for self::get_created(). |
|
378 | + * |
|
379 | + * @since 1.0.19 |
|
380 | + * @param string $context View or edit context. |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + public function get_date_created( $context = 'view' ) { |
|
384 | + return $this->get_created( $context ); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Retrieves the creation date in a timestamp |
|
389 | + * |
|
390 | + * @since 1.0.0 |
|
391 | + * @return int |
|
392 | + */ |
|
393 | + public function get_time_created() { |
|
394 | + $created = $this->get_date_created(); |
|
395 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Get GMT date when the subscription was created. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $context View or edit context. |
|
403 | + * @return string |
|
404 | + */ |
|
405 | + public function get_date_created_gmt( $context = 'view' ) { |
|
406 | 406 | $date = $this->get_date_created( $context ); |
407 | 407 | |
408 | 408 | if ( $date ) { |
409 | 409 | $date = get_gmt_from_date( $date ); |
410 | 410 | } |
411 | - return $date; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Get the date that the subscription will renew. |
|
416 | - * |
|
417 | - * @since 1.0.19 |
|
418 | - * @param string $context View or edit context. |
|
419 | - * @return string |
|
420 | - */ |
|
421 | - public function get_next_renewal_date( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'expiration', $context ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Alias for self::get_next_renewal_date(). |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * @param string $context View or edit context. |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - public function get_expiration( $context = 'view' ) { |
|
433 | - return $this->get_next_renewal_date( $context ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Retrieves the expiration date in a timestamp |
|
438 | - * |
|
439 | - * @since 1.0.0 |
|
440 | - * @return int |
|
441 | - */ |
|
442 | - public function get_expiration_time() { |
|
443 | - $expiration = $this->get_expiration(); |
|
444 | - |
|
445 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
446 | - return current_time( 'timestamp' ); |
|
447 | - } |
|
448 | - |
|
449 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
450 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Get GMT date when the subscription will renew. |
|
455 | - * |
|
456 | - * @since 1.0.19 |
|
457 | - * @param string $context View or edit context. |
|
458 | - * @return string |
|
459 | - */ |
|
460 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
411 | + return $date; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Get the date that the subscription will renew. |
|
416 | + * |
|
417 | + * @since 1.0.19 |
|
418 | + * @param string $context View or edit context. |
|
419 | + * @return string |
|
420 | + */ |
|
421 | + public function get_next_renewal_date( $context = 'view' ) { |
|
422 | + return $this->get_prop( 'expiration', $context ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Alias for self::get_next_renewal_date(). |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * @param string $context View or edit context. |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + public function get_expiration( $context = 'view' ) { |
|
433 | + return $this->get_next_renewal_date( $context ); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Retrieves the expiration date in a timestamp |
|
438 | + * |
|
439 | + * @since 1.0.0 |
|
440 | + * @return int |
|
441 | + */ |
|
442 | + public function get_expiration_time() { |
|
443 | + $expiration = $this->get_expiration(); |
|
444 | + |
|
445 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
446 | + return current_time( 'timestamp' ); |
|
447 | + } |
|
448 | + |
|
449 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
450 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Get GMT date when the subscription will renew. |
|
455 | + * |
|
456 | + * @since 1.0.19 |
|
457 | + * @param string $context View or edit context. |
|
458 | + * @return string |
|
459 | + */ |
|
460 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
461 | 461 | $date = $this->get_next_renewal_date( $context ); |
462 | 462 | |
463 | 463 | if ( $date ) { |
464 | 464 | $date = get_gmt_from_date( $date ); |
465 | 465 | } |
466 | - return $date; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Get the subscription's trial period. |
|
471 | - * |
|
472 | - * @since 1.0.19 |
|
473 | - * @param string $context View or edit context. |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - public function get_trial_period( $context = 'view' ) { |
|
477 | - return $this->get_prop( 'trial_period', $context ); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Get the subscription's status. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - * @param string $context View or edit context. |
|
485 | - * @return string |
|
486 | - */ |
|
487 | - public function get_status( $context = 'view' ) { |
|
488 | - return $this->get_prop( 'status', $context ); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Get the subscription's profile id. |
|
493 | - * |
|
494 | - * @since 1.0.19 |
|
495 | - * @param string $context View or edit context. |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - public function get_profile_id( $context = 'view' ) { |
|
499 | - return $this->get_prop( 'profile_id', $context ); |
|
500 | - } |
|
501 | - |
|
502 | - /* |
|
466 | + return $date; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Get the subscription's trial period. |
|
471 | + * |
|
472 | + * @since 1.0.19 |
|
473 | + * @param string $context View or edit context. |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + public function get_trial_period( $context = 'view' ) { |
|
477 | + return $this->get_prop( 'trial_period', $context ); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Get the subscription's status. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + * @param string $context View or edit context. |
|
485 | + * @return string |
|
486 | + */ |
|
487 | + public function get_status( $context = 'view' ) { |
|
488 | + return $this->get_prop( 'status', $context ); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Get the subscription's profile id. |
|
493 | + * |
|
494 | + * @since 1.0.19 |
|
495 | + * @param string $context View or edit context. |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + public function get_profile_id( $context = 'view' ) { |
|
499 | + return $this->get_prop( 'profile_id', $context ); |
|
500 | + } |
|
501 | + |
|
502 | + /* |
|
503 | 503 | |-------------------------------------------------------------------------- |
504 | 504 | | Setters |
505 | 505 | |-------------------------------------------------------------------------- |
506 | 506 | */ |
507 | 507 | |
508 | - /** |
|
509 | - * Set customer id. |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param int $value The customer's id. |
|
513 | - */ |
|
514 | - public function set_customer_id( $value ) { |
|
515 | - $this->set_prop( 'customer_id', (int) $value ); |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Set parent invoice id. |
|
520 | - * |
|
521 | - * @since 1.0.19 |
|
522 | - * @param int $value The parent invoice id. |
|
523 | - */ |
|
524 | - public function set_parent_invoice_id( $value ) { |
|
525 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Alias for self::set_parent_invoice_id(). |
|
530 | - * |
|
531 | - * @since 1.0.19 |
|
532 | - * @param int $value The parent invoice id. |
|
533 | - */ |
|
508 | + /** |
|
509 | + * Set customer id. |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param int $value The customer's id. |
|
513 | + */ |
|
514 | + public function set_customer_id( $value ) { |
|
515 | + $this->set_prop( 'customer_id', (int) $value ); |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Set parent invoice id. |
|
520 | + * |
|
521 | + * @since 1.0.19 |
|
522 | + * @param int $value The parent invoice id. |
|
523 | + */ |
|
524 | + public function set_parent_invoice_id( $value ) { |
|
525 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Alias for self::set_parent_invoice_id(). |
|
530 | + * |
|
531 | + * @since 1.0.19 |
|
532 | + * @param int $value The parent invoice id. |
|
533 | + */ |
|
534 | 534 | public function set_parent_payment_id( $value ) { |
535 | 535 | $this->set_parent_invoice_id( $value ); |
536 | - } |
|
536 | + } |
|
537 | 537 | |
538 | - /** |
|
538 | + /** |
|
539 | 539 | * Alias for self::set_parent_invoice_id(). |
540 | 540 | * |
541 | 541 | * @since 1.0.19 |
542 | - * @param int $value The parent invoice id. |
|
542 | + * @param int $value The parent invoice id. |
|
543 | 543 | */ |
544 | 544 | public function set_original_payment_id( $value ) { |
545 | 545 | $this->set_parent_invoice_id( $value ); |
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Set subscription's product id. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - * @param int $value The subscription product id. |
|
553 | - */ |
|
554 | - public function set_product_id( $value ) { |
|
555 | - $this->set_prop( 'product_id', (int) $value ); |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * Set the period of a renewal. |
|
560 | - * |
|
561 | - * @since 1.0.19 |
|
562 | - * @param string $value The renewal period. |
|
563 | - */ |
|
564 | - public function set_period( $value ) { |
|
565 | - $this->set_prop( 'period', $value ); |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Set number of periods each renewal is valid for. |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param int $value The subscription frequency. |
|
573 | - */ |
|
574 | - public function set_frequency( $value ) { |
|
575 | - $value = empty( $value ) ? 1 : (int) $value; |
|
576 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Set the initial amount for the subscription. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param float $value The initial subcription amount. |
|
584 | - */ |
|
585 | - public function set_initial_amount( $value ) { |
|
586 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Set the recurring amount for the subscription. |
|
591 | - * |
|
592 | - * @since 1.0.19 |
|
593 | - * @param float $value The recurring subcription amount. |
|
594 | - */ |
|
595 | - public function set_recurring_amount( $value ) { |
|
596 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Set number of times that this subscription can be renewed. |
|
601 | - * |
|
602 | - * @since 1.0.19 |
|
603 | - * @param int $value Bill times. |
|
604 | - */ |
|
605 | - public function set_bill_times( $value ) { |
|
606 | - $this->set_prop( 'bill_times', (int) $value ); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Get transaction id of this subscription's parent invoice. |
|
611 | - * |
|
612 | - * @since 1.0.19 |
|
613 | - * @param string $value Bill times. |
|
614 | - */ |
|
615 | - public function set_transaction_id( $value ) { |
|
616 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Set date when this subscription started. |
|
621 | - * |
|
622 | - * @since 1.0.19 |
|
623 | - * @param string $value strtotime compliant date. |
|
624 | - */ |
|
625 | - public function set_created( $value ) { |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Set subscription's product id. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + * @param int $value The subscription product id. |
|
553 | + */ |
|
554 | + public function set_product_id( $value ) { |
|
555 | + $this->set_prop( 'product_id', (int) $value ); |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * Set the period of a renewal. |
|
560 | + * |
|
561 | + * @since 1.0.19 |
|
562 | + * @param string $value The renewal period. |
|
563 | + */ |
|
564 | + public function set_period( $value ) { |
|
565 | + $this->set_prop( 'period', $value ); |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Set number of periods each renewal is valid for. |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param int $value The subscription frequency. |
|
573 | + */ |
|
574 | + public function set_frequency( $value ) { |
|
575 | + $value = empty( $value ) ? 1 : (int) $value; |
|
576 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Set the initial amount for the subscription. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param float $value The initial subcription amount. |
|
584 | + */ |
|
585 | + public function set_initial_amount( $value ) { |
|
586 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Set the recurring amount for the subscription. |
|
591 | + * |
|
592 | + * @since 1.0.19 |
|
593 | + * @param float $value The recurring subcription amount. |
|
594 | + */ |
|
595 | + public function set_recurring_amount( $value ) { |
|
596 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Set number of times that this subscription can be renewed. |
|
601 | + * |
|
602 | + * @since 1.0.19 |
|
603 | + * @param int $value Bill times. |
|
604 | + */ |
|
605 | + public function set_bill_times( $value ) { |
|
606 | + $this->set_prop( 'bill_times', (int) $value ); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Get transaction id of this subscription's parent invoice. |
|
611 | + * |
|
612 | + * @since 1.0.19 |
|
613 | + * @param string $value Bill times. |
|
614 | + */ |
|
615 | + public function set_transaction_id( $value ) { |
|
616 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Set date when this subscription started. |
|
621 | + * |
|
622 | + * @since 1.0.19 |
|
623 | + * @param string $value strtotime compliant date. |
|
624 | + */ |
|
625 | + public function set_created( $value ) { |
|
626 | 626 | $date = strtotime( $value ); |
627 | 627 | |
628 | 628 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -630,94 +630,94 @@ discard block |
||
630 | 630 | return; |
631 | 631 | } |
632 | 632 | |
633 | - $this->set_prop( 'created', '' ); |
|
633 | + $this->set_prop( 'created', '' ); |
|
634 | 634 | |
635 | - } |
|
635 | + } |
|
636 | 636 | |
637 | - /** |
|
638 | - * Alias for self::set_created(). |
|
639 | - * |
|
640 | - * @since 1.0.19 |
|
641 | - * @param string $value strtotime compliant date. |
|
642 | - */ |
|
643 | - public function set_date_created( $value ) { |
|
644 | - $this->set_created( $value ); |
|
637 | + /** |
|
638 | + * Alias for self::set_created(). |
|
639 | + * |
|
640 | + * @since 1.0.19 |
|
641 | + * @param string $value strtotime compliant date. |
|
642 | + */ |
|
643 | + public function set_date_created( $value ) { |
|
644 | + $this->set_created( $value ); |
|
645 | 645 | } |
646 | 646 | |
647 | - /** |
|
648 | - * Set the date that the subscription will renew. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param string $value strtotime compliant date. |
|
652 | - */ |
|
653 | - public function set_next_renewal_date( $value ) { |
|
654 | - $date = strtotime( $value ); |
|
647 | + /** |
|
648 | + * Set the date that the subscription will renew. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param string $value strtotime compliant date. |
|
652 | + */ |
|
653 | + public function set_next_renewal_date( $value ) { |
|
654 | + $date = strtotime( $value ); |
|
655 | 655 | |
656 | 656 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
657 | 657 | $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
658 | 658 | return; |
659 | - } |
|
660 | - |
|
661 | - $this->set_prop( 'expiration', '' ); |
|
662 | - |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Alias for self::set_next_renewal_date(). |
|
667 | - * |
|
668 | - * @since 1.0.19 |
|
669 | - * @param string $value strtotime compliant date. |
|
670 | - */ |
|
671 | - public function set_expiration( $value ) { |
|
672 | - $this->set_next_renewal_date( $value ); |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Set the subscription's trial period. |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - * @param string $value trial period e.g 1 year. |
|
680 | - */ |
|
681 | - public function set_trial_period( $value ) { |
|
682 | - $this->set_prop( 'trial_period', $value ); |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Set the subscription's status. |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - * @param string $new_status New subscription status. |
|
690 | - */ |
|
691 | - public function set_status( $new_status ) { |
|
692 | - |
|
693 | - // Abort if this is not a valid status; |
|
694 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
695 | - return; |
|
696 | - } |
|
697 | - |
|
698 | - $old_status = $this->get_status(); |
|
699 | - $this->set_prop( 'status', $new_status ); |
|
700 | - |
|
701 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
702 | - $this->status_transition = array( |
|
703 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
704 | - 'to' => $new_status, |
|
705 | - ); |
|
706 | - } |
|
707 | - |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Set the subscription's (remote) profile id. |
|
712 | - * |
|
713 | - * @since 1.0.19 |
|
714 | - * @param string $value the remote profile id. |
|
715 | - */ |
|
716 | - public function set_profile_id( $value ) { |
|
717 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
718 | - } |
|
719 | - |
|
720 | - /* |
|
659 | + } |
|
660 | + |
|
661 | + $this->set_prop( 'expiration', '' ); |
|
662 | + |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Alias for self::set_next_renewal_date(). |
|
667 | + * |
|
668 | + * @since 1.0.19 |
|
669 | + * @param string $value strtotime compliant date. |
|
670 | + */ |
|
671 | + public function set_expiration( $value ) { |
|
672 | + $this->set_next_renewal_date( $value ); |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Set the subscription's trial period. |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + * @param string $value trial period e.g 1 year. |
|
680 | + */ |
|
681 | + public function set_trial_period( $value ) { |
|
682 | + $this->set_prop( 'trial_period', $value ); |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Set the subscription's status. |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + * @param string $new_status New subscription status. |
|
690 | + */ |
|
691 | + public function set_status( $new_status ) { |
|
692 | + |
|
693 | + // Abort if this is not a valid status; |
|
694 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
695 | + return; |
|
696 | + } |
|
697 | + |
|
698 | + $old_status = $this->get_status(); |
|
699 | + $this->set_prop( 'status', $new_status ); |
|
700 | + |
|
701 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
702 | + $this->status_transition = array( |
|
703 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
704 | + 'to' => $new_status, |
|
705 | + ); |
|
706 | + } |
|
707 | + |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Set the subscription's (remote) profile id. |
|
712 | + * |
|
713 | + * @since 1.0.19 |
|
714 | + * @param string $value the remote profile id. |
|
715 | + */ |
|
716 | + public function set_profile_id( $value ) { |
|
717 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
718 | + } |
|
719 | + |
|
720 | + /* |
|
721 | 721 | |-------------------------------------------------------------------------- |
722 | 722 | | Boolean methods |
723 | 723 | |-------------------------------------------------------------------------- |
@@ -726,45 +726,45 @@ discard block |
||
726 | 726 | | |
727 | 727 | */ |
728 | 728 | |
729 | - /** |
|
729 | + /** |
|
730 | 730 | * Checks if the subscription has a given status. |
731 | - * |
|
732 | - * @param string|array String or array of strings to check for. |
|
733 | - * @return bool |
|
731 | + * |
|
732 | + * @param string|array String or array of strings to check for. |
|
733 | + * @return bool |
|
734 | 734 | */ |
735 | 735 | public function has_status( $status ) { |
736 | 736 | return in_array( $this->get_status(), wpinv_parse_list( $status ) ); |
737 | - } |
|
737 | + } |
|
738 | 738 | |
739 | - /** |
|
739 | + /** |
|
740 | 740 | * Checks if the subscription has a trial period. |
741 | - * |
|
742 | - * @return bool |
|
741 | + * |
|
742 | + * @return bool |
|
743 | 743 | */ |
744 | 744 | public function has_trial_period() { |
745 | - $period = $this->get_trial_period(); |
|
745 | + $period = $this->get_trial_period(); |
|
746 | 746 | return ! empty( $period ); |
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Is the subscription active? |
|
751 | - * |
|
752 | - * @return bool |
|
753 | - */ |
|
754 | - public function is_active() { |
|
755 | - return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Is the subscription expired? |
|
760 | - * |
|
761 | - * @return bool |
|
762 | - */ |
|
763 | - public function is_expired() { |
|
764 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
765 | - } |
|
766 | - |
|
767 | - /* |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Is the subscription active? |
|
751 | + * |
|
752 | + * @return bool |
|
753 | + */ |
|
754 | + public function is_active() { |
|
755 | + return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Is the subscription expired? |
|
760 | + * |
|
761 | + * @return bool |
|
762 | + */ |
|
763 | + public function is_expired() { |
|
764 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
765 | + } |
|
766 | + |
|
767 | + /* |
|
768 | 768 | |-------------------------------------------------------------------------- |
769 | 769 | | Additional methods |
770 | 770 | |-------------------------------------------------------------------------- |
@@ -773,27 +773,27 @@ discard block |
||
773 | 773 | | |
774 | 774 | */ |
775 | 775 | |
776 | - /** |
|
777 | - * Backwards compatibilty. |
|
778 | - */ |
|
779 | - public function create( $data = array() ) { |
|
776 | + /** |
|
777 | + * Backwards compatibilty. |
|
778 | + */ |
|
779 | + public function create( $data = array() ) { |
|
780 | 780 | |
781 | - // Set the properties. |
|
782 | - if ( is_array( $data ) ) { |
|
783 | - $this->set_props( $data ); |
|
784 | - } |
|
781 | + // Set the properties. |
|
782 | + if ( is_array( $data ) ) { |
|
783 | + $this->set_props( $data ); |
|
784 | + } |
|
785 | 785 | |
786 | - // Save the item. |
|
787 | - return $this->save(); |
|
786 | + // Save the item. |
|
787 | + return $this->save(); |
|
788 | 788 | |
789 | - } |
|
789 | + } |
|
790 | 790 | |
791 | - /** |
|
792 | - * Backwards compatibilty. |
|
793 | - */ |
|
794 | - public function update( $args = array() ) { |
|
795 | - return $this->create( $args ); |
|
796 | - } |
|
791 | + /** |
|
792 | + * Backwards compatibilty. |
|
793 | + */ |
|
794 | + public function update( $args = array() ) { |
|
795 | + return $this->create( $args ); |
|
796 | + } |
|
797 | 797 | |
798 | 798 | /** |
799 | 799 | * Retrieve renewal payments for a subscription |
@@ -803,15 +803,15 @@ discard block |
||
803 | 803 | */ |
804 | 804 | public function get_child_payments() { |
805 | 805 | return get_posts( |
806 | - array( |
|
807 | - 'post_parent' => $this->get_parent_payment_id(), |
|
808 | - 'numberposts' => -1, |
|
809 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
810 | - 'orderby' => 'ID', |
|
811 | - 'order' => 'DESC', |
|
812 | - 'post_type' => 'wpi_invoice' |
|
813 | - ) |
|
814 | - ); |
|
806 | + array( |
|
807 | + 'post_parent' => $this->get_parent_payment_id(), |
|
808 | + 'numberposts' => -1, |
|
809 | + 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
810 | + 'orderby' => 'ID', |
|
811 | + 'order' => 'DESC', |
|
812 | + 'post_type' => 'wpi_invoice' |
|
813 | + ) |
|
814 | + ); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | /** |
@@ -821,16 +821,16 @@ discard block |
||
821 | 821 | * @return int |
822 | 822 | */ |
823 | 823 | public function get_total_payments() { |
824 | - global $wpdb; |
|
824 | + global $wpdb; |
|
825 | 825 | |
826 | - $count = (int) $wpdb->get_var( |
|
827 | - $wpdb->prepare( |
|
828 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
829 | - $this->get_parent_invoice_id() |
|
830 | - ) |
|
831 | - ); |
|
826 | + $count = (int) $wpdb->get_var( |
|
827 | + $wpdb->prepare( |
|
828 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
829 | + $this->get_parent_invoice_id() |
|
830 | + ) |
|
831 | + ); |
|
832 | 832 | |
833 | - // Maybe include parent invoice. |
|
833 | + // Maybe include parent invoice. |
|
834 | 834 | if ( ! $this->has_status( 'pending' ) ) { |
835 | 835 | $count++; |
836 | 836 | } |
@@ -859,57 +859,57 @@ discard block |
||
859 | 859 | * |
860 | 860 | * @since 2.4 |
861 | 861 | * @param array $args Array of values for the payment, including amount and transaction ID |
862 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
862 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
863 | 863 | * @return bool |
864 | 864 | */ |
865 | 865 | public function add_payment( $args = array(), $invoice = false ) { |
866 | 866 | |
867 | - // Process each payment once. |
|
867 | + // Process each payment once. |
|
868 | 868 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | |
872 | - // Are we creating a new invoice? |
|
873 | - if ( empty( $invoice ) ) { |
|
874 | - $invoice = $this->create_payment(); |
|
872 | + // Are we creating a new invoice? |
|
873 | + if ( empty( $invoice ) ) { |
|
874 | + $invoice = $this->create_payment(); |
|
875 | 875 | |
876 | - if ( empty( $invoice ) ) { |
|
877 | - return false; |
|
878 | - } |
|
876 | + if ( empty( $invoice ) ) { |
|
877 | + return false; |
|
878 | + } |
|
879 | 879 | |
880 | - $invoice->set_status( 'wpi-renewal' ); |
|
880 | + $invoice->set_status( 'wpi-renewal' ); |
|
881 | 881 | |
882 | - } |
|
882 | + } |
|
883 | 883 | |
884 | - // Maybe set a transaction id. |
|
885 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
886 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
887 | - } |
|
884 | + // Maybe set a transaction id. |
|
885 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
886 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
887 | + } |
|
888 | 888 | |
889 | - // Set the completed date. |
|
890 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
889 | + // Set the completed date. |
|
890 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
891 | 891 | |
892 | - // And the gateway. |
|
893 | - if ( ! empty( $args['gateway'] ) ) { |
|
894 | - $invoice->set_gateway( $args['gateway'] ); |
|
895 | - } |
|
892 | + // And the gateway. |
|
893 | + if ( ! empty( $args['gateway'] ) ) { |
|
894 | + $invoice->set_gateway( $args['gateway'] ); |
|
895 | + } |
|
896 | 896 | |
897 | - $invoice->save(); |
|
897 | + $invoice->save(); |
|
898 | 898 | |
899 | - if ( ! $invoice->get_id() ) { |
|
900 | - return 0; |
|
901 | - } |
|
899 | + if ( ! $invoice->get_id() ) { |
|
900 | + return 0; |
|
901 | + } |
|
902 | 902 | |
903 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
904 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
903 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
904 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
905 | 905 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
906 | 906 | |
907 | 907 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
908 | 908 | |
909 | 909 | return $invoice->get_id(); |
910 | - } |
|
910 | + } |
|
911 | 911 | |
912 | - /** |
|
912 | + /** |
|
913 | 913 | * Creates a new invoice and returns it. |
914 | 914 | * |
915 | 915 | * @since 1.0.19 |
@@ -917,104 +917,104 @@ discard block |
||
917 | 917 | */ |
918 | 918 | public function create_payment() { |
919 | 919 | |
920 | - $parent_invoice = $this->get_parent_payment(); |
|
921 | - |
|
922 | - if ( ! $parent_invoice->get_id() ) { |
|
923 | - return false; |
|
924 | - } |
|
925 | - |
|
926 | - // Duplicate the parent invoice. |
|
927 | - $invoice = new WPInv_Invoice(); |
|
928 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
929 | - $invoice->set_id( 0 ); |
|
930 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
931 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
932 | - $invoice->set_transaction_id( '' ); |
|
933 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
934 | - $invoice->set_number( '' ); |
|
935 | - $invoice->set_completed_date( '' ); |
|
936 | - $invoice->set_status( 'wpi-pending' ); |
|
937 | - $invoice->recalculate_total(); |
|
938 | - $invoice->save(); |
|
939 | - |
|
940 | - return $invoice->get_id() ? $invoice : false; |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Renews or completes a subscription |
|
945 | - * |
|
946 | - * @since 1.0.0 |
|
947 | - * @return int The subscription's id |
|
948 | - */ |
|
949 | - public function renew() { |
|
950 | - |
|
951 | - // Complete subscription if applicable |
|
952 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
953 | - return $this->complete(); |
|
954 | - } |
|
955 | - |
|
956 | - // Calculate new expiration |
|
957 | - $frequency = $this->get_frequency(); |
|
958 | - $period = $this->get_period(); |
|
959 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
960 | - |
|
961 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
962 | - $this->set_status( 'active' ); |
|
963 | - return $this->save(); |
|
964 | - |
|
965 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
966 | - |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Marks a subscription as completed |
|
971 | - * |
|
972 | - * Subscription is completed when the number of payments matches the billing_times field |
|
973 | - * |
|
974 | - * @since 1.0.0 |
|
975 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
976 | - */ |
|
977 | - public function complete() { |
|
978 | - |
|
979 | - // Only mark a subscription as complete if it's not already cancelled. |
|
980 | - if ( $this->has_status( 'cancelled' ) ) { |
|
981 | - return false; |
|
982 | - } |
|
983 | - |
|
984 | - $this->set_status( 'completed' ); |
|
985 | - return $this->save(); |
|
986 | - |
|
987 | - } |
|
988 | - |
|
989 | - /** |
|
990 | - * Marks a subscription as expired |
|
991 | - * |
|
992 | - * @since 1.0.0 |
|
993 | - * @param bool $check_expiration |
|
994 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
995 | - */ |
|
996 | - public function expire( $check_expiration = false ) { |
|
997 | - |
|
998 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
999 | - // Do not mark as expired since real expiration date is in the future |
|
1000 | - return false; |
|
1001 | - } |
|
1002 | - |
|
1003 | - $this->set_status( 'expired' ); |
|
1004 | - return $this->save(); |
|
1005 | - |
|
1006 | - } |
|
1007 | - |
|
1008 | - /** |
|
1009 | - * Marks a subscription as failing |
|
1010 | - * |
|
1011 | - * @since 2.4.2 |
|
1012 | - * @return int Subscription id. |
|
1013 | - */ |
|
1014 | - public function failing() { |
|
1015 | - $this->set_status( 'failing' ); |
|
1016 | - return $this->save(); |
|
1017 | - } |
|
920 | + $parent_invoice = $this->get_parent_payment(); |
|
921 | + |
|
922 | + if ( ! $parent_invoice->get_id() ) { |
|
923 | + return false; |
|
924 | + } |
|
925 | + |
|
926 | + // Duplicate the parent invoice. |
|
927 | + $invoice = new WPInv_Invoice(); |
|
928 | + $invoice->set_props( $parent_invoice->get_data() ); |
|
929 | + $invoice->set_id( 0 ); |
|
930 | + $invoice->set_items( $parent_invoice->get_items() ); |
|
931 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
932 | + $invoice->set_transaction_id( '' ); |
|
933 | + $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
934 | + $invoice->set_number( '' ); |
|
935 | + $invoice->set_completed_date( '' ); |
|
936 | + $invoice->set_status( 'wpi-pending' ); |
|
937 | + $invoice->recalculate_total(); |
|
938 | + $invoice->save(); |
|
939 | + |
|
940 | + return $invoice->get_id() ? $invoice : false; |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Renews or completes a subscription |
|
945 | + * |
|
946 | + * @since 1.0.0 |
|
947 | + * @return int The subscription's id |
|
948 | + */ |
|
949 | + public function renew() { |
|
950 | + |
|
951 | + // Complete subscription if applicable |
|
952 | + if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
953 | + return $this->complete(); |
|
954 | + } |
|
955 | + |
|
956 | + // Calculate new expiration |
|
957 | + $frequency = $this->get_frequency(); |
|
958 | + $period = $this->get_period(); |
|
959 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
960 | + |
|
961 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
962 | + $this->set_status( 'active' ); |
|
963 | + return $this->save(); |
|
964 | + |
|
965 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
966 | + |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Marks a subscription as completed |
|
971 | + * |
|
972 | + * Subscription is completed when the number of payments matches the billing_times field |
|
973 | + * |
|
974 | + * @since 1.0.0 |
|
975 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
976 | + */ |
|
977 | + public function complete() { |
|
978 | + |
|
979 | + // Only mark a subscription as complete if it's not already cancelled. |
|
980 | + if ( $this->has_status( 'cancelled' ) ) { |
|
981 | + return false; |
|
982 | + } |
|
983 | + |
|
984 | + $this->set_status( 'completed' ); |
|
985 | + return $this->save(); |
|
986 | + |
|
987 | + } |
|
988 | + |
|
989 | + /** |
|
990 | + * Marks a subscription as expired |
|
991 | + * |
|
992 | + * @since 1.0.0 |
|
993 | + * @param bool $check_expiration |
|
994 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
995 | + */ |
|
996 | + public function expire( $check_expiration = false ) { |
|
997 | + |
|
998 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
999 | + // Do not mark as expired since real expiration date is in the future |
|
1000 | + return false; |
|
1001 | + } |
|
1002 | + |
|
1003 | + $this->set_status( 'expired' ); |
|
1004 | + return $this->save(); |
|
1005 | + |
|
1006 | + } |
|
1007 | + |
|
1008 | + /** |
|
1009 | + * Marks a subscription as failing |
|
1010 | + * |
|
1011 | + * @since 2.4.2 |
|
1012 | + * @return int Subscription id. |
|
1013 | + */ |
|
1014 | + public function failing() { |
|
1015 | + $this->set_status( 'failing' ); |
|
1016 | + return $this->save(); |
|
1017 | + } |
|
1018 | 1018 | |
1019 | 1019 | /** |
1020 | 1020 | * Marks a subscription as cancelled |
@@ -1023,19 +1023,19 @@ discard block |
||
1023 | 1023 | * @return int Subscription id. |
1024 | 1024 | */ |
1025 | 1025 | public function cancel() { |
1026 | - $this->set_status( 'cancelled' ); |
|
1027 | - return $this->save(); |
|
1026 | + $this->set_status( 'cancelled' ); |
|
1027 | + return $this->save(); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | - /** |
|
1031 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1032 | - * |
|
1033 | - * @since 1.0.0 |
|
1034 | - * @return bool |
|
1035 | - */ |
|
1036 | - public function can_cancel() { |
|
1037 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1038 | - } |
|
1030 | + /** |
|
1031 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1032 | + * |
|
1033 | + * @since 1.0.0 |
|
1034 | + * @return bool |
|
1035 | + */ |
|
1036 | + public function can_cancel() { |
|
1037 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1038 | + } |
|
1039 | 1039 | |
1040 | 1040 | /** |
1041 | 1041 | * Returns an array of subscription statuses that can be cancelled |
@@ -1048,82 +1048,82 @@ discard block |
||
1048 | 1048 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - /** |
|
1052 | - * Retrieves the URL to cancel subscription |
|
1053 | - * |
|
1054 | - * @since 1.0.0 |
|
1055 | - * @return string |
|
1056 | - */ |
|
1057 | - public function get_cancel_url() { |
|
1058 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' ); |
|
1059 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1060 | - } |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * Determines if subscription can be manually renewed |
|
1064 | - * |
|
1065 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1066 | - * that can be renewed manually |
|
1067 | - * |
|
1068 | - * @since 2.5 |
|
1069 | - * @return bool |
|
1070 | - */ |
|
1071 | - public function can_renew() { |
|
1072 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1073 | - } |
|
1074 | - |
|
1075 | - /** |
|
1076 | - * Retrieves the URL to renew a subscription |
|
1077 | - * |
|
1078 | - * @since 2.5 |
|
1079 | - * @return string |
|
1080 | - */ |
|
1081 | - public function get_renew_url() { |
|
1082 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' ); |
|
1083 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1084 | - } |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * Determines if subscription can have their payment method updated |
|
1088 | - * |
|
1089 | - * @since 1.0.0 |
|
1090 | - * @return bool |
|
1091 | - */ |
|
1092 | - public function can_update() { |
|
1093 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1094 | - } |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * Retrieves the URL to update subscription |
|
1098 | - * |
|
1099 | - * @since 1.0.0 |
|
1100 | - * @return string |
|
1101 | - */ |
|
1102 | - public function get_update_url() { |
|
1103 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1104 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1105 | - } |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * Retrieves the subscription status label |
|
1109 | - * |
|
1110 | - * @since 1.0.0 |
|
1111 | - * @return string |
|
1112 | - */ |
|
1113 | - public function get_status_label() { |
|
1114 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1115 | - } |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * Retrieves the subscription status class |
|
1119 | - * |
|
1120 | - * @since 1.0.19 |
|
1121 | - * @return string |
|
1122 | - */ |
|
1123 | - public function get_status_class() { |
|
1124 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1125 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1126 | - } |
|
1051 | + /** |
|
1052 | + * Retrieves the URL to cancel subscription |
|
1053 | + * |
|
1054 | + * @since 1.0.0 |
|
1055 | + * @return string |
|
1056 | + */ |
|
1057 | + public function get_cancel_url() { |
|
1058 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' ); |
|
1059 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1060 | + } |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * Determines if subscription can be manually renewed |
|
1064 | + * |
|
1065 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1066 | + * that can be renewed manually |
|
1067 | + * |
|
1068 | + * @since 2.5 |
|
1069 | + * @return bool |
|
1070 | + */ |
|
1071 | + public function can_renew() { |
|
1072 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1073 | + } |
|
1074 | + |
|
1075 | + /** |
|
1076 | + * Retrieves the URL to renew a subscription |
|
1077 | + * |
|
1078 | + * @since 2.5 |
|
1079 | + * @return string |
|
1080 | + */ |
|
1081 | + public function get_renew_url() { |
|
1082 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' ); |
|
1083 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1084 | + } |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * Determines if subscription can have their payment method updated |
|
1088 | + * |
|
1089 | + * @since 1.0.0 |
|
1090 | + * @return bool |
|
1091 | + */ |
|
1092 | + public function can_update() { |
|
1093 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1094 | + } |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * Retrieves the URL to update subscription |
|
1098 | + * |
|
1099 | + * @since 1.0.0 |
|
1100 | + * @return string |
|
1101 | + */ |
|
1102 | + public function get_update_url() { |
|
1103 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1104 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1105 | + } |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * Retrieves the subscription status label |
|
1109 | + * |
|
1110 | + * @since 1.0.0 |
|
1111 | + * @return string |
|
1112 | + */ |
|
1113 | + public function get_status_label() { |
|
1114 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1115 | + } |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * Retrieves the subscription status class |
|
1119 | + * |
|
1120 | + * @since 1.0.19 |
|
1121 | + * @return string |
|
1122 | + */ |
|
1123 | + public function get_status_class() { |
|
1124 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1125 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1126 | + } |
|
1127 | 1127 | |
1128 | 1128 | /** |
1129 | 1129 | * Retrieves the subscription status label |
@@ -1133,11 +1133,11 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public function get_status_label_html() { |
1135 | 1135 | |
1136 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1137 | - $class = esc_attr( $this->get_status_class() ); |
|
1138 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1136 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1137 | + $class = esc_attr( $this->get_status_class() ); |
|
1138 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
1139 | 1139 | |
1140 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1140 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1148,63 +1148,63 @@ discard block |
||
1148 | 1148 | * @return bool |
1149 | 1149 | */ |
1150 | 1150 | public function payment_exists( $txn_id = '' ) { |
1151 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1151 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1152 | 1152 | return ! empty( $invoice_id ); |
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Handle the status transition. |
|
1157 | - */ |
|
1158 | - protected function status_transition() { |
|
1159 | - $status_transition = $this->status_transition; |
|
1160 | - |
|
1161 | - // Reset status transition variable. |
|
1162 | - $this->status_transition = false; |
|
1163 | - |
|
1164 | - if ( $status_transition ) { |
|
1165 | - try { |
|
1166 | - |
|
1167 | - // Fire a hook for the status change. |
|
1168 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1169 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1170 | - |
|
1171 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1172 | - |
|
1173 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1174 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1175 | - |
|
1176 | - // Fire another hook. |
|
1177 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1178 | - do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
1179 | - |
|
1180 | - // Note the transition occurred. |
|
1181 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1182 | - |
|
1183 | - } else { |
|
1184 | - /* translators: %s: new invoice status */ |
|
1185 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1186 | - |
|
1187 | - // Note the transition occurred. |
|
1188 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1189 | - |
|
1190 | - } |
|
1191 | - } catch ( Exception $e ) { |
|
1192 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1193 | - } |
|
1194 | - } |
|
1195 | - |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Save data to the database. |
|
1200 | - * |
|
1201 | - * @since 1.0.19 |
|
1202 | - * @return int subscription ID |
|
1203 | - */ |
|
1204 | - public function save() { |
|
1205 | - parent::save(); |
|
1206 | - $this->status_transition(); |
|
1207 | - return $this->get_id(); |
|
1208 | - } |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Handle the status transition. |
|
1157 | + */ |
|
1158 | + protected function status_transition() { |
|
1159 | + $status_transition = $this->status_transition; |
|
1160 | + |
|
1161 | + // Reset status transition variable. |
|
1162 | + $this->status_transition = false; |
|
1163 | + |
|
1164 | + if ( $status_transition ) { |
|
1165 | + try { |
|
1166 | + |
|
1167 | + // Fire a hook for the status change. |
|
1168 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1169 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1170 | + |
|
1171 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1172 | + |
|
1173 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1174 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1175 | + |
|
1176 | + // Fire another hook. |
|
1177 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1178 | + do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
1179 | + |
|
1180 | + // Note the transition occurred. |
|
1181 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1182 | + |
|
1183 | + } else { |
|
1184 | + /* translators: %s: new invoice status */ |
|
1185 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1186 | + |
|
1187 | + // Note the transition occurred. |
|
1188 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1189 | + |
|
1190 | + } |
|
1191 | + } catch ( Exception $e ) { |
|
1192 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1193 | + } |
|
1194 | + } |
|
1195 | + |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Save data to the database. |
|
1200 | + * |
|
1201 | + * @since 1.0.19 |
|
1202 | + * @return int subscription ID |
|
1203 | + */ |
|
1204 | + public function save() { |
|
1205 | + parent::save(); |
|
1206 | + $this->status_transition(); |
|
1207 | + return $this->get_id(); |
|
1208 | + } |
|
1209 | 1209 | |
1210 | 1210 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; |
7 | 7 | |
8 | 8 | if ( ! class_exists( 'WP_List_Table' ) ) { |
9 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
9 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -14,423 +14,423 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
16 | 16 | |
17 | - /** |
|
18 | - * URL of this page |
|
19 | - * |
|
20 | - * @var string |
|
21 | - * @since 1.0.19 |
|
22 | - */ |
|
23 | - public $base_url; |
|
24 | - |
|
25 | - /** |
|
26 | - * Query |
|
27 | - * |
|
28 | - * @var GetPaid_Subscriptions_Query |
|
29 | - * @since 1.0.19 |
|
30 | - */ |
|
31 | - public $query; |
|
32 | - |
|
33 | - /** |
|
34 | - * Total subscriptions |
|
35 | - * |
|
36 | - * @var string |
|
37 | - * @since 1.0.0 |
|
38 | - */ |
|
39 | - public $total_count; |
|
40 | - |
|
41 | - /** |
|
42 | - * Current status subscriptions |
|
43 | - * |
|
44 | - * @var string |
|
45 | - * @since 1.0.0 |
|
46 | - */ |
|
47 | - public $current_total_count; |
|
48 | - |
|
49 | - /** |
|
50 | - * Status counts |
|
51 | - * |
|
52 | - * @var array |
|
53 | - * @since 1.0.19 |
|
54 | - */ |
|
55 | - public $status_counts; |
|
56 | - |
|
57 | - /** |
|
58 | - * Number of results to show per page |
|
59 | - * |
|
60 | - * @var int |
|
61 | - * @since 1.0.0 |
|
62 | - */ |
|
63 | - public $per_page = 10; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor function. |
|
67 | - */ |
|
68 | - public function __construct() { |
|
69 | - |
|
70 | - parent::__construct( |
|
71 | - array( |
|
72 | - 'singular' => 'subscription', |
|
73 | - 'plural' => 'subscriptions', |
|
74 | - ) |
|
75 | - ); |
|
76 | - |
|
77 | - $this->process_bulk_action(); |
|
78 | - |
|
79 | - $this->prepare_query(); |
|
80 | - |
|
81 | - $this->base_url = remove_query_arg( 'status' ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Prepares the display query |
|
87 | - */ |
|
88 | - public function prepare_query() { |
|
89 | - |
|
90 | - // Prepare query args. |
|
91 | - $query = array( |
|
92 | - 'number' => $this->per_page, |
|
93 | - 'paged' => $this->get_paged(), |
|
94 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
95 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
96 | - 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
97 | - ); |
|
98 | - |
|
99 | - // Prepare class properties. |
|
100 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
101 | - $this->total_count = $this->query->get_total(); |
|
102 | - $this->current_total_count = $this->query->get_total(); |
|
103 | - $this->items = $this->query->get_results(); |
|
104 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
105 | - |
|
106 | - if ( 'all' != $query['status'] ) { |
|
107 | - unset( $query['status'] ); |
|
108 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
109 | - } |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Gets the list of views available on this table. |
|
115 | - * |
|
116 | - * The format is an associative array: |
|
117 | - * - `'id' => 'link'` |
|
118 | - * |
|
119 | - * @since 1.0.0 |
|
120 | - * |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - protected function get_views() { |
|
124 | - |
|
125 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
126 | - $views = array( |
|
127 | - |
|
128 | - 'all' => sprintf( |
|
129 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
130 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
131 | - $current === 'all' ? ' class="current"' : '', |
|
132 | - __('All','invoicing' ), |
|
133 | - $this->total_count |
|
134 | - ) |
|
135 | - |
|
136 | - ); |
|
137 | - |
|
138 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
139 | - |
|
140 | - $views[ $status ] = sprintf( |
|
141 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
142 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
143 | - $current === $status ? ' class="current"' : '', |
|
144 | - sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
145 | - $count |
|
146 | - ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - return $views; |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Render most columns |
|
156 | - * |
|
157 | - * @access private |
|
158 | - * @since 1.0.0 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function column_default( $item, $column_name ) { |
|
162 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * This is how checkbox column renders. |
|
167 | - * |
|
168 | - * @param WPInv_Subscription $item |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function column_cb( $item ) { |
|
172 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Status column |
|
177 | - * |
|
178 | - * @param WPInv_Subscription $item |
|
179 | - * @since 1.0.0 |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function column_status( $item ) { |
|
183 | - return $item->get_status_label_html(); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Subscription column |
|
188 | - * |
|
189 | - * @param WPInv_Subscription $item |
|
190 | - * @since 1.0.0 |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function column_subscription( $item ) { |
|
194 | - |
|
195 | - $username = __( '(Missing User)', 'invoicing' ); |
|
196 | - |
|
197 | - $user = get_userdata( $item->get_customer_id() ); |
|
198 | - if ( $user ) { |
|
199 | - |
|
200 | - $username = sprintf( |
|
201 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
202 | - absint( $user->ID ), |
|
203 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
204 | - ); |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
209 | - $column_content = sprintf( |
|
210 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
211 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
212 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
213 | - $username |
|
214 | - ); |
|
215 | - |
|
216 | - $row_actions = array(); |
|
217 | - |
|
218 | - // View subscription. |
|
219 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
220 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
221 | - |
|
222 | - // View invoice. |
|
223 | - $invoice = get_post( $item->get_product_id() ); |
|
224 | - |
|
225 | - if ( ! empty( $invoice ) ) { |
|
226 | - $view_url = get_edit_post_link( $invoice ); |
|
227 | - $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
228 | - } |
|
229 | - |
|
230 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
231 | - |
|
232 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Renewal date column |
|
237 | - * |
|
238 | - * @param WPInv_Subscription $item |
|
239 | - * @since 1.0.0 |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function column_renewal_date( $item ) { |
|
243 | - |
|
244 | - $expiration = $item->get_expiration(); |
|
245 | - if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
246 | - return "—"; |
|
247 | - } |
|
248 | - |
|
249 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Start date column |
|
255 | - * |
|
256 | - * @param WPInv_Subscription $item |
|
257 | - * @since 1.0.0 |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function column_start_date( $item ) { |
|
261 | - |
|
262 | - $created = $item->get_date_created(); |
|
263 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
264 | - return "—"; |
|
265 | - } |
|
266 | - |
|
267 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
268 | - |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Amount column |
|
273 | - * |
|
274 | - * @param WPInv_Subscription $item |
|
275 | - * @since 1.0.19 |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public function column_amount( $item ) { |
|
279 | - |
|
280 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
281 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
282 | - $period = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() ); |
|
283 | - |
|
284 | - if ( $item->has_trial_period() ) { |
|
285 | - |
|
286 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
287 | - $amount = sprintf( |
|
288 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
289 | - $initial, |
|
290 | - sanitize_text_field( $item->get_trial_period() ), |
|
291 | - $recurring, |
|
292 | - sanitize_text_field( strtolower( $period ) ) |
|
293 | - ); |
|
294 | - |
|
295 | - } else if ( $initial != $recurring ) { |
|
296 | - |
|
297 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
298 | - $amount = sprintf( |
|
299 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
300 | - $initial, |
|
301 | - $recurring, |
|
302 | - sanitize_text_field( strtolower( $period ) ) |
|
303 | - ); |
|
304 | - |
|
305 | - } else { |
|
306 | - |
|
307 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
308 | - $amount = sprintf( |
|
309 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
310 | - $initial, |
|
311 | - sanitize_text_field( strtolower( $period ) ) |
|
312 | - ); |
|
313 | - |
|
314 | - } |
|
315 | - |
|
316 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Billing Times column |
|
321 | - * |
|
322 | - * @param WPInv_Subscription $item |
|
323 | - * @since 1.0.0 |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function column_renewals( $item ) { |
|
327 | - $max_bills = $item->get_bill_times(); |
|
328 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Product ID column |
|
333 | - * |
|
334 | - * @param WPInv_Subscription $item |
|
335 | - * @since 1.0.0 |
|
336 | - * @return string |
|
337 | - */ |
|
338 | - public function column_item( $item ) { |
|
339 | - $_item = get_post( $item->get_product_id() ); |
|
340 | - |
|
341 | - if ( ! empty( $_item ) ) { |
|
342 | - $link = get_edit_post_link( $_item ); |
|
343 | - $link = esc_url( $link ); |
|
344 | - $name = esc_html( get_the_title( $_item ) ); |
|
345 | - return "<a href='$link'>$name</a>"; |
|
346 | - } else { |
|
347 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() ); |
|
348 | - } |
|
349 | - |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Retrieve the current page number |
|
354 | - * |
|
355 | - * @return int |
|
356 | - */ |
|
357 | - public function get_paged() { |
|
358 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Setup the final data for the table |
|
363 | - * |
|
364 | - */ |
|
365 | - public function prepare_items() { |
|
366 | - |
|
367 | - $columns = $this->get_columns(); |
|
368 | - $hidden = array(); |
|
369 | - $sortable = $this->get_sortable_columns(); |
|
370 | - |
|
371 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
372 | - |
|
373 | - $this->set_pagination_args( |
|
374 | - array( |
|
375 | - 'total_items' => $this->current_total_count, |
|
376 | - 'per_page' => $this->per_page, |
|
377 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
378 | - ) |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Table columns |
|
384 | - * |
|
385 | - * @return array |
|
386 | - */ |
|
387 | - public function get_columns(){ |
|
388 | - $columns = array( |
|
389 | - 'cb' => '<input type="checkbox" />', |
|
390 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
391 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
392 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
393 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
394 | - 'item' => __( 'Item', 'invoicing' ), |
|
395 | - 'status' => __( 'Status', 'invoicing' ), |
|
396 | - ); |
|
397 | - |
|
398 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Sortable table columns. |
|
403 | - * |
|
404 | - * @return array |
|
405 | - */ |
|
406 | - public function get_sortable_columns() { |
|
407 | - $sortable = array( |
|
408 | - 'subscription' => array( 'id', true ), |
|
409 | - 'start_date' => array( 'created', true ), |
|
410 | - 'renewal_date' => array( 'expiration', true ), |
|
411 | - 'renewals' => array( 'bill_times', true ), |
|
412 | - 'item' => array( 'product_id', true ), |
|
413 | - 'status' => array( 'status', true ), |
|
414 | - ); |
|
415 | - |
|
416 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Whether the table has items to display or not |
|
421 | - * |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - public function has_items() { |
|
425 | - return ! empty( $this->current_total_count ); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Processes bulk actions. |
|
430 | - * |
|
431 | - */ |
|
432 | - public function process_bulk_action() { |
|
433 | - |
|
434 | - } |
|
17 | + /** |
|
18 | + * URL of this page |
|
19 | + * |
|
20 | + * @var string |
|
21 | + * @since 1.0.19 |
|
22 | + */ |
|
23 | + public $base_url; |
|
24 | + |
|
25 | + /** |
|
26 | + * Query |
|
27 | + * |
|
28 | + * @var GetPaid_Subscriptions_Query |
|
29 | + * @since 1.0.19 |
|
30 | + */ |
|
31 | + public $query; |
|
32 | + |
|
33 | + /** |
|
34 | + * Total subscriptions |
|
35 | + * |
|
36 | + * @var string |
|
37 | + * @since 1.0.0 |
|
38 | + */ |
|
39 | + public $total_count; |
|
40 | + |
|
41 | + /** |
|
42 | + * Current status subscriptions |
|
43 | + * |
|
44 | + * @var string |
|
45 | + * @since 1.0.0 |
|
46 | + */ |
|
47 | + public $current_total_count; |
|
48 | + |
|
49 | + /** |
|
50 | + * Status counts |
|
51 | + * |
|
52 | + * @var array |
|
53 | + * @since 1.0.19 |
|
54 | + */ |
|
55 | + public $status_counts; |
|
56 | + |
|
57 | + /** |
|
58 | + * Number of results to show per page |
|
59 | + * |
|
60 | + * @var int |
|
61 | + * @since 1.0.0 |
|
62 | + */ |
|
63 | + public $per_page = 10; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor function. |
|
67 | + */ |
|
68 | + public function __construct() { |
|
69 | + |
|
70 | + parent::__construct( |
|
71 | + array( |
|
72 | + 'singular' => 'subscription', |
|
73 | + 'plural' => 'subscriptions', |
|
74 | + ) |
|
75 | + ); |
|
76 | + |
|
77 | + $this->process_bulk_action(); |
|
78 | + |
|
79 | + $this->prepare_query(); |
|
80 | + |
|
81 | + $this->base_url = remove_query_arg( 'status' ); |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Prepares the display query |
|
87 | + */ |
|
88 | + public function prepare_query() { |
|
89 | + |
|
90 | + // Prepare query args. |
|
91 | + $query = array( |
|
92 | + 'number' => $this->per_page, |
|
93 | + 'paged' => $this->get_paged(), |
|
94 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
95 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
96 | + 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
97 | + ); |
|
98 | + |
|
99 | + // Prepare class properties. |
|
100 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
101 | + $this->total_count = $this->query->get_total(); |
|
102 | + $this->current_total_count = $this->query->get_total(); |
|
103 | + $this->items = $this->query->get_results(); |
|
104 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
105 | + |
|
106 | + if ( 'all' != $query['status'] ) { |
|
107 | + unset( $query['status'] ); |
|
108 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
109 | + } |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Gets the list of views available on this table. |
|
115 | + * |
|
116 | + * The format is an associative array: |
|
117 | + * - `'id' => 'link'` |
|
118 | + * |
|
119 | + * @since 1.0.0 |
|
120 | + * |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + protected function get_views() { |
|
124 | + |
|
125 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
126 | + $views = array( |
|
127 | + |
|
128 | + 'all' => sprintf( |
|
129 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
130 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
131 | + $current === 'all' ? ' class="current"' : '', |
|
132 | + __('All','invoicing' ), |
|
133 | + $this->total_count |
|
134 | + ) |
|
135 | + |
|
136 | + ); |
|
137 | + |
|
138 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
139 | + |
|
140 | + $views[ $status ] = sprintf( |
|
141 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
142 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
143 | + $current === $status ? ' class="current"' : '', |
|
144 | + sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
145 | + $count |
|
146 | + ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + return $views; |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Render most columns |
|
156 | + * |
|
157 | + * @access private |
|
158 | + * @since 1.0.0 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function column_default( $item, $column_name ) { |
|
162 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * This is how checkbox column renders. |
|
167 | + * |
|
168 | + * @param WPInv_Subscription $item |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function column_cb( $item ) { |
|
172 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Status column |
|
177 | + * |
|
178 | + * @param WPInv_Subscription $item |
|
179 | + * @since 1.0.0 |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function column_status( $item ) { |
|
183 | + return $item->get_status_label_html(); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Subscription column |
|
188 | + * |
|
189 | + * @param WPInv_Subscription $item |
|
190 | + * @since 1.0.0 |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function column_subscription( $item ) { |
|
194 | + |
|
195 | + $username = __( '(Missing User)', 'invoicing' ); |
|
196 | + |
|
197 | + $user = get_userdata( $item->get_customer_id() ); |
|
198 | + if ( $user ) { |
|
199 | + |
|
200 | + $username = sprintf( |
|
201 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
202 | + absint( $user->ID ), |
|
203 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
204 | + ); |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
209 | + $column_content = sprintf( |
|
210 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
211 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
212 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
213 | + $username |
|
214 | + ); |
|
215 | + |
|
216 | + $row_actions = array(); |
|
217 | + |
|
218 | + // View subscription. |
|
219 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
220 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
221 | + |
|
222 | + // View invoice. |
|
223 | + $invoice = get_post( $item->get_product_id() ); |
|
224 | + |
|
225 | + if ( ! empty( $invoice ) ) { |
|
226 | + $view_url = get_edit_post_link( $invoice ); |
|
227 | + $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
228 | + } |
|
229 | + |
|
230 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
231 | + |
|
232 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Renewal date column |
|
237 | + * |
|
238 | + * @param WPInv_Subscription $item |
|
239 | + * @since 1.0.0 |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function column_renewal_date( $item ) { |
|
243 | + |
|
244 | + $expiration = $item->get_expiration(); |
|
245 | + if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
246 | + return "—"; |
|
247 | + } |
|
248 | + |
|
249 | + return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Start date column |
|
255 | + * |
|
256 | + * @param WPInv_Subscription $item |
|
257 | + * @since 1.0.0 |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function column_start_date( $item ) { |
|
261 | + |
|
262 | + $created = $item->get_date_created(); |
|
263 | + if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
264 | + return "—"; |
|
265 | + } |
|
266 | + |
|
267 | + return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
268 | + |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Amount column |
|
273 | + * |
|
274 | + * @param WPInv_Subscription $item |
|
275 | + * @since 1.0.19 |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public function column_amount( $item ) { |
|
279 | + |
|
280 | + $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
281 | + $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
282 | + $period = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() ); |
|
283 | + |
|
284 | + if ( $item->has_trial_period() ) { |
|
285 | + |
|
286 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
287 | + $amount = sprintf( |
|
288 | + _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
289 | + $initial, |
|
290 | + sanitize_text_field( $item->get_trial_period() ), |
|
291 | + $recurring, |
|
292 | + sanitize_text_field( strtolower( $period ) ) |
|
293 | + ); |
|
294 | + |
|
295 | + } else if ( $initial != $recurring ) { |
|
296 | + |
|
297 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
298 | + $amount = sprintf( |
|
299 | + _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
300 | + $initial, |
|
301 | + $recurring, |
|
302 | + sanitize_text_field( strtolower( $period ) ) |
|
303 | + ); |
|
304 | + |
|
305 | + } else { |
|
306 | + |
|
307 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
308 | + $amount = sprintf( |
|
309 | + _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
310 | + $initial, |
|
311 | + sanitize_text_field( strtolower( $period ) ) |
|
312 | + ); |
|
313 | + |
|
314 | + } |
|
315 | + |
|
316 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Billing Times column |
|
321 | + * |
|
322 | + * @param WPInv_Subscription $item |
|
323 | + * @since 1.0.0 |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function column_renewals( $item ) { |
|
327 | + $max_bills = $item->get_bill_times(); |
|
328 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Product ID column |
|
333 | + * |
|
334 | + * @param WPInv_Subscription $item |
|
335 | + * @since 1.0.0 |
|
336 | + * @return string |
|
337 | + */ |
|
338 | + public function column_item( $item ) { |
|
339 | + $_item = get_post( $item->get_product_id() ); |
|
340 | + |
|
341 | + if ( ! empty( $_item ) ) { |
|
342 | + $link = get_edit_post_link( $_item ); |
|
343 | + $link = esc_url( $link ); |
|
344 | + $name = esc_html( get_the_title( $_item ) ); |
|
345 | + return "<a href='$link'>$name</a>"; |
|
346 | + } else { |
|
347 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() ); |
|
348 | + } |
|
349 | + |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Retrieve the current page number |
|
354 | + * |
|
355 | + * @return int |
|
356 | + */ |
|
357 | + public function get_paged() { |
|
358 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Setup the final data for the table |
|
363 | + * |
|
364 | + */ |
|
365 | + public function prepare_items() { |
|
366 | + |
|
367 | + $columns = $this->get_columns(); |
|
368 | + $hidden = array(); |
|
369 | + $sortable = $this->get_sortable_columns(); |
|
370 | + |
|
371 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
372 | + |
|
373 | + $this->set_pagination_args( |
|
374 | + array( |
|
375 | + 'total_items' => $this->current_total_count, |
|
376 | + 'per_page' => $this->per_page, |
|
377 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
378 | + ) |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Table columns |
|
384 | + * |
|
385 | + * @return array |
|
386 | + */ |
|
387 | + public function get_columns(){ |
|
388 | + $columns = array( |
|
389 | + 'cb' => '<input type="checkbox" />', |
|
390 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
391 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
392 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
393 | + 'renewals' => __( 'Renewals', 'invoicing' ), |
|
394 | + 'item' => __( 'Item', 'invoicing' ), |
|
395 | + 'status' => __( 'Status', 'invoicing' ), |
|
396 | + ); |
|
397 | + |
|
398 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Sortable table columns. |
|
403 | + * |
|
404 | + * @return array |
|
405 | + */ |
|
406 | + public function get_sortable_columns() { |
|
407 | + $sortable = array( |
|
408 | + 'subscription' => array( 'id', true ), |
|
409 | + 'start_date' => array( 'created', true ), |
|
410 | + 'renewal_date' => array( 'expiration', true ), |
|
411 | + 'renewals' => array( 'bill_times', true ), |
|
412 | + 'item' => array( 'product_id', true ), |
|
413 | + 'status' => array( 'status', true ), |
|
414 | + ); |
|
415 | + |
|
416 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Whether the table has items to display or not |
|
421 | + * |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + public function has_items() { |
|
425 | + return ! empty( $this->current_total_count ); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Processes bulk actions. |
|
430 | + * |
|
431 | + */ |
|
432 | + public function process_bulk_action() { |
|
433 | + |
|
434 | + } |
|
435 | 435 | |
436 | 436 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - echo aui()->alert( |
|
29 | - array( |
|
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ) |
|
33 | - ); |
|
28 | + echo aui()->alert( |
|
29 | + array( |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ) |
|
33 | + ); |
|
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | 36 | |
37 | - // Display a single subscription. |
|
38 | - wpinv_recurring_subscription_details(); |
|
39 | - } else { |
|
37 | + // Display a single subscription. |
|
38 | + wpinv_recurring_subscription_details(); |
|
39 | + } else { |
|
40 | 40 | |
41 | - // Display a list of available subscriptions. |
|
42 | - getpaid_print_subscriptions_list(); |
|
43 | - } |
|
41 | + // Display a list of available subscriptions. |
|
42 | + getpaid_print_subscriptions_list(); |
|
43 | + } |
|
44 | 44 | |
45 | - ?> |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | </div> |
48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function getpaid_print_subscriptions_list() { |
61 | 61 | |
62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | - $subscribers_table->prepare_items(); |
|
62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | + $subscribers_table->prepare_items(); |
|
64 | 64 | |
65 | - ?> |
|
65 | + ?> |
|
66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | - // Fetch the subscription. |
|
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->get_id() ) { |
|
83 | + // Fetch the subscription. |
|
84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | + if ( ! $sub->get_id() ) { |
|
86 | 86 | |
87 | - echo aui()->alert( |
|
88 | - array( |
|
89 | - 'type' => 'danger', |
|
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | - ) |
|
92 | - ); |
|
87 | + echo aui()->alert( |
|
88 | + array( |
|
89 | + 'type' => 'danger', |
|
90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | + ) |
|
92 | + ); |
|
93 | 93 | |
94 | - return; |
|
95 | - } |
|
94 | + return; |
|
95 | + } |
|
96 | 96 | |
97 | - // Use metaboxes to display the subscription details. |
|
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
97 | + // Use metaboxes to display the subscription details. |
|
98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
102 | 102 | |
103 | - ?> |
|
103 | + ?> |
|
104 | 104 | |
105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
106 | 106 | |
@@ -140,28 +140,28 @@ discard block |
||
140 | 140 | */ |
141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
142 | 142 | |
143 | - // Prepare subscription detail columns. |
|
144 | - $fields = apply_filters( |
|
145 | - 'getpaid_subscription_admin_page_fields', |
|
146 | - array( |
|
147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
153 | - 'item' => __( 'Item', 'invoicing' ), |
|
154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | - 'status' => __( 'Status', 'invoicing' ), |
|
157 | - ) |
|
158 | - ); |
|
159 | - |
|
160 | - if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
161 | - unset( $fields['renews_on'] ); |
|
162 | - } |
|
163 | - |
|
164 | - ?> |
|
143 | + // Prepare subscription detail columns. |
|
144 | + $fields = apply_filters( |
|
145 | + 'getpaid_subscription_admin_page_fields', |
|
146 | + array( |
|
147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | + 'renewals' => __( 'Renewals', 'invoicing' ), |
|
153 | + 'item' => __( 'Item', 'invoicing' ), |
|
154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | + 'status' => __( 'Status', 'invoicing' ), |
|
157 | + ) |
|
158 | + ); |
|
159 | + |
|
160 | + if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
161 | + unset( $fields['renews_on'] ); |
|
162 | + } |
|
163 | + |
|
164 | + ?> |
|
165 | 165 | |
166 | 166 | <table class="table table-borderless" style="font-size: 14px;"> |
167 | 167 | <tbody> |
@@ -195,20 +195,20 @@ discard block |
||
195 | 195 | */ |
196 | 196 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
197 | 197 | |
198 | - $username = __( '(Missing User)', 'invoicing' ); |
|
198 | + $username = __( '(Missing User)', 'invoicing' ); |
|
199 | 199 | |
200 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
201 | - if ( $user ) { |
|
200 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
201 | + if ( $user ) { |
|
202 | 202 | |
203 | - $username = sprintf( |
|
204 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
205 | - absint( $user->ID ), |
|
206 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
207 | - ); |
|
203 | + $username = sprintf( |
|
204 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
205 | + absint( $user->ID ), |
|
206 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
207 | + ); |
|
208 | 208 | |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - echo $username; |
|
211 | + echo $username; |
|
212 | 212 | } |
213 | 213 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
214 | 214 | |
@@ -219,43 +219,43 @@ discard block |
||
219 | 219 | */ |
220 | 220 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
221 | 221 | |
222 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
223 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
224 | - $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
222 | + $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
223 | + $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
224 | + $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
225 | 225 | |
226 | - if ( $subscription->has_trial_period() ) { |
|
226 | + if ( $subscription->has_trial_period() ) { |
|
227 | 227 | |
228 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
229 | - $amount = sprintf( |
|
230 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
231 | - $initial, |
|
232 | - sanitize_text_field( $subscription->get_trial_period() ), |
|
233 | - $recurring, |
|
234 | - sanitize_text_field( strtolower( $period ) ) |
|
235 | - ); |
|
228 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
229 | + $amount = sprintf( |
|
230 | + _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
231 | + $initial, |
|
232 | + sanitize_text_field( $subscription->get_trial_period() ), |
|
233 | + $recurring, |
|
234 | + sanitize_text_field( strtolower( $period ) ) |
|
235 | + ); |
|
236 | 236 | |
237 | - } else if ( $initial != $recurring ) { |
|
237 | + } else if ( $initial != $recurring ) { |
|
238 | 238 | |
239 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
240 | - $amount = sprintf( |
|
241 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
242 | - $initial, |
|
243 | - $recurring, |
|
244 | - sanitize_text_field( strtolower( $period ) ) |
|
245 | - ); |
|
239 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
240 | + $amount = sprintf( |
|
241 | + _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
242 | + $initial, |
|
243 | + $recurring, |
|
244 | + sanitize_text_field( strtolower( $period ) ) |
|
245 | + ); |
|
246 | 246 | |
247 | - } else { |
|
247 | + } else { |
|
248 | 248 | |
249 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
250 | - $amount = sprintf( |
|
251 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
252 | - $initial, |
|
253 | - sanitize_text_field( strtolower( $period ) ) |
|
254 | - ); |
|
249 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
250 | + $amount = sprintf( |
|
251 | + _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
252 | + $initial, |
|
253 | + sanitize_text_field( strtolower( $period ) ) |
|
254 | + ); |
|
255 | 255 | |
256 | - } |
|
256 | + } |
|
257 | 257 | |
258 | - echo "<span>$amount</span>"; |
|
258 | + echo "<span>$amount</span>"; |
|
259 | 259 | } |
260 | 260 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
261 | 261 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @param WPInv_Subscription $subscription |
266 | 266 | */ |
267 | 267 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
268 | - echo '#' . absint( $subscription->get_id() ); |
|
268 | + echo '#' . absint( $subscription->get_id() ); |
|
269 | 269 | } |
270 | 270 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
271 | 271 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | */ |
277 | 277 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
278 | 278 | |
279 | - $created = $subscription->get_date_created(); |
|
280 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
281 | - echo "—"; |
|
282 | - } else { |
|
283 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
284 | - } |
|
279 | + $created = $subscription->get_date_created(); |
|
280 | + if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
281 | + echo "—"; |
|
282 | + } else { |
|
283 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
284 | + } |
|
285 | 285 | |
286 | 286 | } |
287 | 287 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -293,12 +293,12 @@ discard block |
||
293 | 293 | */ |
294 | 294 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
295 | 295 | |
296 | - $expiration = $subscription->get_expiration(); |
|
297 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
298 | - echo "—"; |
|
299 | - } else { |
|
300 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
301 | - } |
|
296 | + $expiration = $subscription->get_expiration(); |
|
297 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
298 | + echo "—"; |
|
299 | + } else { |
|
300 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
301 | + } |
|
302 | 302 | |
303 | 303 | } |
304 | 304 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | * @param WPInv_Subscription $subscription |
310 | 310 | */ |
311 | 311 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
312 | - $max_bills = $subscription->get_bill_times(); |
|
313 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
312 | + $max_bills = $subscription->get_bill_times(); |
|
313 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
314 | 314 | } |
315 | 315 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
316 | 316 | |
@@ -321,16 +321,16 @@ discard block |
||
321 | 321 | */ |
322 | 322 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
323 | 323 | |
324 | - $item = get_post( $subscription->get_product_id() ); |
|
324 | + $item = get_post( $subscription->get_product_id() ); |
|
325 | 325 | |
326 | - if ( ! empty( $item ) ) { |
|
327 | - $link = get_edit_post_link( $item ); |
|
328 | - $link = esc_url( $link ); |
|
329 | - $name = esc_html( get_the_title( $item ) ); |
|
330 | - echo "<a href='$link'>$name</a>"; |
|
331 | - } else { |
|
332 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
333 | - } |
|
326 | + if ( ! empty( $item ) ) { |
|
327 | + $link = get_edit_post_link( $item ); |
|
328 | + $link = esc_url( $link ); |
|
329 | + $name = esc_html( get_the_title( $item ) ); |
|
330 | + echo "<a href='$link'>$name</a>"; |
|
331 | + } else { |
|
332 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
333 | + } |
|
334 | 334 | |
335 | 335 | } |
336 | 336 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -342,13 +342,13 @@ discard block |
||
342 | 342 | */ |
343 | 343 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
344 | 344 | |
345 | - $gateway = $subscription->get_gateway(); |
|
345 | + $gateway = $subscription->get_gateway(); |
|
346 | 346 | |
347 | - if ( ! empty( $gateway ) ) { |
|
348 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
349 | - } else { |
|
350 | - echo "—"; |
|
351 | - } |
|
347 | + if ( ! empty( $gateway ) ) { |
|
348 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
349 | + } else { |
|
350 | + echo "—"; |
|
351 | + } |
|
352 | 352 | |
353 | 353 | } |
354 | 354 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @param WPInv_Subscription $subscription |
360 | 360 | */ |
361 | 361 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
362 | - echo $subscription->get_status_label_html(); |
|
362 | + echo $subscription->get_status_label_html(); |
|
363 | 363 | } |
364 | 364 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
365 | 365 | |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | */ |
371 | 371 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
372 | 372 | |
373 | - $profile_id = $subscription->get_profile_id(); |
|
373 | + $profile_id = $subscription->get_profile_id(); |
|
374 | 374 | |
375 | - if ( ! empty( $profile_id ) ) { |
|
376 | - $profile_id = sanitize_text_field( $profile_id ); |
|
377 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
378 | - } else { |
|
379 | - echo "—"; |
|
380 | - } |
|
375 | + if ( ! empty( $profile_id ) ) { |
|
376 | + $profile_id = sanitize_text_field( $profile_id ); |
|
377 | + echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
378 | + } else { |
|
379 | + echo "—"; |
|
380 | + } |
|
381 | 381 | |
382 | 382 | } |
383 | 383 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -389,39 +389,39 @@ discard block |
||
389 | 389 | */ |
390 | 390 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
391 | 391 | |
392 | - ?> |
|
392 | + ?> |
|
393 | 393 | <div class="mt-3"> |
394 | 394 | |
395 | 395 | <?php |
396 | - echo aui()->select( |
|
397 | - array( |
|
398 | - 'options' => getpaid_get_subscription_statuses(), |
|
399 | - 'name' => 'subscription_status', |
|
400 | - 'id' => 'subscription_status_update_select', |
|
401 | - 'required' => true, |
|
402 | - 'no_wrap' => false, |
|
403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
405 | - 'select2' => true, |
|
406 | - 'value' => $subscription->get_status( 'edit' ), |
|
407 | - ) |
|
408 | - ); |
|
409 | - ?> |
|
396 | + echo aui()->select( |
|
397 | + array( |
|
398 | + 'options' => getpaid_get_subscription_statuses(), |
|
399 | + 'name' => 'subscription_status', |
|
400 | + 'id' => 'subscription_status_update_select', |
|
401 | + 'required' => true, |
|
402 | + 'no_wrap' => false, |
|
403 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
405 | + 'select2' => true, |
|
406 | + 'value' => $subscription->get_status( 'edit' ), |
|
407 | + ) |
|
408 | + ); |
|
409 | + ?> |
|
410 | 410 | |
411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
412 | 412 | |
413 | 413 | <?php |
414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
414 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
415 | 415 | |
416 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
418 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
416 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
417 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
418 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
419 | 419 | |
420 | - if ( $subscription->is_active() ) { |
|
421 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
422 | - } |
|
420 | + if ( $subscription->is_active() ) { |
|
421 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
422 | + } |
|
423 | 423 | |
424 | - echo '</div></div>'; |
|
424 | + echo '</div></div>'; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,27 +431,27 @@ discard block |
||
431 | 431 | */ |
432 | 432 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
433 | 433 | |
434 | - $columns = apply_filters( |
|
435 | - 'getpaid_subscription_related_invoices_columns', |
|
436 | - array( |
|
437 | - |
|
438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
440 | - 'date' => __( 'Date', 'invoicing' ), |
|
441 | - 'status' => __( 'Status', 'invoicing' ), |
|
442 | - 'total' => __( 'Total', 'invoicing' ), |
|
443 | - ) |
|
444 | - ); |
|
445 | - |
|
446 | - // Prepare the invoices. |
|
447 | - $payments = $subscription->get_child_payments(); |
|
448 | - $parent = $subscription->get_parent_invoice(); |
|
449 | - |
|
450 | - if ( $parent->get_id() ) { |
|
451 | - $payments = array_merge( array( $parent ), $payments ); |
|
452 | - } |
|
434 | + $columns = apply_filters( |
|
435 | + 'getpaid_subscription_related_invoices_columns', |
|
436 | + array( |
|
437 | + |
|
438 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
439 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
440 | + 'date' => __( 'Date', 'invoicing' ), |
|
441 | + 'status' => __( 'Status', 'invoicing' ), |
|
442 | + 'total' => __( 'Total', 'invoicing' ), |
|
443 | + ) |
|
444 | + ); |
|
445 | + |
|
446 | + // Prepare the invoices. |
|
447 | + $payments = $subscription->get_child_payments(); |
|
448 | + $parent = $subscription->get_parent_invoice(); |
|
449 | + |
|
450 | + if ( $parent->get_id() ) { |
|
451 | + $payments = array_merge( array( $parent ), $payments ); |
|
452 | + } |
|
453 | 453 | |
454 | - ?> |
|
454 | + ?> |
|
455 | 455 | <div class="m-0" style="overflow: auto;"> |
456 | 456 | |
457 | 457 | <table class="w-100 bg-white"> |
@@ -459,13 +459,13 @@ discard block |
||
459 | 459 | <thead> |
460 | 460 | <tr> |
461 | 461 | <?php |
462 | - foreach ( $columns as $key => $label ) { |
|
463 | - $key = esc_attr( $key ); |
|
464 | - $label = sanitize_text_field( $label ); |
|
462 | + foreach ( $columns as $key => $label ) { |
|
463 | + $key = esc_attr( $key ); |
|
464 | + $label = sanitize_text_field( $label ); |
|
465 | 465 | |
466 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
467 | - } |
|
468 | - ?> |
|
466 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
467 | + } |
|
468 | + ?> |
|
469 | 469 | </tr> |
470 | 470 | </thead> |
471 | 471 | |
@@ -473,57 +473,57 @@ discard block |
||
473 | 473 | |
474 | 474 | <?php |
475 | 475 | |
476 | - foreach( $payments as $payment ) : |
|
476 | + foreach( $payments as $payment ) : |
|
477 | 477 | |
478 | - // Ensure that we have an invoice. |
|
479 | - if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
480 | - $payment = new WPInv_Invoice( $payment ); |
|
481 | - } |
|
478 | + // Ensure that we have an invoice. |
|
479 | + if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
480 | + $payment = new WPInv_Invoice( $payment ); |
|
481 | + } |
|
482 | 482 | |
483 | - // Abort if the invoice is invalid. |
|
484 | - if ( ! $payment->get_id() ) { |
|
485 | - continue; |
|
486 | - } |
|
483 | + // Abort if the invoice is invalid. |
|
484 | + if ( ! $payment->get_id() ) { |
|
485 | + continue; |
|
486 | + } |
|
487 | 487 | |
488 | - echo '<tr>'; |
|
488 | + echo '<tr>'; |
|
489 | 489 | |
490 | - foreach ( array_keys( $columns ) as $key ) { |
|
490 | + foreach ( array_keys( $columns ) as $key ) { |
|
491 | 491 | |
492 | - echo '<td class="p-2 text-left">'; |
|
492 | + echo '<td class="p-2 text-left">'; |
|
493 | 493 | |
494 | - switch( $key ) { |
|
494 | + switch( $key ) { |
|
495 | 495 | |
496 | - case 'total': |
|
497 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
498 | - break; |
|
496 | + case 'total': |
|
497 | + echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
498 | + break; |
|
499 | 499 | |
500 | - case 'relationship': |
|
501 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
502 | - break; |
|
500 | + case 'relationship': |
|
501 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
502 | + break; |
|
503 | 503 | |
504 | - case 'date': |
|
505 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
506 | - break; |
|
504 | + case 'date': |
|
505 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
506 | + break; |
|
507 | 507 | |
508 | - case 'status': |
|
509 | - echo $payment->get_status_label_html(); |
|
510 | - break; |
|
508 | + case 'status': |
|
509 | + echo $payment->get_status_label_html(); |
|
510 | + break; |
|
511 | 511 | |
512 | - case 'invoice': |
|
513 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
515 | - echo "<a href='$link'>$invoice</a>"; |
|
516 | - break; |
|
517 | - } |
|
512 | + case 'invoice': |
|
513 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
514 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
515 | + echo "<a href='$link'>$invoice</a>"; |
|
516 | + break; |
|
517 | + } |
|
518 | 518 | |
519 | - echo '</td>'; |
|
519 | + echo '</td>'; |
|
520 | 520 | |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | - echo '</tr>'; |
|
523 | + echo '</tr>'; |
|
524 | 524 | |
525 | - endforeach; |
|
526 | - ?> |
|
525 | + endforeach; |
|
526 | + ?> |
|
527 | 527 | |
528 | 528 | </tbody> |
529 | 529 | |
@@ -543,30 +543,30 @@ discard block |
||
543 | 543 | */ |
544 | 544 | function wpinv_recurring_process_subscription_deletion() { |
545 | 545 | |
546 | - if( empty( $_POST['sub_id'] ) ) { |
|
547 | - return; |
|
548 | - } |
|
546 | + if( empty( $_POST['sub_id'] ) ) { |
|
547 | + return; |
|
548 | + } |
|
549 | 549 | |
550 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
551 | - return; |
|
552 | - } |
|
550 | + if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
551 | + return; |
|
552 | + } |
|
553 | 553 | |
554 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
555 | - return; |
|
556 | - } |
|
554 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
555 | + return; |
|
556 | + } |
|
557 | 557 | |
558 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
559 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
560 | - } |
|
558 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
559 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
560 | + } |
|
561 | 561 | |
562 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
562 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
563 | 563 | |
564 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
564 | + delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
565 | 565 | |
566 | - $subscription->delete(); |
|
566 | + $subscription->delete(); |
|
567 | 567 | |
568 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
569 | - exit; |
|
568 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
569 | + exit; |
|
570 | 570 | |
571 | 571 | } |
572 | 572 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
@@ -14,38 +14,38 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | - * Register admin scripts |
|
60 | - * |
|
61 | - */ |
|
62 | - public function enqeue_scripts() { |
|
59 | + * Register admin scripts |
|
60 | + * |
|
61 | + */ |
|
62 | + public function enqeue_scripts() { |
|
63 | 63 | global $current_screen; |
64 | 64 | |
65 | 65 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
66 | 66 | |
67 | 67 | if ( ! empty( $current_screen->post_type ) ) { |
68 | - $page = $current_screen->post_type; |
|
68 | + $page = $current_screen->post_type; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // General styles. |
@@ -89,30 +89,30 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | // Payment form scripts. |
92 | - if ( 'wpi_payment_form' == $page ) { |
|
92 | + if ( 'wpi_payment_form' == $page ) { |
|
93 | 93 | $this->load_payment_form_scripts(); |
94 | 94 | } |
95 | 95 | |
96 | 96 | if ( $page == 'wpinv-subscriptions' ) { |
97 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
98 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
99 | - } |
|
97 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
98 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
99 | + } |
|
100 | 100 | |
101 | - if ( $page == 'wpinv-reports' ) { |
|
102 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
103 | - } |
|
101 | + if ( $page == 'wpinv-reports' ) { |
|
102 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-subscriptions' ) { |
|
106 | - wp_enqueue_script( 'postbox' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-subscriptions' ) { |
|
106 | + wp_enqueue_script( 'postbox' ); |
|
107 | + } |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * Returns admin js translations. |
|
113 | - * |
|
114 | - */ |
|
115 | - protected function get_admin_i18() { |
|
112 | + * Returns admin js translations. |
|
113 | + * |
|
114 | + */ |
|
115 | + protected function get_admin_i18() { |
|
116 | 116 | global $post; |
117 | 117 | |
118 | 118 | return array( |
@@ -153,33 +153,33 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | - * Loads payment form js. |
|
157 | - * |
|
158 | - */ |
|
159 | - protected function load_payment_form_scripts() { |
|
156 | + * Loads payment form js. |
|
157 | + * |
|
158 | + */ |
|
159 | + protected function load_payment_form_scripts() { |
|
160 | 160 | global $post; |
161 | 161 | |
162 | 162 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
163 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
164 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
163 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
164 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
165 | 165 | |
166 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
167 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
166 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
167 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
168 | 168 | |
169 | - wp_localize_script( |
|
169 | + wp_localize_script( |
|
170 | 170 | 'wpinv-admin-payment-form-script', |
171 | 171 | 'wpinvPaymentFormAdmin', |
172 | 172 | array( |
173 | - 'elements' => $this->form_elements->get_elements(), |
|
174 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
175 | - 'all_items' => $this->form_elements->get_published_items(), |
|
176 | - 'currency' => wpinv_currency_symbol(), |
|
177 | - 'position' => wpinv_currency_position(), |
|
178 | - 'decimals' => (int) wpinv_decimals(), |
|
179 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
180 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
181 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
182 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
173 | + 'elements' => $this->form_elements->get_elements(), |
|
174 | + 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
175 | + 'all_items' => $this->form_elements->get_published_items(), |
|
176 | + 'currency' => wpinv_currency_symbol(), |
|
177 | + 'position' => wpinv_currency_position(), |
|
178 | + 'decimals' => (int) wpinv_decimals(), |
|
179 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
180 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
181 | + 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
182 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
183 | 183 | ) |
184 | 184 | ); |
185 | 185 | |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Add our classes to admin pages. |
|
191 | + * Add our classes to admin pages. |
|
192 | 192 | * |
193 | 193 | * @param string $classes |
194 | 194 | * @return string |
195 | - * |
|
196 | - */ |
|
195 | + * |
|
196 | + */ |
|
197 | 197 | public function admin_body_class( $classes ) { |
198 | - global $pagenow, $post, $current_screen; |
|
198 | + global $pagenow, $post, $current_screen; |
|
199 | 199 | |
200 | 200 | |
201 | 201 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
202 | 202 | |
203 | 203 | if ( ! empty( $current_screen->post_type ) ) { |
204 | - $page = $current_screen->post_type; |
|
204 | + $page = $current_screen->post_type; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -212,27 +212,27 @@ discard block |
||
212 | 212 | $classes .= ' wpinv-cpt wpinv'; |
213 | 213 | } |
214 | 214 | |
215 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
216 | - $classes .= ' wpi-editable-n'; |
|
217 | - } |
|
215 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
216 | + $classes .= ' wpi-editable-n'; |
|
217 | + } |
|
218 | 218 | |
219 | - return $classes; |
|
219 | + return $classes; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Maybe show the AyeCode Connect Notice. |
|
224 | - */ |
|
225 | - public function init_ayecode_connect_helper(){ |
|
223 | + * Maybe show the AyeCode Connect Notice. |
|
224 | + */ |
|
225 | + public function init_ayecode_connect_helper(){ |
|
226 | 226 | |
227 | 227 | new AyeCode_Connect_Helper( |
228 | 228 | array( |
229 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
230 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
231 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
232 | - 'connect_button' => __("Connect Site","invoicing"), |
|
233 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
234 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
235 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
229 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
230 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
231 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
232 | + 'connect_button' => __("Connect Site","invoicing"), |
|
233 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
234 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
235 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
236 | 236 | ), |
237 | 237 | array( 'wpi-addons' ) |
238 | 238 | ); |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function activation_redirect() { |
246 | 246 | |
247 | - // Bail if no activation redirect. |
|
248 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) { |
|
249 | - return; |
|
250 | - } |
|
247 | + // Bail if no activation redirect. |
|
248 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) { |
|
249 | + return; |
|
250 | + } |
|
251 | 251 | |
252 | - // Delete the redirect transient. |
|
253 | - delete_transient( '_wpinv_activation_redirect' ); |
|
252 | + // Delete the redirect transient. |
|
253 | + delete_transient( '_wpinv_activation_redirect' ); |
|
254 | 254 | |
255 | - // Bail if activating from network, or bulk |
|
256 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
257 | - return; |
|
258 | - } |
|
255 | + // Bail if activating from network, or bulk |
|
256 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
257 | + return; |
|
258 | + } |
|
259 | 259 | |
260 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
261 | - exit; |
|
260 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
261 | + exit; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -274,113 +274,113 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Returns an array of admin notices. |
|
278 | - * |
|
279 | - * @since 1.0.19 |
|
277 | + * Returns an array of admin notices. |
|
278 | + * |
|
279 | + * @since 1.0.19 |
|
280 | 280 | * @return array |
281 | - */ |
|
282 | - public function get_notices() { |
|
283 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
281 | + */ |
|
282 | + public function get_notices() { |
|
283 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
284 | 284 | return is_array( $notices ) ? $notices : array(); |
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Clears all admin notices |
|
289 | - * |
|
290 | - * @access public |
|
291 | - * @since 1.0.19 |
|
292 | - */ |
|
293 | - public function clear_notices() { |
|
294 | - delete_option( 'wpinv_admin_notices' ); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Saves a new admin notice |
|
299 | - * |
|
300 | - * @access public |
|
301 | - * @since 1.0.19 |
|
302 | - */ |
|
303 | - public function save_notice( $type, $message ) { |
|
304 | - $notices = $this->get_notices(); |
|
305 | - |
|
306 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
307 | - $notices[ $type ] = array(); |
|
308 | - } |
|
309 | - |
|
310 | - $notices[ $type ][] = $message; |
|
311 | - |
|
312 | - update_option( 'wpinv_admin_notices', $notices ); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Displays a success notice |
|
317 | - * |
|
318 | - * @param string $msg The message to qeue. |
|
319 | - * @access public |
|
320 | - * @since 1.0.19 |
|
321 | - */ |
|
322 | - public function show_success( $msg ) { |
|
323 | - $this->save_notice( 'success', $msg ); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Displays a error notice |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @param string $msg The message to qeue. |
|
331 | - * @since 1.0.19 |
|
332 | - */ |
|
333 | - public function show_error( $msg ) { |
|
334 | - $this->save_notice( 'error', $msg ); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Displays a warning notice |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @param string $msg The message to qeue. |
|
342 | - * @since 1.0.19 |
|
343 | - */ |
|
344 | - public function show_warning( $msg ) { |
|
345 | - $this->save_notice( 'warning', $msg ); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Displays a info notice |
|
350 | - * |
|
351 | - * @access public |
|
352 | - * @param string $msg The message to qeue. |
|
353 | - * @since 1.0.19 |
|
354 | - */ |
|
355 | - public function show_info( $msg ) { |
|
356 | - $this->save_notice( 'info', $msg ); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Show notices |
|
361 | - * |
|
362 | - * @access public |
|
363 | - * @since 1.0.19 |
|
364 | - */ |
|
365 | - public function show_notices() { |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Clears all admin notices |
|
289 | + * |
|
290 | + * @access public |
|
291 | + * @since 1.0.19 |
|
292 | + */ |
|
293 | + public function clear_notices() { |
|
294 | + delete_option( 'wpinv_admin_notices' ); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Saves a new admin notice |
|
299 | + * |
|
300 | + * @access public |
|
301 | + * @since 1.0.19 |
|
302 | + */ |
|
303 | + public function save_notice( $type, $message ) { |
|
304 | + $notices = $this->get_notices(); |
|
305 | + |
|
306 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
307 | + $notices[ $type ] = array(); |
|
308 | + } |
|
309 | + |
|
310 | + $notices[ $type ][] = $message; |
|
311 | + |
|
312 | + update_option( 'wpinv_admin_notices', $notices ); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Displays a success notice |
|
317 | + * |
|
318 | + * @param string $msg The message to qeue. |
|
319 | + * @access public |
|
320 | + * @since 1.0.19 |
|
321 | + */ |
|
322 | + public function show_success( $msg ) { |
|
323 | + $this->save_notice( 'success', $msg ); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Displays a error notice |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @param string $msg The message to qeue. |
|
331 | + * @since 1.0.19 |
|
332 | + */ |
|
333 | + public function show_error( $msg ) { |
|
334 | + $this->save_notice( 'error', $msg ); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Displays a warning notice |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @param string $msg The message to qeue. |
|
342 | + * @since 1.0.19 |
|
343 | + */ |
|
344 | + public function show_warning( $msg ) { |
|
345 | + $this->save_notice( 'warning', $msg ); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Displays a info notice |
|
350 | + * |
|
351 | + * @access public |
|
352 | + * @param string $msg The message to qeue. |
|
353 | + * @since 1.0.19 |
|
354 | + */ |
|
355 | + public function show_info( $msg ) { |
|
356 | + $this->save_notice( 'info', $msg ); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Show notices |
|
361 | + * |
|
362 | + * @access public |
|
363 | + * @since 1.0.19 |
|
364 | + */ |
|
365 | + public function show_notices() { |
|
366 | 366 | |
367 | 367 | $notices = $this->get_notices(); |
368 | 368 | $this->clear_notices(); |
369 | 369 | |
370 | - foreach ( $notices as $type => $messages ) { |
|
370 | + foreach ( $notices as $type => $messages ) { |
|
371 | 371 | |
372 | - if ( ! is_array( $messages ) ) { |
|
373 | - continue; |
|
374 | - } |
|
372 | + if ( ! is_array( $messages ) ) { |
|
373 | + continue; |
|
374 | + } |
|
375 | 375 | |
376 | 376 | $type = sanitize_key( $type ); |
377 | - foreach ( $messages as $message ) { |
|
377 | + foreach ( $messages as $message ) { |
|
378 | 378 | $message = wp_kses_post( $message ); |
379 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
379 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | } |
383 | 383 | |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |