@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
211 | + $payments = get_posts(array( |
|
212 | 212 | 'post_parent' => (int) $this->parent_payment_id, |
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * @return int |
245 | 245 | */ |
246 | 246 | public function get_times_billed() { |
247 | - $times_billed = (int)$this->get_total_payments(); |
|
247 | + $times_billed = (int) $this->get_total_payments(); |
|
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,32 +336,32 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | 360 | // Send email notifications. |
361 | - wpinv_completed_invoice_notification( $invoice->ID ); |
|
361 | + wpinv_completed_invoice_notification($invoice->ID); |
|
362 | 362 | |
363 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
364 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
363 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
364 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
365 | 365 | |
366 | 366 | return $invoice->ID; |
367 | 367 | } |
@@ -377,12 +377,12 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function get_transaction_id() { |
379 | 379 | |
380 | - if( empty( $this->transaction_id ) ) { |
|
380 | + if (empty($this->transaction_id)) { |
|
381 | 381 | |
382 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
382 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
383 | 383 | |
384 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
385 | - $this->set_transaction_id( $txn_id ); |
|
384 | + if (!empty($txn_id) && (int) $this->parent_payment_id !== (int) $txn_id) { |
|
385 | + $this->set_transaction_id($txn_id); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | } |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | * @since 1.0.0.4 |
398 | 398 | * @return bool |
399 | 399 | */ |
400 | - public function set_transaction_id( $txn_id = '' ) { |
|
401 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
400 | + public function set_transaction_id($txn_id = '') { |
|
401 | + $this->update(array('transaction_id' => $txn_id)); |
|
402 | 402 | $this->transaction_id = $txn_id; |
403 | 403 | } |
404 | 404 | |
@@ -414,35 +414,35 @@ discard block |
||
414 | 414 | |
415 | 415 | |
416 | 416 | // Determine what date to use as the start for the new expiration calculation |
417 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
417 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
418 | 418 | |
419 | - $base_date = $expires; |
|
419 | + $base_date = $expires; |
|
420 | 420 | |
421 | 421 | } else { |
422 | 422 | |
423 | - $base_date = current_time( 'timestamp' ); |
|
423 | + $base_date = current_time('timestamp'); |
|
424 | 424 | |
425 | 425 | } |
426 | 426 | |
427 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
427 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
428 | 428 | |
429 | 429 | |
430 | 430 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
432 | 432 | |
433 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
434 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
433 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
434 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
435 | 435 | } |
436 | 436 | |
437 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
437 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
438 | 438 | |
439 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
439 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
440 | 440 | |
441 | 441 | $this->status = 'active'; |
442 | 442 | $times_billed = $this->get_times_billed(); |
443 | 443 | |
444 | 444 | // Complete subscription if applicable |
445 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
445 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
446 | 446 | $this->complete(); |
447 | 447 | $this->status = 'completed'; |
448 | 448 | } |
@@ -452,10 +452,10 @@ discard block |
||
452 | 452 | 'status' => $this->status, |
453 | 453 | ); |
454 | 454 | |
455 | - $this->subs_db->update( $this->id, $args ); |
|
455 | + $this->subs_db->update($this->id, $args); |
|
456 | 456 | |
457 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
458 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
457 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
458 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
459 | 459 | |
460 | 460 | } |
461 | 461 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | public function complete() { |
471 | 471 | |
472 | 472 | // Only mark a subscription as complete if it's not already cancelled. |
473 | - if ( 'cancelled' === $this->status ) { |
|
473 | + if ('cancelled' === $this->status) { |
|
474 | 474 | return; |
475 | 475 | } |
476 | 476 | |
@@ -478,11 +478,11 @@ discard block |
||
478 | 478 | 'status' => 'completed' |
479 | 479 | ); |
480 | 480 | |
481 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
481 | + if ($this->subs_db->update($this->id, $args)) { |
|
482 | 482 | |
483 | 483 | $this->status = 'completed'; |
484 | 484 | |
485 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
485 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
486 | 486 | |
487 | 487 | } |
488 | 488 | |
@@ -497,15 +497,15 @@ discard block |
||
497 | 497 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
498 | 498 | * @return void |
499 | 499 | */ |
500 | - public function expire( $check_expiration = false ) { |
|
500 | + public function expire($check_expiration = false) { |
|
501 | 501 | |
502 | 502 | $expiration = $this->expiration; |
503 | 503 | |
504 | - if( $check_expiration ) { |
|
504 | + if ($check_expiration) { |
|
505 | 505 | |
506 | 506 | // check_expiration() updates $this->expiration so compare to $expiration above |
507 | 507 | |
508 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
508 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
509 | 509 | |
510 | 510 | return false; // Do not mark as expired since real expiration date is in the future |
511 | 511 | } |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | 'status' => 'expired' |
517 | 517 | ); |
518 | 518 | |
519 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
519 | + if ($this->subs_db->update($this->id, $args)) { |
|
520 | 520 | |
521 | 521 | $this->status = 'expired'; |
522 | 522 | |
523 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
523 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
524 | 524 | |
525 | 525 | } |
526 | 526 | |
@@ -538,11 +538,11 @@ discard block |
||
538 | 538 | 'status' => 'failing' |
539 | 539 | ); |
540 | 540 | |
541 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
541 | + if ($this->subs_db->update($this->id, $args)) { |
|
542 | 542 | |
543 | 543 | $this->status = 'failing'; |
544 | 544 | |
545 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
545 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
546 | 546 | |
547 | 547 | |
548 | 548 | } |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | * @return void |
557 | 557 | */ |
558 | 558 | public function cancel() { |
559 | - if ( 'cancelled' === $this->status ) { |
|
559 | + if ('cancelled' === $this->status) { |
|
560 | 560 | return; // Already cancelled |
561 | 561 | } |
562 | 562 | |
@@ -564,20 +564,20 @@ discard block |
||
564 | 564 | 'status' => 'cancelled' |
565 | 565 | ); |
566 | 566 | |
567 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
568 | - if ( is_user_logged_in() ) { |
|
569 | - $userdata = get_userdata( get_current_user_id() ); |
|
567 | + if ($this->subs_db->update($this->id, $args)) { |
|
568 | + if (is_user_logged_in()) { |
|
569 | + $userdata = get_userdata(get_current_user_id()); |
|
570 | 570 | $user = $userdata->display_name; |
571 | 571 | } else { |
572 | - $user = __( 'gateway', 'invoicing' ); |
|
572 | + $user = __('gateway', 'invoicing'); |
|
573 | 573 | } |
574 | 574 | |
575 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
576 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
575 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
576 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
577 | 577 | |
578 | 578 | $this->status = 'cancelled'; |
579 | 579 | |
580 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
580 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
581 | 581 | } |
582 | 582 | } |
583 | 583 | |
@@ -592,10 +592,10 @@ discard block |
||
592 | 592 | */ |
593 | 593 | public function can_cancel() { |
594 | 594 | $ret = false; |
595 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
595 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
596 | 596 | $ret = true; |
597 | 597 | } |
598 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
598 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * @return array |
607 | 607 | */ |
608 | 608 | public function get_cancellable_statuses() { |
609 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
609 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -617,9 +617,9 @@ discard block |
||
617 | 617 | */ |
618 | 618 | public function get_cancel_url() { |
619 | 619 | |
620 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
620 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
621 | 621 | |
622 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
622 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | */ |
634 | 634 | public function can_renew() { |
635 | 635 | |
636 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
636 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -644,9 +644,9 @@ discard block |
||
644 | 644 | */ |
645 | 645 | public function get_renew_url() { |
646 | 646 | |
647 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
647 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
648 | 648 | |
649 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
649 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * @return bool |
657 | 657 | */ |
658 | 658 | public function can_update() { |
659 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
659 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | /** |
@@ -667,9 +667,9 @@ discard block |
||
667 | 667 | */ |
668 | 668 | public function get_update_url() { |
669 | 669 | |
670 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
670 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
671 | 671 | |
672 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
672 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -682,11 +682,11 @@ discard block |
||
682 | 682 | |
683 | 683 | $ret = false; |
684 | 684 | |
685 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
685 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
686 | 686 | $ret = true; |
687 | 687 | } |
688 | 688 | |
689 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
689 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
690 | 690 | |
691 | 691 | } |
692 | 692 | |
@@ -700,26 +700,26 @@ discard block |
||
700 | 700 | |
701 | 701 | $ret = false; |
702 | 702 | |
703 | - if ( $this->status == 'expired' ) { |
|
703 | + if ($this->status == 'expired') { |
|
704 | 704 | |
705 | 705 | $ret = true; |
706 | 706 | |
707 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
707 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
708 | 708 | |
709 | 709 | $ret = false; |
710 | 710 | $expiration = $this->get_expiration_time(); |
711 | 711 | |
712 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
712 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
713 | 713 | $ret = true; |
714 | 714 | |
715 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
715 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
716 | 716 | $this->expire(); |
717 | 717 | } |
718 | 718 | } |
719 | 719 | |
720 | 720 | } |
721 | 721 | |
722 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
722 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
723 | 723 | |
724 | 724 | } |
725 | 725 | |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | * @return int |
741 | 741 | */ |
742 | 742 | public function get_expiration_time() { |
743 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
743 | + return strtotime($this->expiration, current_time('timestamp')); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
@@ -764,37 +764,37 @@ discard block |
||
764 | 764 | */ |
765 | 765 | public function get_status_label() { |
766 | 766 | |
767 | - switch( $this->get_status() ) { |
|
767 | + switch ($this->get_status()) { |
|
768 | 768 | case 'active' : |
769 | - $status = __( 'Active', 'invoicing' ); |
|
769 | + $status = __('Active', 'invoicing'); |
|
770 | 770 | break; |
771 | 771 | |
772 | 772 | case 'cancelled' : |
773 | - $status = __( 'Cancelled', 'invoicing' ); |
|
773 | + $status = __('Cancelled', 'invoicing'); |
|
774 | 774 | break; |
775 | 775 | |
776 | 776 | case 'expired' : |
777 | - $status = __( 'Expired', 'invoicing' ); |
|
777 | + $status = __('Expired', 'invoicing'); |
|
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'pending' : |
781 | - $status = __( 'Pending', 'invoicing' ); |
|
781 | + $status = __('Pending', 'invoicing'); |
|
782 | 782 | break; |
783 | 783 | |
784 | 784 | case 'failing' : |
785 | - $status = __( 'Failing', 'invoicing' ); |
|
785 | + $status = __('Failing', 'invoicing'); |
|
786 | 786 | break; |
787 | 787 | |
788 | 788 | case 'trialling' : |
789 | - $status = __( 'Trialling', 'invoicing' ); |
|
789 | + $status = __('Trialling', 'invoicing'); |
|
790 | 790 | break; |
791 | 791 | |
792 | 792 | case 'completed' : |
793 | - $status = __( 'Completed', 'invoicing' ); |
|
793 | + $status = __('Completed', 'invoicing'); |
|
794 | 794 | break; |
795 | 795 | |
796 | 796 | default: |
797 | - $status = ucfirst( $this->get_status() ); |
|
797 | + $status = ucfirst($this->get_status()); |
|
798 | 798 | break; |
799 | 799 | } |
800 | 800 | |
@@ -809,51 +809,51 @@ discard block |
||
809 | 809 | */ |
810 | 810 | public function get_status_label_html() { |
811 | 811 | |
812 | - switch( $get_status = $this->get_status() ) { |
|
812 | + switch ($get_status = $this->get_status()) { |
|
813 | 813 | case 'active' : |
814 | - $status = __( 'Active', 'invoicing' ); |
|
814 | + $status = __('Active', 'invoicing'); |
|
815 | 815 | $class = 'label-info'; |
816 | 816 | break; |
817 | 817 | |
818 | 818 | case 'cancelled' : |
819 | - $status = __( 'Cancelled', 'invoicing' ); |
|
819 | + $status = __('Cancelled', 'invoicing'); |
|
820 | 820 | $class = 'label-danger'; |
821 | 821 | break; |
822 | 822 | |
823 | 823 | case 'expired' : |
824 | - $status = __( 'Expired', 'invoicing' ); |
|
824 | + $status = __('Expired', 'invoicing'); |
|
825 | 825 | $class = 'label-default'; |
826 | 826 | break; |
827 | 827 | |
828 | 828 | case 'pending' : |
829 | - $status = __( 'Pending', 'invoicing' ); |
|
829 | + $status = __('Pending', 'invoicing'); |
|
830 | 830 | $class = 'label-primary'; |
831 | 831 | break; |
832 | 832 | |
833 | 833 | case 'failing' : |
834 | - $status = __( 'Failing', 'invoicing' ); |
|
834 | + $status = __('Failing', 'invoicing'); |
|
835 | 835 | $class = 'label-danger'; |
836 | 836 | break; |
837 | 837 | |
838 | 838 | case 'trialling' : |
839 | - $status = __( 'Trialling', 'invoicing' ); |
|
839 | + $status = __('Trialling', 'invoicing'); |
|
840 | 840 | $class = 'label-info'; |
841 | 841 | break; |
842 | 842 | |
843 | 843 | case 'completed' : |
844 | - $status = __( 'Completed', 'invoicing' ); |
|
844 | + $status = __('Completed', 'invoicing'); |
|
845 | 845 | $class = 'label-success'; |
846 | 846 | break; |
847 | 847 | |
848 | 848 | default: |
849 | - $status = ucfirst( $this->get_status() ); |
|
849 | + $status = ucfirst($this->get_status()); |
|
850 | 850 | $class = 'label-default'; |
851 | 851 | break; |
852 | 852 | } |
853 | 853 | |
854 | 854 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
855 | 855 | |
856 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
856 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -863,18 +863,18 @@ discard block |
||
863 | 863 | * @param string $txn_id The transaction ID from the merchant processor |
864 | 864 | * @return bool |
865 | 865 | */ |
866 | - public function payment_exists( $txn_id = '' ) { |
|
866 | + public function payment_exists($txn_id = '') { |
|
867 | 867 | global $wpdb; |
868 | 868 | |
869 | - if ( empty( $txn_id ) ) { |
|
869 | + if (empty($txn_id)) { |
|
870 | 870 | return false; |
871 | 871 | } |
872 | 872 | |
873 | - $txn_id = esc_sql( $txn_id ); |
|
873 | + $txn_id = esc_sql($txn_id); |
|
874 | 874 | |
875 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
875 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
876 | 876 | |
877 | - if ( $purchase != null ) { |
|
877 | + if ($purchase != null) { |
|
878 | 878 | return true; |
879 | 879 | } |
880 | 880 |