@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | function wpinv_subscription_init() { |
6 | 6 | return WPInv_Subscriptions::instance(); |
7 | 7 | } |
8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Main WPInv_Subscriptions Instance |
21 | 21 | */ |
22 | 22 | public static function instance() { |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if (!isset(self::$instance)) { |
|
24 | 24 | self::$instance = new WPInv_Subscriptions; |
25 | 25 | |
26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | - private function __construct(){ |
|
37 | + private function __construct() { |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | private function setup_constants() { |
64 | 64 | |
65 | 65 | // Make sure CAL_GREGORIAN is defined. |
66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
67 | - define( 'CAL_GREGORIAN', 1 ); |
|
66 | + if (!defined('CAL_GREGORIAN')) { |
|
67 | + define('CAL_GREGORIAN', 1); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function actions() { |
78 | 78 | |
79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 ); |
|
80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
84 | - add_action( 'getpaid_checkout_before_gateway', array( $this, 'add_subscription' ), -999 ); |
|
85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
86 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
87 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
80 | + add_action('admin_notices', array($this, 'notices')); |
|
81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
84 | + add_action('getpaid_checkout_before_gateway', array($this, 'add_subscription'), -999); |
|
85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
86 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
87 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | public function wpinv_subscriptions_list() { |
107 | 107 | add_submenu_page( |
108 | 108 | 'wpinv', |
109 | - __( 'Subscriptions', 'invoicing' ), |
|
110 | - __( 'Subscriptions', 'invoicing' ), |
|
109 | + __('Subscriptions', 'invoicing'), |
|
110 | + __('Subscriptions', 'invoicing'), |
|
111 | 111 | wpinv_get_capability(), |
112 | 112 | 'wpinv-subscriptions', |
113 | 113 | 'wpinv_subscriptions_page' |
@@ -116,37 +116,37 @@ discard block |
||
116 | 116 | |
117 | 117 | public function notices() { |
118 | 118 | |
119 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
119 | + if (empty($_GET['wpinv-message'])) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | $type = 'updated'; |
124 | 124 | $message = ''; |
125 | 125 | |
126 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
126 | + switch (strtolower($_GET['wpinv-message'])) { |
|
127 | 127 | |
128 | 128 | case 'updated' : |
129 | 129 | |
130 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
130 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
131 | 131 | |
132 | 132 | break; |
133 | 133 | |
134 | 134 | case 'deleted' : |
135 | 135 | |
136 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
136 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
137 | 137 | |
138 | 138 | break; |
139 | 139 | |
140 | 140 | case 'cancelled' : |
141 | 141 | |
142 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
142 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
143 | 143 | |
144 | 144 | break; |
145 | 145 | |
146 | 146 | } |
147 | 147 | |
148 | - if ( ! empty( $message ) ) { |
|
149 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
148 | + if (!empty($message)) { |
|
149 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | } |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | * @return void |
160 | 160 | */ |
161 | 161 | function wpinv_get_actions() { |
162 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
163 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
162 | + if (isset($_GET['wpinv_action'])) { |
|
163 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @return void |
173 | 173 | */ |
174 | 174 | function wpinv_post_actions() { |
175 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
176 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
175 | + if (isset($_POST['wpinv_action'])) { |
|
176 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -184,29 +184,29 @@ discard block |
||
184 | 184 | * @param int $frequency_count The frequency of the period. |
185 | 185 | * @return mixed|string|void |
186 | 186 | */ |
187 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
187 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
188 | 188 | |
189 | 189 | $frequency = ''; |
190 | 190 | //Format period details |
191 | - switch ( strtolower( $period ) ) { |
|
191 | + switch (strtolower($period)) { |
|
192 | 192 | case 'day' : |
193 | 193 | case 'd' : |
194 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
194 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
195 | 195 | break; |
196 | 196 | case 'week' : |
197 | 197 | case 'w' : |
198 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
198 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
199 | 199 | break; |
200 | 200 | case 'month' : |
201 | 201 | case 'm' : |
202 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
202 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
203 | 203 | break; |
204 | 204 | case 'year' : |
205 | 205 | case 'y' : |
206 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
206 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
207 | 207 | break; |
208 | 208 | default : |
209 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
209 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
210 | 210 | break; |
211 | 211 | } |
212 | 212 | |
@@ -221,50 +221,50 @@ discard block |
||
221 | 221 | * @since 1.0.0 |
222 | 222 | * @return void |
223 | 223 | */ |
224 | - public function wpinv_process_cancellation( $data ) { |
|
224 | + public function wpinv_process_cancellation($data) { |
|
225 | 225 | |
226 | 226 | |
227 | - if( empty( $data['sub_id'] ) ) { |
|
227 | + if (empty($data['sub_id'])) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | - if( ! is_user_logged_in() ) { |
|
231 | + if (!is_user_logged_in()) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
236 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
235 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
236 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
237 | 237 | } |
238 | 238 | |
239 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
240 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
239 | + $data['sub_id'] = absint($data['sub_id']); |
|
240 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
241 | 241 | |
242 | - if( ! $subscription->can_cancel() ) { |
|
243 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
242 | + if (!$subscription->can_cancel()) { |
|
243 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | try { |
247 | 247 | |
248 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
248 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
249 | 249 | |
250 | 250 | $subscription->cancel(); |
251 | 251 | |
252 | - if( is_admin() ) { |
|
252 | + if (is_admin()) { |
|
253 | 253 | |
254 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
254 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
255 | 255 | exit; |
256 | 256 | |
257 | 257 | } else { |
258 | 258 | |
259 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
260 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
261 | - wp_safe_redirect( $redirect ); |
|
259 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
260 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
261 | + wp_safe_redirect($redirect); |
|
262 | 262 | exit; |
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | - } catch ( Exception $e ) { |
|
267 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
266 | + } catch (Exception $e) { |
|
267 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | } |
@@ -277,33 +277,33 @@ discard block |
||
277 | 277 | * @since 1.0.0 |
278 | 278 | * @return void |
279 | 279 | */ |
280 | - public function add_subscription( $invoice ) { |
|
280 | + public function add_subscription($invoice) { |
|
281 | 281 | |
282 | - $invoice = new WPInv_Invoice( $invoice ); |
|
282 | + $invoice = new WPInv_Invoice($invoice); |
|
283 | 283 | |
284 | 284 | // Abort if it is not recurring. |
285 | - if ( ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
285 | + if (!$invoice->is_recurring() || $invoice->is_renewal()) { |
|
286 | 286 | return; |
287 | 287 | } |
288 | 288 | |
289 | 289 | // Should we create a subscription for the invoice? |
290 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
290 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Get the recurring item. |
295 | - $subscription_item = $invoice->get_recurring( true ); |
|
295 | + $subscription_item = $invoice->get_recurring(true); |
|
296 | 296 | |
297 | 297 | // Prepare the subscription details. |
298 | - $period = $subscription_item->get_recurring_period( true ); |
|
298 | + $period = $subscription_item->get_recurring_period(true); |
|
299 | 299 | $interval = $subscription_item->get_recurring_interval(); |
300 | 300 | $add_period = $interval . ' ' . $period; |
301 | 301 | $trial_period = ''; |
302 | 302 | |
303 | - if ( $invoice->has_free_trial() ) { |
|
303 | + if ($invoice->has_free_trial()) { |
|
304 | 304 | |
305 | - if ( $subscription_item->has_free_trial() ) { |
|
306 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
305 | + if ($subscription_item->has_free_trial()) { |
|
306 | + $trial_period = $subscription_item->get_trial_period(true); |
|
307 | 307 | $free_interval = $subscription_item->get_trial_interval(); |
308 | 308 | } else { |
309 | 309 | $trial_period = $period; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | // Calculate the next renewal date. |
319 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $add_period", current_time( 'timestamp' ) ) ); |
|
319 | + $expiration = date('Y-m-d H:i:s', strtotime("+ $add_period", current_time('timestamp'))); |
|
320 | 320 | |
321 | 321 | // Subscription arguments. |
322 | 322 | $args = array( |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | 'initial_amount' => $invoice->get_initial_total(), |
330 | 330 | 'recurring_amount' => $invoice->get_recurring_total(), |
331 | 331 | 'bill_times' => $subscription_item->get_recurring_limit(), |
332 | - 'created' => current_time( 'mysql' ), |
|
332 | + 'created' => current_time('mysql'), |
|
333 | 333 | 'expiration' => $expiration, |
334 | 334 | 'trial_period' => $trial_period, |
335 | 335 | 'profile_id' => '', |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | ); |
338 | 338 | |
339 | 339 | // Create or update the subscription. |
340 | - $subscription = wpinv_get_subscription( $invoice ); |
|
340 | + $subscription = wpinv_get_subscription($invoice); |
|
341 | 341 | |
342 | - if ( empty( $subscription ) ) { |
|
342 | + if (empty($subscription)) { |
|
343 | 343 | |
344 | 344 | $subscription = new WPInv_Subscription(); |
345 | - $subscription->create( $args ); |
|
345 | + $subscription->create($args); |
|
346 | 346 | |
347 | 347 | } else { |
348 | 348 | |
349 | 349 | |
350 | - unset( $args['transaction_id'] ); |
|
351 | - unset( $args['profile_id'] ); |
|
352 | - $subscription->update( $args ); |
|
350 | + unset($args['transaction_id']); |
|
351 | + unset($args['profile_id']); |
|
352 | + $subscription->update($args); |
|
353 | 353 | |
354 | 354 | } |
355 | 355 | |
@@ -362,21 +362,21 @@ discard block |
||
362 | 362 | * @param array $data |
363 | 363 | * @since 1.0.19 |
364 | 364 | */ |
365 | - public function admin_update_single_subscription( $args ) { |
|
365 | + public function admin_update_single_subscription($args) { |
|
366 | 366 | |
367 | 367 | // Ensure the subscription exists and that a status has been given. |
368 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
368 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | 372 | // Retrieve the subscriptions. |
373 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
373 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
374 | 374 | |
375 | - if ( $subscription->get_id() ) { |
|
375 | + if ($subscription->get_id()) { |
|
376 | 376 | |
377 | - $subscription->set_status( $args['subscription_status'] ); |
|
377 | + $subscription->set_status($args['subscription_status']); |
|
378 | 378 | $subscription->save(); |
379 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
379 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
380 | 380 | |
381 | 381 | } |
382 | 382 | |
@@ -388,25 +388,25 @@ discard block |
||
388 | 388 | * @param array $data |
389 | 389 | * @since 1.0.19 |
390 | 390 | */ |
391 | - public function admin_renew_single_subscription( $args ) { |
|
391 | + public function admin_renew_single_subscription($args) { |
|
392 | 392 | |
393 | 393 | // Ensure the subscription exists and that a status has been given. |
394 | - if ( empty( $args['id'] ) ) { |
|
394 | + if (empty($args['id'])) { |
|
395 | 395 | return; |
396 | 396 | } |
397 | 397 | |
398 | 398 | // Retrieve the subscriptions. |
399 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
399 | + $subscription = new WPInv_Subscription($args['id']); |
|
400 | 400 | |
401 | - if ( $subscription->get_id() ) { |
|
401 | + if ($subscription->get_id()) { |
|
402 | 402 | |
403 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
403 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
404 | 404 | |
405 | - if ( $subscription->add_payment( $args ) ) { |
|
405 | + if ($subscription->add_payment($args)) { |
|
406 | 406 | $subscription->renew(); |
407 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
407 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
408 | 408 | } else { |
409 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
409 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | wp_safe_redirect( |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * @param string $prop The prop to set. |
64 | 64 | * @param mixed $value The value to retrieve. |
65 | 65 | */ |
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
66 | + public function set($prop, $value) { |
|
67 | + $this->data[$prop] = $value; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @param string $prop The prop to set. |
74 | 74 | * @return mixed The value. |
75 | 75 | */ |
76 | - public function get( $prop ) { |
|
76 | + public function get($prop) { |
|
77 | 77 | |
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
78 | + if (isset($this->data[$prop])) { |
|
79 | + return $this->data[$prop]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return null; |
@@ -88,29 +88,29 @@ discard block |
||
88 | 88 | public function set_properties() { |
89 | 89 | |
90 | 90 | // Sessions. |
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
91 | + $this->set('session', new WPInv_Session_Handler()); |
|
92 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
93 | 93 | $this->form_elements = new WPInv_Payment_Form_Elements(); |
94 | 94 | $this->tax = new WPInv_EUVat(); |
95 | 95 | $this->tax->init(); |
96 | 96 | $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
97 | 97 | |
98 | 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() ); |
|
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 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Define plugin constants. |
110 | 110 | */ |
111 | 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 ) ); |
|
112 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
113 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
114 | 114 | $this->version = WPINV_VERSION; |
115 | 115 | } |
116 | 116 | |
@@ -121,26 +121,26 @@ discard block |
||
121 | 121 | */ |
122 | 122 | protected function init_hooks() { |
123 | 123 | /* Internationalize the text strings used. */ |
124 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
124 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
125 | 125 | |
126 | 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' ) ); |
|
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 | 130 | |
131 | - if ( class_exists( 'BuddyPress' ) ) { |
|
132 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
131 | + if (class_exists('BuddyPress')) { |
|
132 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
133 | 133 | } |
134 | 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' ) ); |
|
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 | 140 | |
141 | 141 | // Fires after registering actions. |
142 | - do_action( 'wpinv_actions', $this ); |
|
143 | - do_action( 'getpaid_actions', $this ); |
|
142 | + do_action('wpinv_actions', $this); |
|
143 | + do_action('getpaid_actions', $this); |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | /* Internationalize the text strings used. */ |
149 | 149 | $this->load_textdomain(); |
150 | 150 | |
151 | - do_action( 'wpinv_loaded' ); |
|
151 | + do_action('wpinv_loaded'); |
|
152 | 152 | |
153 | 153 | // Fix oxygen page builder conflict |
154 | - if ( function_exists( 'ct_css_output' ) ) { |
|
154 | + if (function_exists('ct_css_output')) { |
|
155 | 155 | wpinv_oxygen_fix_conflict(); |
156 | 156 | } |
157 | 157 | } |
@@ -161,21 +161,21 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @since 1.0 |
163 | 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(); |
|
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 | 167 | } |
168 | 168 | |
169 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
169 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
170 | 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' ); |
|
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 | 174 | |
175 | 175 | /** |
176 | 176 | * Define language constants. |
177 | 177 | */ |
178 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -184,114 +184,114 @@ discard block |
||
184 | 184 | public function includes() { |
185 | 185 | |
186 | 186 | // Start with the settings. |
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
188 | 188 | |
189 | 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' ); |
|
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 | 193 | |
194 | 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' ); |
|
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 | 209 | |
210 | 210 | // Register autoloader. |
211 | 211 | try { |
212 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
213 | - } catch ( Exception $e ) { |
|
214 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + spl_autoload_register(array($this, 'autoload'), true); |
|
213 | + } catch (Exception $e) { |
|
214 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
215 | 215 | } |
216 | 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' ); |
|
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 | 240 | |
241 | 241 | /** |
242 | 242 | * Load the tax class. |
243 | 243 | */ |
244 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
245 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
244 | + if (!class_exists('WPInv_EUVat')) { |
|
245 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
246 | 246 | } |
247 | 247 | |
248 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
249 | - if ( !empty( $gateways ) ) { |
|
250 | - foreach ( $gateways as $gateway ) { |
|
251 | - if ( $gateway == 'manual' ) { |
|
248 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
249 | + if (!empty($gateways)) { |
|
250 | + foreach ($gateways as $gateway) { |
|
251 | + if ($gateway == 'manual') { |
|
252 | 252 | continue; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
256 | 256 | |
257 | - if ( file_exists( $gateway_file ) ) { |
|
258 | - require_once( $gateway_file ); |
|
257 | + if (file_exists($gateway_file)) { |
|
258 | + require_once($gateway_file); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
263 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
264 | 264 | GetPaid_Post_Types_Admin::init(); |
265 | 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' ); |
|
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 | 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' ); |
|
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 | 275 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
276 | 276 | // load the user class only on the users.php page |
277 | 277 | global $pagenow; |
278 | - if($pagenow=='users.php'){ |
|
278 | + if ($pagenow == 'users.php') { |
|
279 | 279 | new WPInv_Admin_Users(); |
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | 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' ); |
|
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 | 287 | } |
288 | 288 | |
289 | 289 | // include css inliner |
290 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
291 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
290 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
291 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
292 | 292 | } |
293 | 293 | |
294 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
294 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -302,21 +302,21 @@ discard block |
||
302 | 302 | * @since 1.0.19 |
303 | 303 | * @return void |
304 | 304 | */ |
305 | - public function autoload( $class_name ) { |
|
305 | + public function autoload($class_name) { |
|
306 | 306 | |
307 | 307 | // Normalize the class name... |
308 | - $class_name = strtolower( $class_name ); |
|
308 | + $class_name = strtolower($class_name); |
|
309 | 309 | |
310 | 310 | // ... and make sure it is our class. |
311 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
311 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
312 | 312 | return; |
313 | 313 | } |
314 | 314 | |
315 | 315 | // Next, prepare the file name from the class. |
316 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
316 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
317 | 317 | |
318 | 318 | // Base path of the classes. |
319 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
319 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
320 | 320 | |
321 | 321 | // And an array of possible locations in order of importance. |
322 | 322 | $locations = array( |
@@ -328,10 +328,10 @@ discard block |
||
328 | 328 | "$plugin_path/includes/admin/meta-boxes", |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
331 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
332 | 332 | |
333 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
334 | - include trailingslashit( $location ) . $file_name; |
|
333 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
334 | + include trailingslashit($location) . $file_name; |
|
335 | 335 | break; |
336 | 336 | } |
337 | 337 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | public function init() { |
346 | 346 | |
347 | 347 | // Fires before getpaid inits. |
348 | - do_action( 'before_getpaid_init', $this ); |
|
348 | + do_action('before_getpaid_init', $this); |
|
349 | 349 | |
350 | 350 | // Load default gateways. |
351 | 351 | $gateways = apply_filters( |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | ) |
360 | 360 | ); |
361 | 361 | |
362 | - foreach ( $gateways as $id => $class ) { |
|
363 | - $this->gateways[ $id ] = new $class(); |
|
362 | + foreach ($gateways as $id => $class) { |
|
363 | + $this->gateways[$id] = new $class(); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | // Fires after getpaid inits. |
367 | - do_action( 'getpaid_init', $this ); |
|
367 | + do_action('getpaid_init', $this); |
|
368 | 368 | |
369 | 369 | } |
370 | 370 | |
@@ -374,82 +374,82 @@ discard block |
||
374 | 374 | public function maybe_process_ipn() { |
375 | 375 | |
376 | 376 | // Ensure that this is an IPN request. |
377 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
377 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
381 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
382 | 382 | |
383 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
384 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
383 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
384 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
385 | 385 | exit; |
386 | 386 | |
387 | 387 | } |
388 | 388 | |
389 | 389 | public function enqueue_scripts() { |
390 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
390 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
391 | 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' ); |
|
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 | 395 | |
396 | 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' ) ); |
|
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 | 399 | |
400 | 400 | $localize = array(); |
401 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
402 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
401 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
402 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
403 | 403 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
404 | 404 | $localize['currency_pos'] = wpinv_currency_position(); |
405 | 405 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
406 | 406 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
407 | 407 | $localize['decimals'] = wpinv_decimals(); |
408 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
408 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
409 | 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' ); |
|
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 | 413 | |
414 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
414 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
415 | 415 | |
416 | - wp_enqueue_script( 'jquery-blockui' ); |
|
416 | + wp_enqueue_script('jquery-blockui'); |
|
417 | 417 | $autofill_api = wpinv_get_option('address_autofill_api'); |
418 | 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' ); |
|
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 | 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 ); |
|
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 | 425 | } |
426 | 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 ); |
|
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 | 429 | |
430 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
431 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
430 | + wp_enqueue_script('wpinv-front-script'); |
|
431 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
432 | 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 ); |
|
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 | 435 | } |
436 | 436 | |
437 | 437 | public function wpinv_actions() { |
438 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
439 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
438 | + if (isset($_REQUEST['wpi_action'])) { |
|
439 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
440 | 440 | } |
441 | 441 | } |
442 | 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() ); |
|
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 | 446 | } |
447 | 447 | |
448 | 448 | return $wp_query; |
449 | 449 | } |
450 | 450 | |
451 | 451 | public function bp_invoicing_init() { |
452 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
452 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | ) |
471 | 471 | ); |
472 | 472 | |
473 | - foreach ( $widgets as $widget ) { |
|
474 | - register_widget( $widget ); |
|
473 | + foreach ($widgets as $widget) { |
|
474 | + register_widget($widget); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | } |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | * @since 1.0.19 |
483 | 483 | * @param int[] $excluded_posts_ids |
484 | 484 | */ |
485 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
485 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
486 | 486 | |
487 | 487 | // Ensure that we have an array. |
488 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
488 | + if (!is_array($excluded_posts_ids)) { |
|
489 | 489 | $excluded_posts_ids = array(); |
490 | 490 | } |
491 | 491 | |
@@ -493,24 +493,24 @@ discard block |
||
493 | 493 | $our_pages = array(); |
494 | 494 | |
495 | 495 | // Checkout page. |
496 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
496 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
497 | 497 | |
498 | 498 | // Success page. |
499 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
499 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
500 | 500 | |
501 | 501 | // Failure page. |
502 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
502 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
503 | 503 | |
504 | 504 | // History page. |
505 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
505 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
506 | 506 | |
507 | 507 | // Subscriptions page. |
508 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
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 | 512 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
513 | - return array_unique( $excluded_posts_ids ); |
|
513 | + return array_unique($excluded_posts_ids); |
|
514 | 514 | |
515 | 515 | } |
516 | 516 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * The Subscription Class |
@@ -70,27 +70,27 @@ discard block |
||
70 | 70 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
71 | 71 | * @param bool $deprecated |
72 | 72 | */ |
73 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
73 | + function __construct($subscription = 0, $deprecated = false) { |
|
74 | 74 | |
75 | - parent::__construct( $subscription ); |
|
75 | + parent::__construct($subscription); |
|
76 | 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 ); |
|
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 | 85 | } else { |
86 | - $this->set_object_read( true ); |
|
86 | + $this->set_object_read(true); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | // Load the datastore. |
90 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
90 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
91 | 91 | |
92 | - if ( $this->get_id() > 0 ) { |
|
93 | - $this->data_store->read( $this ); |
|
92 | + if ($this->get_id() > 0) { |
|
93 | + $this->data_store->read($this); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | } |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | * @since 1.0.19 |
106 | 106 | * @return int |
107 | 107 | */ |
108 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
108 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
109 | 109 | global $wpdb; |
110 | 110 | |
111 | 111 | // Trim the value. |
112 | - $value = trim( $value ); |
|
112 | + $value = trim($value); |
|
113 | 113 | |
114 | - if ( empty( $value ) ) { |
|
114 | + if (empty($value)) { |
|
115 | 115 | return 0; |
116 | 116 | } |
117 | 117 | |
118 | - if ( 'invoice_id' == $field ) { |
|
118 | + if ('invoice_id' == $field) { |
|
119 | 119 | $field = 'parent_payment_id'; |
120 | 120 | } |
121 | 121 | |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | ); |
128 | 128 | |
129 | 129 | // Ensure a field has been passed. |
130 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
130 | + if (empty($field) || !in_array($field, $fields)) { |
|
131 | 131 | return 0; |
132 | 132 | } |
133 | 133 | |
134 | 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 ) ) { |
|
135 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
136 | + if (!empty($subscription_id)) { |
|
137 | 137 | return $subscription_id; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // Fetch from the db. |
141 | 141 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
142 | 142 | $subscription_id = (int) $wpdb->get_var( |
143 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
143 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
144 | 144 | ); |
145 | 145 | |
146 | - if ( empty( $subscription_id ) ) { |
|
146 | + if (empty($subscription_id)) { |
|
147 | 147 | return 0; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Update the cache with our data. |
151 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
151 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
152 | 152 | |
153 | 153 | return $subscription_id; |
154 | 154 | } |
@@ -157,17 +157,17 @@ discard block |
||
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' ); |
|
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 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Checks if a subscription key is set. |
168 | 168 | */ |
169 | - public function _isset( $key ) { |
|
170 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
169 | + public function _isset($key) { |
|
170 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /* |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * @param string $context View or edit context. |
193 | 193 | * @return int |
194 | 194 | */ |
195 | - public function get_customer_id( $context = 'view' ) { |
|
196 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | + public function get_customer_id($context = 'view') { |
|
196 | + return (int) $this->get_prop('customer_id', $context); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param string $context View or edit context. |
204 | 204 | * @return WP_User|false WP_User object on success, false on failure. |
205 | 205 | */ |
206 | - public function get_customer( $context = 'view' ) { |
|
207 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | + public function get_customer($context = 'view') { |
|
207 | + return get_userdata($this->get_customer_id($context)); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param string $context View or edit context. |
215 | 215 | * @return int |
216 | 216 | */ |
217 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
218 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | + public function get_parent_invoice_id($context = 'view') { |
|
218 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | * @param string $context View or edit context. |
226 | 226 | * @return int |
227 | 227 | */ |
228 | - public function get_parent_payment_id( $context = 'view' ) { |
|
229 | - return $this->get_parent_invoice_id( $context ); |
|
228 | + public function get_parent_payment_id($context = 'view') { |
|
229 | + return $this->get_parent_invoice_id($context); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | * @since 1.0.0 |
236 | 236 | * @return int |
237 | 237 | */ |
238 | - public function get_original_payment_id( $context = 'view' ) { |
|
239 | - return $this->get_parent_invoice_id( $context ); |
|
238 | + public function get_original_payment_id($context = 'view') { |
|
239 | + return $this->get_parent_invoice_id($context); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | * @param string $context View or edit context. |
247 | 247 | * @return WPInv_Invoice |
248 | 248 | */ |
249 | - public function get_parent_invoice( $context = 'view' ) { |
|
250 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | + public function get_parent_invoice($context = 'view') { |
|
250 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | * @param string $context View or edit context. |
258 | 258 | * @return WPInv_Invoice |
259 | 259 | */ |
260 | - public function get_parent_payment( $context = 'view' ) { |
|
261 | - return $this->get_parent_invoice( $context ); |
|
260 | + public function get_parent_payment($context = 'view') { |
|
261 | + return $this->get_parent_invoice($context); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | * @param string $context View or edit context. |
269 | 269 | * @return int |
270 | 270 | */ |
271 | - public function get_product_id( $context = 'view' ) { |
|
272 | - return (int) $this->get_prop( 'product_id', $context ); |
|
271 | + public function get_product_id($context = 'view') { |
|
272 | + return (int) $this->get_prop('product_id', $context); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param string $context View or edit context. |
280 | 280 | * @return WPInv_Item |
281 | 281 | */ |
282 | - public function get_product( $context = 'view' ) { |
|
283 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | + public function get_product($context = 'view') { |
|
283 | + return new WPInv_Item($this->get_product_id($context)); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param string $context View or edit context. |
293 | 293 | * @return string |
294 | 294 | */ |
295 | - public function get_gateway( $context = 'view' ) { |
|
296 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | + public function get_gateway($context = 'view') { |
|
296 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | * @param string $context View or edit context. |
304 | 304 | * @return string |
305 | 305 | */ |
306 | - public function get_period( $context = 'view' ) { |
|
307 | - return $this->get_prop( 'period', $context ); |
|
306 | + public function get_period($context = 'view') { |
|
307 | + return $this->get_prop('period', $context); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * @param string $context View or edit context. |
315 | 315 | * @return int |
316 | 316 | */ |
317 | - public function get_frequency( $context = 'view' ) { |
|
318 | - return (int) $this->get_prop( 'frequency', $context ); |
|
317 | + public function get_frequency($context = 'view') { |
|
318 | + return (int) $this->get_prop('frequency', $context); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | * @param string $context View or edit context. |
326 | 326 | * @return float |
327 | 327 | */ |
328 | - public function get_initial_amount( $context = 'view' ) { |
|
329 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | + public function get_initial_amount($context = 'view') { |
|
329 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @param string $context View or edit context. |
337 | 337 | * @return float |
338 | 338 | */ |
339 | - public function get_recurring_amount( $context = 'view' ) { |
|
340 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | + public function get_recurring_amount($context = 'view') { |
|
340 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * @param string $context View or edit context. |
348 | 348 | * @return int |
349 | 349 | */ |
350 | - public function get_bill_times( $context = 'view' ) { |
|
351 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | + public function get_bill_times($context = 'view') { |
|
351 | + return (int) $this->get_prop('bill_times', $context); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @param string $context View or edit context. |
359 | 359 | * @return string |
360 | 360 | */ |
361 | - public function get_transaction_id( $context = 'view' ) { |
|
362 | - return $this->get_prop( 'transaction_id', $context ); |
|
361 | + public function get_transaction_id($context = 'view') { |
|
362 | + return $this->get_prop('transaction_id', $context); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | * @param string $context View or edit context. |
370 | 370 | * @return string |
371 | 371 | */ |
372 | - public function get_created( $context = 'view' ) { |
|
373 | - return $this->get_prop( 'created', $context ); |
|
372 | + public function get_created($context = 'view') { |
|
373 | + return $this->get_prop('created', $context); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @param string $context View or edit context. |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - public function get_date_created( $context = 'view' ) { |
|
384 | - return $this->get_created( $context ); |
|
383 | + public function get_date_created($context = 'view') { |
|
384 | + return $this->get_created($context); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function get_time_created() { |
394 | 394 | $created = $this->get_date_created(); |
395 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
395 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -402,11 +402,11 @@ discard block |
||
402 | 402 | * @param string $context View or edit context. |
403 | 403 | * @return string |
404 | 404 | */ |
405 | - public function get_date_created_gmt( $context = 'view' ) { |
|
406 | - $date = $this->get_date_created( $context ); |
|
405 | + public function get_date_created_gmt($context = 'view') { |
|
406 | + $date = $this->get_date_created($context); |
|
407 | 407 | |
408 | - if ( $date ) { |
|
409 | - $date = get_gmt_from_date( $date ); |
|
408 | + if ($date) { |
|
409 | + $date = get_gmt_from_date($date); |
|
410 | 410 | } |
411 | 411 | return $date; |
412 | 412 | } |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | * @param string $context View or edit context. |
419 | 419 | * @return string |
420 | 420 | */ |
421 | - public function get_next_renewal_date( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'expiration', $context ); |
|
421 | + public function get_next_renewal_date($context = 'view') { |
|
422 | + return $this->get_prop('expiration', $context); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * @param string $context View or edit context. |
430 | 430 | * @return string |
431 | 431 | */ |
432 | - public function get_expiration( $context = 'view' ) { |
|
433 | - return $this->get_next_renewal_date( $context ); |
|
432 | + public function get_expiration($context = 'view') { |
|
433 | + return $this->get_next_renewal_date($context); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -442,12 +442,12 @@ discard block |
||
442 | 442 | public function get_expiration_time() { |
443 | 443 | $expiration = $this->get_expiration(); |
444 | 444 | |
445 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
446 | - return current_time( 'timestamp' ); |
|
445 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
446 | + return current_time('timestamp'); |
|
447 | 447 | } |
448 | 448 | |
449 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
450 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
450 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | * @param string $context View or edit context. |
458 | 458 | * @return string |
459 | 459 | */ |
460 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
461 | - $date = $this->get_next_renewal_date( $context ); |
|
460 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
461 | + $date = $this->get_next_renewal_date($context); |
|
462 | 462 | |
463 | - if ( $date ) { |
|
464 | - $date = get_gmt_from_date( $date ); |
|
463 | + if ($date) { |
|
464 | + $date = get_gmt_from_date($date); |
|
465 | 465 | } |
466 | 466 | return $date; |
467 | 467 | } |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | * @param string $context View or edit context. |
474 | 474 | * @return string |
475 | 475 | */ |
476 | - public function get_trial_period( $context = 'view' ) { |
|
477 | - return $this->get_prop( 'trial_period', $context ); |
|
476 | + public function get_trial_period($context = 'view') { |
|
477 | + return $this->get_prop('trial_period', $context); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | * @param string $context View or edit context. |
485 | 485 | * @return string |
486 | 486 | */ |
487 | - public function get_status( $context = 'view' ) { |
|
488 | - return $this->get_prop( 'status', $context ); |
|
487 | + public function get_status($context = 'view') { |
|
488 | + return $this->get_prop('status', $context); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | * @param string $context View or edit context. |
496 | 496 | * @return string |
497 | 497 | */ |
498 | - public function get_profile_id( $context = 'view' ) { |
|
499 | - return $this->get_prop( 'profile_id', $context ); |
|
498 | + public function get_profile_id($context = 'view') { |
|
499 | + return $this->get_prop('profile_id', $context); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /* |
@@ -511,8 +511,8 @@ discard block |
||
511 | 511 | * @since 1.0.19 |
512 | 512 | * @param int $value The customer's id. |
513 | 513 | */ |
514 | - public function set_customer_id( $value ) { |
|
515 | - $this->set_prop( 'customer_id', (int) $value ); |
|
514 | + public function set_customer_id($value) { |
|
515 | + $this->set_prop('customer_id', (int) $value); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | * @since 1.0.19 |
522 | 522 | * @param int $value The parent invoice id. |
523 | 523 | */ |
524 | - public function set_parent_invoice_id( $value ) { |
|
525 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | + public function set_parent_invoice_id($value) { |
|
525 | + $this->set_prop('parent_payment_id', (int) $value); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @since 1.0.19 |
532 | 532 | * @param int $value The parent invoice id. |
533 | 533 | */ |
534 | - public function set_parent_payment_id( $value ) { |
|
535 | - $this->set_parent_invoice_id( $value ); |
|
534 | + public function set_parent_payment_id($value) { |
|
535 | + $this->set_parent_invoice_id($value); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | * @since 1.0.19 |
542 | 542 | * @param int $value The parent invoice id. |
543 | 543 | */ |
544 | - public function set_original_payment_id( $value ) { |
|
545 | - $this->set_parent_invoice_id( $value ); |
|
544 | + public function set_original_payment_id($value) { |
|
545 | + $this->set_parent_invoice_id($value); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | * @since 1.0.19 |
552 | 552 | * @param int $value The subscription product id. |
553 | 553 | */ |
554 | - public function set_product_id( $value ) { |
|
555 | - $this->set_prop( 'product_id', (int) $value ); |
|
554 | + public function set_product_id($value) { |
|
555 | + $this->set_prop('product_id', (int) $value); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @since 1.0.19 |
562 | 562 | * @param string $value The renewal period. |
563 | 563 | */ |
564 | - public function set_period( $value ) { |
|
565 | - $this->set_prop( 'period', $value ); |
|
564 | + public function set_period($value) { |
|
565 | + $this->set_prop('period', $value); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | * @since 1.0.19 |
572 | 572 | * @param int $value The subscription frequency. |
573 | 573 | */ |
574 | - public function set_frequency( $value ) { |
|
575 | - $value = empty( $value ) ? 1 : (int) $value; |
|
576 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
574 | + public function set_frequency($value) { |
|
575 | + $value = empty($value) ? 1 : (int) $value; |
|
576 | + $this->set_prop('frequency', absint($value)); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -582,8 +582,8 @@ discard block |
||
582 | 582 | * @since 1.0.19 |
583 | 583 | * @param float $value The initial subcription amount. |
584 | 584 | */ |
585 | - public function set_initial_amount( $value ) { |
|
586 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | + public function set_initial_amount($value) { |
|
586 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -592,8 +592,8 @@ discard block |
||
592 | 592 | * @since 1.0.19 |
593 | 593 | * @param float $value The recurring subcription amount. |
594 | 594 | */ |
595 | - public function set_recurring_amount( $value ) { |
|
596 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | + public function set_recurring_amount($value) { |
|
596 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -602,8 +602,8 @@ discard block |
||
602 | 602 | * @since 1.0.19 |
603 | 603 | * @param int $value Bill times. |
604 | 604 | */ |
605 | - public function set_bill_times( $value ) { |
|
606 | - $this->set_prop( 'bill_times', (int) $value ); |
|
605 | + public function set_bill_times($value) { |
|
606 | + $this->set_prop('bill_times', (int) $value); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -612,8 +612,8 @@ discard block |
||
612 | 612 | * @since 1.0.19 |
613 | 613 | * @param string $value Bill times. |
614 | 614 | */ |
615 | - public function set_transaction_id( $value ) { |
|
616 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | + public function set_transaction_id($value) { |
|
616 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -622,15 +622,15 @@ discard block |
||
622 | 622 | * @since 1.0.19 |
623 | 623 | * @param string $value strtotime compliant date. |
624 | 624 | */ |
625 | - public function set_created( $value ) { |
|
626 | - $date = strtotime( $value ); |
|
625 | + public function set_created($value) { |
|
626 | + $date = strtotime($value); |
|
627 | 627 | |
628 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
629 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
628 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
629 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
630 | 630 | return; |
631 | 631 | } |
632 | 632 | |
633 | - $this->set_prop( 'created', '' ); |
|
633 | + $this->set_prop('created', ''); |
|
634 | 634 | |
635 | 635 | } |
636 | 636 | |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | * @since 1.0.19 |
641 | 641 | * @param string $value strtotime compliant date. |
642 | 642 | */ |
643 | - public function set_date_created( $value ) { |
|
644 | - $this->set_created( $value ); |
|
643 | + public function set_date_created($value) { |
|
644 | + $this->set_created($value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,15 +650,15 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param string $value strtotime compliant date. |
652 | 652 | */ |
653 | - public function set_next_renewal_date( $value ) { |
|
654 | - $date = strtotime( $value ); |
|
653 | + public function set_next_renewal_date($value) { |
|
654 | + $date = strtotime($value); |
|
655 | 655 | |
656 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
657 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
656 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
657 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
658 | 658 | return; |
659 | 659 | } |
660 | 660 | |
661 | - $this->set_prop( 'expiration', '' ); |
|
661 | + $this->set_prop('expiration', ''); |
|
662 | 662 | |
663 | 663 | } |
664 | 664 | |
@@ -668,8 +668,8 @@ discard block |
||
668 | 668 | * @since 1.0.19 |
669 | 669 | * @param string $value strtotime compliant date. |
670 | 670 | */ |
671 | - public function set_expiration( $value ) { |
|
672 | - $this->set_next_renewal_date( $value ); |
|
671 | + public function set_expiration($value) { |
|
672 | + $this->set_next_renewal_date($value); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -678,8 +678,8 @@ discard block |
||
678 | 678 | * @since 1.0.19 |
679 | 679 | * @param string $value trial period e.g 1 year. |
680 | 680 | */ |
681 | - public function set_trial_period( $value ) { |
|
682 | - $this->set_prop( 'trial_period', $value ); |
|
681 | + public function set_trial_period($value) { |
|
682 | + $this->set_prop('trial_period', $value); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | /** |
@@ -688,19 +688,19 @@ discard block |
||
688 | 688 | * @since 1.0.19 |
689 | 689 | * @param string $new_status New subscription status. |
690 | 690 | */ |
691 | - public function set_status( $new_status ) { |
|
691 | + public function set_status($new_status) { |
|
692 | 692 | |
693 | 693 | // Abort if this is not a valid status; |
694 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
694 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
695 | 695 | return; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $old_status = $this->get_status(); |
699 | - $this->set_prop( 'status', $new_status ); |
|
699 | + $this->set_prop('status', $new_status); |
|
700 | 700 | |
701 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
701 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
702 | 702 | $this->status_transition = array( |
703 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
703 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
704 | 704 | 'to' => $new_status, |
705 | 705 | ); |
706 | 706 | } |
@@ -713,8 +713,8 @@ discard block |
||
713 | 713 | * @since 1.0.19 |
714 | 714 | * @param string $value the remote profile id. |
715 | 715 | */ |
716 | - public function set_profile_id( $value ) { |
|
717 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | + public function set_profile_id($value) { |
|
717 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /* |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | * @param string|array String or array of strings to check for. |
733 | 733 | * @return bool |
734 | 734 | */ |
735 | - public function has_status( $status ) { |
|
736 | - return in_array( $this->get_status(), wpinv_parse_list( $status ) ); |
|
735 | + public function has_status($status) { |
|
736 | + return in_array($this->get_status(), wpinv_parse_list($status)); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | */ |
744 | 744 | public function has_trial_period() { |
745 | 745 | $period = $this->get_trial_period(); |
746 | - return ! empty( $period ); |
|
746 | + return !empty($period); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | * @return bool |
753 | 753 | */ |
754 | 754 | public function is_active() { |
755 | - return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
755 | + return $this->has_status('active trialling') && $this->get_expiration_time() > current_time('mysql'); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | /** |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | * @return bool |
762 | 762 | */ |
763 | 763 | public function is_expired() { |
764 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
764 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /* |
@@ -776,11 +776,11 @@ discard block |
||
776 | 776 | /** |
777 | 777 | * Backwards compatibilty. |
778 | 778 | */ |
779 | - public function create( $data = array() ) { |
|
779 | + public function create($data = array()) { |
|
780 | 780 | |
781 | 781 | // Set the properties. |
782 | - if ( is_array( $data ) ) { |
|
783 | - $this->set_props( $data ); |
|
782 | + if (is_array($data)) { |
|
783 | + $this->set_props($data); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | // Save the item. |
@@ -791,8 +791,8 @@ discard block |
||
791 | 791 | /** |
792 | 792 | * Backwards compatibilty. |
793 | 793 | */ |
794 | - public function update( $args = array() ) { |
|
795 | - return $this->create( $args ); |
|
794 | + public function update($args = array()) { |
|
795 | + return $this->create($args); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | array( |
807 | 807 | 'post_parent' => $this->get_parent_payment_id(), |
808 | 808 | 'numberposts' => -1, |
809 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
809 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
810 | 810 | 'orderby' => 'ID', |
811 | 811 | 'order' => 'DESC', |
812 | 812 | 'post_type' => 'wpi_invoice' |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | ); |
832 | 832 | |
833 | 833 | // Maybe include parent invoice. |
834 | - if ( ! $this->has_status( 'pending' ) ) { |
|
834 | + if (!$this->has_status('pending')) { |
|
835 | 835 | $count++; |
836 | 836 | } |
837 | 837 | |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | public function get_times_billed() { |
848 | 848 | $times_billed = $this->get_total_payments(); |
849 | 849 | |
850 | - if ( $this->has_trial_period() && $times_billed > 0 ) { |
|
850 | + if ($this->has_trial_period() && $times_billed > 0) { |
|
851 | 851 | $times_billed--; |
852 | 852 | } |
853 | 853 | |
@@ -862,49 +862,49 @@ discard block |
||
862 | 862 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
863 | 863 | * @return bool |
864 | 864 | */ |
865 | - public function add_payment( $args = array(), $invoice = false ) { |
|
865 | + public function add_payment($args = array(), $invoice = false) { |
|
866 | 866 | |
867 | 867 | // Process each payment once. |
868 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
868 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | |
872 | 872 | // Are we creating a new invoice? |
873 | - if ( empty( $invoice ) ) { |
|
873 | + if (empty($invoice)) { |
|
874 | 874 | $invoice = $this->create_payment(); |
875 | 875 | |
876 | - if ( empty( $invoice ) ) { |
|
876 | + if (empty($invoice)) { |
|
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | - $invoice->set_status( 'wpi-renewal' ); |
|
880 | + $invoice->set_status('wpi-renewal'); |
|
881 | 881 | |
882 | 882 | } |
883 | 883 | |
884 | 884 | // Maybe set a transaction id. |
885 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
886 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
885 | + if (!empty($args['transaction_id'])) { |
|
886 | + $invoice->set_transaction_id($args['transaction_id']); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | // Set the completed date. |
890 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
890 | + $invoice->set_completed_date(current_time('mysql')); |
|
891 | 891 | |
892 | 892 | // And the gateway. |
893 | - if ( ! empty( $args['gateway'] ) ) { |
|
894 | - $invoice->set_gateway( $args['gateway'] ); |
|
893 | + if (!empty($args['gateway'])) { |
|
894 | + $invoice->set_gateway($args['gateway']); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | $invoice->save(); |
898 | 898 | |
899 | - if ( ! $invoice->get_id() ) { |
|
899 | + if (!$invoice->get_id()) { |
|
900 | 900 | return 0; |
901 | 901 | } |
902 | 902 | |
903 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
904 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
905 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
903 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
904 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
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 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
907 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
908 | 908 | |
909 | 909 | return $invoice->get_id(); |
910 | 910 | } |
@@ -919,21 +919,21 @@ discard block |
||
919 | 919 | |
920 | 920 | $parent_invoice = $this->get_parent_payment(); |
921 | 921 | |
922 | - if ( ! $parent_invoice->get_id() ) { |
|
922 | + if (!$parent_invoice->get_id()) { |
|
923 | 923 | return false; |
924 | 924 | } |
925 | 925 | |
926 | 926 | // Duplicate the parent invoice. |
927 | 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' ); |
|
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 | 937 | $invoice->recalculate_total(); |
938 | 938 | $invoice->save(); |
939 | 939 | |
@@ -949,20 +949,20 @@ discard block |
||
949 | 949 | public function renew() { |
950 | 950 | |
951 | 951 | // Complete subscription if applicable |
952 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
952 | + if ($this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times()) { |
|
953 | 953 | return $this->complete(); |
954 | 954 | } |
955 | 955 | |
956 | 956 | // Calculate new expiration |
957 | 957 | $frequency = $this->get_frequency(); |
958 | 958 | $period = $this->get_period(); |
959 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
959 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
960 | 960 | |
961 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
962 | - $this->set_status( 'active' ); |
|
961 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
962 | + $this->set_status('active'); |
|
963 | 963 | return $this->save(); |
964 | 964 | |
965 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
965 | + do_action('getpaid_subscription_renewed', $this); |
|
966 | 966 | |
967 | 967 | } |
968 | 968 | |
@@ -977,11 +977,11 @@ discard block |
||
977 | 977 | public function complete() { |
978 | 978 | |
979 | 979 | // Only mark a subscription as complete if it's not already cancelled. |
980 | - if ( $this->has_status( 'cancelled' ) ) { |
|
980 | + if ($this->has_status('cancelled')) { |
|
981 | 981 | return false; |
982 | 982 | } |
983 | 983 | |
984 | - $this->set_status( 'completed' ); |
|
984 | + $this->set_status('completed'); |
|
985 | 985 | return $this->save(); |
986 | 986 | |
987 | 987 | } |
@@ -993,14 +993,14 @@ discard block |
||
993 | 993 | * @param bool $check_expiration |
994 | 994 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
995 | 995 | */ |
996 | - public function expire( $check_expiration = false ) { |
|
996 | + public function expire($check_expiration = false) { |
|
997 | 997 | |
998 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
998 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
999 | 999 | // Do not mark as expired since real expiration date is in the future |
1000 | 1000 | return false; |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - $this->set_status( 'expired' ); |
|
1003 | + $this->set_status('expired'); |
|
1004 | 1004 | return $this->save(); |
1005 | 1005 | |
1006 | 1006 | } |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | * @return int Subscription id. |
1013 | 1013 | */ |
1014 | 1014 | public function failing() { |
1015 | - $this->set_status( 'failing' ); |
|
1015 | + $this->set_status('failing'); |
|
1016 | 1016 | return $this->save(); |
1017 | 1017 | } |
1018 | 1018 | |
@@ -1023,7 +1023,7 @@ discard block |
||
1023 | 1023 | * @return int Subscription id. |
1024 | 1024 | */ |
1025 | 1025 | public function cancel() { |
1026 | - $this->set_status( 'cancelled' ); |
|
1026 | + $this->set_status('cancelled'); |
|
1027 | 1027 | return $this->save(); |
1028 | 1028 | } |
1029 | 1029 | |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | * @return bool |
1035 | 1035 | */ |
1036 | 1036 | public function can_cancel() { |
1037 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1037 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | /** |
@@ -1045,7 +1045,7 @@ discard block |
||
1045 | 1045 | * @return array |
1046 | 1046 | */ |
1047 | 1047 | public function get_cancellable_statuses() { |
1048 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
1048 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | /** |
@@ -1055,8 +1055,8 @@ discard block |
||
1055 | 1055 | * @return string |
1056 | 1056 | */ |
1057 | 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 ); |
|
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 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | /** |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | * @return bool |
1070 | 1070 | */ |
1071 | 1071 | public function can_renew() { |
1072 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1072 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
@@ -1079,8 +1079,8 @@ discard block |
||
1079 | 1079 | * @return string |
1080 | 1080 | */ |
1081 | 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 ); |
|
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 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
@@ -1090,7 +1090,7 @@ discard block |
||
1090 | 1090 | * @return bool |
1091 | 1091 | */ |
1092 | 1092 | public function can_update() { |
1093 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1093 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | /** |
@@ -1100,8 +1100,8 @@ discard block |
||
1100 | 1100 | * @return string |
1101 | 1101 | */ |
1102 | 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 ); |
|
1103 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
1104 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | /** |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | * @return string |
1112 | 1112 | */ |
1113 | 1113 | public function get_status_label() { |
1114 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1114 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | /** |
@@ -1122,7 +1122,7 @@ discard block |
||
1122 | 1122 | */ |
1123 | 1123 | public function get_status_class() { |
1124 | 1124 | $statuses = getpaid_get_subscription_status_classes(); |
1125 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1125 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary'; |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | /** |
@@ -1133,9 +1133,9 @@ 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 | 1140 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
1141 | 1141 | } |
@@ -1147,9 +1147,9 @@ discard block |
||
1147 | 1147 | * @param string $txn_id The transaction ID from the merchant processor |
1148 | 1148 | * @return bool |
1149 | 1149 | */ |
1150 | - public function payment_exists( $txn_id = '' ) { |
|
1151 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1152 | - return ! empty( $invoice_id ); |
|
1150 | + public function payment_exists($txn_id = '') { |
|
1151 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
1152 | + return !empty($invoice_id); |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | /** |
@@ -1161,35 +1161,35 @@ discard block |
||
1161 | 1161 | // Reset status transition variable. |
1162 | 1162 | $this->status_transition = false; |
1163 | 1163 | |
1164 | - if ( $status_transition ) { |
|
1164 | + if ($status_transition) { |
|
1165 | 1165 | try { |
1166 | 1166 | |
1167 | 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 ); |
|
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 | 1170 | |
1171 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1171 | + if (!empty($status_transition['from'])) { |
|
1172 | 1172 | |
1173 | 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'] ) ); |
|
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 | 1175 | |
1176 | 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 ); |
|
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 | 1179 | |
1180 | 1180 | // Note the transition occurred. |
1181 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1181 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1182 | 1182 | |
1183 | 1183 | } else { |
1184 | 1184 | /* translators: %s: new invoice status */ |
1185 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1185 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1186 | 1186 | |
1187 | 1187 | // Note the transition occurred. |
1188 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1188 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1189 | 1189 | |
1190 | 1190 | } |
1191 | - } catch ( Exception $e ) { |
|
1192 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1191 | + } catch (Exception $e) { |
|
1192 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains functions that display the subscriptions admin page. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
17 | 17 | ?> |
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
21 | 21 | <div class="bsui"> |
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | 25 | // Verify user permissions. |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | |
28 | 28 | echo aui()->alert( |
29 | 29 | array( |
30 | 30 | 'type' => 'danger', |
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
32 | 32 | ) |
33 | 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 | 37 | // Display a single subscription. |
38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | 83 | // Fetch the subscription. |
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->get_id() ) { |
|
84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
85 | + if (!$sub->get_id()) { |
|
86 | 86 | |
87 | 87 | echo aui()->alert( |
88 | 88 | array( |
89 | 89 | 'type' => 'danger', |
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
91 | 91 | ) |
92 | 92 | ); |
93 | 93 | |
@@ -95,31 +95,31 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 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 ); |
|
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 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
105 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
106 | 106 | |
107 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
108 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
109 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
107 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
108 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
109 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
110 | 110 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
111 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
111 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
112 | 112 | |
113 | 113 | <div id="poststuff"> |
114 | 114 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
115 | 115 | |
116 | 116 | <div id="postbox-container-1" class="postbox-container"> |
117 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
117 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
118 | 118 | </div> |
119 | 119 | |
120 | 120 | <div id="postbox-container-2" class="postbox-container"> |
121 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
122 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
121 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
122 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
123 | 123 | </div> |
124 | 124 | |
125 | 125 | </div> |
@@ -138,27 +138,27 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param WPInv_Subscription $sub |
140 | 140 | */ |
141 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
141 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
142 | 142 | |
143 | 143 | // Prepare subscription detail columns. |
144 | 144 | $fields = apply_filters( |
145 | 145 | 'getpaid_subscription_admin_page_fields', |
146 | 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' ), |
|
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 | 157 | ) |
158 | 158 | ); |
159 | 159 | |
160 | - if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
161 | - unset( $fields['renews_on'] ); |
|
160 | + if (!$sub->is_active() && isset($fields['renews_on'])) { |
|
161 | + unset($fields['renews_on']); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | ?> |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | <table class="table table-borderless" style="font-size: 14px;"> |
167 | 167 | <tbody> |
168 | 168 | |
169 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
169 | + <?php foreach ($fields as $key => $label) : ?> |
|
170 | 170 | |
171 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
171 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
172 | 172 | |
173 | 173 | <th class="w-25" style="font-weight: 500;"> |
174 | - <?php echo sanitize_text_field( $label ); ?> |
|
174 | + <?php echo sanitize_text_field($label); ?> |
|
175 | 175 | </th> |
176 | 176 | |
177 | 177 | <td class="w-75 text-muted"> |
178 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?> |
|
178 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?> |
|
179 | 179 | </td> |
180 | 180 | |
181 | 181 | </tr> |
@@ -193,201 +193,201 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param WPInv_Subscription $subscription |
195 | 195 | */ |
196 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
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 | 203 | $username = sprintf( |
204 | 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 ) |
|
205 | + absint($user->ID), |
|
206 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
210 | 210 | |
211 | 211 | echo $username; |
212 | 212 | } |
213 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
213 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
214 | 214 | |
215 | 215 | /** |
216 | 216 | * Displays the subscription amount. |
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription $subscription |
219 | 219 | */ |
220 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
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 | 228 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
229 | 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' ), |
|
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 | 231 | $initial, |
232 | - sanitize_text_field( $subscription->get_trial_period() ), |
|
232 | + sanitize_text_field($subscription->get_trial_period()), |
|
233 | 233 | $recurring, |
234 | - sanitize_text_field( strtolower( $period ) ) |
|
234 | + sanitize_text_field(strtolower($period)) |
|
235 | 235 | ); |
236 | 236 | |
237 | - } else if ( $initial != $recurring ) { |
|
237 | + } else if ($initial != $recurring) { |
|
238 | 238 | |
239 | 239 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
240 | 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' ), |
|
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 | 242 | $initial, |
243 | 243 | $recurring, |
244 | - sanitize_text_field( strtolower( $period ) ) |
|
244 | + sanitize_text_field(strtolower($period)) |
|
245 | 245 | ); |
246 | 246 | |
247 | 247 | } else { |
248 | 248 | |
249 | 249 | // translators: $1: is the recurring amount, $2: is the recurring period |
250 | 250 | $amount = sprintf( |
251 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
251 | + _x('%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing'), |
|
252 | 252 | $initial, |
253 | - sanitize_text_field( strtolower( $period ) ) |
|
253 | + sanitize_text_field(strtolower($period)) |
|
254 | 254 | ); |
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | 258 | echo "<span>$amount</span>"; |
259 | 259 | } |
260 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
260 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Displays the subscription id. |
264 | 264 | * |
265 | 265 | * @param WPInv_Subscription $subscription |
266 | 266 | */ |
267 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
268 | - echo '#' . absint( $subscription->get_id() ); |
|
267 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
268 | + echo '#' . absint($subscription->get_id()); |
|
269 | 269 | } |
270 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
270 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
271 | 271 | |
272 | 272 | /** |
273 | 273 | * Displays the subscription renewal date. |
274 | 274 | * |
275 | 275 | * @param WPInv_Subscription $subscription |
276 | 276 | */ |
277 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
277 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
278 | 278 | |
279 | 279 | $created = $subscription->get_date_created(); |
280 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
280 | + if (empty($created) || '0000-00-00 00:00:00' == $created) { |
|
281 | 281 | echo "—"; |
282 | 282 | } else { |
283 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
283 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($created)); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | } |
287 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
287 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
288 | 288 | |
289 | 289 | /** |
290 | 290 | * Displays the subscription renewal date. |
291 | 291 | * |
292 | 292 | * @param WPInv_Subscription $subscription |
293 | 293 | */ |
294 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
294 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
295 | 295 | |
296 | 296 | $expiration = $subscription->get_expiration(); |
297 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
297 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
298 | 298 | echo "—"; |
299 | 299 | } else { |
300 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
300 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($expiration)); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | } |
304 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
304 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
305 | 305 | |
306 | 306 | /** |
307 | 307 | * Displays the subscription renewal count. |
308 | 308 | * |
309 | 309 | * @param WPInv_Subscription $subscription |
310 | 310 | */ |
311 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
311 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
312 | 312 | $max_bills = $subscription->get_bill_times(); |
313 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
313 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
314 | 314 | } |
315 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
315 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Displays the subscription item. |
319 | 319 | * |
320 | 320 | * @param WPInv_Subscription $subscription |
321 | 321 | */ |
322 | -function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
|
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 ) ); |
|
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 | 330 | echo "<a href='$link'>$name</a>"; |
331 | 331 | } else { |
332 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
332 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | } |
336 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
|
336 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item'); |
|
337 | 337 | |
338 | 338 | /** |
339 | 339 | * Displays the subscription gateway. |
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
343 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
344 | 344 | |
345 | 345 | $gateway = $subscription->get_gateway(); |
346 | 346 | |
347 | - if ( ! empty( $gateway ) ) { |
|
348 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
347 | + if (!empty($gateway)) { |
|
348 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
349 | 349 | } else { |
350 | 350 | echo "—"; |
351 | 351 | } |
352 | 352 | |
353 | 353 | } |
354 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
354 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Displays the subscription status. |
358 | 358 | * |
359 | 359 | * @param WPInv_Subscription $subscription |
360 | 360 | */ |
361 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
361 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
362 | 362 | echo $subscription->get_status_label_html(); |
363 | 363 | } |
364 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
364 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
365 | 365 | |
366 | 366 | /** |
367 | 367 | * Displays the subscription profile id. |
368 | 368 | * |
369 | 369 | * @param WPInv_Subscription $subscription |
370 | 370 | */ |
371 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
371 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
372 | 372 | |
373 | 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 ); |
|
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 | 378 | } else { |
379 | 379 | echo "—"; |
380 | 380 | } |
381 | 381 | |
382 | 382 | } |
383 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
383 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Displays the subscriptions update metabox. |
387 | 387 | * |
388 | 388 | * @param WPInv_Subscription $subscription |
389 | 389 | */ |
390 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
390 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
391 | 391 | |
392 | 392 | ?> |
393 | 393 | <div class="mt-3"> |
@@ -400,10 +400,10 @@ discard block |
||
400 | 400 | 'id' => 'subscription_status_update_select', |
401 | 401 | 'required' => true, |
402 | 402 | 'no_wrap' => false, |
403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
403 | + 'label' => __('Subscription Status', 'invoicing'), |
|
404 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
405 | 405 | 'select2' => true, |
406 | - 'value' => $subscription->get_status( 'edit' ), |
|
406 | + 'value' => $subscription->get_status('edit'), |
|
407 | 407 | ) |
408 | 408 | ); |
409 | 409 | ?> |
@@ -411,13 +411,13 @@ discard block |
||
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() ) { |
|
420 | + if ($subscription->is_active()) { |
|
421 | 421 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
422 | 422 | } |
423 | 423 | |
@@ -429,17 +429,17 @@ discard block |
||
429 | 429 | * |
430 | 430 | * @param WPInv_Subscription $subscription |
431 | 431 | */ |
432 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
432 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
433 | 433 | |
434 | 434 | $columns = apply_filters( |
435 | 435 | 'getpaid_subscription_related_invoices_columns', |
436 | 436 | array( |
437 | 437 | |
438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
440 | - 'date' => __( 'Date', 'invoicing' ), |
|
441 | - 'status' => __( 'Status', 'invoicing' ), |
|
442 | - 'total' => __( 'Total', 'invoicing' ), |
|
438 | + 'invoice' => __('Invoice', 'invoicing'), |
|
439 | + 'relationship' => __('Relationship', 'invoicing'), |
|
440 | + 'date' => __('Date', 'invoicing'), |
|
441 | + 'status' => __('Status', 'invoicing'), |
|
442 | + 'total' => __('Total', 'invoicing'), |
|
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | $payments = $subscription->get_child_payments(); |
448 | 448 | $parent = $subscription->get_parent_invoice(); |
449 | 449 | |
450 | - if ( $parent->get_id() ) { |
|
451 | - $payments = array_merge( array( $parent ), $payments ); |
|
450 | + if ($parent->get_id()) { |
|
451 | + $payments = array_merge(array($parent), $payments); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | ?> |
@@ -459,9 +459,9 @@ 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 | 466 | echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
467 | 467 | } |
@@ -473,36 +473,36 @@ discard block |
||
473 | 473 | |
474 | 474 | <?php |
475 | 475 | |
476 | - foreach( $payments as $payment ) : |
|
476 | + foreach ($payments as $payment) : |
|
477 | 477 | |
478 | 478 | // Ensure that we have an invoice. |
479 | - if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
480 | - $payment = new WPInv_Invoice( $payment ); |
|
479 | + if (!is_a($payment, 'WPInv_Invoice')) { |
|
480 | + $payment = new WPInv_Invoice($payment); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | // Abort if the invoice is invalid. |
484 | - if ( ! $payment->get_id() ) { |
|
484 | + if (!$payment->get_id()) { |
|
485 | 485 | continue; |
486 | 486 | } |
487 | 487 | |
488 | 488 | echo '<tr>'; |
489 | 489 | |
490 | - foreach ( array_keys( $columns ) as $key ) { |
|
490 | + foreach (array_keys($columns) as $key) { |
|
491 | 491 | |
492 | 492 | echo '<td class="p-2 text-left">'; |
493 | 493 | |
494 | - switch( $key ) { |
|
494 | + switch ($key) { |
|
495 | 495 | |
496 | 496 | case 'total': |
497 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
497 | + echo '<strong>' . wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($payment->get_total)), $payment->get_currency()) . '</strong>'; |
|
498 | 498 | break; |
499 | 499 | |
500 | 500 | case 'relationship': |
501 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
501 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
502 | 502 | break; |
503 | 503 | |
504 | 504 | case 'date': |
505 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
505 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($payment->get_date_created())); |
|
506 | 506 | break; |
507 | 507 | |
508 | 508 | case 'status': |
@@ -510,8 +510,8 @@ discard block |
||
510 | 510 | break; |
511 | 511 | |
512 | 512 | case 'invoice': |
513 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
513 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
514 | + $invoice = sanitize_text_field($payment->get_number()); |
|
515 | 515 | echo "<a href='$link'>$invoice</a>"; |
516 | 516 | break; |
517 | 517 | } |
@@ -543,30 +543,30 @@ discard block |
||
543 | 543 | */ |
544 | 544 | function wpinv_recurring_process_subscription_deletion() { |
545 | 545 | |
546 | - if( empty( $_POST['sub_id'] ) ) { |
|
546 | + if (empty($_POST['sub_id'])) { |
|
547 | 547 | return; |
548 | 548 | } |
549 | 549 | |
550 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
550 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
551 | 551 | return; |
552 | 552 | } |
553 | 553 | |
554 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
554 | + if (!current_user_can('manage_invoicing')) { |
|
555 | 555 | return; |
556 | 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 ) ); |
|
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 | 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 | 566 | $subscription->delete(); |
567 | 567 | |
568 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
568 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
569 | 569 | exit; |
570 | 570 | |
571 | 571 | } |
572 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
572 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_filter( 'wpinv_renew_authorizenet_subscription_profile', array( $this, 'renew_subscription' ) ); |
|
74 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
73 | + add_filter('wpinv_renew_authorizenet_subscription_profile', array($this, 'renew_subscription')); |
|
74 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | echo $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,64 +100,64 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ) |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | return $response; |
142 | 142 | } |
143 | 143 | |
144 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
144 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
145 | 145 | |
146 | 146 | // Save the payment token. |
147 | - if ( $save ) { |
|
147 | + if ($save) { |
|
148 | 148 | $this->save_token( |
149 | 149 | array( |
150 | 150 | 'id' => $response->customerPaymentProfileIdList[0], |
151 | - 'name' => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
151 | + 'name' => $this->get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
152 | 152 | 'default' => true, |
153 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
153 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
154 | 154 | ) |
155 | 155 | ); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Add a note about the validation response. |
159 | 159 | $invoice->add_note( |
160 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
160 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
161 | 161 | false, |
162 | 162 | false, |
163 | 163 | true |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @return string|WP_Error Profile id. |
175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
176 | 176 | */ |
177 | - public function get_customer_profile( $profile_id ) { |
|
177 | + public function get_customer_profile($profile_id) { |
|
178 | 178 | |
179 | 179 | // Generate args. |
180 | 180 | $args = array( |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | ) |
185 | 185 | ); |
186 | 186 | |
187 | - return $this->post( $args, false ); |
|
187 | + return $this->post($args, false); |
|
188 | 188 | |
189 | 189 | } |
190 | 190 | |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
200 | 200 | * @return string|WP_Error Profile id. |
201 | 201 | */ |
202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
202 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
203 | 203 | |
204 | 204 | // Remove non-digits from the number |
205 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
205 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
206 | 206 | |
207 | 207 | // Generate args. |
208 | 208 | $args = array( |
@@ -213,34 +213,34 @@ discard block |
||
213 | 213 | |
214 | 214 | // Billing information. |
215 | 215 | 'billTo' => array( |
216 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
217 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
218 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
219 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
220 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
221 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
222 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
216 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
217 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
218 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
219 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
220 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
221 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
222 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
223 | 223 | ), |
224 | 224 | |
225 | 225 | // Payment information. |
226 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ) |
|
226 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']) |
|
227 | 227 | ), |
228 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
228 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
229 | 229 | ) |
230 | 230 | ); |
231 | 231 | |
232 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
232 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
233 | 233 | |
234 | - if ( is_wp_error( $response ) ) { |
|
234 | + if (is_wp_error($response)) { |
|
235 | 235 | return $response; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Save the payment token. |
239 | - if ( $save ) { |
|
239 | + if ($save) { |
|
240 | 240 | $this->save_token( |
241 | 241 | array( |
242 | 242 | 'id' => $response->customerPaymentProfileId, |
243 | - 'name' => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
243 | + 'name' => $this->get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
244 | 244 | 'default' => true |
245 | 245 | ) |
246 | 246 | ); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | // Add a note about the validation response. |
250 | 250 | $invoice->add_note( |
251 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
251 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
252 | 252 | false, |
253 | 253 | false, |
254 | 254 | true |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return string|WP_Error Profile id. |
268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
269 | 269 | */ |
270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
270 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
271 | 271 | |
272 | 272 | // Generate args. |
273 | 273 | $args = array( |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | ) |
279 | 279 | ); |
280 | 280 | |
281 | - return $this->post( $args, false ); |
|
281 | + return $this->post($args, false); |
|
282 | 282 | |
283 | 283 | } |
284 | 284 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
292 | 292 | * @return WP_Error|object |
293 | 293 | */ |
294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
294 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
295 | 295 | |
296 | 296 | // Generate args. |
297 | 297 | $args = array( |
@@ -311,24 +311,24 @@ discard block |
||
311 | 311 | ) |
312 | 312 | ), |
313 | 313 | 'order' => array( |
314 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
314 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
315 | 315 | ), |
316 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
316 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
317 | 317 | 'tax' => array( |
318 | 318 | 'amount' => $invoice->get_total_tax(), |
319 | 319 | 'name' => getpaid_tax()->get_vat_name(), |
320 | 320 | ), |
321 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
321 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
322 | 322 | 'customer' => array( |
323 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
324 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
323 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
324 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
325 | 325 | ), |
326 | 326 | 'customerIP' => $invoice->get_ip(), |
327 | 327 | ) |
328 | 328 | ) |
329 | 329 | ); |
330 | -log_noptin_message( $args ); |
|
331 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
330 | +log_noptin_message($args); |
|
331 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -338,43 +338,43 @@ discard block |
||
338 | 338 | * @param stdClass $result Api response. |
339 | 339 | * @param WPInv_Invoice $invoice Invoice. |
340 | 340 | */ |
341 | - public function process_charge_response( $result, $invoice ) { |
|
341 | + public function process_charge_response($result, $invoice) { |
|
342 | 342 | |
343 | 343 | wpinv_clear_errors(); |
344 | 344 | |
345 | - switch ( (int) $result->transactionResponse->responseCode ) { |
|
345 | + switch ((int) $result->transactionResponse->responseCode) { |
|
346 | 346 | |
347 | 347 | case 1: |
348 | 348 | case 4: |
349 | 349 | |
350 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
351 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
350 | + if (!empty($result->transactionResponse->transId)) { |
|
351 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
352 | 352 | } |
353 | 353 | |
354 | - if ( 1 == (int) $result->transactionResponse->responseCode ) { |
|
354 | + if (1 == (int) $result->transactionResponse->responseCode) { |
|
355 | 355 | $invoice->mark_paid(); |
356 | 356 | } else { |
357 | - $invoice->set_status( 'wpi-onhold' ); |
|
357 | + $invoice->set_status('wpi-onhold'); |
|
358 | 358 | $invoice->add_note( |
359 | 359 | sprintf( |
360 | - __( 'Held for review: %s', 'invoicing' ), |
|
360 | + __('Held for review: %s', 'invoicing'), |
|
361 | 361 | $result->transactionResponse->messages->message[0]->description |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | 365 | |
366 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
366 | + $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
367 | 367 | $invoice->save(); |
368 | 368 | |
369 | 369 | return; |
370 | 370 | |
371 | 371 | case 2: |
372 | 372 | case 3: |
373 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
373 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
374 | 374 | |
375 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
375 | + if (!empty($result->transactionResponse->errors)) { |
|
376 | 376 | $errors = (object) $result->transactionResponse->errors; |
377 | - wpinv_set_error( $errors->error[0]->errorCode, $errors->error[0]->errorText ); |
|
377 | + wpinv_set_error($errors->error[0]->errorCode, $errors->error[0]->errorText); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | return; |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | * @param array $card Card details. |
391 | 391 | * @return array |
392 | 392 | */ |
393 | - public function get_payment_information( $card ) { |
|
393 | + public function get_payment_information($card) { |
|
394 | 394 | return array( |
395 | 395 | |
396 | - 'creditCard' => array ( |
|
396 | + 'creditCard' => array( |
|
397 | 397 | 'cardNumber' => $card['cc_number'], |
398 | 398 | 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
399 | 399 | 'cardCode' => $card['cc_cvv2'], |
@@ -409,30 +409,30 @@ discard block |
||
409 | 409 | * @param string $card_number Card number. |
410 | 410 | * @return string |
411 | 411 | */ |
412 | - public function get_card_name( $card_number ) { |
|
412 | + public function get_card_name($card_number) { |
|
413 | 413 | |
414 | - switch( $card_number ) { |
|
414 | + switch ($card_number) { |
|
415 | 415 | |
416 | - case( preg_match ( '/^4/', $card_number ) >= 1 ): |
|
417 | - return __( 'Visa', 'invoicing' ); |
|
416 | + case(preg_match('/^4/', $card_number) >= 1): |
|
417 | + return __('Visa', 'invoicing'); |
|
418 | 418 | |
419 | - case( preg_match ( '/^5[1-5]/', $card_number ) >= 1 ): |
|
420 | - return __( 'Mastercard', 'invoicing' ); |
|
419 | + case(preg_match('/^5[1-5]/', $card_number) >= 1): |
|
420 | + return __('Mastercard', 'invoicing'); |
|
421 | 421 | |
422 | - case( preg_match ( '/^3[47]/', $card_number ) >= 1 ): |
|
423 | - return __( 'Amex', 'invoicing' ); |
|
422 | + case(preg_match('/^3[47]/', $card_number) >= 1): |
|
423 | + return __('Amex', 'invoicing'); |
|
424 | 424 | |
425 | - case( preg_match ( '/^3(?:0[0-5]|[68])/', $card_number ) >= 1 ): |
|
426 | - return __( 'Diners Club', 'invoicing' ); |
|
425 | + case(preg_match('/^3(?:0[0-5]|[68])/', $card_number) >= 1): |
|
426 | + return __('Diners Club', 'invoicing'); |
|
427 | 427 | |
428 | - case( preg_match ( '/^6(?:011|5)/', $card_number ) >= 1 ): |
|
429 | - return __( 'Discover', 'invoicing' ); |
|
428 | + case(preg_match('/^6(?:011|5)/', $card_number) >= 1): |
|
429 | + return __('Discover', 'invoicing'); |
|
430 | 430 | |
431 | - case( preg_match ( '/^(?:2131|1800|35\d{3})/', $card_number ) >= 1 ): |
|
432 | - return __( 'JCB', 'invoicing' ); |
|
431 | + case(preg_match('/^(?:2131|1800|35\d{3})/', $card_number) >= 1): |
|
432 | + return __('JCB', 'invoicing'); |
|
433 | 433 | |
434 | 434 | default: |
435 | - return __( 'Card', 'invoicing' ); |
|
435 | + return __('Card', 'invoicing'); |
|
436 | 436 | break; |
437 | 437 | } |
438 | 438 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * @param WPInv_Invoice $invoice Invoice. |
446 | 446 | * @return string |
447 | 447 | */ |
448 | - public function get_customer_profile_meta_name( $invoice ) { |
|
449 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
448 | + public function get_customer_profile_meta_name($invoice) { |
|
449 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | * @param WPInv_Invoice $invoice Invoice. |
457 | 457 | * @return string |
458 | 458 | */ |
459 | - public function get_api_url( $invoice ) { |
|
460 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
459 | + public function get_api_url($invoice) { |
|
460 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | public function get_auth_params() { |
470 | 470 | |
471 | 471 | return array( |
472 | - 'name' => $this->get_option( 'login_id' ), |
|
473 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
472 | + 'name' => $this->get_option('login_id'), |
|
473 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
474 | 474 | ); |
475 | 475 | |
476 | 476 | } |
@@ -483,34 +483,34 @@ discard block |
||
483 | 483 | * @param WPInv_Invoice $invoice |
484 | 484 | * @return WP_Error|string The payment profile id |
485 | 485 | */ |
486 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
486 | + public function validate_submission_data($submission_data, $invoice) { |
|
487 | 487 | |
488 | 488 | // Validate authentication details. |
489 | 489 | $auth = $this->get_auth_params(); |
490 | 490 | |
491 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
492 | - return new WP_Error( 'invalid_settings', __( 'This gateway has not been set up.', 'invoicing') ); |
|
491 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
492 | + return new WP_Error('invalid_settings', __('This gateway has not been set up.', 'invoicing')); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | // Validate the payment method. |
496 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
497 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
496 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
497 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | // Are we adding a new payment method? |
501 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
501 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
502 | 502 | return $submission_data['getpaid-authorizenet-payment-method']; |
503 | 503 | } |
504 | 504 | |
505 | 505 | // Retrieve the customer profile id. |
506 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
506 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
507 | 507 | |
508 | 508 | // Create payment method. |
509 | - if ( empty( $profile_id ) ) { |
|
510 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
509 | + if (empty($profile_id)) { |
|
510 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
511 | 511 | } |
512 | 512 | |
513 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
513 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
514 | 514 | |
515 | 515 | } |
516 | 516 | |
@@ -521,15 +521,15 @@ discard block |
||
521 | 521 | * @param WPInv_Invoice $invoice Invoice. |
522 | 522 | * @return array |
523 | 523 | */ |
524 | - public function get_line_items( $invoice ) { |
|
524 | + public function get_line_items($invoice) { |
|
525 | 525 | $items = array(); |
526 | 526 | |
527 | - foreach ( $invoice->get_items() as $item ) { |
|
527 | + foreach ($invoice->get_items() as $item) { |
|
528 | 528 | |
529 | 529 | $items[] = array( |
530 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
531 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
532 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
530 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
531 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
532 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
533 | 533 | 'quantity' => (int) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(), |
534 | 534 | 'unitPrice' => (float) $item->get_price(), |
535 | 535 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
@@ -548,40 +548,40 @@ discard block |
||
548 | 548 | * @param WPInv_Invoice $invoice Invoice. |
549 | 549 | * @return stdClass|WP_Error |
550 | 550 | */ |
551 | - public function post( $post, $invoice ){ |
|
551 | + public function post($post, $invoice) { |
|
552 | 552 | |
553 | - $url = $this->get_api_url( $invoice ); |
|
553 | + $url = $this->get_api_url($invoice); |
|
554 | 554 | $response = wp_remote_post( |
555 | 555 | $url, |
556 | 556 | array( |
557 | 557 | 'headers' => array( |
558 | 558 | 'Content-Type' => 'application/json; charset=utf-8' |
559 | 559 | ), |
560 | - 'body' => json_encode( $post ), |
|
560 | + 'body' => json_encode($post), |
|
561 | 561 | 'method' => 'POST' |
562 | 562 | ) |
563 | 563 | ); |
564 | 564 | |
565 | - if ( is_wp_error( $response ) ) { |
|
565 | + if (is_wp_error($response)) { |
|
566 | 566 | return $response; |
567 | 567 | } |
568 | 568 | |
569 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
569 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
570 | 570 | $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
571 | - $response = json_decode( $response ); |
|
571 | + $response = json_decode($response); |
|
572 | 572 | |
573 | - if ( empty( $response ) ) { |
|
574 | - return new WP_Error( 'invalid_reponse', __( 'Invalid response', 'invoicing' ) ); |
|
573 | + if (empty($response)) { |
|
574 | + return new WP_Error('invalid_reponse', __('Invalid response', 'invoicing')); |
|
575 | 575 | } |
576 | 576 | |
577 | - if ( $response->messages->resultCode == 'Error' ) { |
|
577 | + if ($response->messages->resultCode == 'Error') { |
|
578 | 578 | |
579 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
579 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
580 | 580 | $error = $response->transactionResponse->errors[0]; |
581 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
581 | + return new WP_Error($error->errorCode, $error->errorText); |
|
582 | 582 | } |
583 | 583 | |
584 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
584 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | return $response; |
@@ -597,49 +597,49 @@ discard block |
||
597 | 597 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
598 | 598 | * @return array |
599 | 599 | */ |
600 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
600 | + public function process_payment($invoice, $submission_data, $submission) { |
|
601 | 601 | |
602 | 602 | // Validate the submitted data. |
603 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
603 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
604 | 604 | |
605 | 605 | // Do we have an error? |
606 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
607 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | + if (is_wp_error($payment_profile_id)) { |
|
607 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
608 | 608 | wpinv_send_back_to_checkout(); |
609 | 609 | } |
610 | 610 | |
611 | 611 | // Save the payment method to the order. |
612 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
612 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
613 | 613 | |
614 | 614 | // Check if this is a subscription or not. |
615 | - if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice ) ) { |
|
616 | - $this->process_subscription( $invoice, $subscription ); |
|
615 | + if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice)) { |
|
616 | + $this->process_subscription($invoice, $subscription); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | // If it is free, send to the success page. |
620 | - if ( ! $invoice->needs_payment() ) { |
|
620 | + if (!$invoice->needs_payment()) { |
|
621 | 621 | $invoice->mark_paid(); |
622 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
622 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // Charge the payment profile. |
626 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
627 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
626 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
627 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
628 | 628 | |
629 | 629 | // Do we have an error? |
630 | - if ( is_wp_error( $result ) ) { |
|
631 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
630 | + if (is_wp_error($result)) { |
|
631 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
632 | 632 | wpinv_send_back_to_checkout(); |
633 | 633 | } |
634 | 634 | |
635 | 635 | // Process the response. |
636 | - $this->process_charge_response( $result, $invoice ); |
|
636 | + $this->process_charge_response($result, $invoice); |
|
637 | 637 | |
638 | - if ( wpinv_get_errors() ) { |
|
638 | + if (wpinv_get_errors()) { |
|
639 | 639 | wpinv_send_back_to_checkout(); |
640 | 640 | } |
641 | 641 | |
642 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
642 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
643 | 643 | |
644 | 644 | exit; |
645 | 645 | |
@@ -651,40 +651,40 @@ discard block |
||
651 | 651 | * @param WPInv_Invoice $invoice Invoice. |
652 | 652 | * @param WPInv_Subscription $subscription Subscription. |
653 | 653 | */ |
654 | - public function process_subscription( $invoice, $subscription ) { |
|
654 | + public function process_subscription($invoice, $subscription) { |
|
655 | 655 | |
656 | 656 | // Check if there is an initial amount to charge. |
657 | - if ( (float) $invoice->get_total() > 0 ) { |
|
657 | + if ((float) $invoice->get_total() > 0) { |
|
658 | 658 | |
659 | 659 | // Retrieve the payment method. |
660 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
661 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
662 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
660 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
661 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
662 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
663 | 663 | |
664 | 664 | // Do we have an error? |
665 | - if ( is_wp_error( $result ) ) { |
|
666 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
665 | + if (is_wp_error($result)) { |
|
666 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
667 | 667 | wpinv_send_back_to_checkout(); |
668 | 668 | } |
669 | 669 | |
670 | 670 | // Process the response. |
671 | - $this->process_charge_response( $result, $invoice ); |
|
671 | + $this->process_charge_response($result, $invoice); |
|
672 | 672 | |
673 | - if ( wpinv_get_errors() ) { |
|
673 | + if (wpinv_get_errors()) { |
|
674 | 674 | wpinv_send_back_to_checkout(); |
675 | 675 | } |
676 | 676 | |
677 | 677 | } |
678 | 678 | |
679 | 679 | // Recalculate the new subscription expiry. |
680 | - $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created ); |
|
681 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
680 | + $duration = strtotime($subscription->expiration) - strtotime($subscription->created); |
|
681 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
682 | 682 | |
683 | 683 | // Schedule an action to run when the subscription expires. |
684 | 684 | $action_id = as_schedule_single_action( |
685 | - strtotime( $expiry ), |
|
685 | + strtotime($expiry), |
|
686 | 686 | 'wpinv_renew_authorizenet_subscription_profile', |
687 | - array( $invoice->get_id() ), |
|
687 | + array($invoice->get_id()), |
|
688 | 688 | 'invoicing' |
689 | 689 | ); |
690 | 690 | |
@@ -693,12 +693,12 @@ discard block |
||
693 | 693 | array( |
694 | 694 | 'profile_id' => $action_id, |
695 | 695 | 'status' => 'trialling' == $subscription->status ? 'trialling' : 'active', |
696 | - 'created' => current_time( 'mysql' ), |
|
696 | + 'created' => current_time('mysql'), |
|
697 | 697 | 'expiration' => $expiry, |
698 | 698 | ) |
699 | 699 | ); |
700 | 700 | |
701 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
701 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
702 | 702 | |
703 | 703 | } |
704 | 704 | |
@@ -707,45 +707,45 @@ discard block |
||
707 | 707 | * |
708 | 708 | * @param int $invoice Invoice id. |
709 | 709 | */ |
710 | - public function renew_subscription( $invoice ) { |
|
710 | + public function renew_subscription($invoice) { |
|
711 | 711 | |
712 | 712 | // Retrieve the subscription. |
713 | - $subscription = wpinv_get_subscription( $invoice ); |
|
714 | - if ( empty( $subscription ) ) { |
|
713 | + $subscription = wpinv_get_subscription($invoice); |
|
714 | + if (empty($subscription)) { |
|
715 | 715 | return; |
716 | 716 | } |
717 | 717 | |
718 | 718 | // Abort if it is canceled or complete. |
719 | - if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) { |
|
719 | + if ($subscription->status == 'completed' || $subscription->status == 'cancelled') { |
|
720 | 720 | return; |
721 | 721 | } |
722 | 722 | |
723 | 723 | // Retrieve the invoice. |
724 | - $invoice = new WPInv_Invoice( $invoice ); |
|
724 | + $invoice = new WPInv_Invoice($invoice); |
|
725 | 725 | |
726 | 726 | // If we have not maxed out on bill times... |
727 | 727 | $times_billed = $subscription->get_times_billed(); |
728 | 728 | $max_bills = $subscription->bill_times; |
729 | 729 | |
730 | - if ( empty( $max_bills ) || $max_bills > $times_billed ) { |
|
730 | + if (empty($max_bills) || $max_bills > $times_billed) { |
|
731 | 731 | |
732 | 732 | $new_invoice = $subscription->create_payment(); |
733 | 733 | |
734 | - if ( empty( $new_invoice ) ) { |
|
735 | - $invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
734 | + if (empty($new_invoice)) { |
|
735 | + $invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
736 | 736 | $subscription->failing(); |
737 | 737 | return; |
738 | 738 | } |
739 | 739 | |
740 | 740 | // retrieve the payment method. |
741 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
742 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
743 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
741 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
742 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
743 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
744 | 744 | |
745 | 745 | // Do we have an error? |
746 | - if ( is_wp_error( $result ) ) { |
|
746 | + if (is_wp_error($result)) { |
|
747 | 747 | $invoice->add_note( |
748 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
748 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
749 | 749 | true, |
750 | 750 | false, |
751 | 751 | true |
@@ -755,12 +755,12 @@ discard block |
||
755 | 755 | } |
756 | 756 | |
757 | 757 | // Process the response. |
758 | - $this->process_charge_response( $result, $new_invoice ); |
|
758 | + $this->process_charge_response($result, $new_invoice); |
|
759 | 759 | |
760 | - if ( wpinv_get_errors() ) { |
|
760 | + if (wpinv_get_errors()) { |
|
761 | 761 | |
762 | 762 | $invoice->add_note( |
763 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
763 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
764 | 764 | true, |
765 | 765 | false, |
766 | 766 | true |
@@ -782,17 +782,17 @@ discard block |
||
782 | 782 | // Renew/Complete the subscription. |
783 | 783 | $subscription->renew(); |
784 | 784 | |
785 | - if ( 'completed' != $subscription->status ) { |
|
785 | + if ('completed' != $subscription->status) { |
|
786 | 786 | |
787 | 787 | // Schedule an action to run when the subscription expires. |
788 | 788 | $action_id = as_schedule_single_action( |
789 | - strtotime( $subscription->expiration ), |
|
789 | + strtotime($subscription->expiration), |
|
790 | 790 | 'wpinv_renew_authorizenet_subscription_profile', |
791 | - array( $invoice->get_id() ), |
|
791 | + array($invoice->get_id()), |
|
792 | 792 | 'invoicing' |
793 | 793 | ); |
794 | 794 | |
795 | - $subscription->update( array( 'profile_id' => $action_id, ) ); |
|
795 | + $subscription->update(array('profile_id' => $action_id,)); |
|
796 | 796 | |
797 | 797 | } |
798 | 798 | |
@@ -806,9 +806,9 @@ discard block |
||
806 | 806 | * @param WPInv_Subscription $subscription Subscription. |
807 | 807 | * @param WPInv_Invoice $invoice Invoice. |
808 | 808 | */ |
809 | - public function cancel_subscription( $subscription, $invoice ) { |
|
809 | + public function cancel_subscription($subscription, $invoice) { |
|
810 | 810 | |
811 | - if ( as_unschedule_action( 'wpinv_renew_authorizenet_subscription_profile', array( $invoice->get_id() ), 'invoicing' ) ) { |
|
811 | + if (as_unschedule_action('wpinv_renew_authorizenet_subscription_profile', array($invoice->get_id()), 'invoicing')) { |
|
812 | 812 | return; |
813 | 813 | } |
814 | 814 | |
@@ -835,45 +835,45 @@ discard block |
||
835 | 835 | $this->maybe_process_old_ipn(); |
836 | 836 | |
837 | 837 | // Validate the IPN. |
838 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
839 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
838 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
839 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500)); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | // Event type. |
843 | - $posted = json_decode( file_get_contents('php://input') ); |
|
844 | - if ( empty( $posted ) ) { |
|
845 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
843 | + $posted = json_decode(file_get_contents('php://input')); |
|
844 | + if (empty($posted)) { |
|
845 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500)); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | // Process the IPN. |
849 | - $posted = (object) wp_unslash( $posted ); |
|
849 | + $posted = (object) wp_unslash($posted); |
|
850 | 850 | |
851 | 851 | // Process refunds. |
852 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
853 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
852 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
853 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
854 | 854 | |
855 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
855 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
856 | 856 | $invoice->refund(); |
857 | 857 | } |
858 | 858 | |
859 | 859 | } |
860 | 860 | |
861 | 861 | // Held funds approved. |
862 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
863 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
862 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
863 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
864 | 864 | |
865 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
866 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' )); |
|
865 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
866 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | } |
870 | 870 | |
871 | 871 | // Held funds declined. |
872 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
873 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
872 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
873 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
874 | 874 | |
875 | - if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) { |
|
876 | - $invoice->set_status( 'wpi-failed', __( 'Payment desclined', 'invoicing' ) ); |
|
875 | + if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) { |
|
876 | + $invoice->set_status('wpi-failed', __('Payment desclined', 'invoicing')); |
|
877 | 877 | $invoice->save(); |
878 | 878 | } |
879 | 879 | |
@@ -891,41 +891,41 @@ discard block |
||
891 | 891 | public function maybe_process_old_ipn() { |
892 | 892 | |
893 | 893 | // Ensure that we are using the old subscriptions. |
894 | - if ( empty( $_POST['x_subscription_id'] ) ) { |
|
894 | + if (empty($_POST['x_subscription_id'])) { |
|
895 | 895 | return; |
896 | 896 | } |
897 | 897 | |
898 | 898 | // Check validity. |
899 | - $signature = $this->get_option( 'signature_key' ); |
|
900 | - if ( ! empty( $signature ) ) { |
|
901 | - $login_id = $this->get_option( 'login_id' ); |
|
899 | + $signature = $this->get_option('signature_key'); |
|
900 | + if (!empty($signature)) { |
|
901 | + $login_id = $this->get_option('login_id'); |
|
902 | 902 | $trans_id = $_POST['x_trans_id']; |
903 | 903 | $amount = $_POST['x_amount']; |
904 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
904 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
905 | 905 | |
906 | - if ( ! hash_equals( $hash, $_POST['x_SHA2_Hash'] ) ) { |
|
906 | + if (!hash_equals($hash, $_POST['x_SHA2_Hash'])) { |
|
907 | 907 | exit; |
908 | 908 | } |
909 | 909 | |
910 | 910 | } |
911 | 911 | |
912 | 912 | // Fetch the associated subscription. |
913 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $_POST['x_subscription_id'] ); |
|
914 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
913 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($_POST['x_subscription_id']); |
|
914 | + $subscription = new WPInv_Subscription($subscription_id); |
|
915 | 915 | |
916 | 916 | // Abort if it is missing or completed. |
917 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
917 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
918 | 918 | return; |
919 | 919 | } |
920 | 920 | |
921 | 921 | // Payment status. |
922 | - if ( 1 == $_POST['x_response_code'] ) { |
|
922 | + if (1 == $_POST['x_response_code']) { |
|
923 | 923 | |
924 | 924 | $invoice = $subscription->create_payment(); |
925 | - $invoice->set_transaction_id( sanitize_text_field( $_POST['x_trans_id'] ) ); |
|
926 | - $invoice->set_status( 'wpi-renewal' ); |
|
925 | + $invoice->set_transaction_id(sanitize_text_field($_POST['x_trans_id'])); |
|
926 | + $invoice->set_status('wpi-renewal'); |
|
927 | 927 | $invoice->save(); |
928 | - $subscription->add_payment( $invoice ); |
|
928 | + $subscription->add_payment($invoice); |
|
929 | 929 | $subscription->renew(); |
930 | 930 | |
931 | 931 | } else { |
@@ -941,28 +941,28 @@ discard block |
||
941 | 941 | */ |
942 | 942 | public function validate_ipn() { |
943 | 943 | |
944 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
944 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
945 | 945 | |
946 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
946 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
947 | 947 | return false; |
948 | 948 | } |
949 | 949 | |
950 | - $signature = $this->get_option( 'signature_key' ); |
|
950 | + $signature = $this->get_option('signature_key'); |
|
951 | 951 | |
952 | - if ( empty( $signature ) ) { |
|
953 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
952 | + if (empty($signature)) { |
|
953 | + wpinv_error_log('Error: You have not set a signature key'); |
|
954 | 954 | return false; |
955 | 955 | } |
956 | 956 | |
957 | - $hash = hash_hmac ( 'sha512', file_get_contents('php://input'), hex2bin( $signature ) ); |
|
957 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
958 | 958 | |
959 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
960 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
959 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
960 | + wpinv_error_log('Successfully validated the IPN'); |
|
961 | 961 | return true; |
962 | 962 | } |
963 | 963 | |
964 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
965 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
964 | + wpinv_error_log('IPN hash is not valid'); |
|
965 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
966 | 966 | return false; |
967 | 967 | |
968 | 968 | } |
@@ -970,11 +970,11 @@ discard block |
||
970 | 970 | /** |
971 | 971 | * Displays a notice on the checkout page if sandbox is enabled. |
972 | 972 | */ |
973 | - public function sandbox_notice( $description, $gateway ) { |
|
973 | + public function sandbox_notice($description, $gateway) { |
|
974 | 974 | |
975 | - if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) { |
|
975 | + if ($this->id == $gateway && wpinv_is_test_mode($this->id)) { |
|
976 | 976 | $description .= '<br>' . sprintf( |
977 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
977 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
978 | 978 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
979 | 979 | '</a>' |
980 | 980 | ); |
@@ -988,42 +988,42 @@ discard block |
||
988 | 988 | * |
989 | 989 | * @param array $admin_settings |
990 | 990 | */ |
991 | - public function admin_settings( $admin_settings ) { |
|
991 | + public function admin_settings($admin_settings) { |
|
992 | 992 | |
993 | 993 | $currencies = sprintf( |
994 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
995 | - implode( ', ', $this->currencies ) |
|
994 | + __('Supported Currencies: %s', 'invoicing'), |
|
995 | + implode(', ', $this->currencies) |
|
996 | 996 | ); |
997 | 997 | |
998 | 998 | $admin_settings['authorizenet_active']['desc'] .= $admin_settings['authorizenet_active']['desc'] . " ($currencies)"; |
999 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
999 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
1000 | 1000 | |
1001 | 1001 | $admin_settings['authorizenet_login_id'] = array( |
1002 | 1002 | 'type' => 'text', |
1003 | 1003 | 'id' => 'authorizenet_login_id', |
1004 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
1005 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
1004 | + 'name' => __('API Login ID', 'invoicing'), |
|
1005 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
1006 | 1006 | ); |
1007 | 1007 | |
1008 | 1008 | $admin_settings['authorizenet_transaction_key'] = array( |
1009 | 1009 | 'type' => 'text', |
1010 | 1010 | 'id' => 'authorizenet_transaction_key', |
1011 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
1011 | + 'name' => __('Transaction Key', 'invoicing'), |
|
1012 | 1012 | ); |
1013 | 1013 | |
1014 | 1014 | $admin_settings['authorizenet_signature_key'] = array( |
1015 | 1015 | 'type' => 'text', |
1016 | 1016 | 'id' => 'authorizenet_signature_key', |
1017 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
1018 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
1017 | + 'name' => __('Signature Key', 'invoicing'), |
|
1018 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
1019 | 1019 | ); |
1020 | 1020 | |
1021 | 1021 | $admin_settings['authorizenet_ipn_url'] = array( |
1022 | 1022 | 'type' => 'ipn_url', |
1023 | 1023 | 'id' => 'authorizenet_ipn_url', |
1024 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
1024 | + 'name' => __('Webhook URL', 'invoicing'), |
|
1025 | 1025 | 'std' => $this->notify_url, |
1026 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
1026 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
1027 | 1027 | 'custom' => 'authorizenet', |
1028 | 1028 | 'readonly' => true, |
1029 | 1029 | ); |