@@ -12,38 +12,38 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // (Maybe) set form items. |
|
38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
39 | - |
|
40 | - // Confirm items key. |
|
41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
44 | - } |
|
45 | - |
|
46 | - $items = array(); |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // (Maybe) set form items. |
|
38 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
39 | + |
|
40 | + // Confirm items key. |
|
41 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | + if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
44 | + } |
|
45 | + |
|
46 | + $items = array(); |
|
47 | 47 | $item_ids = array(); |
48 | 48 | |
49 | 49 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -74,58 +74,58 @@ discard block |
||
74 | 74 | |
75 | 75 | $payment_form->set_items( $items ); |
76 | 76 | |
77 | - } |
|
78 | - |
|
79 | - // Process each individual item. |
|
80 | - foreach ( $payment_form->get_items() as $item ) { |
|
81 | - $this->process_item( $item, $selected_items, $submission ); |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
77 | + } |
|
85 | 78 | |
86 | - /** |
|
87 | - * Process a single item. |
|
88 | - * |
|
89 | - * @param GetPaid_Form_Item $item |
|
90 | - * @param array $selected_items |
|
91 | - * @param GetPaid_Payment_Form_Submission $submission |
|
92 | - */ |
|
93 | - public function process_item( $item, $selected_items, $submission ) { |
|
79 | + // Process each individual item. |
|
80 | + foreach ( $payment_form->get_items() as $item ) { |
|
81 | + $this->process_item( $item, $selected_items, $submission ); |
|
82 | + } |
|
94 | 83 | |
95 | - // Abort if this is an optional item and it has not been selected. |
|
96 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
97 | - return; |
|
98 | - } |
|
84 | + } |
|
99 | 85 | |
100 | - // (maybe) let customers change the quantities and prices. |
|
101 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
102 | - |
|
103 | - // Maybe change the quantities. |
|
104 | - if ( $item->allows_quantities() ) { |
|
105 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
106 | - } |
|
86 | + /** |
|
87 | + * Process a single item. |
|
88 | + * |
|
89 | + * @param GetPaid_Form_Item $item |
|
90 | + * @param array $selected_items |
|
91 | + * @param GetPaid_Payment_Form_Submission $submission |
|
92 | + */ |
|
93 | + public function process_item( $item, $selected_items, $submission ) { |
|
94 | + |
|
95 | + // Abort if this is an optional item and it has not been selected. |
|
96 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
97 | + return; |
|
98 | + } |
|
99 | + |
|
100 | + // (maybe) let customers change the quantities and prices. |
|
101 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
102 | + |
|
103 | + // Maybe change the quantities. |
|
104 | + if ( $item->allows_quantities() ) { |
|
105 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
106 | + } |
|
107 | 107 | |
108 | - // Maybe change the price. |
|
109 | - if ( $item->user_can_set_their_price() ) { |
|
110 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
108 | + // Maybe change the price. |
|
109 | + if ( $item->user_can_set_their_price() ) { |
|
110 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
111 | 111 | |
112 | - if ( $item->get_minimum_price() > $price ) { |
|
113 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
114 | - } |
|
112 | + if ( $item->get_minimum_price() > $price ) { |
|
113 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
114 | + } |
|
115 | 115 | |
116 | - $item->set_price( $price ); |
|
116 | + $item->set_price( $price ); |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - if ( 0 == $item->get_quantity() ) { |
|
123 | - return; |
|
124 | - } |
|
122 | + if ( 0 == $item->get_quantity() ) { |
|
123 | + return; |
|
124 | + } |
|
125 | 125 | |
126 | - // Save the item. |
|
127 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
126 | + // Save the item. |
|
127 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
128 | 128 | |
129 | - } |
|
129 | + } |
|
130 | 130 | |
131 | 131 | } |
@@ -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 | * Payment form submission itemss class |
@@ -23,37 +23,37 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // (Maybe) set form items. |
38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
38 | + if (isset($data['getpaid-form-items'])) { |
|
39 | 39 | |
40 | 40 | // Confirm items key. |
41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
41 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
42 | + if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) { |
|
43 | + throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing')); |
|
44 | 44 | } |
45 | 45 | |
46 | - $items = array(); |
|
46 | + $items = array(); |
|
47 | 47 | $item_ids = array(); |
48 | 48 | |
49 | - foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
|
50 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
51 | - $item = new GetPaid_Form_Item( $item_id ); |
|
52 | - $item->set_quantity( $qty ); |
|
49 | + foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) { |
|
50 | + if (!in_array($item_id, $item_ids)) { |
|
51 | + $item = new GetPaid_Form_Item($item_id); |
|
52 | + $item->set_quantity($qty); |
|
53 | 53 | |
54 | - if ( 0 == $qty ) { |
|
55 | - $item->set_allow_quantities( true ); |
|
56 | - $item->set_is_required( false ); |
|
54 | + if (0 == $qty) { |
|
55 | + $item->set_allow_quantities(true); |
|
56 | + $item->set_is_required(false); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $item_ids[] = $item->get_id(); |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - if ( ! $payment_form->is_default() ) { |
|
64 | + if (!$payment_form->is_default()) { |
|
65 | 65 | |
66 | - foreach ( $payment_form->get_items() as $item ) { |
|
67 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
66 | + foreach ($payment_form->get_items() as $item) { |
|
67 | + if (!in_array($item->get_id(), $item_ids)) { |
|
68 | 68 | $item_ids[] = $item->get_id(); |
69 | 69 | $items[] = $item; |
70 | 70 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | |
73 | 73 | } |
74 | 74 | |
75 | - $payment_form->set_items( $items ); |
|
75 | + $payment_form->set_items($items); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | |
79 | 79 | // Process each individual item. |
80 | - foreach ( $payment_form->get_items() as $item ) { |
|
81 | - $this->process_item( $item, $selected_items, $submission ); |
|
80 | + foreach ($payment_form->get_items() as $item) { |
|
81 | + $this->process_item($item, $selected_items, $submission); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
@@ -90,41 +90,41 @@ discard block |
||
90 | 90 | * @param array $selected_items |
91 | 91 | * @param GetPaid_Payment_Form_Submission $submission |
92 | 92 | */ |
93 | - public function process_item( $item, $selected_items, $submission ) { |
|
93 | + public function process_item($item, $selected_items, $submission) { |
|
94 | 94 | |
95 | 95 | // Abort if this is an optional item and it has not been selected. |
96 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
96 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | 100 | // (maybe) let customers change the quantities and prices. |
101 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
101 | + if (isset($selected_items[$item->get_id()])) { |
|
102 | 102 | |
103 | 103 | // Maybe change the quantities. |
104 | - if ( $item->allows_quantities() ) { |
|
105 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
104 | + if ($item->allows_quantities()) { |
|
105 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Maybe change the price. |
109 | - if ( $item->user_can_set_their_price() ) { |
|
110 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
109 | + if ($item->user_can_set_their_price()) { |
|
110 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
111 | 111 | |
112 | - if ( $item->get_minimum_price() > $price ) { |
|
113 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
112 | + if ($item->get_minimum_price() > $price) { |
|
113 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price()))); |
|
114 | 114 | } |
115 | 115 | |
116 | - $item->set_price( $price ); |
|
116 | + $item->set_price($price); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
121 | 121 | |
122 | - if ( 0 == $item->get_quantity() ) { |
|
122 | + if (0 == $item->get_quantity()) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Save the item. |
127 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
127 | + $this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | - $discount = new WPInv_Discount( $post_id ); |
|
378 | + $discount = new WPInv_Discount($post_id); |
|
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | 382 | array( |
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
|
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
383 | + 'code' => isset($_POST['wpinv_discount_code']) ? wpinv_clean($_POST['wpinv_discount_code']) : null, |
|
384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? floatval($_POST['wpinv_discount_amount']) : null, |
|
385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
388 | + 'type' => isset($_POST['wpinv_discount_type']) ? wpinv_clean($_POST['wpinv_discount_type']) : null, |
|
389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
390 | + 'items' => isset($_POST['wpinv_discount_items']) ? wpinv_clean($_POST['wpinv_discount_items']) : array(), |
|
391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? wpinv_clean($_POST['wpinv_discount_excluded_items']) : array(), |
|
392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? intval($_POST['wpinv_discount_max_uses']) : null, |
|
393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? floatval($_POST['wpinv_discount_min_total']) : null, |
|
394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? floatval($_POST['wpinv_discount_max_total']) : null, |
|
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | 398 | $discount->save(); |
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
400 | 400 | } |
401 | 401 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,198 +10,198 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * The last error code. |
|
128 | - * |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - public $last_error_code = null; |
|
132 | - |
|
133 | - /** |
|
134 | - * Class constructor. |
|
135 | - * |
|
136 | - */ |
|
137 | - public function __construct() { |
|
138 | - |
|
139 | - // Set the state and country to the default state and country. |
|
140 | - $this->country = wpinv_default_billing_country(); |
|
141 | - $this->state = wpinv_get_default_state(); |
|
142 | - |
|
143 | - // Do we have an actual submission? |
|
144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | - $this->load_data( $_POST ); |
|
146 | - } |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Loads submission data. |
|
152 | - * |
|
153 | - * @param array $data |
|
154 | - */ |
|
155 | - public function load_data( $data ) { |
|
156 | - |
|
157 | - // Remove slashes from the submitted data... |
|
158 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
159 | - |
|
160 | - // Allow plugins to filter the data. |
|
161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
162 | - |
|
163 | - // Cache it... |
|
164 | - $this->data = $data; |
|
165 | - |
|
166 | - // Then generate a unique id from the data. |
|
167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
168 | - |
|
169 | - // Finally, process the submission. |
|
170 | - try { |
|
171 | - |
|
172 | - // Each process is passed an instance of the class (with reference) |
|
173 | - // and should throw an Exception whenever it encounters one. |
|
174 | - $processors = apply_filters( |
|
175 | - 'getpaid_payment_form_submission_processors', |
|
176 | - array( |
|
177 | - array( $this, 'process_payment_form' ), |
|
178 | - array( $this, 'process_invoice' ), |
|
179 | - array( $this, 'process_fees' ), |
|
180 | - array( $this, 'process_items' ), |
|
181 | - array( $this, 'process_discount' ), |
|
182 | - array( $this, 'process_taxes' ), |
|
183 | - ), |
|
184 | - $this |
|
185 | - ); |
|
186 | - |
|
187 | - foreach ( $processors as $processor ) { |
|
188 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | - } |
|
190 | - |
|
191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
192 | - $this->last_error = $e->getMessage(); |
|
193 | - $this->last_error_code = $e->getErrorCode(); |
|
194 | - } catch ( Exception $e ) { |
|
195 | - $this->last_error = $e->getMessage(); |
|
196 | - $this->last_error_code = $e->getCode(); |
|
197 | - } |
|
198 | - |
|
199 | - // Fired when we are done processing a submission. |
|
200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * The last error code. |
|
128 | + * |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + public $last_error_code = null; |
|
132 | + |
|
133 | + /** |
|
134 | + * Class constructor. |
|
135 | + * |
|
136 | + */ |
|
137 | + public function __construct() { |
|
138 | + |
|
139 | + // Set the state and country to the default state and country. |
|
140 | + $this->country = wpinv_default_billing_country(); |
|
141 | + $this->state = wpinv_get_default_state(); |
|
142 | + |
|
143 | + // Do we have an actual submission? |
|
144 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | + $this->load_data( $_POST ); |
|
146 | + } |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Loads submission data. |
|
152 | + * |
|
153 | + * @param array $data |
|
154 | + */ |
|
155 | + public function load_data( $data ) { |
|
156 | + |
|
157 | + // Remove slashes from the submitted data... |
|
158 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
159 | + |
|
160 | + // Allow plugins to filter the data. |
|
161 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
162 | + |
|
163 | + // Cache it... |
|
164 | + $this->data = $data; |
|
165 | + |
|
166 | + // Then generate a unique id from the data. |
|
167 | + $this->id = md5( wp_json_encode( $data ) ); |
|
168 | + |
|
169 | + // Finally, process the submission. |
|
170 | + try { |
|
171 | + |
|
172 | + // Each process is passed an instance of the class (with reference) |
|
173 | + // and should throw an Exception whenever it encounters one. |
|
174 | + $processors = apply_filters( |
|
175 | + 'getpaid_payment_form_submission_processors', |
|
176 | + array( |
|
177 | + array( $this, 'process_payment_form' ), |
|
178 | + array( $this, 'process_invoice' ), |
|
179 | + array( $this, 'process_fees' ), |
|
180 | + array( $this, 'process_items' ), |
|
181 | + array( $this, 'process_discount' ), |
|
182 | + array( $this, 'process_taxes' ), |
|
183 | + ), |
|
184 | + $this |
|
185 | + ); |
|
186 | + |
|
187 | + foreach ( $processors as $processor ) { |
|
188 | + call_user_func_array( $processor, array( &$this ) ); |
|
189 | + } |
|
190 | + |
|
191 | + } catch( GetPaid_Payment_Exception $e ) { |
|
192 | + $this->last_error = $e->getMessage(); |
|
193 | + $this->last_error_code = $e->getErrorCode(); |
|
194 | + } catch ( Exception $e ) { |
|
195 | + $this->last_error = $e->getMessage(); |
|
196 | + $this->last_error_code = $e->getCode(); |
|
197 | + } |
|
198 | + |
|
199 | + // Fired when we are done processing a submission. |
|
200 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /* |
|
205 | 205 | |-------------------------------------------------------------------------- |
206 | 206 | | Payment Forms. |
207 | 207 | |-------------------------------------------------------------------------- |
@@ -210,39 +210,39 @@ discard block |
||
210 | 210 | | submission has an active payment form etc. |
211 | 211 | */ |
212 | 212 | |
213 | - /** |
|
214 | - * Prepares the submission's payment form. |
|
215 | - * |
|
216 | - * @since 1.0.19 |
|
217 | - */ |
|
218 | - public function process_payment_form() { |
|
213 | + /** |
|
214 | + * Prepares the submission's payment form. |
|
215 | + * |
|
216 | + * @since 1.0.19 |
|
217 | + */ |
|
218 | + public function process_payment_form() { |
|
219 | 219 | |
220 | - // Every submission needs an active payment form. |
|
221 | - if ( empty( $this->data['form_id'] ) ) { |
|
222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
223 | - } |
|
220 | + // Every submission needs an active payment form. |
|
221 | + if ( empty( $this->data['form_id'] ) ) { |
|
222 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
223 | + } |
|
224 | 224 | |
225 | - // Fetch the payment form. |
|
226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
225 | + // Fetch the payment form. |
|
226 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | 227 | |
228 | - if ( ! $this->payment_form->is_active() ) { |
|
229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
230 | - } |
|
228 | + if ( ! $this->payment_form->is_active() ) { |
|
229 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
230 | + } |
|
231 | 231 | |
232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | - } |
|
232 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + } |
|
234 | 234 | |
235 | 235 | /** |
236 | - * Returns the payment form. |
|
237 | - * |
|
238 | - * @since 1.0.19 |
|
239 | - * @return GetPaid_Payment_Form |
|
240 | - */ |
|
241 | - public function get_payment_form() { |
|
242 | - return $this->payment_form; |
|
243 | - } |
|
236 | + * Returns the payment form. |
|
237 | + * |
|
238 | + * @since 1.0.19 |
|
239 | + * @return GetPaid_Payment_Form |
|
240 | + */ |
|
241 | + public function get_payment_form() { |
|
242 | + return $this->payment_form; |
|
243 | + } |
|
244 | 244 | |
245 | - /* |
|
245 | + /* |
|
246 | 246 | |-------------------------------------------------------------------------- |
247 | 247 | | Invoices. |
248 | 248 | |-------------------------------------------------------------------------- |
@@ -251,84 +251,84 @@ discard block |
||
251 | 251 | | might be for an existing invoice. |
252 | 252 | */ |
253 | 253 | |
254 | - /** |
|
255 | - * Prepares the submission's invoice. |
|
256 | - * |
|
257 | - * @since 1.0.19 |
|
258 | - */ |
|
259 | - public function process_invoice() { |
|
254 | + /** |
|
255 | + * Prepares the submission's invoice. |
|
256 | + * |
|
257 | + * @since 1.0.19 |
|
258 | + */ |
|
259 | + public function process_invoice() { |
|
260 | 260 | |
261 | - // Abort if there is no invoice. |
|
262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | - return; |
|
264 | - } |
|
261 | + // Abort if there is no invoice. |
|
262 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + return; |
|
264 | + } |
|
265 | 265 | |
266 | - // If the submission is for an existing invoice, ensure that it exists |
|
267 | - // and that it is not paid for. |
|
268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
266 | + // If the submission is for an existing invoice, ensure that it exists |
|
267 | + // and that it is not paid for. |
|
268 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
269 | 269 | |
270 | 270 | if ( empty( $invoice ) ) { |
271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
272 | - } |
|
271 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
272 | + } |
|
273 | 273 | |
274 | - if ( $invoice->is_paid() ) { |
|
275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
276 | - } |
|
274 | + if ( $invoice->is_paid() ) { |
|
275 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
276 | + } |
|
277 | 277 | |
278 | - $this->payment_form->invoice = $invoice; |
|
279 | - if ( ! $this->payment_form->is_default() ) { |
|
278 | + $this->payment_form->invoice = $invoice; |
|
279 | + if ( ! $this->payment_form->is_default() ) { |
|
280 | 280 | |
281 | - $items = array(); |
|
282 | - $item_ids = array(); |
|
281 | + $items = array(); |
|
282 | + $item_ids = array(); |
|
283 | 283 | |
284 | - foreach ( $invoice->get_items() as $item ) { |
|
285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
286 | - $item_ids[] = $item->get_id(); |
|
287 | - $items[] = $item; |
|
288 | - } |
|
289 | - } |
|
284 | + foreach ( $invoice->get_items() as $item ) { |
|
285 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
286 | + $item_ids[] = $item->get_id(); |
|
287 | + $items[] = $item; |
|
288 | + } |
|
289 | + } |
|
290 | 290 | |
291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
293 | - $item_ids[] = $item->get_id(); |
|
294 | - $items[] = $item; |
|
295 | - } |
|
296 | - } |
|
291 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
293 | + $item_ids[] = $item->get_id(); |
|
294 | + $items[] = $item; |
|
295 | + } |
|
296 | + } |
|
297 | 297 | |
298 | - $this->payment_form->set_items( $items ); |
|
298 | + $this->payment_form->set_items( $items ); |
|
299 | 299 | |
300 | - } else { |
|
301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | - } |
|
303 | - |
|
304 | - $this->country = $invoice->get_country(); |
|
305 | - $this->state = $invoice->get_state(); |
|
306 | - $this->invoice = $invoice; |
|
307 | - |
|
308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Returns the associated invoice. |
|
313 | - * |
|
314 | - * @since 1.0.19 |
|
315 | - * @return WPInv_Invoice |
|
316 | - */ |
|
317 | - public function get_invoice() { |
|
318 | - return $this->invoice; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Checks whether there is an invoice associated with this submission. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function has_invoice() { |
|
328 | - return ! empty( $this->invoice ); |
|
329 | - } |
|
330 | - |
|
331 | - /* |
|
300 | + } else { |
|
301 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
302 | + } |
|
303 | + |
|
304 | + $this->country = $invoice->get_country(); |
|
305 | + $this->state = $invoice->get_state(); |
|
306 | + $this->invoice = $invoice; |
|
307 | + |
|
308 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Returns the associated invoice. |
|
313 | + * |
|
314 | + * @since 1.0.19 |
|
315 | + * @return WPInv_Invoice |
|
316 | + */ |
|
317 | + public function get_invoice() { |
|
318 | + return $this->invoice; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Checks whether there is an invoice associated with this submission. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @return bool |
|
326 | + */ |
|
327 | + public function has_invoice() { |
|
328 | + return ! empty( $this->invoice ); |
|
329 | + } |
|
330 | + |
|
331 | + /* |
|
332 | 332 | |-------------------------------------------------------------------------- |
333 | 333 | | Items. |
334 | 334 | |-------------------------------------------------------------------------- |
@@ -337,129 +337,129 @@ discard block |
||
337 | 337 | | recurring item. But can have an unlimited number of non-recurring items. |
338 | 338 | */ |
339 | 339 | |
340 | - /** |
|
341 | - * Prepares the submission's items. |
|
342 | - * |
|
343 | - * @since 1.0.19 |
|
344 | - */ |
|
345 | - public function process_items() { |
|
346 | - |
|
347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | - |
|
349 | - foreach ( $processor->items as $item ) { |
|
350 | - $this->add_item( $item ); |
|
351 | - } |
|
352 | - |
|
353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Adds an item to the submission. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - * @param GetPaid_Form_Item $item |
|
361 | - */ |
|
362 | - public function add_item( $item ) { |
|
363 | - |
|
364 | - // Make sure that it is available for purchase. |
|
365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | - return; |
|
367 | - } |
|
368 | - |
|
369 | - // Each submission can only contain one recurring item. |
|
370 | - if ( $item->is_recurring() ) { |
|
371 | - $this->has_recurring = $item->get_id(); |
|
372 | - } |
|
373 | - |
|
374 | - // Update the items and totals. |
|
375 | - $this->items[ $item->get_id() ] = $item; |
|
376 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
377 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
378 | - |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Removes a specific item. |
|
383 | - * |
|
384 | - * You should not call this method after the discounts and taxes |
|
385 | - * have been calculated. |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - */ |
|
389 | - public function remove_item( $item_id ) { |
|
390 | - |
|
391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
394 | - |
|
395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | - $this->has_recurring = 0; |
|
397 | - } |
|
398 | - |
|
399 | - unset( $this->items[ $item_id ] ); |
|
400 | - } |
|
401 | - |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns the subtotal. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - */ |
|
409 | - public function get_subtotal() { |
|
410 | - |
|
411 | - if ( wpinv_prices_include_tax() ) { |
|
412 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
413 | - } |
|
414 | - |
|
415 | - return $this->totals['subtotal']['initial']; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Returns the recurring subtotal. |
|
420 | - * |
|
421 | - * @since 1.0.19 |
|
422 | - */ |
|
423 | - public function get_recurring_subtotal() { |
|
424 | - |
|
425 | - if ( wpinv_prices_include_tax() ) { |
|
426 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
427 | - } |
|
428 | - |
|
429 | - return $this->totals['subtotal']['recurring']; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Returns all items. |
|
434 | - * |
|
435 | - * @since 1.0.19 |
|
436 | - * @return GetPaid_Form_Item[] |
|
437 | - */ |
|
438 | - public function get_items() { |
|
439 | - return $this->items; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Checks if there's a single subscription group in the submission. |
|
444 | - * |
|
445 | - * @since 2.3.0 |
|
446 | - * @return bool |
|
447 | - */ |
|
448 | - public function has_subscription_group() { |
|
449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Checks if there are multipe subscription groups in the submission. |
|
454 | - * |
|
455 | - * @since 2.3.0 |
|
456 | - * @return bool |
|
457 | - */ |
|
458 | - public function has_multiple_subscription_groups() { |
|
459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | - } |
|
461 | - |
|
462 | - /* |
|
340 | + /** |
|
341 | + * Prepares the submission's items. |
|
342 | + * |
|
343 | + * @since 1.0.19 |
|
344 | + */ |
|
345 | + public function process_items() { |
|
346 | + |
|
347 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
348 | + |
|
349 | + foreach ( $processor->items as $item ) { |
|
350 | + $this->add_item( $item ); |
|
351 | + } |
|
352 | + |
|
353 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Adds an item to the submission. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + * @param GetPaid_Form_Item $item |
|
361 | + */ |
|
362 | + public function add_item( $item ) { |
|
363 | + |
|
364 | + // Make sure that it is available for purchase. |
|
365 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
366 | + return; |
|
367 | + } |
|
368 | + |
|
369 | + // Each submission can only contain one recurring item. |
|
370 | + if ( $item->is_recurring() ) { |
|
371 | + $this->has_recurring = $item->get_id(); |
|
372 | + } |
|
373 | + |
|
374 | + // Update the items and totals. |
|
375 | + $this->items[ $item->get_id() ] = $item; |
|
376 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
377 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
378 | + |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Removes a specific item. |
|
383 | + * |
|
384 | + * You should not call this method after the discounts and taxes |
|
385 | + * have been calculated. |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + */ |
|
389 | + public function remove_item( $item_id ) { |
|
390 | + |
|
391 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
394 | + |
|
395 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
396 | + $this->has_recurring = 0; |
|
397 | + } |
|
398 | + |
|
399 | + unset( $this->items[ $item_id ] ); |
|
400 | + } |
|
401 | + |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns the subtotal. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + */ |
|
409 | + public function get_subtotal() { |
|
410 | + |
|
411 | + if ( wpinv_prices_include_tax() ) { |
|
412 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
413 | + } |
|
414 | + |
|
415 | + return $this->totals['subtotal']['initial']; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Returns the recurring subtotal. |
|
420 | + * |
|
421 | + * @since 1.0.19 |
|
422 | + */ |
|
423 | + public function get_recurring_subtotal() { |
|
424 | + |
|
425 | + if ( wpinv_prices_include_tax() ) { |
|
426 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
427 | + } |
|
428 | + |
|
429 | + return $this->totals['subtotal']['recurring']; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Returns all items. |
|
434 | + * |
|
435 | + * @since 1.0.19 |
|
436 | + * @return GetPaid_Form_Item[] |
|
437 | + */ |
|
438 | + public function get_items() { |
|
439 | + return $this->items; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Checks if there's a single subscription group in the submission. |
|
444 | + * |
|
445 | + * @since 2.3.0 |
|
446 | + * @return bool |
|
447 | + */ |
|
448 | + public function has_subscription_group() { |
|
449 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Checks if there are multipe subscription groups in the submission. |
|
454 | + * |
|
455 | + * @since 2.3.0 |
|
456 | + * @return bool |
|
457 | + */ |
|
458 | + public function has_multiple_subscription_groups() { |
|
459 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
460 | + } |
|
461 | + |
|
462 | + /* |
|
463 | 463 | |-------------------------------------------------------------------------- |
464 | 464 | | Taxes |
465 | 465 | |-------------------------------------------------------------------------- |
@@ -468,128 +468,128 @@ discard block |
||
468 | 468 | | or only one-time. |
469 | 469 | */ |
470 | 470 | |
471 | - /** |
|
472 | - * Prepares the submission's taxes. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function process_taxes() { |
|
477 | - |
|
478 | - // Abort if we're not using taxes. |
|
479 | - if ( ! $this->use_taxes() ) { |
|
480 | - return; |
|
481 | - } |
|
482 | - |
|
483 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | - if ( ! empty( $country ) ) { |
|
486 | - $this->country = $country; |
|
487 | - } |
|
488 | - |
|
489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | - if ( ! empty( $state ) ) { |
|
491 | - $this->state = $state; |
|
492 | - } |
|
493 | - |
|
494 | - // Confirm if the provided country and the ip country are similar. |
|
495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
498 | - } |
|
499 | - |
|
500 | - // Abort if the country is not taxable. |
|
501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | - return; |
|
503 | - } |
|
504 | - |
|
505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | - |
|
507 | - foreach ( $processor->taxes as $tax ) { |
|
508 | - $this->add_tax( $tax ); |
|
509 | - } |
|
510 | - |
|
511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Adds a tax to the submission. |
|
516 | - * |
|
517 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
518 | - * @since 1.0.19 |
|
519 | - */ |
|
520 | - public function add_tax( $tax ) { |
|
521 | - |
|
522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
525 | - } |
|
526 | - |
|
527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Removes a specific tax. |
|
535 | - * |
|
536 | - * @since 1.0.19 |
|
537 | - */ |
|
538 | - public function remove_tax( $tax_name ) { |
|
539 | - |
|
540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | - unset( $this->taxes[ $tax_name ] ); |
|
544 | - } |
|
545 | - |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Whether or not we'll use taxes for the submission. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - */ |
|
553 | - public function use_taxes() { |
|
554 | - |
|
555 | - $use_taxes = wpinv_use_taxes(); |
|
556 | - |
|
557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | - $use_taxes = false; |
|
559 | - } |
|
560 | - |
|
561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | - |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Returns the tax. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - */ |
|
570 | - public function get_tax() { |
|
571 | - return $this->totals['taxes']['initial']; |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Returns the recurring tax. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - */ |
|
579 | - public function get_recurring_tax() { |
|
580 | - return $this->totals['taxes']['recurring']; |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Returns all taxes. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - */ |
|
588 | - public function get_taxes() { |
|
589 | - return $this->taxes; |
|
590 | - } |
|
591 | - |
|
592 | - /* |
|
471 | + /** |
|
472 | + * Prepares the submission's taxes. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function process_taxes() { |
|
477 | + |
|
478 | + // Abort if we're not using taxes. |
|
479 | + if ( ! $this->use_taxes() ) { |
|
480 | + return; |
|
481 | + } |
|
482 | + |
|
483 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
484 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | + if ( ! empty( $country ) ) { |
|
486 | + $this->country = $country; |
|
487 | + } |
|
488 | + |
|
489 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | + if ( ! empty( $state ) ) { |
|
491 | + $this->state = $state; |
|
492 | + } |
|
493 | + |
|
494 | + // Confirm if the provided country and the ip country are similar. |
|
495 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
498 | + } |
|
499 | + |
|
500 | + // Abort if the country is not taxable. |
|
501 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
502 | + return; |
|
503 | + } |
|
504 | + |
|
505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
506 | + |
|
507 | + foreach ( $processor->taxes as $tax ) { |
|
508 | + $this->add_tax( $tax ); |
|
509 | + } |
|
510 | + |
|
511 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Adds a tax to the submission. |
|
516 | + * |
|
517 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
518 | + * @since 1.0.19 |
|
519 | + */ |
|
520 | + public function add_tax( $tax ) { |
|
521 | + |
|
522 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
525 | + } |
|
526 | + |
|
527 | + $this->taxes[ $tax['name'] ] = $tax; |
|
528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Removes a specific tax. |
|
535 | + * |
|
536 | + * @since 1.0.19 |
|
537 | + */ |
|
538 | + public function remove_tax( $tax_name ) { |
|
539 | + |
|
540 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | + unset( $this->taxes[ $tax_name ] ); |
|
544 | + } |
|
545 | + |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Whether or not we'll use taxes for the submission. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + */ |
|
553 | + public function use_taxes() { |
|
554 | + |
|
555 | + $use_taxes = wpinv_use_taxes(); |
|
556 | + |
|
557 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
558 | + $use_taxes = false; |
|
559 | + } |
|
560 | + |
|
561 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
562 | + |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Returns the tax. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + */ |
|
570 | + public function get_tax() { |
|
571 | + return $this->totals['taxes']['initial']; |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Returns the recurring tax. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + */ |
|
579 | + public function get_recurring_tax() { |
|
580 | + return $this->totals['taxes']['recurring']; |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Returns all taxes. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + */ |
|
588 | + public function get_taxes() { |
|
589 | + return $this->taxes; |
|
590 | + } |
|
591 | + |
|
592 | + /* |
|
593 | 593 | |-------------------------------------------------------------------------- |
594 | 594 | | Discounts |
595 | 595 | |-------------------------------------------------------------------------- |
@@ -598,99 +598,99 @@ discard block |
||
598 | 598 | | or only one-time. They also do not have to come from a discount code. |
599 | 599 | */ |
600 | 600 | |
601 | - /** |
|
602 | - * Prepares the submission's discount. |
|
603 | - * |
|
604 | - * @since 1.0.19 |
|
605 | - */ |
|
606 | - public function process_discount() { |
|
607 | - |
|
608 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
609 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | - |
|
612 | - foreach ( $processor->discounts as $discount ) { |
|
613 | - $this->add_discount( $discount ); |
|
614 | - } |
|
615 | - |
|
616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Adds a discount to the submission. |
|
621 | - * |
|
622 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
623 | - * @since 1.0.19 |
|
624 | - */ |
|
625 | - public function add_discount( $discount ) { |
|
626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Removes a discount from the submission. |
|
633 | - * |
|
634 | - * @since 1.0.19 |
|
635 | - */ |
|
636 | - public function remove_discount( $name ) { |
|
637 | - |
|
638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | - unset( $this->discounts[ $name ] ); |
|
642 | - } |
|
643 | - |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Checks whether there is a discount code associated with this submission. |
|
648 | - * |
|
649 | - * @since 1.0.19 |
|
650 | - * @return bool |
|
651 | - */ |
|
652 | - public function has_discount_code() { |
|
653 | - return ! empty( $this->discounts['discount_code'] ); |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * Returns the discount code. |
|
658 | - * |
|
659 | - * @since 1.0.19 |
|
660 | - * @return string |
|
661 | - */ |
|
662 | - public function get_discount_code() { |
|
663 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Returns the discount. |
|
668 | - * |
|
669 | - * @since 1.0.19 |
|
670 | - */ |
|
671 | - public function get_discount() { |
|
672 | - return $this->totals['discount']['initial']; |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Returns the recurring discount. |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - */ |
|
680 | - public function get_recurring_discount() { |
|
681 | - return $this->totals['discount']['recurring']; |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Returns all discounts. |
|
686 | - * |
|
687 | - * @since 1.0.19 |
|
688 | - */ |
|
689 | - public function get_discounts() { |
|
690 | - return $this->discounts; |
|
691 | - } |
|
692 | - |
|
693 | - /* |
|
601 | + /** |
|
602 | + * Prepares the submission's discount. |
|
603 | + * |
|
604 | + * @since 1.0.19 |
|
605 | + */ |
|
606 | + public function process_discount() { |
|
607 | + |
|
608 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
609 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
610 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
611 | + |
|
612 | + foreach ( $processor->discounts as $discount ) { |
|
613 | + $this->add_discount( $discount ); |
|
614 | + } |
|
615 | + |
|
616 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Adds a discount to the submission. |
|
621 | + * |
|
622 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
623 | + * @since 1.0.19 |
|
624 | + */ |
|
625 | + public function add_discount( $discount ) { |
|
626 | + $this->discounts[ $discount['name'] ] = $discount; |
|
627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Removes a discount from the submission. |
|
633 | + * |
|
634 | + * @since 1.0.19 |
|
635 | + */ |
|
636 | + public function remove_discount( $name ) { |
|
637 | + |
|
638 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | + unset( $this->discounts[ $name ] ); |
|
642 | + } |
|
643 | + |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Checks whether there is a discount code associated with this submission. |
|
648 | + * |
|
649 | + * @since 1.0.19 |
|
650 | + * @return bool |
|
651 | + */ |
|
652 | + public function has_discount_code() { |
|
653 | + return ! empty( $this->discounts['discount_code'] ); |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * Returns the discount code. |
|
658 | + * |
|
659 | + * @since 1.0.19 |
|
660 | + * @return string |
|
661 | + */ |
|
662 | + public function get_discount_code() { |
|
663 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Returns the discount. |
|
668 | + * |
|
669 | + * @since 1.0.19 |
|
670 | + */ |
|
671 | + public function get_discount() { |
|
672 | + return $this->totals['discount']['initial']; |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Returns the recurring discount. |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + */ |
|
680 | + public function get_recurring_discount() { |
|
681 | + return $this->totals['discount']['recurring']; |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Returns all discounts. |
|
686 | + * |
|
687 | + * @since 1.0.19 |
|
688 | + */ |
|
689 | + public function get_discounts() { |
|
690 | + return $this->discounts; |
|
691 | + } |
|
692 | + |
|
693 | + /* |
|
694 | 694 | |-------------------------------------------------------------------------- |
695 | 695 | | Fees |
696 | 696 | |-------------------------------------------------------------------------- |
@@ -700,89 +700,89 @@ discard block |
||
700 | 700 | | fees. |
701 | 701 | */ |
702 | 702 | |
703 | - /** |
|
704 | - * Prepares the submission's fees. |
|
705 | - * |
|
706 | - * @since 1.0.19 |
|
707 | - */ |
|
708 | - public function process_fees() { |
|
709 | - |
|
710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | - |
|
712 | - foreach ( $fees_processor->fees as $fee ) { |
|
713 | - $this->add_fee( $fee ); |
|
714 | - } |
|
715 | - |
|
716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Adds a fee to the submission. |
|
721 | - * |
|
722 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
723 | - * @since 1.0.19 |
|
724 | - */ |
|
725 | - public function add_fee( $fee ) { |
|
726 | - |
|
727 | - $this->fees[ $fee['name'] ] = $fee; |
|
728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
730 | - |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Removes a fee from the submission. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - */ |
|
738 | - public function remove_fee( $name ) { |
|
739 | - |
|
740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | - unset( $this->fees[ $name ] ); |
|
744 | - } |
|
745 | - |
|
746 | - } |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns the fees. |
|
750 | - * |
|
751 | - * @since 1.0.19 |
|
752 | - */ |
|
753 | - public function get_fee() { |
|
754 | - return $this->totals['fees']['initial']; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * Returns the recurring fees. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - */ |
|
762 | - public function get_recurring_fee() { |
|
763 | - return $this->totals['fees']['recurring']; |
|
764 | - } |
|
765 | - |
|
766 | - /** |
|
767 | - * Returns all fees. |
|
768 | - * |
|
769 | - * @since 1.0.19 |
|
770 | - */ |
|
771 | - public function get_fees() { |
|
772 | - return $this->fees; |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * Checks if there are any fees for the form. |
|
777 | - * |
|
778 | - * @return bool |
|
779 | - * @since 1.0.19 |
|
780 | - */ |
|
781 | - public function has_fees() { |
|
782 | - return count( $this->fees ) !== 0; |
|
783 | - } |
|
784 | - |
|
785 | - /* |
|
703 | + /** |
|
704 | + * Prepares the submission's fees. |
|
705 | + * |
|
706 | + * @since 1.0.19 |
|
707 | + */ |
|
708 | + public function process_fees() { |
|
709 | + |
|
710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
711 | + |
|
712 | + foreach ( $fees_processor->fees as $fee ) { |
|
713 | + $this->add_fee( $fee ); |
|
714 | + } |
|
715 | + |
|
716 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Adds a fee to the submission. |
|
721 | + * |
|
722 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
723 | + * @since 1.0.19 |
|
724 | + */ |
|
725 | + public function add_fee( $fee ) { |
|
726 | + |
|
727 | + $this->fees[ $fee['name'] ] = $fee; |
|
728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
730 | + |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Removes a fee from the submission. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + */ |
|
738 | + public function remove_fee( $name ) { |
|
739 | + |
|
740 | + if ( isset( $this->fees[ $name ] ) ) { |
|
741 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | + unset( $this->fees[ $name ] ); |
|
744 | + } |
|
745 | + |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns the fees. |
|
750 | + * |
|
751 | + * @since 1.0.19 |
|
752 | + */ |
|
753 | + public function get_fee() { |
|
754 | + return $this->totals['fees']['initial']; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * Returns the recurring fees. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + */ |
|
762 | + public function get_recurring_fee() { |
|
763 | + return $this->totals['fees']['recurring']; |
|
764 | + } |
|
765 | + |
|
766 | + /** |
|
767 | + * Returns all fees. |
|
768 | + * |
|
769 | + * @since 1.0.19 |
|
770 | + */ |
|
771 | + public function get_fees() { |
|
772 | + return $this->fees; |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * Checks if there are any fees for the form. |
|
777 | + * |
|
778 | + * @return bool |
|
779 | + * @since 1.0.19 |
|
780 | + */ |
|
781 | + public function has_fees() { |
|
782 | + return count( $this->fees ) !== 0; |
|
783 | + } |
|
784 | + |
|
785 | + /* |
|
786 | 786 | |-------------------------------------------------------------------------- |
787 | 787 | | MISC |
788 | 788 | |-------------------------------------------------------------------------- |
@@ -790,119 +790,119 @@ discard block |
||
790 | 790 | | Extra submission functions. |
791 | 791 | */ |
792 | 792 | |
793 | - /** |
|
794 | - * Checks if this is the initial fetch. |
|
795 | - * |
|
796 | - * @return bool |
|
797 | - * @since 1.0.19 |
|
798 | - */ |
|
799 | - public function is_initial_fetch() { |
|
800 | - return empty( $this->data['initial_state'] ); |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * Returns the total amount to collect for this submission. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - */ |
|
808 | - public function get_total() { |
|
809 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
810 | - return max( $total, 0 ); |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Returns the recurring total amount to collect for this submission. |
|
815 | - * |
|
816 | - * @since 1.0.19 |
|
817 | - */ |
|
818 | - public function get_recurring_total() { |
|
819 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
820 | - return max( $total, 0 ); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Whether payment details should be collected for this submission. |
|
825 | - * |
|
826 | - * @since 1.0.19 |
|
827 | - */ |
|
828 | - public function should_collect_payment_details() { |
|
829 | - $initial = $this->get_total(); |
|
830 | - $recurring = $this->get_recurring_total(); |
|
831 | - |
|
832 | - if ( $this->has_recurring == 0 ) { |
|
833 | - $recurring = 0; |
|
834 | - } |
|
835 | - |
|
836 | - $collect = $initial > 0 || $recurring > 0; |
|
837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Returns the billing email of the user. |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - */ |
|
845 | - public function get_billing_email() { |
|
846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * Checks if the submitter has a billing email. |
|
851 | - * |
|
852 | - * @since 1.0.19 |
|
853 | - */ |
|
854 | - public function has_billing_email() { |
|
855 | - $billing_email = $this->get_billing_email(); |
|
856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Returns the appropriate currency for the submission. |
|
861 | - * |
|
862 | - * @since 1.0.19 |
|
863 | - * @return string |
|
864 | - */ |
|
865 | - public function get_currency() { |
|
866 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * Returns the raw submission data. |
|
871 | - * |
|
872 | - * @since 1.0.19 |
|
873 | - * @return array |
|
874 | - */ |
|
875 | - public function get_data() { |
|
876 | - return $this->data; |
|
877 | - } |
|
878 | - |
|
879 | - /** |
|
880 | - * Returns a field from the submission data |
|
881 | - * |
|
882 | - * @param string $field |
|
883 | - * @since 1.0.19 |
|
884 | - * @return mixed|null |
|
885 | - */ |
|
886 | - public function get_field( $field, $sub_array_key = null ) { |
|
887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
888 | - } |
|
889 | - |
|
890 | - /** |
|
891 | - * Checks if a required field is set. |
|
892 | - * |
|
893 | - * @since 1.0.19 |
|
894 | - */ |
|
895 | - public function is_required_field_set( $field ) { |
|
896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * Formats an amount |
|
901 | - * |
|
902 | - * @since 1.0.19 |
|
903 | - */ |
|
904 | - public function format_amount( $amount ) { |
|
905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
906 | - } |
|
793 | + /** |
|
794 | + * Checks if this is the initial fetch. |
|
795 | + * |
|
796 | + * @return bool |
|
797 | + * @since 1.0.19 |
|
798 | + */ |
|
799 | + public function is_initial_fetch() { |
|
800 | + return empty( $this->data['initial_state'] ); |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * Returns the total amount to collect for this submission. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + */ |
|
808 | + public function get_total() { |
|
809 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
810 | + return max( $total, 0 ); |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Returns the recurring total amount to collect for this submission. |
|
815 | + * |
|
816 | + * @since 1.0.19 |
|
817 | + */ |
|
818 | + public function get_recurring_total() { |
|
819 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
820 | + return max( $total, 0 ); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Whether payment details should be collected for this submission. |
|
825 | + * |
|
826 | + * @since 1.0.19 |
|
827 | + */ |
|
828 | + public function should_collect_payment_details() { |
|
829 | + $initial = $this->get_total(); |
|
830 | + $recurring = $this->get_recurring_total(); |
|
831 | + |
|
832 | + if ( $this->has_recurring == 0 ) { |
|
833 | + $recurring = 0; |
|
834 | + } |
|
835 | + |
|
836 | + $collect = $initial > 0 || $recurring > 0; |
|
837 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Returns the billing email of the user. |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + */ |
|
845 | + public function get_billing_email() { |
|
846 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * Checks if the submitter has a billing email. |
|
851 | + * |
|
852 | + * @since 1.0.19 |
|
853 | + */ |
|
854 | + public function has_billing_email() { |
|
855 | + $billing_email = $this->get_billing_email(); |
|
856 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Returns the appropriate currency for the submission. |
|
861 | + * |
|
862 | + * @since 1.0.19 |
|
863 | + * @return string |
|
864 | + */ |
|
865 | + public function get_currency() { |
|
866 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * Returns the raw submission data. |
|
871 | + * |
|
872 | + * @since 1.0.19 |
|
873 | + * @return array |
|
874 | + */ |
|
875 | + public function get_data() { |
|
876 | + return $this->data; |
|
877 | + } |
|
878 | + |
|
879 | + /** |
|
880 | + * Returns a field from the submission data |
|
881 | + * |
|
882 | + * @param string $field |
|
883 | + * @since 1.0.19 |
|
884 | + * @return mixed|null |
|
885 | + */ |
|
886 | + public function get_field( $field, $sub_array_key = null ) { |
|
887 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
888 | + } |
|
889 | + |
|
890 | + /** |
|
891 | + * Checks if a required field is set. |
|
892 | + * |
|
893 | + * @since 1.0.19 |
|
894 | + */ |
|
895 | + public function is_required_field_set( $field ) { |
|
896 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * Formats an amount |
|
901 | + * |
|
902 | + * @since 1.0.19 |
|
903 | + */ |
|
904 | + public function format_amount( $amount ) { |
|
905 | + return wpinv_price( $amount, $this->get_currency() ); |
|
906 | + } |
|
907 | 907 | |
908 | 908 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | $this->state = wpinv_get_default_state(); |
142 | 142 | |
143 | 143 | // Do we have an actual submission? |
144 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
145 | - $this->load_data( $_POST ); |
|
144 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
145 | + $this->load_data($_POST); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | } |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @param array $data |
154 | 154 | */ |
155 | - public function load_data( $data ) { |
|
155 | + public function load_data($data) { |
|
156 | 156 | |
157 | 157 | // Remove slashes from the submitted data... |
158 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
158 | + $data = wp_kses_post_deep(wp_unslash($data)); |
|
159 | 159 | |
160 | 160 | // Allow plugins to filter the data. |
161 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
161 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
162 | 162 | |
163 | 163 | // Cache it... |
164 | 164 | $this->data = $data; |
165 | 165 | |
166 | 166 | // Then generate a unique id from the data. |
167 | - $this->id = md5( wp_json_encode( $data ) ); |
|
167 | + $this->id = md5(wp_json_encode($data)); |
|
168 | 168 | |
169 | 169 | // Finally, process the submission. |
170 | 170 | try { |
@@ -174,30 +174,30 @@ discard block |
||
174 | 174 | $processors = apply_filters( |
175 | 175 | 'getpaid_payment_form_submission_processors', |
176 | 176 | array( |
177 | - array( $this, 'process_payment_form' ), |
|
178 | - array( $this, 'process_invoice' ), |
|
179 | - array( $this, 'process_fees' ), |
|
180 | - array( $this, 'process_items' ), |
|
181 | - array( $this, 'process_discount' ), |
|
182 | - array( $this, 'process_taxes' ), |
|
177 | + array($this, 'process_payment_form'), |
|
178 | + array($this, 'process_invoice'), |
|
179 | + array($this, 'process_fees'), |
|
180 | + array($this, 'process_items'), |
|
181 | + array($this, 'process_discount'), |
|
182 | + array($this, 'process_taxes'), |
|
183 | 183 | ), |
184 | 184 | $this |
185 | 185 | ); |
186 | 186 | |
187 | - foreach ( $processors as $processor ) { |
|
188 | - call_user_func_array( $processor, array( &$this ) ); |
|
187 | + foreach ($processors as $processor) { |
|
188 | + call_user_func_array($processor, array(&$this)); |
|
189 | 189 | } |
190 | 190 | |
191 | - } catch( GetPaid_Payment_Exception $e ) { |
|
191 | + } catch (GetPaid_Payment_Exception $e) { |
|
192 | 192 | $this->last_error = $e->getMessage(); |
193 | 193 | $this->last_error_code = $e->getErrorCode(); |
194 | - } catch ( Exception $e ) { |
|
194 | + } catch (Exception $e) { |
|
195 | 195 | $this->last_error = $e->getMessage(); |
196 | 196 | $this->last_error_code = $e->getCode(); |
197 | 197 | } |
198 | 198 | |
199 | 199 | // Fired when we are done processing a submission. |
200 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
200 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -218,18 +218,18 @@ discard block |
||
218 | 218 | public function process_payment_form() { |
219 | 219 | |
220 | 220 | // Every submission needs an active payment form. |
221 | - if ( empty( $this->data['form_id'] ) ) { |
|
222 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
221 | + if (empty($this->data['form_id'])) { |
|
222 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Fetch the payment form. |
226 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
226 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
227 | 227 | |
228 | - if ( ! $this->payment_form->is_active() ) { |
|
229 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
228 | + if (!$this->payment_form->is_active()) { |
|
229 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
232 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -259,53 +259,53 @@ discard block |
||
259 | 259 | public function process_invoice() { |
260 | 260 | |
261 | 261 | // Abort if there is no invoice. |
262 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
262 | + if (empty($this->data['invoice_id'])) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | 266 | // If the submission is for an existing invoice, ensure that it exists |
267 | 267 | // and that it is not paid for. |
268 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
268 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
269 | 269 | |
270 | - if ( empty( $invoice ) ) { |
|
271 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
270 | + if (empty($invoice)) { |
|
271 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
272 | 272 | } |
273 | 273 | |
274 | - if ( $invoice->is_paid() ) { |
|
275 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
274 | + if ($invoice->is_paid()) { |
|
275 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $this->payment_form->invoice = $invoice; |
279 | - if ( ! $this->payment_form->is_default() ) { |
|
279 | + if (!$this->payment_form->is_default()) { |
|
280 | 280 | |
281 | 281 | $items = array(); |
282 | 282 | $item_ids = array(); |
283 | 283 | |
284 | - foreach ( $invoice->get_items() as $item ) { |
|
285 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
284 | + foreach ($invoice->get_items() as $item) { |
|
285 | + if (!in_array($item->get_id(), $item_ids)) { |
|
286 | 286 | $item_ids[] = $item->get_id(); |
287 | 287 | $items[] = $item; |
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
292 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | + foreach ($this->payment_form->get_items() as $item) { |
|
292 | + if (!in_array($item->get_id(), $item_ids)) { |
|
293 | 293 | $item_ids[] = $item->get_id(); |
294 | 294 | $items[] = $item; |
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - $this->payment_form->set_items( $items ); |
|
298 | + $this->payment_form->set_items($items); |
|
299 | 299 | |
300 | 300 | } else { |
301 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
301 | + $this->payment_form->set_items($invoice->get_items()); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | $this->country = $invoice->get_country(); |
305 | 305 | $this->state = $invoice->get_state(); |
306 | 306 | $this->invoice = $invoice; |
307 | 307 | |
308 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
308 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @return bool |
326 | 326 | */ |
327 | 327 | public function has_invoice() { |
328 | - return ! empty( $this->invoice ); |
|
328 | + return !empty($this->invoice); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /* |
@@ -344,13 +344,13 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function process_items() { |
346 | 346 | |
347 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
347 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
348 | 348 | |
349 | - foreach ( $processor->items as $item ) { |
|
350 | - $this->add_item( $item ); |
|
349 | + foreach ($processor->items as $item) { |
|
350 | + $this->add_item($item); |
|
351 | 351 | } |
352 | 352 | |
353 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
353 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,20 +359,20 @@ discard block |
||
359 | 359 | * @since 1.0.19 |
360 | 360 | * @param GetPaid_Form_Item $item |
361 | 361 | */ |
362 | - public function add_item( $item ) { |
|
362 | + public function add_item($item) { |
|
363 | 363 | |
364 | 364 | // Make sure that it is available for purchase. |
365 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
365 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | |
369 | 369 | // Each submission can only contain one recurring item. |
370 | - if ( $item->is_recurring() ) { |
|
370 | + if ($item->is_recurring()) { |
|
371 | 371 | $this->has_recurring = $item->get_id(); |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Update the items and totals. |
375 | - $this->items[ $item->get_id() ] = $item; |
|
375 | + $this->items[$item->get_id()] = $item; |
|
376 | 376 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
377 | 377 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
378 | 378 | |
@@ -386,17 +386,17 @@ discard block |
||
386 | 386 | * |
387 | 387 | * @since 1.0.19 |
388 | 388 | */ |
389 | - public function remove_item( $item_id ) { |
|
389 | + public function remove_item($item_id) { |
|
390 | 390 | |
391 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
392 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
393 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
391 | + if (isset($this->items[$item_id])) { |
|
392 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
393 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
394 | 394 | |
395 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
395 | + if ($this->items[$item_id]->is_recurring()) { |
|
396 | 396 | $this->has_recurring = 0; |
397 | 397 | } |
398 | 398 | |
399 | - unset( $this->items[ $item_id ] ); |
|
399 | + unset($this->items[$item_id]); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | */ |
409 | 409 | public function get_subtotal() { |
410 | 410 | |
411 | - if ( wpinv_prices_include_tax() ) { |
|
411 | + if (wpinv_prices_include_tax()) { |
|
412 | 412 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
413 | 413 | } |
414 | 414 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | */ |
423 | 423 | public function get_recurring_subtotal() { |
424 | 424 | |
425 | - if ( wpinv_prices_include_tax() ) { |
|
425 | + if (wpinv_prices_include_tax()) { |
|
426 | 426 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
427 | 427 | } |
428 | 428 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @return bool |
447 | 447 | */ |
448 | 448 | public function has_subscription_group() { |
449 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
449 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @return bool |
457 | 457 | */ |
458 | 458 | public function has_multiple_subscription_groups() { |
459 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
459 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /* |
@@ -476,39 +476,39 @@ discard block |
||
476 | 476 | public function process_taxes() { |
477 | 477 | |
478 | 478 | // Abort if we're not using taxes. |
479 | - if ( ! $this->use_taxes() ) { |
|
479 | + if (!$this->use_taxes()) { |
|
480 | 480 | return; |
481 | 481 | } |
482 | 482 | |
483 | 483 | // If a custom country && state has been passed in, use it to calculate taxes. |
484 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
485 | - if ( ! empty( $country ) ) { |
|
484 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
485 | + if (!empty($country)) { |
|
486 | 486 | $this->country = $country; |
487 | 487 | } |
488 | 488 | |
489 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
490 | - if ( ! empty( $state ) ) { |
|
489 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
490 | + if (!empty($state)) { |
|
491 | 491 | $this->state = $state; |
492 | 492 | } |
493 | 493 | |
494 | 494 | // Confirm if the provided country and the ip country are similar. |
495 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
496 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
497 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
495 | + $address_confirmed = $this->get_field('confirm-address'); |
|
496 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
497 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | // Abort if the country is not taxable. |
501 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
501 | + if (!wpinv_is_country_taxable($this->country)) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
505 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
506 | 506 | |
507 | - foreach ( $processor->taxes as $tax ) { |
|
508 | - $this->add_tax( $tax ); |
|
507 | + foreach ($processor->taxes as $tax) { |
|
508 | + $this->add_tax($tax); |
|
509 | 509 | } |
510 | 510 | |
511 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
511 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -517,16 +517,16 @@ discard block |
||
517 | 517 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
518 | 518 | * @since 1.0.19 |
519 | 519 | */ |
520 | - public function add_tax( $tax ) { |
|
520 | + public function add_tax($tax) { |
|
521 | 521 | |
522 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
523 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
524 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
522 | + if (wpinv_round_tax_per_tax_rate()) { |
|
523 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
524 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
525 | 525 | } |
526 | 526 | |
527 | - $this->taxes[ $tax['name'] ] = $tax; |
|
528 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
529 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
527 | + $this->taxes[$tax['name']] = $tax; |
|
528 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
529 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
530 | 530 | |
531 | 531 | } |
532 | 532 | |
@@ -535,12 +535,12 @@ discard block |
||
535 | 535 | * |
536 | 536 | * @since 1.0.19 |
537 | 537 | */ |
538 | - public function remove_tax( $tax_name ) { |
|
538 | + public function remove_tax($tax_name) { |
|
539 | 539 | |
540 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
541 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
542 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
543 | - unset( $this->taxes[ $tax_name ] ); |
|
540 | + if (isset($this->taxes[$tax_name])) { |
|
541 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
542 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
543 | + unset($this->taxes[$tax_name]); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | } |
@@ -554,11 +554,11 @@ discard block |
||
554 | 554 | |
555 | 555 | $use_taxes = wpinv_use_taxes(); |
556 | 556 | |
557 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
557 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
558 | 558 | $use_taxes = false; |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
561 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
562 | 562 | |
563 | 563 | } |
564 | 564 | |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | |
608 | 608 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
609 | 609 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
610 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
610 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
611 | 611 | |
612 | - foreach ( $processor->discounts as $discount ) { |
|
613 | - $this->add_discount( $discount ); |
|
612 | + foreach ($processor->discounts as $discount) { |
|
613 | + $this->add_discount($discount); |
|
614 | 614 | } |
615 | 615 | |
616 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
616 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -622,10 +622,10 @@ discard block |
||
622 | 622 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
623 | 623 | * @since 1.0.19 |
624 | 624 | */ |
625 | - public function add_discount( $discount ) { |
|
626 | - $this->discounts[ $discount['name'] ] = $discount; |
|
627 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
628 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
625 | + public function add_discount($discount) { |
|
626 | + $this->discounts[$discount['name']] = $discount; |
|
627 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
628 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | * |
634 | 634 | * @since 1.0.19 |
635 | 635 | */ |
636 | - public function remove_discount( $name ) { |
|
636 | + public function remove_discount($name) { |
|
637 | 637 | |
638 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
639 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
640 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
641 | - unset( $this->discounts[ $name ] ); |
|
638 | + if (isset($this->discounts[$name])) { |
|
639 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
640 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
641 | + unset($this->discounts[$name]); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | } |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @return bool |
651 | 651 | */ |
652 | 652 | public function has_discount_code() { |
653 | - return ! empty( $this->discounts['discount_code'] ); |
|
653 | + return !empty($this->discounts['discount_code']); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -707,13 +707,13 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function process_fees() { |
709 | 709 | |
710 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
710 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
711 | 711 | |
712 | - foreach ( $fees_processor->fees as $fee ) { |
|
713 | - $this->add_fee( $fee ); |
|
712 | + foreach ($fees_processor->fees as $fee) { |
|
713 | + $this->add_fee($fee); |
|
714 | 714 | } |
715 | 715 | |
716 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
716 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -722,11 +722,11 @@ discard block |
||
722 | 722 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
723 | 723 | * @since 1.0.19 |
724 | 724 | */ |
725 | - public function add_fee( $fee ) { |
|
725 | + public function add_fee($fee) { |
|
726 | 726 | |
727 | - $this->fees[ $fee['name'] ] = $fee; |
|
728 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
729 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
727 | + $this->fees[$fee['name']] = $fee; |
|
728 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
729 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
730 | 730 | |
731 | 731 | } |
732 | 732 | |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | * |
736 | 736 | * @since 1.0.19 |
737 | 737 | */ |
738 | - public function remove_fee( $name ) { |
|
738 | + public function remove_fee($name) { |
|
739 | 739 | |
740 | - if ( isset( $this->fees[ $name ] ) ) { |
|
741 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
742 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
743 | - unset( $this->fees[ $name ] ); |
|
740 | + if (isset($this->fees[$name])) { |
|
741 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
742 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
743 | + unset($this->fees[$name]); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | * @since 1.0.19 |
780 | 780 | */ |
781 | 781 | public function has_fees() { |
782 | - return count( $this->fees ) !== 0; |
|
782 | + return count($this->fees) !== 0; |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /* |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | * @since 1.0.19 |
798 | 798 | */ |
799 | 799 | public function is_initial_fetch() { |
800 | - return empty( $this->data['initial_state'] ); |
|
800 | + return empty($this->data['initial_state']); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | */ |
808 | 808 | public function get_total() { |
809 | 809 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
810 | - return max( $total, 0 ); |
|
810 | + return max($total, 0); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | /** |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | public function get_recurring_total() { |
819 | 819 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
820 | - return max( $total, 0 ); |
|
820 | + return max($total, 0); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
@@ -829,12 +829,12 @@ discard block |
||
829 | 829 | $initial = $this->get_total(); |
830 | 830 | $recurring = $this->get_recurring_total(); |
831 | 831 | |
832 | - if ( $this->has_recurring == 0 ) { |
|
832 | + if ($this->has_recurring == 0) { |
|
833 | 833 | $recurring = 0; |
834 | 834 | } |
835 | 835 | |
836 | 836 | $collect = $initial > 0 || $recurring > 0; |
837 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
837 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @since 1.0.19 |
844 | 844 | */ |
845 | 845 | public function get_billing_email() { |
846 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
846 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | */ |
854 | 854 | public function has_billing_email() { |
855 | 855 | $billing_email = $this->get_billing_email(); |
856 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
856 | + return !empty($billing_email) && is_email($billing_email); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -883,8 +883,8 @@ discard block |
||
883 | 883 | * @since 1.0.19 |
884 | 884 | * @return mixed|null |
885 | 885 | */ |
886 | - public function get_field( $field, $sub_array_key = null ) { |
|
887 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
886 | + public function get_field($field, $sub_array_key = null) { |
|
887 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -892,8 +892,8 @@ discard block |
||
892 | 892 | * |
893 | 893 | * @since 1.0.19 |
894 | 894 | */ |
895 | - public function is_required_field_set( $field ) { |
|
896 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
895 | + public function is_required_field_set($field) { |
|
896 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
@@ -901,8 +901,8 @@ discard block |
||
901 | 901 | * |
902 | 902 | * @since 1.0.19 |
903 | 903 | */ |
904 | - public function format_amount( $amount ) { |
|
905 | - return wpinv_price( $amount, $this->get_currency() ); |
|
904 | + public function format_amount($amount) { |
|
905 | + return wpinv_price($amount, $this->get_currency()); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | } |
@@ -13,65 +13,65 @@ discard block |
||
13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'worldpay'; |
21 | 21 | |
22 | 22 | /** |
23 | - * Payment method order. |
|
24 | - * |
|
25 | - * @var int |
|
26 | - */ |
|
23 | + * Payment method order. |
|
24 | + * |
|
25 | + * @var int |
|
26 | + */ |
|
27 | 27 | public $order = 5; |
28 | 28 | |
29 | 29 | /** |
30 | - * Endpoint for requests from Worldpay. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $notify_url; |
|
35 | - |
|
36 | - /** |
|
37 | - * Endpoint for requests to Worldpay. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
30 | + * Endpoint for requests from Worldpay. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $notify_url; |
|
35 | + |
|
36 | + /** |
|
37 | + * Endpoint for requests to Worldpay. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | 41 | protected $endpoint; |
42 | 42 | |
43 | 43 | /** |
44 | - * An array of features that this gateway supports. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
44 | + * An array of features that this gateway supports. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | 48 | protected $supports = array( 'sandbox' ); |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a subscription. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
65 | + * URL to view a subscription. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
70 | 70 | |
71 | 71 | /** |
72 | - * Class constructor. |
|
73 | - */ |
|
74 | - public function __construct() { |
|
72 | + * Class constructor. |
|
73 | + */ |
|
74 | + public function __construct() { |
|
75 | 75 | |
76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Process Payment. |
|
89 | - * |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice Invoice. |
|
92 | - * @param array $submission_data Posted checkout fields. |
|
93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
88 | + * Process Payment. |
|
89 | + * |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice Invoice. |
|
92 | + * @param array $submission_data Posted checkout fields. |
|
93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * Get the Worldpay request URL for an invoice. |
|
132 | - * |
|
133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_request_url( $invoice ) { |
|
131 | + * Get the Worldpay request URL for an invoice. |
|
132 | + * |
|
133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_request_url( $invoice ) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
143 | - } |
|
143 | + } |
|
144 | 144 | |
145 | 145 | /** |
146 | - * Get Worldpay Args for passing to Worldpay. |
|
147 | - * |
|
148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - protected function get_worldpay_args( $invoice ) { |
|
152 | - |
|
153 | - return apply_filters( |
|
154 | - 'getpaid_worldpay_args', |
|
155 | - array( |
|
146 | + * Get Worldpay Args for passing to Worldpay. |
|
147 | + * |
|
148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + protected function get_worldpay_args( $invoice ) { |
|
152 | + |
|
153 | + return apply_filters( |
|
154 | + 'getpaid_worldpay_args', |
|
155 | + array( |
|
156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
179 | 179 | ), |
180 | - $invoice |
|
181 | - ); |
|
180 | + $invoice |
|
181 | + ); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Secures worldpay args with an md5 hash. |
|
187 | - * |
|
188 | - * @param array $args Gateway args. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public function hash_args( $args ) { |
|
186 | + * Secures worldpay args with an md5 hash. |
|
187 | + * |
|
188 | + * @param array $args Gateway args. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public function hash_args( $args ) { |
|
192 | 192 | |
193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Processes ipns and marks payments as complete. |
|
208 | - * |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function verify_ipn() { |
|
207 | + * Processes ipns and marks payments as complete. |
|
208 | + * |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function verify_ipn() { |
|
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | - } |
|
215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
230 | 230 | } |
231 | 231 | |
232 | - // Update the ip address. |
|
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
232 | + // Update the ip address. |
|
233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
235 | 235 | } |
236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Worldpay IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Worldpay IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Filters the gateway settings. |
|
309 | - * |
|
310 | - * @param array $admin_settings |
|
311 | - */ |
|
312 | - public function admin_settings( $admin_settings ) { |
|
308 | + * Filters the gateway settings. |
|
309 | + * |
|
310 | + * @param array $admin_settings |
|
311 | + */ |
|
312 | + public function admin_settings( $admin_settings ) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | 'readonly' => true |
351 | 351 | ); |
352 | 352 | |
353 | - return $admin_settings; |
|
354 | - } |
|
353 | + return $admin_settings; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -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 | * Worldpay Payment Gateway class. |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @var array |
47 | 47 | */ |
48 | - protected $supports = array( 'sandbox' ); |
|
48 | + protected $supports = array('sandbox'); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Currencies this gateway is allowed for. |
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
55 | + public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function __construct() { |
75 | 75 | |
76 | - $this->method_title = __( 'Worldpay', 'invoicing' ); |
|
77 | - $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
|
78 | - $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' ); |
|
79 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
76 | + $this->method_title = __('Worldpay', 'invoicing'); |
|
77 | + $this->title = __('Worldpay - Credit Card / Debit Card', 'invoicing'); |
|
78 | + $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing'); |
|
79 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
80 | 80 | |
81 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
82 | - add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) ); |
|
81 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
82 | + add_filter('getpaid_worldpay_args', array($this, 'hash_args')); |
|
83 | 83 | |
84 | 84 | parent::__construct(); |
85 | 85 | } |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
94 | 94 | * @return array |
95 | 95 | */ |
96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
96 | + public function process_payment($invoice, $submission_data, $submission) { |
|
97 | 97 | |
98 | 98 | // Get redirect url. |
99 | - $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
|
99 | + $worldpay_redirect = esc_url($this->get_request_url($invoice)); |
|
100 | 100 | |
101 | 101 | // Get submission args. |
102 | - $worldpay_args = $this->get_worldpay_args( $invoice ); |
|
102 | + $worldpay_args = $this->get_worldpay_args($invoice); |
|
103 | 103 | |
104 | 104 | $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>"; |
105 | 105 | |
106 | - foreach ( $worldpay_args as $key => $value ) { |
|
106 | + foreach ($worldpay_args as $key => $value) { |
|
107 | 107 | |
108 | - if ( false === $value || '' === trim( $value ) ) { |
|
108 | + if (false === $value || '' === trim($value)) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | |
112 | - $value = esc_attr( $value ); |
|
113 | - $key = wpinv_clean( $key ); |
|
112 | + $value = esc_attr($value); |
|
113 | + $key = wpinv_clean($key); |
|
114 | 114 | $form .= "<input type='hidden' name='$key' value='$value'>"; |
115 | 115 | } |
116 | 116 | |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @param WPInv_Invoice $invoice Invoice object. |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - public function get_request_url( $invoice ) { |
|
136 | + public function get_request_url($invoice) { |
|
137 | 137 | |
138 | 138 | // Endpoint for this request |
139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
139 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
140 | 140 | |
141 | 141 | return $this->endpoint; |
142 | 142 | |
@@ -148,34 +148,34 @@ discard block |
||
148 | 148 | * @param WPInv_Invoice $invoice Invoice object. |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - protected function get_worldpay_args( $invoice ) { |
|
151 | + protected function get_worldpay_args($invoice) { |
|
152 | 152 | |
153 | 153 | return apply_filters( |
154 | 154 | 'getpaid_worldpay_args', |
155 | 155 | array( |
156 | - 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
|
157 | - 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
|
158 | - 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
|
159 | - 'instId' => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory |
|
160 | - 'testMode' => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory |
|
161 | - 'name' => wpinv_clean( $invoice->get_full_name() ), |
|
162 | - 'address' => wpinv_clean( $invoice->get_address() ), |
|
163 | - 'postcode' => wpinv_clean( $invoice->get_zip() ), |
|
164 | - 'tel' => wpinv_clean( $invoice->get_phone() ), |
|
165 | - 'email' => sanitize_email( $invoice->get_email() ), |
|
166 | - 'country' => wpinv_clean( $invoice->get_country() ), |
|
167 | - 'desc' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
168 | - 'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
169 | - 'MC_callback' => esc_url_raw( $this->notify_url ), |
|
170 | - 'resultfile' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
171 | - 'MC_key' => wpinv_clean( $invoice->get_key() ), |
|
156 | + 'amount' => wpinv_sanitize_amount($invoice->get_total()), // mandatory |
|
157 | + 'cartId' => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased |
|
158 | + 'currency' => wpinv_clean($invoice->get_currency()), // mandatory |
|
159 | + 'instId' => wpinv_clean($this->get_option('instId', '')), // mandatory |
|
160 | + 'testMode' => $this->is_sandbox($invoice) ? 100 : 0, // mandatory |
|
161 | + 'name' => wpinv_clean($invoice->get_full_name()), |
|
162 | + 'address' => wpinv_clean($invoice->get_address()), |
|
163 | + 'postcode' => wpinv_clean($invoice->get_zip()), |
|
164 | + 'tel' => wpinv_clean($invoice->get_phone()), |
|
165 | + 'email' => sanitize_email($invoice->get_email()), |
|
166 | + 'country' => wpinv_clean($invoice->get_country()), |
|
167 | + 'desc' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
168 | + 'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
169 | + 'MC_callback' => esc_url_raw($this->notify_url), |
|
170 | + 'resultfile' => esc_url_raw($this->get_return_url($invoice)), |
|
171 | + 'MC_key' => wpinv_clean($invoice->get_key()), |
|
172 | 172 | 'MC_invoice_id' => $invoice->get_id(), |
173 | - 'address1' => wpinv_clean( $invoice->get_address() ), |
|
174 | - 'town' => wpinv_clean( $invoice->get_city() ), |
|
175 | - 'region' => wpinv_clean( $invoice->get_state() ), |
|
176 | - 'amountString' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
177 | - 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
|
178 | - 'compName' => wpinv_clean( $invoice->get_company() ), |
|
173 | + 'address1' => wpinv_clean($invoice->get_address()), |
|
174 | + 'town' => wpinv_clean($invoice->get_city()), |
|
175 | + 'region' => wpinv_clean($invoice->get_state()), |
|
176 | + 'amountString' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
177 | + 'countryString' => wpinv_clean(wpinv_country_name($invoice->get_country())), |
|
178 | + 'compName' => wpinv_clean($invoice->get_company()), |
|
179 | 179 | ), |
180 | 180 | $invoice |
181 | 181 | ); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | * @param array $args Gateway args. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - public function hash_args( $args ) { |
|
191 | + public function hash_args($args) { |
|
192 | 192 | |
193 | - $md5_secret = $this->get_option( 'md5_secret' ); |
|
193 | + $md5_secret = $this->get_option('md5_secret'); |
|
194 | 194 | |
195 | 195 | // Abort if there is no secret. |
196 | - if ( empty( $md5_secret ) ) { |
|
196 | + if (empty($md5_secret)) { |
|
197 | 197 | return $args; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Hash the args. |
201 | - $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" ); |
|
201 | + $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}"); |
|
202 | 202 | |
203 | 203 | return $args; |
204 | 204 | } |
@@ -211,43 +211,43 @@ discard block |
||
211 | 211 | public function verify_ipn() { |
212 | 212 | |
213 | 213 | // Validate the IPN. |
214 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
214 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
215 | + wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500)); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | // Process the IPN. |
219 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
220 | - $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] ); |
|
219 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
220 | + $invoice = wpinv_get_invoice($posted['MC_invoice_id']); |
|
221 | 221 | |
222 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
222 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
223 | 223 | |
224 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
225 | - wpinv_error_log( 'Payment status:' . $posted['transStatus'] ); |
|
224 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
225 | + wpinv_error_log('Payment status:' . $posted['transStatus']); |
|
226 | 226 | |
227 | 227 | // Update the transaction id. |
228 | - if ( ! empty( $posted['transId'] ) ) { |
|
229 | - $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
|
228 | + if (!empty($posted['transId'])) { |
|
229 | + $invoice->set_transaction_id(wpinv_clean($posted['transId'])); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // Update the ip address. |
233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
234 | - $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
|
233 | + if (!empty($posted['ipAddress'])) { |
|
234 | + $invoice->set_ip(wpinv_clean($posted['ipAddress'])); |
|
235 | 235 | } |
236 | 236 | |
237 | - if ( $posted['transStatus'] == 'Y' ) { |
|
238 | - $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) ); |
|
237 | + if ($posted['transStatus'] == 'Y') { |
|
238 | + $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime'])); |
|
239 | 239 | $invoice->mark_paid(); |
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | - if ( $posted['transStatus'] == 'C' ) { |
|
244 | - $invoice->set_status( 'wpi-failed' ); |
|
245 | - $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true ); |
|
243 | + if ($posted['transStatus'] == 'C') { |
|
244 | + $invoice->set_status('wpi-failed'); |
|
245 | + $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true); |
|
246 | 246 | $invoice->save(); |
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
250 | - wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] ); |
|
250 | + wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']); |
|
251 | 251 | $invoice->save(); |
252 | 252 | |
253 | 253 | } |
@@ -261,27 +261,27 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Worldpay IPN response' ); |
|
264 | + wpinv_error_log('Validating Worldpay IPN response'); |
|
265 | 265 | |
266 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
266 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
267 | 267 | |
268 | 268 | // Verify installation. |
269 | - if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) { |
|
270 | - wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' ); |
|
269 | + if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) { |
|
270 | + wpinv_error_log('Received invalid installation ID from Worldpay IPN'); |
|
271 | 271 | return false; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Verify invoice. |
275 | - if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) { |
|
276 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
275 | + if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) { |
|
276 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // (maybe) verify password. |
281 | - $password = $this->get_option( 'callback_password' ); |
|
281 | + $password = $this->get_option('callback_password'); |
|
282 | 282 | |
283 | - if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) { |
|
284 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
283 | + if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) { |
|
284 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | /** |
293 | 293 | * Displays a notice on the checkout page if sandbox is enabled. |
294 | 294 | */ |
295 | - public function sandbox_notice( $description, $gateway ) { |
|
296 | - if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) { |
|
295 | + public function sandbox_notice($description, $gateway) { |
|
296 | + if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) { |
|
297 | 297 | $description .= '<br>' . sprintf( |
298 | - __( 'SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
298 | + __('SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
299 | 299 | '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">', |
300 | 300 | '</a>' |
301 | 301 | ); |
@@ -309,43 +309,43 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param array $admin_settings |
311 | 311 | */ |
312 | - public function admin_settings( $admin_settings ) { |
|
312 | + public function admin_settings($admin_settings) { |
|
313 | 313 | |
314 | 314 | $currencies = sprintf( |
315 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
316 | - implode( ', ', $this->currencies ) |
|
315 | + __('Supported Currencies: %s', 'invoicing'), |
|
316 | + implode(', ', $this->currencies) |
|
317 | 317 | ); |
318 | 318 | |
319 | 319 | $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)"; |
320 | - $admin_settings['worldpay_desc']['std'] = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' ); |
|
320 | + $admin_settings['worldpay_desc']['std'] = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing'); |
|
321 | 321 | |
322 | 322 | $admin_settings['worldpay_instId'] = array( |
323 | 323 | 'type' => 'text', |
324 | 324 | 'id' => 'worldpay_instId', |
325 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
326 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
325 | + 'name' => __('Installation Id', 'invoicing'), |
|
326 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
327 | 327 | ); |
328 | 328 | |
329 | 329 | $admin_settings['worldpay_md5_secret'] = array( |
330 | 330 | 'type' => 'text', |
331 | 331 | 'id' => 'worldpay_md5_secret', |
332 | - 'name' => __( 'MD5 secret', 'invoicing' ), |
|
333 | - 'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>', |
|
332 | + 'name' => __('MD5 secret', 'invoicing'), |
|
333 | + 'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>', |
|
334 | 334 | ); |
335 | 335 | |
336 | 336 | $admin_settings['worldpay_callbackPW'] = array( |
337 | 337 | 'type' => 'text', |
338 | 338 | 'id' => 'worldpay_callbackPW', |
339 | - 'name' => __( 'Payment Response password', 'invoicing' ), |
|
340 | - 'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ), |
|
339 | + 'name' => __('Payment Response password', 'invoicing'), |
|
340 | + 'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'), |
|
341 | 341 | ); |
342 | 342 | |
343 | 343 | $admin_settings['worldpay_ipn_url'] = array( |
344 | 344 | 'type' => 'ipn_url', |
345 | 345 | 'id' => 'worldpay_ipn_url', |
346 | - 'name' => __( 'Payment Response URL', 'invoicing' ), |
|
346 | + 'name' => __('Payment Response URL', 'invoicing'), |
|
347 | 347 | 'std' => $this->notify_url, |
348 | - 'desc' => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ), |
|
348 | + 'desc' => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'), |
|
349 | 349 | 'custom' => 'worldpay', |
350 | 350 | 'readonly' => true |
351 | 351 | ); |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Returns the API authentication params. |
|
93 | - * |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_auth_params() { |
|
92 | + * Returns the API authentication params. |
|
93 | + * |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_auth_params() { |
|
98 | 98 | |
99 | 99 | return array( |
100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Cancels a subscription remotely |
|
108 | - * |
|
109 | - * |
|
110 | - * @param WPInv_Subscription $subscription Subscription. |
|
107 | + * Cancels a subscription remotely |
|
108 | + * |
|
109 | + * |
|
110 | + * @param WPInv_Subscription $subscription Subscription. |
|
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | - */ |
|
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
112 | + */ |
|
113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Processes ipns. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function verify_ipn() { |
|
129 | + * Processes ipns. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function verify_ipn() { |
|
134 | 134 | |
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Validates IPN invoices. |
|
179 | - * |
|
178 | + * Validates IPN invoices. |
|
179 | + * |
|
180 | 180 | * @param WPInv_Invoice $invoice |
181 | 181 | * @param object $payload |
182 | - * @return void |
|
183 | - */ |
|
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Process subscriptio IPNS. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function maybe_process_old_ipn() { |
|
191 | + * Process subscriptio IPNS. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function maybe_process_old_ipn() { |
|
196 | 196 | |
197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | - * Validates the old IPN signature. |
|
237 | + * Validates the old IPN signature. |
|
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | - */ |
|
241 | - public function validate_old_ipn_signature( $posted ) { |
|
240 | + */ |
|
241 | + public function validate_old_ipn_signature( $posted ) { |
|
242 | 242 | |
243 | 243 | $signature = $this->get_option( 'signature_key' ); |
244 | 244 | if ( ! empty( $signature ) ) { |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Authorize.NET IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Authorize.NET IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
265 | 265 |
@@ -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 Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function get_api_url( $invoice ) { |
|
32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
31 | + public function get_api_url($invoice) { |
|
32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | 41 | * @return stdClass|WP_Error |
42 | 42 | */ |
43 | - public function post( $post, $invoice ){ |
|
43 | + public function post($post, $invoice) { |
|
44 | 44 | |
45 | - $url = $this->get_api_url( $invoice ); |
|
45 | + $url = $this->get_api_url($invoice); |
|
46 | 46 | $response = wp_remote_post( |
47 | 47 | $url, |
48 | 48 | array( |
49 | 49 | 'headers' => array( |
50 | 50 | 'Content-Type' => 'application/json; charset=utf-8' |
51 | 51 | ), |
52 | - 'body' => json_encode( $post ), |
|
52 | + 'body' => json_encode($post), |
|
53 | 53 | 'method' => 'POST' |
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - if ( is_wp_error( $response ) ) { |
|
57 | + if (is_wp_error($response)) { |
|
58 | 58 | return $response; |
59 | 59 | } |
60 | 60 | |
61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
62 | 62 | $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
63 | - $response = json_decode( $response ); |
|
63 | + $response = json_decode($response); |
|
64 | 64 | |
65 | - if ( empty( $response ) ) { |
|
66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
65 | + if (empty($response)) { |
|
66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
69 | + if ($response->messages->resultCode == 'Error') { |
|
70 | 70 | |
71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
72 | - wpinv_error_log( $response ); |
|
71 | + if ($this->is_sandbox($invoice)) { |
|
72 | + wpinv_error_log($response); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
77 | 77 | } |
78 | 78 | |
79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
80 | 80 | $error = $response->transactionResponse->errors[0]; |
81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
82 | 82 | } |
83 | 83 | |
84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | public function get_auth_params() { |
98 | 98 | |
99 | 99 | return array( |
100 | - 'name' => $this->get_option( 'login_id' ), |
|
101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
100 | + 'name' => $this->get_option('login_id'), |
|
101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | 112 | */ |
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
113 | + public function cancel_subscription($subscription, $invoice) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
144 | - if ( empty( $posted ) ) { |
|
145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
143 | + $posted = json_decode(file_get_contents('php://input')); |
|
144 | + if (empty($posted)) { |
|
145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Process the IPN. |
149 | - $posted = (object) wp_unslash( $posted ); |
|
149 | + $posted = (object) wp_unslash($posted); |
|
150 | 150 | |
151 | 151 | // Process refunds. |
152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
155 | 155 | $invoice->refund(); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Held funds approved. |
159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Held funds declined. |
166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
170 | 170 | $invoice->save(); |
171 | 171 | } |
172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param object $payload |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function maybe_process_old_ipn() { |
196 | 196 | |
197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
198 | 198 | |
199 | 199 | // Only process subscriptions subscriptions. |
200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
200 | + if (empty($data['x_subscription_id'])) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check validity. |
205 | - $this->validate_old_ipn_signature( $data ); |
|
205 | + $this->validate_old_ipn_signature($data); |
|
206 | 206 | |
207 | 207 | // Fetch the associated subscription. |
208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
210 | 210 | |
211 | 211 | // Abort if it is missing or completed. |
212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Payment status. |
217 | - if ( 1 == $data['x_response_code'] ) { |
|
217 | + if (1 == $data['x_response_code']) { |
|
218 | 218 | |
219 | 219 | // Renew the subscription. |
220 | 220 | $subscription->add_payment( |
221 | 221 | array( |
222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
223 | 223 | 'gateway' => $this->id |
224 | 224 | ) |
225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | 240 | */ |
241 | - public function validate_old_ipn_signature( $posted ) { |
|
241 | + public function validate_old_ipn_signature($posted) { |
|
242 | 242 | |
243 | - $signature = $this->get_option( 'signature_key' ); |
|
244 | - if ( ! empty( $signature ) ) { |
|
245 | - $login_id = $this->get_option( 'login_id' ); |
|
246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
248 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
243 | + $signature = $this->get_option('signature_key'); |
|
244 | + if (!empty($signature)) { |
|
245 | + $login_id = $this->get_option('login_id'); |
|
246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
249 | 249 | |
250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
252 | 252 | exit; |
253 | 253 | } |
254 | 254 | |
@@ -261,28 +261,28 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
264 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
265 | 265 | |
266 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
266 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | |
270 | - $signature = $this->get_option( 'signature_key' ); |
|
270 | + $signature = $this->get_option('signature_key'); |
|
271 | 271 | |
272 | - if ( empty( $signature ) ) { |
|
273 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
272 | + if (empty($signature)) { |
|
273 | + wpinv_error_log('Error: You have not set a signature key'); |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | |
277 | - $hash = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
277 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
278 | 278 | |
279 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
280 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
279 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
280 | + wpinv_error_log('Successfully validated the IPN'); |
|
281 | 281 | return true; |
282 | 282 | } |
283 | 283 | |
284 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
285 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
284 | + wpinv_error_log('IPN hash is not valid'); |
|
285 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
286 | 286 | return false; |
287 | 287 | |
288 | 288 | } |
@@ -12,474 +12,474 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | 216 | |
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | 223 | |
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
231 | 231 | |
232 | - // Process a refund. |
|
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + // Process a refund. |
|
233 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | - } |
|
237 | + if ( ! $invoice->is_refunded() ) { |
|
238 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | + } |
|
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | - } |
|
241 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | + } |
|
243 | 243 | |
244 | - // Process payments. |
|
245 | - if ( $payment_status == 'completed' ) { |
|
244 | + // Process payments. |
|
245 | + if ( $payment_status == 'completed' ) { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | - } |
|
247 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | + } |
|
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
252 | 252 | |
253 | - $note = ''; |
|
253 | + $note = ''; |
|
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | - } |
|
255 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | + } |
|
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | - } |
|
259 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | + } |
|
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - // Pending payments. |
|
269 | - if ( $payment_status == 'pending' ) { |
|
268 | + // Pending payments. |
|
269 | + if ( $payment_status == 'pending' ) { |
|
270 | 270 | |
271 | - /* translators: %s: pending reason. */ |
|
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + /* translators: %s: pending reason. */ |
|
272 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | - } |
|
274 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | + } |
|
276 | 276 | |
277 | - /* translators: %s: payment status. */ |
|
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + /* translators: %s: payment status. */ |
|
278 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Handles one time payments. |
|
284 | - * |
|
285 | - * @param WPInv_Invoice $invoice Invoice object. |
|
286 | - * @param array $posted Posted data. |
|
287 | - */ |
|
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | - } |
|
282 | + /** |
|
283 | + * Handles one time payments. |
|
284 | + * |
|
285 | + * @param WPInv_Invoice $invoice Invoice object. |
|
286 | + * @param array $posted Posted data. |
|
287 | + */ |
|
288 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Handles subscription sign ups. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice Invoice object. |
|
296 | - * @param array $posted Posted data. |
|
297 | - */ |
|
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
292 | + /** |
|
293 | + * Handles subscription sign ups. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice Invoice object. |
|
296 | + * @param array $posted Posted data. |
|
297 | + */ |
|
298 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
301 | 301 | |
302 | - // Make sure the invoice has a subscription. |
|
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + // Make sure the invoice has a subscription. |
|
303 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | - } |
|
305 | + if ( empty( $subscription ) ) { |
|
306 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | + } |
|
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
310 | 310 | |
311 | - // Validate the IPN. |
|
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + // Validate the IPN. |
|
312 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
315 | 315 | |
316 | - // Activate the subscription. |
|
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | - $subscription->activate(); |
|
316 | + // Activate the subscription. |
|
317 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | + $subscription->activate(); |
|
322 | 322 | |
323 | - // Set the transaction id. |
|
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | - } |
|
323 | + // Set the transaction id. |
|
324 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | + } |
|
328 | 328 | |
329 | - // Update the payment status. |
|
330 | - $invoice->mark_paid(); |
|
329 | + // Update the payment status. |
|
330 | + $invoice->mark_paid(); |
|
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
335 | - } |
|
334 | + wpinv_error_log( 'Subscription started.', false ); |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Handles subscription renewals. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice Invoice object. |
|
341 | - * @param array $posted Posted data. |
|
342 | - */ |
|
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
337 | + /** |
|
338 | + * Handles subscription renewals. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice Invoice object. |
|
341 | + * @param array $posted Posted data. |
|
342 | + */ |
|
343 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
344 | 344 | |
345 | - // Make sure the invoice has a subscription. |
|
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + // Make sure the invoice has a subscription. |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | - } |
|
348 | + if ( empty( $subscription ) ) { |
|
349 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | + } |
|
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
353 | 353 | |
354 | - // PayPal sends a subscr_payment for the first payment too. |
|
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + // PayPal sends a subscr_payment for the first payment too. |
|
355 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach( $dates as $date ) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | - continue; |
|
366 | - } |
|
364 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | + continue; |
|
366 | + } |
|
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | - } |
|
368 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | + } |
|
372 | 372 | |
373 | - return $invoice->mark_paid(); |
|
374 | - |
|
375 | - } |
|
373 | + return $invoice->mark_paid(); |
|
374 | + |
|
375 | + } |
|
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | - |
|
379 | - // Abort if the payment is already recorded. |
|
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | - } |
|
383 | - |
|
384 | - $args = array( |
|
385 | - 'transaction_id' => $posted['txn_id'], |
|
386 | - 'gateway' => $this->id, |
|
387 | - ); |
|
388 | - |
|
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
377 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | + |
|
379 | + // Abort if the payment is already recorded. |
|
380 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | + } |
|
383 | + |
|
384 | + $args = array( |
|
385 | + 'transaction_id' => $posted['txn_id'], |
|
386 | + 'gateway' => $this->id, |
|
387 | + ); |
|
388 | + |
|
389 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
392 | - return; |
|
393 | - } |
|
391 | + if ( empty( $invoice ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
397 | 397 | |
398 | - $subscription->renew(); |
|
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + $subscription->renew(); |
|
399 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
400 | 400 | |
401 | - } |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * Handles subscription cancelations. |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice Invoice object. |
|
407 | - */ |
|
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
403 | + /** |
|
404 | + * Handles subscription cancelations. |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice Invoice object. |
|
407 | + */ |
|
408 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
409 | 409 | |
410 | - // Make sure the invoice has a subscription. |
|
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | - |
|
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | - } |
|
416 | - |
|
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | - $subscription->cancel(); |
|
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
410 | + // Make sure the invoice has a subscription. |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | + |
|
413 | + if ( empty( $subscription ) ) { |
|
414 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | + } |
|
416 | + |
|
417 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | + $subscription->cancel(); |
|
419 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * Handles subscription completions. |
|
425 | - * |
|
426 | - * @param WPInv_Invoice $invoice Invoice object. |
|
427 | - * @param array $posted Posted data. |
|
428 | - */ |
|
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
423 | + /** |
|
424 | + * Handles subscription completions. |
|
425 | + * |
|
426 | + * @param WPInv_Invoice $invoice Invoice object. |
|
427 | + * @param array $posted Posted data. |
|
428 | + */ |
|
429 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
430 | 430 | |
431 | - // Make sure the invoice has a subscription. |
|
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + // Make sure the invoice has a subscription. |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | - } |
|
434 | + if ( empty( $subscription ) ) { |
|
435 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | + } |
|
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | - $subscription->complete(); |
|
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
438 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | + $subscription->complete(); |
|
440 | + wpinv_error_log( 'Subscription completed.', false ); |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * Handles subscription fails. |
|
446 | - * |
|
447 | - * @param WPInv_Invoice $invoice Invoice object. |
|
448 | - * @param array $posted Posted data. |
|
449 | - */ |
|
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
444 | + /** |
|
445 | + * Handles subscription fails. |
|
446 | + * |
|
447 | + * @param WPInv_Invoice $invoice Invoice object. |
|
448 | + * @param array $posted Posted data. |
|
449 | + */ |
|
450 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
451 | 451 | |
452 | - // Make sure the invoice has a subscription. |
|
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + // Make sure the invoice has a subscription. |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | - } |
|
455 | + if ( empty( $subscription ) ) { |
|
456 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | + } |
|
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | - $subscription->failing(); |
|
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
459 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | + $subscription->failing(); |
|
461 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
462 | 462 | |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | - /** |
|
466 | - * Handles subscription suspensions. |
|
467 | - * |
|
468 | - * @param WPInv_Invoice $invoice Invoice object. |
|
469 | - * @param array $posted Posted data. |
|
470 | - */ |
|
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
465 | + /** |
|
466 | + * Handles subscription suspensions. |
|
467 | + * |
|
468 | + * @param WPInv_Invoice $invoice Invoice object. |
|
469 | + * @param array $posted Posted data. |
|
470 | + */ |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
472 | 472 | |
473 | - // Make sure the invoice has a subscription. |
|
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + // Make sure the invoice has a subscription. |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | - } |
|
479 | - |
|
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | - $subscription->cancel(); |
|
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | - } |
|
476 | + if ( empty( $subscription ) ) { |
|
477 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | + } |
|
479 | + |
|
480 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | + $subscription->cancel(); |
|
482 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | + } |
|
484 | 484 | |
485 | 485 | } |
@@ -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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + wpinv_error_log('Validated PayPal Email', false); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,70 +212,70 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
231 | 231 | |
232 | 232 | // Process a refund. |
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + if (!$invoice->is_refunded()) { |
|
238 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
239 | 239 | } |
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + return wpinv_error_log($posted['reason_code'], false); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Process payments. |
245 | - if ( $payment_status == 'completed' ) { |
|
245 | + if ($payment_status == 'completed') { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
247 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
248 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
249 | 249 | } |
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
252 | 252 | |
253 | 253 | $note = ''; |
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + if (!empty($posted['mc_fee'])) { |
|
256 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + if (!empty($posted['payer_status'])) { |
|
260 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
261 | 261 | } |
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
264 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Pending payments. |
269 | - if ( $payment_status == 'pending' ) { |
|
269 | + if ($payment_status == 'pending') { |
|
270 | 270 | |
271 | 271 | /* translators: %s: pending reason. */ |
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /* translators: %s: payment status. */ |
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
279 | 279 | |
280 | 280 | } |
281 | 281 | |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param WPInv_Invoice $invoice Invoice object. |
286 | 286 | * @param array $posted Posted data. |
287 | 287 | */ |
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + protected function ipn_txn_cart($invoice, $posted) { |
|
289 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,43 +295,43 @@ discard block |
||
295 | 295 | * @param WPInv_Invoice $invoice Invoice object. |
296 | 296 | * @param array $posted Posted data. |
297 | 297 | */ |
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log('Processing subscription signup', false); |
|
301 | 301 | |
302 | 302 | // Make sure the invoice has a subscription. |
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
305 | + if (empty($subscription)) { |
|
306 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
307 | 307 | } |
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
310 | 310 | |
311 | 311 | // Validate the IPN. |
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
312 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
313 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
314 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
315 | 315 | |
316 | 316 | // Activate the subscription. |
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
318 | + $subscription->set_date_created(current_time('mysql')); |
|
319 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
320 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
321 | 321 | $subscription->activate(); |
322 | 322 | |
323 | 323 | // Set the transaction id. |
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
324 | + if (!empty($posted['txn_id'])) { |
|
325 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
326 | + $invoice->set_transaction_id($posted['txn_id']); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Update the payment status. |
330 | 330 | $invoice->mark_paid(); |
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | + wpinv_error_log('Subscription started.', false); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -340,45 +340,45 @@ discard block |
||
340 | 340 | * @param WPInv_Invoice $invoice Invoice object. |
341 | 341 | * @param array $posted Posted data. |
342 | 342 | */ |
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
344 | 344 | |
345 | 345 | // Make sure the invoice has a subscription. |
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
348 | + if (empty($subscription)) { |
|
349 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
350 | 350 | } |
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
353 | 353 | |
354 | 354 | // PayPal sends a subscr_payment for the first payment too. |
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
355 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
356 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
357 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
358 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
359 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
360 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach ($dates as $date) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + if ($date !== $today_date && $date !== $payment_date) { |
|
365 | 365 | continue; |
366 | 366 | } |
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
368 | + if (!empty($posted['txn_id'])) { |
|
369 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
370 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | return $invoice->mark_paid(); |
374 | 374 | |
375 | 375 | } |
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
378 | 378 | |
379 | 379 | // Abort if the payment is already recorded. |
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
380 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
381 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $args = array( |
@@ -386,17 +386,17 @@ discard block |
||
386 | 386 | 'gateway' => $this->id, |
387 | 387 | ); |
388 | 388 | |
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
391 | + if (empty($invoice)) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
396 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
397 | 397 | |
398 | 398 | $subscription->renew(); |
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | + wpinv_error_log('Subscription renewed.', false); |
|
400 | 400 | |
401 | 401 | } |
402 | 402 | |
@@ -405,18 +405,18 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @param WPInv_Invoice $invoice Invoice object. |
407 | 407 | */ |
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
409 | 409 | |
410 | 410 | // Make sure the invoice has a subscription. |
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
412 | 412 | |
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | + if (empty($subscription)) { |
|
414 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | 415 | } |
416 | 416 | |
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
418 | 418 | $subscription->cancel(); |
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | + wpinv_error_log('Subscription cancelled.', false); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | |
@@ -426,18 +426,18 @@ discard block |
||
426 | 426 | * @param WPInv_Invoice $invoice Invoice object. |
427 | 427 | * @param array $posted Posted data. |
428 | 428 | */ |
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | + protected function ipn_txn_subscr_eot($invoice) { |
|
430 | 430 | |
431 | 431 | // Make sure the invoice has a subscription. |
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
434 | + if (empty($subscription)) { |
|
435 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
436 | 436 | } |
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
439 | 439 | $subscription->complete(); |
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
440 | + wpinv_error_log('Subscription completed.', false); |
|
441 | 441 | |
442 | 442 | } |
443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
447 | 447 | * @param WPInv_Invoice $invoice Invoice object. |
448 | 448 | * @param array $posted Posted data. |
449 | 449 | */ |
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | + protected function ipn_txn_subscr_failed($invoice) { |
|
451 | 451 | |
452 | 452 | // Make sure the invoice has a subscription. |
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
455 | + if (empty($subscription)) { |
|
456 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
457 | 457 | } |
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
460 | 460 | $subscription->failing(); |
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | + wpinv_error_log('Subscription marked as failing.', false); |
|
462 | 462 | |
463 | 463 | } |
464 | 464 | |
@@ -468,18 +468,18 @@ discard block |
||
468 | 468 | * @param WPInv_Invoice $invoice Invoice object. |
469 | 469 | * @param array $posted Posted data. |
470 | 470 | */ |
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
472 | 472 | |
473 | 473 | // Make sure the invoice has a subscription. |
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
476 | + if (empty($subscription)) { |
|
477 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
478 | 478 | } |
479 | 479 | |
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
481 | 481 | $subscription->cancel(); |
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + wpinv_error_log('Subscription cancelled.', false); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | } |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -260,18 +260,18 @@ discard block |
||
260 | 260 | check_ajax_referer( 'getpaid_form_nonce' ); |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | - echo aui()->alert( |
|
265 | - array( |
|
266 | - 'type' => 'warning', |
|
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | - ) |
|
263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | + echo aui()->alert( |
|
265 | + array( |
|
266 | + 'type' => 'warning', |
|
267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + ) |
|
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | + if ( ! empty( $_GET['form'] ) ) { |
|
275 | 275 | $form = urldecode( $_GET['form'] ); |
276 | 276 | |
277 | 277 | if ( false !== strpos( $form, '|' ) ) { |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | getpaid_display_payment_form( $form ); |
326 | 326 | } |
327 | 327 | |
328 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
328 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | + getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | + getpaid_display_item_payment_form( $items ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | if ( is_wp_error( $error ) ) { |
651 | 651 | $alert = $error->get_error_message(); |
652 | 652 | wp_send_json_success( compact( 'alert' ) ); |
653 | - } |
|
653 | + } |
|
654 | 654 | |
655 | 655 | // Update totals. |
656 | 656 | $invoice->recalculate_total(); |
@@ -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 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -105,36 +105,36 @@ discard block |
||
105 | 105 | 'payment_form_refresh_prices' => true, |
106 | 106 | ); |
107 | 107 | |
108 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
109 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
109 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | 111 | |
112 | - if ( $nopriv ) { |
|
113 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
114 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | + if ($nopriv) { |
|
113 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function add_note() { |
121 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
122 | 122 | |
123 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
123 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
124 | 124 | die(-1); |
125 | 125 | } |
126 | 126 | |
127 | - $post_id = absint( $_POST['post_id'] ); |
|
128 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
129 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
127 | + $post_id = absint($_POST['post_id']); |
|
128 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
129 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
130 | 130 | |
131 | 131 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
132 | 132 | |
133 | - if ( $post_id > 0 ) { |
|
134 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
133 | + if ($post_id > 0) { |
|
134 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
135 | 135 | |
136 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
137 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
136 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
137 | + wpinv_get_invoice_note_line_item($note_id); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public static function delete_note() { |
145 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
145 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
146 | 146 | |
147 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
147 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
148 | 148 | die(-1); |
149 | 149 | } |
150 | 150 | |
151 | - $note_id = (int)$_POST['note_id']; |
|
151 | + $note_id = (int) $_POST['note_id']; |
|
152 | 152 | |
153 | - if ( $note_id > 0 ) { |
|
154 | - wp_delete_comment( $note_id, true ); |
|
153 | + if ($note_id > 0) { |
|
154 | + wp_delete_comment($note_id, true); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | die(); |
@@ -169,34 +169,34 @@ discard block |
||
169 | 169 | public static function get_billing_details() { |
170 | 170 | |
171 | 171 | // Verify nonce. |
172 | - check_ajax_referer( 'wpinv-nonce' ); |
|
172 | + check_ajax_referer('wpinv-nonce'); |
|
173 | 173 | |
174 | 174 | // Can the user manage the plugin? |
175 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
175 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
176 | 176 | die(-1); |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Do we have a user id? |
180 | 180 | $user_id = $_GET['user_id']; |
181 | 181 | |
182 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
182 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
183 | 183 | die(-1); |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Fetch the billing details. |
187 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
188 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
187 | + $billing_details = wpinv_get_user_address($user_id); |
|
188 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
189 | 189 | |
190 | 190 | // unset the user id and email. |
191 | - $to_ignore = array( 'user_id', 'email' ); |
|
191 | + $to_ignore = array('user_id', 'email'); |
|
192 | 192 | |
193 | - foreach ( $to_ignore as $key ) { |
|
194 | - if ( isset( $billing_details[ $key ] ) ) { |
|
195 | - unset( $billing_details[ $key ] ); |
|
193 | + foreach ($to_ignore as $key) { |
|
194 | + if (isset($billing_details[$key])) { |
|
195 | + unset($billing_details[$key]); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - wp_send_json_success( $billing_details ); |
|
199 | + wp_send_json_success($billing_details); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | |
@@ -206,47 +206,47 @@ discard block |
||
206 | 206 | public static function check_new_user_email() { |
207 | 207 | |
208 | 208 | // Verify nonce. |
209 | - check_ajax_referer( 'wpinv-nonce' ); |
|
209 | + check_ajax_referer('wpinv-nonce'); |
|
210 | 210 | |
211 | 211 | // Can the user manage the plugin? |
212 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
212 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
213 | 213 | die(-1); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // We need an email address. |
217 | - if ( empty( $_GET['email'] ) ) { |
|
218 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
217 | + if (empty($_GET['email'])) { |
|
218 | + _e("Provide the new user's email address", 'invoicing'); |
|
219 | 219 | exit; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Ensure the email is valid. |
223 | - $email = sanitize_text_field( $_GET['email'] ); |
|
224 | - if ( ! is_email( $email ) ) { |
|
225 | - _e( 'Invalid email address', 'invoicing' ); |
|
223 | + $email = sanitize_text_field($_GET['email']); |
|
224 | + if (!is_email($email)) { |
|
225 | + _e('Invalid email address', 'invoicing'); |
|
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // And it does not exist. |
230 | - $id = email_exists( $email ); |
|
231 | - if ( $id ) { |
|
232 | - wp_send_json_success( compact( 'id' ) ); |
|
230 | + $id = email_exists($email); |
|
231 | + if ($id) { |
|
232 | + wp_send_json_success(compact('id')); |
|
233 | 233 | } |
234 | 234 | |
235 | - wp_send_json_success( true ); |
|
235 | + wp_send_json_success(true); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | public static function run_tool() { |
239 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
240 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
239 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
240 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
241 | 241 | die(-1); |
242 | 242 | } |
243 | 243 | |
244 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
244 | + $tool = sanitize_text_field($_POST['tool']); |
|
245 | 245 | |
246 | - do_action( 'wpinv_run_tool' ); |
|
246 | + do_action('wpinv_run_tool'); |
|
247 | 247 | |
248 | - if ( !empty( $tool ) ) { |
|
249 | - do_action( 'wpinv_tool_' . $tool ); |
|
248 | + if (!empty($tool)) { |
|
249 | + do_action('wpinv_tool_' . $tool); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -257,43 +257,43 @@ discard block |
||
257 | 257 | global $getpaid_force_checkbox; |
258 | 258 | |
259 | 259 | // Check nonce. |
260 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
260 | + check_ajax_referer('getpaid_form_nonce'); |
|
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
263 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
264 | 264 | echo aui()->alert( |
265 | 265 | array( |
266 | 266 | 'type' => 'warning', |
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | - $form = urldecode( $_GET['form'] ); |
|
274 | + if (!empty($_GET['form'])) { |
|
275 | + $form = urldecode($_GET['form']); |
|
276 | 276 | |
277 | - if ( false !== strpos( $form, '|' ) ) { |
|
278 | - $form_pos = strpos( $form, '|' ); |
|
279 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
280 | - $form = substr( $form, 0, $form_pos ); |
|
277 | + if (false !== strpos($form, '|')) { |
|
278 | + $form_pos = strpos($form, '|'); |
|
279 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
280 | + $form = substr($form, 0, $form_pos); |
|
281 | 281 | |
282 | 282 | // Retrieve appropriate payment form. |
283 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
284 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
283 | + $payment_form = new GetPaid_Payment_Form($form); |
|
284 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
285 | 285 | |
286 | 286 | $items = array(); |
287 | 287 | $item_ids = array(); |
288 | 288 | |
289 | - foreach ( $_items as $item_id => $qty ) { |
|
290 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
291 | - $item = new GetPaid_Form_Item( $item_id ); |
|
292 | - $item->set_quantity( $qty ); |
|
289 | + foreach ($_items as $item_id => $qty) { |
|
290 | + if (!in_array($item_id, $item_ids)) { |
|
291 | + $item = new GetPaid_Form_Item($item_id); |
|
292 | + $item->set_quantity($qty); |
|
293 | 293 | |
294 | - if ( 0 == $qty ) { |
|
295 | - $item->set_allow_quantities( true ); |
|
296 | - $item->set_is_required( false ); |
|
294 | + if (0 == $qty) { |
|
295 | + $item->set_allow_quantities(true); |
|
296 | + $item->set_is_required(false); |
|
297 | 297 | $getpaid_force_checkbox = true; |
298 | 298 | } |
299 | 299 | |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - if ( ! $payment_form->is_default() ) { |
|
305 | + if (!$payment_form->is_default()) { |
|
306 | 306 | |
307 | - foreach ( $payment_form->get_items() as $item ) { |
|
308 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
307 | + foreach ($payment_form->get_items() as $item) { |
|
308 | + if (!in_array($item->get_id(), $item_ids)) { |
|
309 | 309 | $item_ids[] = $item->get_id(); |
310 | 310 | $items[] = $item; |
311 | 311 | } |
@@ -313,23 +313,23 @@ discard block |
||
313 | 313 | |
314 | 314 | } |
315 | 315 | |
316 | - $payment_form->set_items( $items ); |
|
317 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
318 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
316 | + $payment_form->set_items($items); |
|
317 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
318 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
319 | 319 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
320 | 320 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
321 | - $payment_form->display( $extra_items ); |
|
321 | + $payment_form->display($extra_items); |
|
322 | 322 | $getpaid_force_checkbox = false; |
323 | 323 | |
324 | 324 | } else { |
325 | - getpaid_display_payment_form( $form ); |
|
325 | + getpaid_display_payment_form($form); |
|
326 | 326 | } |
327 | 327 | |
328 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
329 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
328 | + } else if (!empty($_GET['invoice'])) { |
|
329 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
330 | 330 | } else { |
331 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
332 | - getpaid_display_item_payment_form( $items ); |
|
331 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
332 | + getpaid_display_item_payment_form($items); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | exit; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | public static function payment_form() { |
345 | 345 | |
346 | 346 | // Check nonce. |
347 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
347 | + check_ajax_referer('getpaid_form_nonce'); |
|
348 | 348 | |
349 | 349 | // ... form fields... |
350 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
351 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
350 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
351 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
352 | 352 | exit; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Process the payment form. |
356 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
357 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
356 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
357 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
358 | 358 | $checkout->process_checkout(); |
359 | 359 | |
360 | 360 | exit; |
@@ -367,55 +367,55 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public static function get_payment_form_states_field() { |
369 | 369 | |
370 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
370 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
371 | 371 | exit; |
372 | 372 | } |
373 | 373 | |
374 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
374 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
375 | 375 | |
376 | - if ( empty( $elements ) ) { |
|
376 | + if (empty($elements)) { |
|
377 | 377 | exit; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $address_fields = array(); |
381 | - foreach ( $elements as $element ) { |
|
382 | - if ( 'address' === $element['type'] ) { |
|
381 | + foreach ($elements as $element) { |
|
382 | + if ('address' === $element['type']) { |
|
383 | 383 | $address_fields = $element; |
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | 387 | |
388 | - if ( empty( $address_fields ) ) { |
|
388 | + if (empty($address_fields)) { |
|
389 | 389 | exit; |
390 | 390 | } |
391 | 391 | |
392 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
392 | + foreach ($address_fields['fields'] as $address_field) { |
|
393 | 393 | |
394 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
394 | + if ('wpinv_state' == $address_field['name']) { |
|
395 | 395 | |
396 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
397 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
398 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
399 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
400 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
401 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
396 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
397 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
398 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
399 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
400 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
401 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
402 | 402 | |
403 | - if ( ! empty( $address_field['required'] ) ) { |
|
403 | + if (!empty($address_field['required'])) { |
|
404 | 404 | $label .= "<span class='text-danger'> *</span>"; |
405 | 405 | } |
406 | 406 | |
407 | - $html = getpaid_get_states_select_markup ( |
|
408 | - sanitize_text_field( $_GET['country'] ), |
|
407 | + $html = getpaid_get_states_select_markup( |
|
408 | + sanitize_text_field($_GET['country']), |
|
409 | 409 | $value, |
410 | 410 | $placeholder, |
411 | 411 | $label, |
412 | 412 | $description, |
413 | - ! empty( $address_field['required'] ), |
|
413 | + !empty($address_field['required']), |
|
414 | 414 | $wrap_class, |
415 | - wpinv_clean( $_GET['name'] ) |
|
415 | + wpinv_clean($_GET['name']) |
|
416 | 416 | ); |
417 | 417 | |
418 | - wp_send_json_success( $html ); |
|
418 | + wp_send_json_success($html); |
|
419 | 419 | exit; |
420 | 420 | |
421 | 421 | } |
@@ -431,66 +431,66 @@ discard block |
||
431 | 431 | public static function recalculate_invoice_totals() { |
432 | 432 | |
433 | 433 | // Verify nonce. |
434 | - check_ajax_referer( 'wpinv-nonce' ); |
|
434 | + check_ajax_referer('wpinv-nonce'); |
|
435 | 435 | |
436 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
436 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
437 | 437 | exit; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // We need an invoice. |
441 | - if ( empty( $_POST['post_id'] ) ) { |
|
441 | + if (empty($_POST['post_id'])) { |
|
442 | 442 | exit; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Fetch the invoice. |
446 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
446 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
447 | 447 | |
448 | 448 | // Ensure it exists. |
449 | - if ( ! $invoice->get_id() ) { |
|
449 | + if (!$invoice->get_id()) { |
|
450 | 450 | exit; |
451 | 451 | } |
452 | 452 | |
453 | 453 | // Maybe set the country, state, currency. |
454 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
455 | - if ( isset( $_POST[ $key ] ) ) { |
|
454 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
455 | + if (isset($_POST[$key])) { |
|
456 | 456 | $method = "set_$key"; |
457 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
457 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Maybe disable taxes. |
462 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
462 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
463 | 463 | |
464 | 464 | // Discount code. |
465 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
466 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
467 | - if ( $discount->exists() ) { |
|
468 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
465 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
466 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
467 | + if ($discount->exists()) { |
|
468 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
469 | 469 | } else { |
470 | - $invoice->remove_discount( 'discount_code' ); |
|
470 | + $invoice->remove_discount('discount_code'); |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Recalculate totals. |
475 | 475 | $invoice->recalculate_total(); |
476 | 476 | |
477 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
478 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
479 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
480 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
481 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
477 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
478 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
479 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
480 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
481 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $totals = array( |
485 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
486 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
487 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
485 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
486 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
487 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
488 | 488 | 'total' => $total, |
489 | 489 | ); |
490 | 490 | |
491 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
491 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
492 | 492 | |
493 | - wp_send_json_success( compact( 'totals' ) ); |
|
493 | + wp_send_json_success(compact('totals')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -499,33 +499,33 @@ discard block |
||
499 | 499 | public static function get_invoice_items() { |
500 | 500 | |
501 | 501 | // Verify nonce. |
502 | - check_ajax_referer( 'wpinv-nonce' ); |
|
502 | + check_ajax_referer('wpinv-nonce'); |
|
503 | 503 | |
504 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
504 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
505 | 505 | exit; |
506 | 506 | } |
507 | 507 | |
508 | 508 | // We need an invoice and items. |
509 | - if ( empty( $_POST['post_id'] ) ) { |
|
509 | + if (empty($_POST['post_id'])) { |
|
510 | 510 | exit; |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Fetch the invoice. |
514 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
514 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
515 | 515 | |
516 | 516 | // Ensure it exists. |
517 | - if ( ! $invoice->get_id() ) { |
|
517 | + if (!$invoice->get_id()) { |
|
518 | 518 | exit; |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Return an array of invoice items. |
522 | 522 | $items = array(); |
523 | 523 | |
524 | - foreach ( $invoice->get_items() as $item ) { |
|
525 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
524 | + foreach ($invoice->get_items() as $item) { |
|
525 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
526 | 526 | } |
527 | 527 | |
528 | - wp_send_json_success( compact( 'items' ) ); |
|
528 | + wp_send_json_success(compact('items')); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -534,50 +534,50 @@ discard block |
||
534 | 534 | public static function edit_invoice_item() { |
535 | 535 | |
536 | 536 | // Verify nonce. |
537 | - check_ajax_referer( 'wpinv-nonce' ); |
|
537 | + check_ajax_referer('wpinv-nonce'); |
|
538 | 538 | |
539 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
539 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
540 | 540 | exit; |
541 | 541 | } |
542 | 542 | |
543 | 543 | // We need an invoice and item details. |
544 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
544 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
545 | 545 | exit; |
546 | 546 | } |
547 | 547 | |
548 | 548 | // Fetch the invoice. |
549 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
549 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
550 | 550 | |
551 | 551 | // Ensure it exists and its not been paid for. |
552 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
552 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
553 | 553 | exit; |
554 | 554 | } |
555 | 555 | |
556 | 556 | // Format the data. |
557 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
557 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
558 | 558 | |
559 | 559 | // Ensure that we have an item id. |
560 | - if ( empty( $data['id'] ) ) { |
|
560 | + if (empty($data['id'])) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Abort if the invoice does not have the specified item. |
565 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
565 | + $item = $invoice->get_item((int) $data['id']); |
|
566 | 566 | |
567 | - if ( empty( $item ) ) { |
|
567 | + if (empty($item)) { |
|
568 | 568 | exit; |
569 | 569 | } |
570 | 570 | |
571 | 571 | // Update the item. |
572 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
573 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
574 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
575 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
572 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
573 | + $item->set_name(sanitize_text_field($data['name'])); |
|
574 | + $item->set_description(wp_kses_post($data['description'])); |
|
575 | + $item->set_quantity(floatval($data['quantity'])); |
|
576 | 576 | |
577 | 577 | // Add it to the invoice. |
578 | - $error = $invoice->add_item( $item ); |
|
578 | + $error = $invoice->add_item($item); |
|
579 | 579 | $alert = false; |
580 | - if ( is_wp_error( $error ) ) { |
|
580 | + if (is_wp_error($error)) { |
|
581 | 581 | $alert = $error->get_error_message(); |
582 | 582 | } |
583 | 583 | |
@@ -590,11 +590,11 @@ discard block |
||
590 | 590 | // Return an array of invoice items. |
591 | 591 | $items = array(); |
592 | 592 | |
593 | - foreach ( $invoice->get_items() as $item ) { |
|
594 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
593 | + foreach ($invoice->get_items() as $item) { |
|
594 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
595 | 595 | } |
596 | 596 | |
597 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
597 | + wp_send_json_success(compact('items', 'alert')); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -603,53 +603,53 @@ discard block |
||
603 | 603 | public static function create_invoice_item() { |
604 | 604 | |
605 | 605 | // Verify nonce. |
606 | - check_ajax_referer( 'wpinv-nonce' ); |
|
606 | + check_ajax_referer('wpinv-nonce'); |
|
607 | 607 | |
608 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
608 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
609 | 609 | exit; |
610 | 610 | } |
611 | 611 | |
612 | 612 | // We need an invoice and item details. |
613 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
613 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
614 | 614 | exit; |
615 | 615 | } |
616 | 616 | |
617 | 617 | // Fetch the invoice. |
618 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['invoice_id'] ) ); |
|
618 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['invoice_id'])); |
|
619 | 619 | |
620 | 620 | // Ensure it exists and its not been paid for. |
621 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
621 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
622 | 622 | exit; |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Format the data. |
626 | - $data = wp_unslash( $_POST['_wpinv_quick'] ); |
|
626 | + $data = wp_unslash($_POST['_wpinv_quick']); |
|
627 | 627 | |
628 | 628 | $item = new WPInv_Item(); |
629 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
630 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
631 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
632 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
633 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
634 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
635 | - $item->set_status( 'publish' ); |
|
629 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
630 | + $item->set_name(sanitize_text_field($data['name'])); |
|
631 | + $item->set_description(wp_kses_post($data['description'])); |
|
632 | + $item->set_type(sanitize_text_field($data['type'])); |
|
633 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
634 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
635 | + $item->set_status('publish'); |
|
636 | 636 | $item->save(); |
637 | 637 | |
638 | - if ( ! $item->exists() ) { |
|
639 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
640 | - wp_send_json_success( compact( 'alert' ) ); |
|
638 | + if (!$item->exists()) { |
|
639 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
640 | + wp_send_json_success(compact('alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
644 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
643 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
644 | + $item->set_quantity(floatval($data['qty'])); |
|
645 | 645 | |
646 | 646 | // Add it to the invoice. |
647 | - $error = $invoice->add_item( $item ); |
|
647 | + $error = $invoice->add_item($item); |
|
648 | 648 | $alert = false; |
649 | 649 | |
650 | - if ( is_wp_error( $error ) ) { |
|
650 | + if (is_wp_error($error)) { |
|
651 | 651 | $alert = $error->get_error_message(); |
652 | - wp_send_json_success( compact( 'alert' ) ); |
|
652 | + wp_send_json_success(compact('alert')); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | // Update totals. |
@@ -662,9 +662,9 @@ discard block |
||
662 | 662 | $invoice->recalculate_total(); |
663 | 663 | $invoice->save(); |
664 | 664 | ob_start(); |
665 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
665 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
666 | 666 | $row = ob_get_clean(); |
667 | - wp_send_json_success( compact( 'row' ) ); |
|
667 | + wp_send_json_success(compact('row')); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -673,33 +673,33 @@ discard block |
||
673 | 673 | public static function remove_invoice_item() { |
674 | 674 | |
675 | 675 | // Verify nonce. |
676 | - check_ajax_referer( 'wpinv-nonce' ); |
|
676 | + check_ajax_referer('wpinv-nonce'); |
|
677 | 677 | |
678 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
678 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
679 | 679 | exit; |
680 | 680 | } |
681 | 681 | |
682 | 682 | // We need an invoice and an item. |
683 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
683 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
684 | 684 | exit; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Fetch the invoice. |
688 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
688 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
689 | 689 | |
690 | 690 | // Ensure it exists and its not been paid for. |
691 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
691 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
692 | 692 | exit; |
693 | 693 | } |
694 | 694 | |
695 | 695 | // Abort if the invoice does not have the specified item. |
696 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
696 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
697 | 697 | |
698 | - if ( empty( $item ) ) { |
|
698 | + if (empty($item)) { |
|
699 | 699 | exit; |
700 | 700 | } |
701 | 701 | |
702 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
702 | + $invoice->remove_item((int) $_POST['item_id']); |
|
703 | 703 | |
704 | 704 | // Update totals. |
705 | 705 | $invoice->recalculate_total(); |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | // Return an array of invoice items. |
711 | 711 | $items = array(); |
712 | 712 | |
713 | - foreach ( $invoice->get_items() as $item ) { |
|
714 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
713 | + foreach ($invoice->get_items() as $item) { |
|
714 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
715 | 715 | } |
716 | 716 | |
717 | - wp_send_json_success( compact( 'items' ) ); |
|
717 | + wp_send_json_success(compact('items')); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -723,69 +723,69 @@ discard block |
||
723 | 723 | public static function recalculate_full_prices() { |
724 | 724 | |
725 | 725 | // Verify nonce. |
726 | - check_ajax_referer( 'wpinv-nonce' ); |
|
726 | + check_ajax_referer('wpinv-nonce'); |
|
727 | 727 | |
728 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
728 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
729 | 729 | exit; |
730 | 730 | } |
731 | 731 | |
732 | 732 | // We need an invoice and item. |
733 | - if ( empty( $_POST['post_id'] ) ) { |
|
733 | + if (empty($_POST['post_id'])) { |
|
734 | 734 | exit; |
735 | 735 | } |
736 | 736 | |
737 | 737 | // Fetch the invoice. |
738 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
738 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
739 | 739 | $alert = false; |
740 | 740 | |
741 | 741 | // Ensure it exists and its not been paid for. |
742 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
742 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
743 | 743 | exit; |
744 | 744 | } |
745 | 745 | |
746 | - $invoice->set_items( array() ); |
|
746 | + $invoice->set_items(array()); |
|
747 | 747 | |
748 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
748 | + if (!empty($_POST['getpaid_items'])) { |
|
749 | 749 | |
750 | - foreach ( $_POST['getpaid_items'] as $item_id => $args ) { |
|
751 | - $item = new GetPaid_Form_Item( $item_id ); |
|
750 | + foreach ($_POST['getpaid_items'] as $item_id => $args) { |
|
751 | + $item = new GetPaid_Form_Item($item_id); |
|
752 | 752 | |
753 | - if ( $item->exists() ) { |
|
754 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
755 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
756 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
757 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
758 | - $invoice->add_item( $item ); |
|
753 | + if ($item->exists()) { |
|
754 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
755 | + $item->set_quantity(floatval($args['quantity'])); |
|
756 | + $item->set_name(sanitize_text_field($args['name'])); |
|
757 | + $item->set_description(wp_kses_post($args['description'])); |
|
758 | + $invoice->add_item($item); |
|
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | 762 | } |
763 | 763 | |
764 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
764 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
765 | 765 | |
766 | 766 | // Maybe set the country, state, currency. |
767 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
768 | - if ( isset( $_POST[ $key ] ) ) { |
|
769 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
767 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
768 | + if (isset($_POST[$key])) { |
|
769 | + $_key = str_replace('wpinv_', '', $key); |
|
770 | 770 | $method = "set_$_key"; |
771 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
771 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
776 | - if ( $discount->exists() ) { |
|
777 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
775 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
776 | + if ($discount->exists()) { |
|
777 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
778 | 778 | } else { |
779 | - $invoice->remove_discount( 'discount_code' ); |
|
779 | + $invoice->remove_discount('discount_code'); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | // Save the invoice. |
783 | 783 | $invoice->recalculate_total(); |
784 | 784 | $invoice->save(); |
785 | 785 | ob_start(); |
786 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
786 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
787 | 787 | $table = ob_get_clean(); |
788 | - wp_send_json_success( compact( 'table' ) ); |
|
788 | + wp_send_json_success(compact('table')); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | /** |
@@ -794,42 +794,42 @@ discard block |
||
794 | 794 | public static function admin_add_invoice_item() { |
795 | 795 | |
796 | 796 | // Verify nonce. |
797 | - check_ajax_referer( 'wpinv-nonce' ); |
|
797 | + check_ajax_referer('wpinv-nonce'); |
|
798 | 798 | |
799 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
799 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
800 | 800 | exit; |
801 | 801 | } |
802 | 802 | |
803 | 803 | // We need an invoice and item. |
804 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
804 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
805 | 805 | exit; |
806 | 806 | } |
807 | 807 | |
808 | 808 | // Fetch the invoice. |
809 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
809 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
810 | 810 | $alert = false; |
811 | 811 | |
812 | 812 | // Ensure it exists and its not been paid for. |
813 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
813 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
814 | 814 | exit; |
815 | 815 | } |
816 | 816 | |
817 | 817 | // Add the item. |
818 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
819 | - $error = $invoice->add_item( $item ); |
|
818 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
819 | + $error = $invoice->add_item($item); |
|
820 | 820 | |
821 | - if ( is_wp_error( $error ) ) { |
|
821 | + if (is_wp_error($error)) { |
|
822 | 822 | $alert = $error->get_error_message(); |
823 | - wp_send_json_success( compact( 'alert' ) ); |
|
823 | + wp_send_json_success(compact('alert')); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | // Save the invoice. |
827 | 827 | $invoice->recalculate_total(); |
828 | 828 | $invoice->save(); |
829 | 829 | ob_start(); |
830 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
830 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
831 | 831 | $row = ob_get_clean(); |
832 | - wp_send_json_success( compact( 'row' ) ); |
|
832 | + wp_send_json_success(compact('row')); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,39 +838,39 @@ discard block |
||
838 | 838 | public static function add_invoice_items() { |
839 | 839 | |
840 | 840 | // Verify nonce. |
841 | - check_ajax_referer( 'wpinv-nonce' ); |
|
841 | + check_ajax_referer('wpinv-nonce'); |
|
842 | 842 | |
843 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
843 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
844 | 844 | exit; |
845 | 845 | } |
846 | 846 | |
847 | 847 | // We need an invoice and items. |
848 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
848 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
849 | 849 | exit; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Fetch the invoice. |
853 | - $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) ); |
|
853 | + $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id'])); |
|
854 | 854 | $alert = false; |
855 | 855 | |
856 | 856 | // Ensure it exists and its not been paid for. |
857 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
857 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
858 | 858 | exit; |
859 | 859 | } |
860 | 860 | |
861 | 861 | // Add the items. |
862 | - foreach ( $_POST['items'] as $data ) { |
|
862 | + foreach ($_POST['items'] as $data) { |
|
863 | 863 | |
864 | - $item = new GetPaid_Form_Item( (int) $data[ 'id' ] ); |
|
864 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
865 | 865 | |
866 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
867 | - $item->set_quantity( floatval( $data[ 'qty' ] ) ); |
|
866 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
867 | + $item->set_quantity(floatval($data['qty'])); |
|
868 | 868 | } |
869 | 869 | |
870 | - if ( $item->get_id() > 0 ) { |
|
871 | - $error = $invoice->add_item( $item ); |
|
870 | + if ($item->get_id() > 0) { |
|
871 | + $error = $invoice->add_item($item); |
|
872 | 872 | |
873 | - if ( is_wp_error( $error ) ) { |
|
873 | + if (is_wp_error($error)) { |
|
874 | 874 | $alert = $error->get_error_message(); |
875 | 875 | } |
876 | 876 | |
@@ -885,11 +885,11 @@ discard block |
||
885 | 885 | // Return an array of invoice items. |
886 | 886 | $items = array(); |
887 | 887 | |
888 | - foreach ( $invoice->get_items() as $item ) { |
|
889 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
888 | + foreach ($invoice->get_items() as $item) { |
|
889 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
890 | 890 | } |
891 | 891 | |
892 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
892 | + wp_send_json_success(compact('items', 'alert')); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -898,15 +898,15 @@ discard block |
||
898 | 898 | public static function get_invoicing_items() { |
899 | 899 | |
900 | 900 | // Verify nonce. |
901 | - check_ajax_referer( 'wpinv-nonce' ); |
|
901 | + check_ajax_referer('wpinv-nonce'); |
|
902 | 902 | |
903 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
903 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
904 | 904 | exit; |
905 | 905 | } |
906 | 906 | |
907 | 907 | // We need a search term. |
908 | - if ( empty( $_GET['search'] ) ) { |
|
909 | - wp_send_json_success( array() ); |
|
908 | + if (empty($_GET['search'])) { |
|
909 | + wp_send_json_success(array()); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | // Retrieve items. |
@@ -915,8 +915,8 @@ discard block |
||
915 | 915 | 'orderby' => 'title', |
916 | 916 | 'order' => 'ASC', |
917 | 917 | 'posts_per_page' => -1, |
918 | - 'post_status' => array( 'publish' ), |
|
919 | - 's' => trim( $_GET['search'] ), |
|
918 | + 'post_status' => array('publish'), |
|
919 | + 's' => trim($_GET['search']), |
|
920 | 920 | 'meta_query' => array( |
921 | 921 | array( |
922 | 922 | 'key' => '_wpinv_type', |
@@ -926,21 +926,21 @@ discard block |
||
926 | 926 | ) |
927 | 927 | ); |
928 | 928 | |
929 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
929 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
930 | 930 | $data = array(); |
931 | 931 | |
932 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
932 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
933 | 933 | |
934 | - foreach ( $items as $item ) { |
|
935 | - $item = new GetPaid_Form_Item( $item ); |
|
934 | + foreach ($items as $item) { |
|
935 | + $item = new GetPaid_Form_Item($item); |
|
936 | 936 | $data[] = array( |
937 | 937 | 'id' => (int) $item->get_id(), |
938 | - 'text' => strip_tags( $item->get_name() ), |
|
939 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
938 | + 'text' => strip_tags($item->get_name()), |
|
939 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
940 | 940 | ); |
941 | 941 | } |
942 | 942 | |
943 | - wp_send_json_success( $data ); |
|
943 | + wp_send_json_success($data); |
|
944 | 944 | |
945 | 945 | } |
946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
950 | 950 | public static function get_customers() { |
951 | 951 | |
952 | 952 | // Verify nonce. |
953 | - check_ajax_referer( 'wpinv-nonce' ); |
|
953 | + check_ajax_referer('wpinv-nonce'); |
|
954 | 954 | |
955 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
955 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
956 | 956 | exit; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // We need a search term. |
960 | - if ( empty( $_GET['search'] ) ) { |
|
961 | - wp_send_json_success( array() ); |
|
960 | + if (empty($_GET['search'])) { |
|
961 | + wp_send_json_success(array()); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // Retrieve customers. |
965 | 965 | |
966 | 966 | $customer_args = array( |
967 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
967 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
968 | 968 | 'orderby' => 'display_name', |
969 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
970 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
969 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
970 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
971 | 971 | ); |
972 | 972 | |
973 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
973 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
974 | 974 | $data = array(); |
975 | 975 | |
976 | - foreach ( $customers as $customer ) { |
|
976 | + foreach ($customers as $customer) { |
|
977 | 977 | $data[] = array( |
978 | 978 | 'id' => (int) $customer->ID, |
979 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
979 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
980 | 980 | ); |
981 | 981 | } |
982 | 982 | |
983 | - wp_send_json_success( $data ); |
|
983 | + wp_send_json_success($data); |
|
984 | 984 | |
985 | 985 | } |
986 | 986 | |
@@ -990,28 +990,28 @@ discard block |
||
990 | 990 | public static function get_aui_states_field() { |
991 | 991 | |
992 | 992 | // Verify nonce. |
993 | - check_ajax_referer( 'wpinv-nonce' ); |
|
993 | + check_ajax_referer('wpinv-nonce'); |
|
994 | 994 | |
995 | 995 | // We need a country. |
996 | - if ( empty( $_GET['country'] ) ) { |
|
996 | + if (empty($_GET['country'])) { |
|
997 | 997 | exit; |
998 | 998 | } |
999 | 999 | |
1000 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
1001 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1002 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1003 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
1000 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
1001 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1002 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1003 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1004 | 1004 | |
1005 | - if ( empty( $states ) ) { |
|
1005 | + if (empty($states)) { |
|
1006 | 1006 | |
1007 | 1007 | $html = aui()->input( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'text', |
1010 | 1010 | 'id' => 'wpinv_state', |
1011 | 1011 | 'name' => $name, |
1012 | - 'label' => __( 'State', 'invoicing' ), |
|
1012 | + 'label' => __('State', 'invoicing'), |
|
1013 | 1013 | 'label_type' => 'vertical', |
1014 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1014 | + 'placeholder' => __('State', 'invoicing'), |
|
1015 | 1015 | 'class' => $class, |
1016 | 1016 | 'value' => $state, |
1017 | 1017 | ) |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | array( |
1024 | 1024 | 'id' => 'wpinv_state', |
1025 | 1025 | 'name' => $name, |
1026 | - 'label' => __( 'State', 'invoicing' ), |
|
1026 | + 'label' => __('State', 'invoicing'), |
|
1027 | 1027 | 'label_type' => 'vertical', |
1028 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1028 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1029 | 1029 | 'class' => $class, |
1030 | 1030 | 'value' => $state, |
1031 | 1031 | 'options' => $states, |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | wp_send_json_success( |
1040 | 1040 | array( |
1041 | 1041 | 'html' => $html, |
1042 | - 'select' => ! empty ( $states ) |
|
1042 | + 'select' => !empty ($states) |
|
1043 | 1043 | ) |
1044 | 1044 | ); |
1045 | 1045 | |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | public static function payment_form_refresh_prices() { |
1054 | 1054 | |
1055 | 1055 | // Check nonce. |
1056 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1056 | + check_ajax_referer('getpaid_form_nonce'); |
|
1057 | 1057 | |
1058 | 1058 | // ... form fields... |
1059 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1060 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1059 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1060 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1061 | 1061 | exit; |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | $submission = new GetPaid_Payment_Form_Submission(); |
1066 | 1066 | |
1067 | 1067 | // Do we have an error? |
1068 | - if ( ! empty( $submission->last_error ) ) { |
|
1068 | + if (!empty($submission->last_error)) { |
|
1069 | 1069 | wp_send_json_error( |
1070 | 1070 | array( |
1071 | 1071 | 'code' => $submission->last_error_code, |
@@ -1075,12 +1075,12 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | // Prepare the response. |
1078 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1078 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1079 | 1079 | |
1080 | 1080 | // Filter the response. |
1081 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1081 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1082 | 1082 | |
1083 | - wp_send_json_success( $response ); |
|
1083 | + wp_send_json_success($response); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | } |
@@ -14,90 +14,90 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
67 | 67 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
75 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
76 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
77 | - |
|
78 | - // Setup/welcome |
|
79 | - if ( ! empty( $_GET['page'] ) ) { |
|
80 | - switch ( $_GET['page'] ) { |
|
81 | - case 'gp-setup' : |
|
82 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
83 | - break; |
|
84 | - } |
|
85 | - } |
|
68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
75 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
76 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
77 | + |
|
78 | + // Setup/welcome |
|
79 | + if ( ! empty( $_GET['page'] ) ) { |
|
80 | + switch ( $_GET['page'] ) { |
|
81 | + case 'gp-setup' : |
|
82 | + include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
83 | + break; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * Register admin scripts |
|
91 | - * |
|
92 | - */ |
|
93 | - public function enqeue_scripts() { |
|
90 | + * Register admin scripts |
|
91 | + * |
|
92 | + */ |
|
93 | + public function enqeue_scripts() { |
|
94 | 94 | global $current_screen, $pagenow; |
95 | 95 | |
96 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
97 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
96 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
97 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
98 | 98 | |
99 | 99 | if ( ! empty( $current_screen->post_type ) ) { |
100 | - $page = $current_screen->post_type; |
|
100 | + $page = $current_screen->post_type; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | // General styles. |
@@ -118,54 +118,54 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | // Payment form scripts. |
121 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
121 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
122 | 122 | $this->load_payment_form_scripts(); |
123 | 123 | } |
124 | 124 | |
125 | - if ( $page == 'wpinv-subscriptions' ) { |
|
126 | - wp_enqueue_script( 'postbox' ); |
|
127 | - } |
|
125 | + if ( $page == 'wpinv-subscriptions' ) { |
|
126 | + wp_enqueue_script( 'postbox' ); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Returns admin js translations. |
|
133 | - * |
|
134 | - */ |
|
135 | - protected function get_admin_i18() { |
|
132 | + * Returns admin js translations. |
|
133 | + * |
|
134 | + */ |
|
135 | + protected function get_admin_i18() { |
|
136 | 136 | global $post; |
137 | 137 | |
138 | - $date_range = array( |
|
139 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
140 | - ); |
|
138 | + $date_range = array( |
|
139 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
140 | + ); |
|
141 | 141 | |
142 | - if ( $date_range['period'] == 'custom' ) { |
|
142 | + if ( $date_range['period'] == 'custom' ) { |
|
143 | 143 | |
144 | - if ( isset( $_GET['from'] ) ) { |
|
145 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
146 | - } |
|
144 | + if ( isset( $_GET['from'] ) ) { |
|
145 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
146 | + } |
|
147 | 147 | |
148 | - if ( isset( $_GET['to'] ) ) { |
|
149 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
150 | - } |
|
148 | + if ( isset( $_GET['to'] ) ) { |
|
149 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
150 | + } |
|
151 | 151 | |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | $i18n = array( |
155 | 155 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
156 | 156 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
157 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
160 | - 'date_range' => $date_range, |
|
157 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
160 | + 'date_range' => $date_range, |
|
161 | 161 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
162 | 162 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
163 | 163 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
164 | 164 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
165 | 165 | 'tax' => wpinv_tax_amount(), |
166 | 166 | 'discount' => 0, |
167 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
168 | - 'currency' => wpinv_get_currency(), |
|
167 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
168 | + 'currency' => wpinv_get_currency(), |
|
169 | 169 | 'currency_pos' => wpinv_currency_position(), |
170 | 170 | 'thousand_sep' => wpinv_thousands_separator(), |
171 | 171 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -185,118 +185,118 @@ discard block |
||
185 | 185 | 'item_description' => __( 'Item Description', 'invoicing' ), |
186 | 186 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
187 | 187 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
188 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
188 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
192 | 192 | ); |
193 | 193 | |
194 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
194 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
195 | 195 | |
196 | - $invoice = new WPInv_Invoice( $post ); |
|
197 | - $i18n['save_invoice'] = sprintf( |
|
198 | - __( 'Save %s', 'invoicing' ), |
|
199 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
200 | - ); |
|
196 | + $invoice = new WPInv_Invoice( $post ); |
|
197 | + $i18n['save_invoice'] = sprintf( |
|
198 | + __( 'Save %s', 'invoicing' ), |
|
199 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
200 | + ); |
|
201 | 201 | |
202 | - $i18n['invoice_description'] = sprintf( |
|
203 | - __( '%s Description', 'invoicing' ), |
|
204 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
205 | - ); |
|
202 | + $i18n['invoice_description'] = sprintf( |
|
203 | + __( '%s Description', 'invoicing' ), |
|
204 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
205 | + ); |
|
206 | 206 | |
207 | - } |
|
208 | - return $i18n; |
|
209 | - } |
|
207 | + } |
|
208 | + return $i18n; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Change the admin footer text on GetPaid admin pages. |
|
213 | - * |
|
214 | - * @since 2.0.0 |
|
215 | - * @param string $footer_text |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function admin_footer_text( $footer_text ) { |
|
219 | - global $current_screen; |
|
211 | + /** |
|
212 | + * Change the admin footer text on GetPaid admin pages. |
|
213 | + * |
|
214 | + * @since 2.0.0 |
|
215 | + * @param string $footer_text |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function admin_footer_text( $footer_text ) { |
|
219 | + global $current_screen; |
|
220 | 220 | |
221 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
221 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
222 | 222 | |
223 | 223 | if ( ! empty( $current_screen->post_type ) ) { |
224 | - $page = $current_screen->post_type; |
|
224 | + $page = $current_screen->post_type; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // General styles. |
228 | 228 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
229 | 229 | |
230 | - // Change the footer text |
|
231 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
232 | - |
|
233 | - $rating_url = esc_url( |
|
234 | - wp_nonce_url( |
|
235 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
236 | - 'getpaid-nonce', |
|
237 | - 'getpaid-nonce' |
|
238 | - ) |
|
239 | - ); |
|
240 | - |
|
241 | - $footer_text = sprintf( |
|
242 | - /* translators: %s: five stars */ |
|
243 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
244 | - "<a href='$rating_url'>★★★★★</a>" |
|
245 | - ); |
|
246 | - |
|
247 | - } else { |
|
248 | - |
|
249 | - $footer_text = sprintf( |
|
250 | - /* translators: %s: GetPaid */ |
|
251 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
252 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
253 | - ); |
|
254 | - |
|
255 | - } |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - return $footer_text; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Redirects to wp.org to rate the plugin. |
|
264 | - * |
|
265 | - * @since 2.0.0 |
|
266 | - */ |
|
267 | - public function redirect_to_wordpress_rating_page() { |
|
268 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | - exit; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Loads payment form js. |
|
275 | - * |
|
276 | - */ |
|
277 | - protected function load_payment_form_scripts() { |
|
230 | + // Change the footer text |
|
231 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
232 | + |
|
233 | + $rating_url = esc_url( |
|
234 | + wp_nonce_url( |
|
235 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
236 | + 'getpaid-nonce', |
|
237 | + 'getpaid-nonce' |
|
238 | + ) |
|
239 | + ); |
|
240 | + |
|
241 | + $footer_text = sprintf( |
|
242 | + /* translators: %s: five stars */ |
|
243 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
244 | + "<a href='$rating_url'>★★★★★</a>" |
|
245 | + ); |
|
246 | + |
|
247 | + } else { |
|
248 | + |
|
249 | + $footer_text = sprintf( |
|
250 | + /* translators: %s: GetPaid */ |
|
251 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
252 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
253 | + ); |
|
254 | + |
|
255 | + } |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + return $footer_text; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Redirects to wp.org to rate the plugin. |
|
264 | + * |
|
265 | + * @since 2.0.0 |
|
266 | + */ |
|
267 | + public function redirect_to_wordpress_rating_page() { |
|
268 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | + exit; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Loads payment form js. |
|
275 | + * |
|
276 | + */ |
|
277 | + protected function load_payment_form_scripts() { |
|
278 | 278 | global $post; |
279 | 279 | |
280 | 280 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
281 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
281 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | 283 | |
284 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
284 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
286 | 286 | |
287 | - wp_localize_script( |
|
287 | + wp_localize_script( |
|
288 | 288 | 'wpinv-admin-payment-form-script', |
289 | 289 | 'wpinvPaymentFormAdmin', |
290 | 290 | array( |
291 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | - 'currency' => wpinv_currency_symbol(), |
|
294 | - 'position' => wpinv_currency_position(), |
|
295 | - 'decimals' => (int) wpinv_decimals(), |
|
296 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
297 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
298 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
299 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
291 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | + 'currency' => wpinv_currency_symbol(), |
|
294 | + 'position' => wpinv_currency_position(), |
|
295 | + 'decimals' => (int) wpinv_decimals(), |
|
296 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
297 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
298 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
299 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
300 | 300 | ) |
301 | 301 | ); |
302 | 302 | |
@@ -305,20 +305,20 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Add our classes to admin pages. |
|
308 | + * Add our classes to admin pages. |
|
309 | 309 | * |
310 | 310 | * @param string $classes |
311 | 311 | * @return string |
312 | - * |
|
313 | - */ |
|
312 | + * |
|
313 | + */ |
|
314 | 314 | public function admin_body_class( $classes ) { |
315 | - global $pagenow, $post, $current_screen; |
|
315 | + global $pagenow, $post, $current_screen; |
|
316 | 316 | |
317 | 317 | |
318 | 318 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
319 | 319 | |
320 | 320 | if ( ! empty( $current_screen->post_type ) ) { |
321 | - $page = $current_screen->post_type; |
|
321 | + $page = $current_screen->post_type; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -327,68 +327,68 @@ discard block |
||
327 | 327 | |
328 | 328 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
329 | 329 | $classes .= ' wpinv-cpt wpinv'; |
330 | - } |
|
330 | + } |
|
331 | 331 | |
332 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
332 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | 333 | $classes .= ' getpaid-is-invoice-cpt'; |
334 | 334 | } |
335 | 335 | |
336 | - return $classes; |
|
336 | + return $classes; |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Maybe show the AyeCode Connect Notice. |
|
341 | - */ |
|
342 | - public function init_ayecode_connect_helper(){ |
|
340 | + * Maybe show the AyeCode Connect Notice. |
|
341 | + */ |
|
342 | + public function init_ayecode_connect_helper(){ |
|
343 | 343 | |
344 | - // Register with the deactivation survey class. |
|
345 | - AyeCode_Deactivation_Survey::instance(array( |
|
346 | - 'slug' => 'invoicing', |
|
347 | - 'version' => WPINV_VERSION, |
|
348 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
349 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
350 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
351 | - )); |
|
344 | + // Register with the deactivation survey class. |
|
345 | + AyeCode_Deactivation_Survey::instance(array( |
|
346 | + 'slug' => 'invoicing', |
|
347 | + 'version' => WPINV_VERSION, |
|
348 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
349 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
350 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
351 | + )); |
|
352 | 352 | |
353 | 353 | new AyeCode_Connect_Helper( |
354 | 354 | array( |
355 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
356 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
357 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
358 | - 'connect_button' => __("Connect Site","invoicing"), |
|
359 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
360 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
361 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
355 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
356 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
357 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
358 | + 'connect_button' => __("Connect Site","invoicing"), |
|
359 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
360 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
361 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
362 | 362 | ), |
363 | 363 | array( 'wpi-addons' ) |
364 | 364 | ); |
365 | 365 | |
366 | 366 | } |
367 | 367 | |
368 | - /** |
|
369 | - * Redirect users to settings on activation. |
|
370 | - * |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public function activation_redirect() { |
|
368 | + /** |
|
369 | + * Redirect users to settings on activation. |
|
370 | + * |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public function activation_redirect() { |
|
374 | 374 | |
375 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
375 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
376 | 376 | |
377 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
378 | - return; |
|
379 | - } |
|
377 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
378 | + return; |
|
379 | + } |
|
380 | 380 | |
381 | - // Bail if activating from network, or bulk |
|
382 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
383 | - return; |
|
384 | - } |
|
381 | + // Bail if activating from network, or bulk |
|
382 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
383 | + return; |
|
384 | + } |
|
385 | 385 | |
386 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
386 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
387 | 387 | |
388 | 388 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
389 | 389 | exit; |
390 | 390 | |
391 | - } |
|
391 | + } |
|
392 | 392 | |
393 | 393 | /** |
394 | 394 | * Fires an admin action after verifying that a user can fire them. |
@@ -402,498 +402,498 @@ discard block |
||
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
405 | + /** |
|
406 | 406 | * Sends a payment reminder to a customer. |
407 | - * |
|
408 | - * @param array $args |
|
407 | + * |
|
408 | + * @param array $args |
|
409 | 409 | */ |
410 | 410 | public function duplicate_payment_form( $args ) { |
411 | 411 | |
412 | - if ( empty( $args['form_id'] ) ) { |
|
413 | - return; |
|
414 | - } |
|
415 | - |
|
416 | - $form = new GetPaid_Payment_Form( $args['form_id'] ); |
|
412 | + if ( empty( $args['form_id'] ) ) { |
|
413 | + return; |
|
414 | + } |
|
417 | 415 | |
418 | - if ( ! $form->exists() ) { |
|
419 | - return; |
|
420 | - } |
|
416 | + $form = new GetPaid_Payment_Form( $args['form_id'] ); |
|
421 | 417 | |
422 | - $new_form = new GetPaid_Payment_Form(); |
|
423 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
424 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
425 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
426 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
427 | - $new_form->save(); |
|
418 | + if ( ! $form->exists() ) { |
|
419 | + return; |
|
420 | + } |
|
428 | 421 | |
429 | - if ( $new_form->exists() ) { |
|
430 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
431 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
432 | - } else { |
|
433 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
434 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
435 | - } |
|
422 | + $new_form = new GetPaid_Payment_Form(); |
|
423 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
424 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
425 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
426 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
427 | + $new_form->save(); |
|
428 | + |
|
429 | + if ( $new_form->exists() ) { |
|
430 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
431 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
432 | + } else { |
|
433 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
434 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
435 | + } |
|
436 | 436 | |
437 | - wp_redirect( $url ); |
|
438 | - exit; |
|
439 | - } |
|
437 | + wp_redirect( $url ); |
|
438 | + exit; |
|
439 | + } |
|
440 | 440 | |
441 | - /** |
|
441 | + /** |
|
442 | 442 | * Sends a payment reminder to a customer. |
443 | - * |
|
444 | - * @param array $args |
|
443 | + * |
|
444 | + * @param array $args |
|
445 | 445 | */ |
446 | 446 | public function send_customer_invoice( $args ) { |
447 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
447 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
448 | 448 | |
449 | - if ( $sent ) { |
|
450 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
451 | - } else { |
|
452 | - $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
453 | - } |
|
449 | + if ( $sent ) { |
|
450 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
451 | + } else { |
|
452 | + $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
453 | + } |
|
454 | 454 | |
455 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
456 | - exit; |
|
457 | - } |
|
455 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
456 | + exit; |
|
457 | + } |
|
458 | 458 | |
459 | - /** |
|
459 | + /** |
|
460 | 460 | * Sends a payment reminder to a customer. |
461 | - * |
|
462 | - * @param array $args |
|
461 | + * |
|
462 | + * @param array $args |
|
463 | 463 | */ |
464 | 464 | public function send_customer_payment_reminder( $args ) { |
465 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
465 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
466 | 466 | |
467 | - if ( $sent ) { |
|
468 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
469 | - } else { |
|
470 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
471 | - } |
|
467 | + if ( $sent ) { |
|
468 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
469 | + } else { |
|
470 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
471 | + } |
|
472 | 472 | |
473 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
474 | - exit; |
|
475 | - } |
|
473 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
474 | + exit; |
|
475 | + } |
|
476 | 476 | |
477 | - /** |
|
477 | + /** |
|
478 | 478 | * Resets tax rates. |
479 | - * |
|
479 | + * |
|
480 | 480 | */ |
481 | 481 | public function admin_reset_tax_rates() { |
482 | 482 | |
483 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
484 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
485 | - exit; |
|
483 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
484 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
485 | + exit; |
|
486 | 486 | |
487 | - } |
|
487 | + } |
|
488 | 488 | |
489 | - /** |
|
489 | + /** |
|
490 | 490 | * Resets admin pages. |
491 | - * |
|
491 | + * |
|
492 | 492 | */ |
493 | 493 | public function admin_create_missing_pages() { |
494 | - $installer = new GetPaid_Installer(); |
|
495 | - $installer->create_pages(); |
|
496 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
497 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
498 | - exit; |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
494 | + $installer = new GetPaid_Installer(); |
|
495 | + $installer->create_pages(); |
|
496 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
497 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
498 | + exit; |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | 502 | * Creates an missing admin tables. |
503 | - * |
|
503 | + * |
|
504 | 504 | */ |
505 | 505 | public function admin_create_missing_tables() { |
506 | - global $wpdb; |
|
507 | - $installer = new GetPaid_Installer(); |
|
506 | + global $wpdb; |
|
507 | + $installer = new GetPaid_Installer(); |
|
508 | 508 | |
509 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
510 | - $installer->create_subscriptions_table(); |
|
509 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
510 | + $installer->create_subscriptions_table(); |
|
511 | 511 | |
512 | - if ( $wpdb->last_error !== '' ) { |
|
513 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
514 | - } |
|
515 | - } |
|
512 | + if ( $wpdb->last_error !== '' ) { |
|
513 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
514 | + } |
|
515 | + } |
|
516 | 516 | |
517 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
518 | - $installer->create_invoices_table(); |
|
517 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
518 | + $installer->create_invoices_table(); |
|
519 | 519 | |
520 | - if ( $wpdb->last_error !== '' ) { |
|
521 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
522 | - } |
|
523 | - } |
|
520 | + if ( $wpdb->last_error !== '' ) { |
|
521 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
522 | + } |
|
523 | + } |
|
524 | 524 | |
525 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
526 | - $installer->create_invoice_items_table(); |
|
525 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
526 | + $installer->create_invoice_items_table(); |
|
527 | 527 | |
528 | - if ( $wpdb->last_error !== '' ) { |
|
529 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
530 | - } |
|
531 | - } |
|
528 | + if ( $wpdb->last_error !== '' ) { |
|
529 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
530 | + } |
|
531 | + } |
|
532 | 532 | |
533 | - if ( ! $this->has_notices() ) { |
|
534 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
535 | - } |
|
533 | + if ( ! $this->has_notices() ) { |
|
534 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
535 | + } |
|
536 | 536 | |
537 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
538 | - exit; |
|
539 | - } |
|
537 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
538 | + exit; |
|
539 | + } |
|
540 | 540 | |
541 | - /** |
|
541 | + /** |
|
542 | 542 | * Migrates old invoices to the new database tables. |
543 | - * |
|
543 | + * |
|
544 | 544 | */ |
545 | 545 | public function admin_migrate_old_invoices() { |
546 | 546 | |
547 | - // Migrate the invoices. |
|
548 | - $installer = new GetPaid_Installer(); |
|
549 | - $installer->migrate_old_invoices(); |
|
547 | + // Migrate the invoices. |
|
548 | + $installer = new GetPaid_Installer(); |
|
549 | + $installer->migrate_old_invoices(); |
|
550 | 550 | |
551 | - // Show an admin message. |
|
552 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
551 | + // Show an admin message. |
|
552 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
553 | 553 | |
554 | - // Redirect the admin. |
|
555 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
556 | - exit; |
|
554 | + // Redirect the admin. |
|
555 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
556 | + exit; |
|
557 | 557 | |
558 | - } |
|
558 | + } |
|
559 | 559 | |
560 | - /** |
|
560 | + /** |
|
561 | 561 | * Download customers. |
562 | - * |
|
562 | + * |
|
563 | 563 | */ |
564 | 564 | public function admin_download_customers() { |
565 | - global $wpdb; |
|
565 | + global $wpdb; |
|
566 | 566 | |
567 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
567 | + $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
568 | 568 | |
569 | - header( "Content-Type:text/csv" ); |
|
570 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
569 | + header( "Content-Type:text/csv" ); |
|
570 | + header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
571 | 571 | |
572 | - $post_types = ''; |
|
572 | + $post_types = ''; |
|
573 | 573 | |
574 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
575 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
576 | - } |
|
574 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
575 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
576 | + } |
|
577 | 577 | |
578 | - $post_types = rtrim( $post_types, ' OR' ); |
|
578 | + $post_types = rtrim( $post_types, ' OR' ); |
|
579 | 579 | |
580 | - $customers = $wpdb->get_col( |
|
581 | - $wpdb->prepare( |
|
582 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
583 | - ) |
|
584 | - ); |
|
580 | + $customers = $wpdb->get_col( |
|
581 | + $wpdb->prepare( |
|
582 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
583 | + ) |
|
584 | + ); |
|
585 | 585 | |
586 | - $columns = array( |
|
587 | - 'name' => __( 'Name', 'invoicing' ), |
|
588 | - 'email' => __( 'Email', 'invoicing' ), |
|
589 | - 'country' => __( 'Country', 'invoicing' ), |
|
590 | - 'state' => __( 'State', 'invoicing' ), |
|
591 | - 'city' => __( 'City', 'invoicing' ), |
|
592 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
593 | - 'address' => __( 'Address', 'invoicing' ), |
|
594 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
595 | - 'company' => __( 'Company', 'invoicing' ), |
|
596 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
597 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
598 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
599 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
600 | - ); |
|
586 | + $columns = array( |
|
587 | + 'name' => __( 'Name', 'invoicing' ), |
|
588 | + 'email' => __( 'Email', 'invoicing' ), |
|
589 | + 'country' => __( 'Country', 'invoicing' ), |
|
590 | + 'state' => __( 'State', 'invoicing' ), |
|
591 | + 'city' => __( 'City', 'invoicing' ), |
|
592 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
593 | + 'address' => __( 'Address', 'invoicing' ), |
|
594 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
595 | + 'company' => __( 'Company', 'invoicing' ), |
|
596 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
597 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
598 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
599 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
600 | + ); |
|
601 | 601 | |
602 | - // Output the csv column headers. |
|
603 | - fputcsv( $output, array_values( $columns ) ); |
|
602 | + // Output the csv column headers. |
|
603 | + fputcsv( $output, array_values( $columns ) ); |
|
604 | 604 | |
605 | - // Loop through |
|
606 | - $table = new WPInv_Customers_Table(); |
|
607 | - foreach ( $customers as $customer_id ) { |
|
605 | + // Loop through |
|
606 | + $table = new WPInv_Customers_Table(); |
|
607 | + foreach ( $customers as $customer_id ) { |
|
608 | 608 | |
609 | - $user = get_user_by( 'id', $customer_id ); |
|
610 | - $row = array(); |
|
611 | - if ( empty( $user ) ) { |
|
612 | - continue; |
|
613 | - } |
|
609 | + $user = get_user_by( 'id', $customer_id ); |
|
610 | + $row = array(); |
|
611 | + if ( empty( $user ) ) { |
|
612 | + continue; |
|
613 | + } |
|
614 | 614 | |
615 | - foreach ( array_keys( $columns ) as $column ) { |
|
615 | + foreach ( array_keys( $columns ) as $column ) { |
|
616 | 616 | |
617 | - $method = 'column_' . $column; |
|
617 | + $method = 'column_' . $column; |
|
618 | 618 | |
619 | - if ( 'name' == $column ) { |
|
620 | - $value = esc_html( $user->display_name ); |
|
621 | - } else if( 'email' == $column ) { |
|
622 | - $value = sanitize_email( $user->user_email ); |
|
623 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
624 | - $value = strip_tags( $table->$method( $user ) ); |
|
625 | - } |
|
619 | + if ( 'name' == $column ) { |
|
620 | + $value = esc_html( $user->display_name ); |
|
621 | + } else if( 'email' == $column ) { |
|
622 | + $value = sanitize_email( $user->user_email ); |
|
623 | + } else if ( is_callable( array( $table, $method ) ) ) { |
|
624 | + $value = strip_tags( $table->$method( $user ) ); |
|
625 | + } |
|
626 | 626 | |
627 | - if ( empty( $value ) ) { |
|
628 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
629 | - } |
|
627 | + if ( empty( $value ) ) { |
|
628 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
629 | + } |
|
630 | 630 | |
631 | - $row[] = $value; |
|
631 | + $row[] = $value; |
|
632 | 632 | |
633 | - } |
|
633 | + } |
|
634 | 634 | |
635 | - fputcsv( $output, $row ); |
|
636 | - } |
|
635 | + fputcsv( $output, $row ); |
|
636 | + } |
|
637 | 637 | |
638 | - fclose( $output ); |
|
639 | - exit; |
|
638 | + fclose( $output ); |
|
639 | + exit; |
|
640 | 640 | |
641 | - } |
|
641 | + } |
|
642 | 642 | |
643 | - /** |
|
643 | + /** |
|
644 | 644 | * Installs a plugin. |
645 | - * |
|
646 | - * @param array $data |
|
645 | + * |
|
646 | + * @param array $data |
|
647 | 647 | */ |
648 | 648 | public function admin_install_plugin( $data ) { |
649 | 649 | |
650 | - if ( ! empty( $data['plugins'] ) ) { |
|
651 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
652 | - wp_cache_flush(); |
|
650 | + if ( ! empty( $data['plugins'] ) ) { |
|
651 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
652 | + wp_cache_flush(); |
|
653 | 653 | |
654 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
655 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
656 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
657 | - $installed = $upgrader->install( $plugin_zip ); |
|
654 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
655 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
656 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
657 | + $installed = $upgrader->install( $plugin_zip ); |
|
658 | 658 | |
659 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
660 | - activate_plugin( $file, '', false, true ); |
|
661 | - } else { |
|
662 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
663 | - } |
|
659 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
660 | + activate_plugin( $file, '', false, true ); |
|
661 | + } else { |
|
662 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
663 | + } |
|
664 | 664 | |
665 | - } |
|
665 | + } |
|
666 | 666 | |
667 | - } |
|
667 | + } |
|
668 | 668 | |
669 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
670 | - wp_safe_redirect( $redirect ); |
|
671 | - exit; |
|
669 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
670 | + wp_safe_redirect( $redirect ); |
|
671 | + exit; |
|
672 | 672 | |
673 | - } |
|
673 | + } |
|
674 | 674 | |
675 | - /** |
|
675 | + /** |
|
676 | 676 | * Connects a gateway. |
677 | - * |
|
678 | - * @param array $data |
|
677 | + * |
|
678 | + * @param array $data |
|
679 | 679 | */ |
680 | 680 | public function admin_connect_gateway( $data ) { |
681 | 681 | |
682 | - if ( ! empty( $data['plugin'] ) ) { |
|
682 | + if ( ! empty( $data['plugin'] ) ) { |
|
683 | 683 | |
684 | - $gateway = sanitize_key( $data['plugin'] ); |
|
685 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
684 | + $gateway = sanitize_key( $data['plugin'] ); |
|
685 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
686 | 686 | |
687 | - if ( ! empty( $connect_url ) ) { |
|
688 | - wp_redirect( $connect_url ); |
|
689 | - exit; |
|
690 | - } |
|
687 | + if ( ! empty( $connect_url ) ) { |
|
688 | + wp_redirect( $connect_url ); |
|
689 | + exit; |
|
690 | + } |
|
691 | 691 | |
692 | - if ( 'stripe' == $data['plugin'] ) { |
|
693 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
694 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
695 | - wp_cache_flush(); |
|
692 | + if ( 'stripe' == $data['plugin'] ) { |
|
693 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
694 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
695 | + wp_cache_flush(); |
|
696 | 696 | |
697 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
698 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
699 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
700 | - $upgrader->install( $plugin_zip ); |
|
701 | - } |
|
697 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
698 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
699 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
700 | + $upgrader->install( $plugin_zip ); |
|
701 | + } |
|
702 | 702 | |
703 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
704 | - } |
|
703 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
704 | + } |
|
705 | 705 | |
706 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
707 | - if ( ! empty( $connect_url ) ) { |
|
708 | - wp_redirect( $connect_url ); |
|
709 | - exit; |
|
710 | - } |
|
706 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
707 | + if ( ! empty( $connect_url ) ) { |
|
708 | + wp_redirect( $connect_url ); |
|
709 | + exit; |
|
710 | + } |
|
711 | 711 | |
712 | - } |
|
712 | + } |
|
713 | 713 | |
714 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
715 | - wp_safe_redirect( $redirect ); |
|
716 | - exit; |
|
714 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
715 | + wp_safe_redirect( $redirect ); |
|
716 | + exit; |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | - /** |
|
720 | + /** |
|
721 | 721 | * Recalculates discounts. |
722 | - * |
|
722 | + * |
|
723 | 723 | */ |
724 | 724 | public function admin_recalculate_discounts() { |
725 | - global $wpdb; |
|
725 | + global $wpdb; |
|
726 | 726 | |
727 | - // Fetch all invoices that have discount codes. |
|
728 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
729 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
727 | + // Fetch all invoices that have discount codes. |
|
728 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
729 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
730 | 730 | |
731 | - foreach ( $invoices as $invoice ) { |
|
731 | + foreach ( $invoices as $invoice ) { |
|
732 | 732 | |
733 | - $invoice = new WPInv_Invoice( $invoice ); |
|
733 | + $invoice = new WPInv_Invoice( $invoice ); |
|
734 | 734 | |
735 | - if ( ! $invoice->exists() ) { |
|
736 | - continue; |
|
737 | - } |
|
735 | + if ( ! $invoice->exists() ) { |
|
736 | + continue; |
|
737 | + } |
|
738 | 738 | |
739 | - // Abort if the discount does not exist or does not apply here. |
|
740 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
741 | - if ( ! $discount->exists() ) { |
|
742 | - continue; |
|
743 | - } |
|
739 | + // Abort if the discount does not exist or does not apply here. |
|
740 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
741 | + if ( ! $discount->exists() ) { |
|
742 | + continue; |
|
743 | + } |
|
744 | 744 | |
745 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
746 | - $invoice->recalculate_total(); |
|
745 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
746 | + $invoice->recalculate_total(); |
|
747 | 747 | |
748 | - if ( $invoice->get_total_discount() > 0 ) { |
|
749 | - $invoice->save(); |
|
750 | - } |
|
748 | + if ( $invoice->get_total_discount() > 0 ) { |
|
749 | + $invoice->save(); |
|
750 | + } |
|
751 | 751 | |
752 | - } |
|
752 | + } |
|
753 | 753 | |
754 | - // Show an admin message. |
|
755 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
754 | + // Show an admin message. |
|
755 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
756 | 756 | |
757 | - // Redirect the admin. |
|
758 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
759 | - exit; |
|
757 | + // Redirect the admin. |
|
758 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
759 | + exit; |
|
760 | 760 | |
761 | - } |
|
761 | + } |
|
762 | 762 | |
763 | 763 | /** |
764 | - * Returns an array of admin notices. |
|
765 | - * |
|
766 | - * @since 1.0.19 |
|
764 | + * Returns an array of admin notices. |
|
765 | + * |
|
766 | + * @since 1.0.19 |
|
767 | 767 | * @return array |
768 | - */ |
|
769 | - public function get_notices() { |
|
770 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
768 | + */ |
|
769 | + public function get_notices() { |
|
770 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
771 | 771 | return is_array( $notices ) ? $notices : array(); |
772 | - } |
|
772 | + } |
|
773 | 773 | |
774 | - /** |
|
775 | - * Checks if we have any admin notices. |
|
776 | - * |
|
777 | - * @since 2.0.4 |
|
774 | + /** |
|
775 | + * Checks if we have any admin notices. |
|
776 | + * |
|
777 | + * @since 2.0.4 |
|
778 | 778 | * @return array |
779 | - */ |
|
780 | - public function has_notices() { |
|
781 | - return count( $this->get_notices() ) > 0; |
|
782 | - } |
|
783 | - |
|
784 | - /** |
|
785 | - * Clears all admin notices |
|
786 | - * |
|
787 | - * @access public |
|
788 | - * @since 1.0.19 |
|
789 | - */ |
|
790 | - public function clear_notices() { |
|
791 | - delete_option( 'wpinv_admin_notices' ); |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * Saves a new admin notice |
|
796 | - * |
|
797 | - * @access public |
|
798 | - * @since 1.0.19 |
|
799 | - */ |
|
800 | - public function save_notice( $type, $message ) { |
|
801 | - $notices = $this->get_notices(); |
|
802 | - |
|
803 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
804 | - $notices[ $type ] = array(); |
|
805 | - } |
|
806 | - |
|
807 | - $notices[ $type ][] = $message; |
|
808 | - |
|
809 | - update_option( 'wpinv_admin_notices', $notices ); |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * Displays a success notice |
|
814 | - * |
|
815 | - * @param string $msg The message to qeue. |
|
816 | - * @access public |
|
817 | - * @since 1.0.19 |
|
818 | - */ |
|
819 | - public function show_success( $msg ) { |
|
820 | - $this->save_notice( 'success', $msg ); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Displays a error notice |
|
825 | - * |
|
826 | - * @access public |
|
827 | - * @param string $msg The message to qeue. |
|
828 | - * @since 1.0.19 |
|
829 | - */ |
|
830 | - public function show_error( $msg ) { |
|
831 | - $this->save_notice( 'error', $msg ); |
|
832 | - } |
|
833 | - |
|
834 | - /** |
|
835 | - * Displays a warning notice |
|
836 | - * |
|
837 | - * @access public |
|
838 | - * @param string $msg The message to qeue. |
|
839 | - * @since 1.0.19 |
|
840 | - */ |
|
841 | - public function show_warning( $msg ) { |
|
842 | - $this->save_notice( 'warning', $msg ); |
|
843 | - } |
|
844 | - |
|
845 | - /** |
|
846 | - * Displays a info notice |
|
847 | - * |
|
848 | - * @access public |
|
849 | - * @param string $msg The message to qeue. |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function show_info( $msg ) { |
|
853 | - $this->save_notice( 'info', $msg ); |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Show notices |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function show_notices() { |
|
779 | + */ |
|
780 | + public function has_notices() { |
|
781 | + return count( $this->get_notices() ) > 0; |
|
782 | + } |
|
783 | + |
|
784 | + /** |
|
785 | + * Clears all admin notices |
|
786 | + * |
|
787 | + * @access public |
|
788 | + * @since 1.0.19 |
|
789 | + */ |
|
790 | + public function clear_notices() { |
|
791 | + delete_option( 'wpinv_admin_notices' ); |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * Saves a new admin notice |
|
796 | + * |
|
797 | + * @access public |
|
798 | + * @since 1.0.19 |
|
799 | + */ |
|
800 | + public function save_notice( $type, $message ) { |
|
801 | + $notices = $this->get_notices(); |
|
802 | + |
|
803 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
804 | + $notices[ $type ] = array(); |
|
805 | + } |
|
806 | + |
|
807 | + $notices[ $type ][] = $message; |
|
808 | + |
|
809 | + update_option( 'wpinv_admin_notices', $notices ); |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * Displays a success notice |
|
814 | + * |
|
815 | + * @param string $msg The message to qeue. |
|
816 | + * @access public |
|
817 | + * @since 1.0.19 |
|
818 | + */ |
|
819 | + public function show_success( $msg ) { |
|
820 | + $this->save_notice( 'success', $msg ); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Displays a error notice |
|
825 | + * |
|
826 | + * @access public |
|
827 | + * @param string $msg The message to qeue. |
|
828 | + * @since 1.0.19 |
|
829 | + */ |
|
830 | + public function show_error( $msg ) { |
|
831 | + $this->save_notice( 'error', $msg ); |
|
832 | + } |
|
833 | + |
|
834 | + /** |
|
835 | + * Displays a warning notice |
|
836 | + * |
|
837 | + * @access public |
|
838 | + * @param string $msg The message to qeue. |
|
839 | + * @since 1.0.19 |
|
840 | + */ |
|
841 | + public function show_warning( $msg ) { |
|
842 | + $this->save_notice( 'warning', $msg ); |
|
843 | + } |
|
844 | + |
|
845 | + /** |
|
846 | + * Displays a info notice |
|
847 | + * |
|
848 | + * @access public |
|
849 | + * @param string $msg The message to qeue. |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function show_info( $msg ) { |
|
853 | + $this->save_notice( 'info', $msg ); |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Show notices |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function show_notices() { |
|
863 | 863 | |
864 | 864 | $notices = $this->get_notices(); |
865 | 865 | $this->clear_notices(); |
866 | 866 | |
867 | - foreach ( $notices as $type => $messages ) { |
|
867 | + foreach ( $notices as $type => $messages ) { |
|
868 | 868 | |
869 | - if ( ! is_array( $messages ) ) { |
|
870 | - continue; |
|
871 | - } |
|
869 | + if ( ! is_array( $messages ) ) { |
|
870 | + continue; |
|
871 | + } |
|
872 | 872 | |
873 | 873 | $type = sanitize_key( $type ); |
874 | - foreach ( $messages as $message ) { |
|
874 | + foreach ( $messages as $message ) { |
|
875 | 875 | $message = wp_kses_post( $message ); |
876 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
876 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | } |
880 | 880 | |
881 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
882 | - |
|
883 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
884 | - $url = wp_nonce_url( |
|
885 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
886 | - 'getpaid-nonce', |
|
887 | - 'getpaid-nonce' |
|
888 | - ); |
|
889 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
890 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
891 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
892 | - break; |
|
893 | - } |
|
881 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
882 | + |
|
883 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
884 | + $url = wp_nonce_url( |
|
885 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
886 | + 'getpaid-nonce', |
|
887 | + 'getpaid-nonce' |
|
888 | + ); |
|
889 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
890 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
891 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
892 | + break; |
|
893 | + } |
|
894 | 894 | |
895 | - } |
|
895 | + } |
|
896 | 896 | |
897 | - } |
|
897 | + } |
|
898 | 898 | |
899 | 899 | } |
@@ -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 | * The main admin class. |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Class constructor. |
39 | 39 | */ |
40 | - public function __construct(){ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,32 +54,32 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
75 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
76 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
63 | + add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page')); |
|
64 | + add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form')); |
|
65 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
66 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
67 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
68 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
69 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
70 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
71 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
72 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
73 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
74 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
75 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
76 | + do_action('getpaid_init_admin_hooks', $this); |
|
77 | 77 | |
78 | 78 | // Setup/welcome |
79 | - if ( ! empty( $_GET['page'] ) ) { |
|
80 | - switch ( $_GET['page'] ) { |
|
79 | + if (!empty($_GET['page'])) { |
|
80 | + switch ($_GET['page']) { |
|
81 | 81 | case 'gp-setup' : |
82 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
82 | + include_once(dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'); |
|
83 | 83 | break; |
84 | 84 | } |
85 | 85 | } |
@@ -93,37 +93,37 @@ discard block |
||
93 | 93 | public function enqeue_scripts() { |
94 | 94 | global $current_screen, $pagenow; |
95 | 95 | |
96 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
96 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
97 | 97 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
98 | 98 | |
99 | - if ( ! empty( $current_screen->post_type ) ) { |
|
99 | + if (!empty($current_screen->post_type)) { |
|
100 | 100 | $page = $current_screen->post_type; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // General styles. |
104 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page ) { |
|
104 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page) { |
|
105 | 105 | |
106 | 106 | // Styles. |
107 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
108 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
109 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
107 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
108 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
109 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
110 | 110 | |
111 | 111 | // Scripts. |
112 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
112 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
113 | 113 | |
114 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
115 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
116 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
114 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
115 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
116 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
120 | 120 | // Payment form scripts. |
121 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
121 | + if ('wpi_payment_form' == $page && $editing) { |
|
122 | 122 | $this->load_payment_form_scripts(); |
123 | 123 | } |
124 | 124 | |
125 | - if ( $page == 'wpinv-subscriptions' ) { |
|
126 | - wp_enqueue_script( 'postbox' ); |
|
125 | + if ($page == 'wpinv-subscriptions') { |
|
126 | + wp_enqueue_script('postbox'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | } |
@@ -136,32 +136,32 @@ discard block |
||
136 | 136 | global $post; |
137 | 137 | |
138 | 138 | $date_range = array( |
139 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
139 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days' |
|
140 | 140 | ); |
141 | 141 | |
142 | - if ( $date_range['period'] == 'custom' ) { |
|
142 | + if ($date_range['period'] == 'custom') { |
|
143 | 143 | |
144 | - if ( isset( $_GET['from'] ) ) { |
|
145 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
144 | + if (isset($_GET['from'])) { |
|
145 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
146 | 146 | } |
147 | 147 | |
148 | - if ( isset( $_GET['to'] ) ) { |
|
149 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
148 | + if (isset($_GET['to'])) { |
|
149 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | } |
153 | 153 | |
154 | 154 | $i18n = array( |
155 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
156 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
157 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
155 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
156 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
157 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
158 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
159 | + 'rest_root' => esc_url_raw(rest_url()), |
|
160 | 160 | 'date_range' => $date_range, |
161 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
162 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
163 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
164 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
161 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
162 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
163 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
164 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
165 | 165 | 'tax' => wpinv_tax_amount(), |
166 | 166 | 'discount' => 0, |
167 | 167 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -170,38 +170,38 @@ discard block |
||
170 | 170 | 'thousand_sep' => wpinv_thousands_separator(), |
171 | 171 | 'decimal_sep' => wpinv_decimal_separator(), |
172 | 172 | 'decimals' => wpinv_decimals(), |
173 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
174 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
175 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
176 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
177 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
178 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
179 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
180 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
181 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
182 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
183 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
184 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
185 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
186 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
187 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
188 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
173 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
174 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
175 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
176 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
177 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
178 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
179 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
180 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
181 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
182 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
183 | + 'action_edit' => __('Edit', 'invoicing'), |
|
184 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
185 | + 'item_description' => __('Item Description', 'invoicing'), |
|
186 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
187 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
188 | + 'searching' => __('Searching', 'invoicing'), |
|
189 | + 'loading' => __('Loading...', 'invoicing'), |
|
190 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
191 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
192 | 192 | ); |
193 | 193 | |
194 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
194 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
195 | 195 | |
196 | - $invoice = new WPInv_Invoice( $post ); |
|
196 | + $invoice = new WPInv_Invoice($post); |
|
197 | 197 | $i18n['save_invoice'] = sprintf( |
198 | - __( 'Save %s', 'invoicing' ), |
|
199 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
198 | + __('Save %s', 'invoicing'), |
|
199 | + ucfirst($invoice->get_invoice_quote_type()) |
|
200 | 200 | ); |
201 | 201 | |
202 | 202 | $i18n['invoice_description'] = sprintf( |
203 | - __( '%s Description', 'invoicing' ), |
|
204 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | + __('%s Description', 'invoicing'), |
|
204 | + ucfirst($invoice->get_invoice_quote_type()) |
|
205 | 205 | ); |
206 | 206 | |
207 | 207 | } |
@@ -215,24 +215,24 @@ discard block |
||
215 | 215 | * @param string $footer_text |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function admin_footer_text( $footer_text ) { |
|
218 | + public function admin_footer_text($footer_text) { |
|
219 | 219 | global $current_screen; |
220 | 220 | |
221 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
221 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
222 | 222 | |
223 | - if ( ! empty( $current_screen->post_type ) ) { |
|
223 | + if (!empty($current_screen->post_type)) { |
|
224 | 224 | $page = $current_screen->post_type; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // General styles. |
228 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
228 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
229 | 229 | |
230 | 230 | // Change the footer text |
231 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
231 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
232 | 232 | |
233 | - $rating_url = esc_url( |
|
233 | + $rating_url = esc_url( |
|
234 | 234 | wp_nonce_url( |
235 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
235 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
236 | 236 | 'getpaid-nonce', |
237 | 237 | 'getpaid-nonce' |
238 | 238 | ) |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | |
241 | 241 | $footer_text = sprintf( |
242 | 242 | /* translators: %s: five stars */ |
243 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
243 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
244 | 244 | "<a href='$rating_url'>★★★★★</a>" |
245 | 245 | ); |
246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | $footer_text = sprintf( |
250 | 250 | /* translators: %s: GetPaid */ |
251 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
251 | + __('Thank you for using %s!', 'invoicing'), |
|
252 | 252 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
253 | 253 | ); |
254 | 254 | |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | * @since 2.0.0 |
266 | 266 | */ |
267 | 267 | public function redirect_to_wordpress_rating_page() { |
268 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
268 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
269 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
@@ -277,30 +277,30 @@ discard block |
||
277 | 277 | protected function load_payment_form_scripts() { |
278 | 278 | global $post; |
279 | 279 | |
280 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
281 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
280 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
281 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
282 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
283 | 283 | |
284 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
284 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
285 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
286 | 286 | |
287 | 287 | wp_localize_script( |
288 | 288 | 'wpinv-admin-payment-form-script', |
289 | 289 | 'wpinvPaymentFormAdmin', |
290 | 290 | array( |
291 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
291 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
292 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
293 | 293 | 'currency' => wpinv_currency_symbol(), |
294 | 294 | 'position' => wpinv_currency_position(), |
295 | 295 | 'decimals' => (int) wpinv_decimals(), |
296 | 296 | 'thousands_sep' => wpinv_thousands_separator(), |
297 | 297 | 'decimals_sep' => wpinv_decimal_separator(), |
298 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
298 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
299 | 299 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
300 | 300 | ) |
301 | 301 | ); |
302 | 302 | |
303 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
303 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
304 | 304 | |
305 | 305 | } |
306 | 306 | |
@@ -311,25 +311,25 @@ discard block |
||
311 | 311 | * @return string |
312 | 312 | * |
313 | 313 | */ |
314 | - public function admin_body_class( $classes ) { |
|
314 | + public function admin_body_class($classes) { |
|
315 | 315 | global $pagenow, $post, $current_screen; |
316 | 316 | |
317 | 317 | |
318 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
318 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
319 | 319 | |
320 | - if ( ! empty( $current_screen->post_type ) ) { |
|
320 | + if (!empty($current_screen->post_type)) { |
|
321 | 321 | $page = $current_screen->post_type; |
322 | 322 | } |
323 | 323 | |
324 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
325 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
324 | + if (false !== stripos($page, 'wpi')) { |
|
325 | + $classes .= ' wpi-' . sanitize_key($page); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
328 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
329 | 329 | $classes .= ' wpinv-cpt wpinv'; |
330 | 330 | } |
331 | 331 | |
332 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
332 | + if (getpaid_is_invoice_post_type($page)) { |
|
333 | 333 | $classes .= ' getpaid-is-invoice-cpt'; |
334 | 334 | } |
335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | /** |
340 | 340 | * Maybe show the AyeCode Connect Notice. |
341 | 341 | */ |
342 | - public function init_ayecode_connect_helper(){ |
|
342 | + public function init_ayecode_connect_helper() { |
|
343 | 343 | |
344 | 344 | // Register with the deactivation survey class. |
345 | 345 | AyeCode_Deactivation_Survey::instance(array( |
@@ -347,20 +347,20 @@ discard block |
||
347 | 347 | 'version' => WPINV_VERSION, |
348 | 348 | 'support_url' => 'https://wpgetpaid.com/support/', |
349 | 349 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
350 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
350 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
351 | 351 | )); |
352 | 352 | |
353 | 353 | new AyeCode_Connect_Helper( |
354 | 354 | array( |
355 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
356 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
357 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
358 | - 'connect_button' => __("Connect Site","invoicing"), |
|
359 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
360 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
361 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
355 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
356 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
357 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
358 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
359 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
360 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
361 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
362 | 362 | ), |
363 | - array( 'wpi-addons' ) |
|
363 | + array('wpi-addons') |
|
364 | 364 | ); |
365 | 365 | |
366 | 366 | } |
@@ -372,20 +372,20 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function activation_redirect() { |
374 | 374 | |
375 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
375 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
376 | 376 | |
377 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
377 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Bail if activating from network, or bulk |
382 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
382 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | |
386 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
386 | + update_option('wpinv_redirected_to_settings', 1); |
|
387 | 387 | |
388 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
388 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
389 | 389 | exit; |
390 | 390 | |
391 | 391 | } |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public function maybe_do_admin_action() { |
397 | 397 | |
398 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
399 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
400 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
398 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
399 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
400 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
@@ -407,34 +407,34 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @param array $args |
409 | 409 | */ |
410 | - public function duplicate_payment_form( $args ) { |
|
410 | + public function duplicate_payment_form($args) { |
|
411 | 411 | |
412 | - if ( empty( $args['form_id'] ) ) { |
|
412 | + if (empty($args['form_id'])) { |
|
413 | 413 | return; |
414 | 414 | } |
415 | 415 | |
416 | - $form = new GetPaid_Payment_Form( $args['form_id'] ); |
|
416 | + $form = new GetPaid_Payment_Form($args['form_id']); |
|
417 | 417 | |
418 | - if ( ! $form->exists() ) { |
|
418 | + if (!$form->exists()) { |
|
419 | 419 | return; |
420 | 420 | } |
421 | 421 | |
422 | 422 | $new_form = new GetPaid_Payment_Form(); |
423 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
424 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
425 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
426 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
423 | + $new_form->set_author($form->get_author('edit')); |
|
424 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
425 | + $new_form->set_elements($form->get_elements('edit')); |
|
426 | + $new_form->set_items($form->get_items('edit')); |
|
427 | 427 | $new_form->save(); |
428 | 428 | |
429 | - if ( $new_form->exists() ) { |
|
430 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
431 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
429 | + if ($new_form->exists()) { |
|
430 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
431 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
432 | 432 | } else { |
433 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
434 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
433 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
434 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
435 | 435 | } |
436 | 436 | |
437 | - wp_redirect( $url ); |
|
437 | + wp_redirect($url); |
|
438 | 438 | exit; |
439 | 439 | } |
440 | 440 | |
@@ -443,16 +443,16 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @param array $args |
445 | 445 | */ |
446 | - public function send_customer_invoice( $args ) { |
|
447 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
446 | + public function send_customer_invoice($args) { |
|
447 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
448 | 448 | |
449 | - if ( $sent ) { |
|
450 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
449 | + if ($sent) { |
|
450 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
451 | 451 | } else { |
452 | - $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
452 | + $this->show_error(__('Could not send the invoice to the customer', 'invoicing')); |
|
453 | 453 | } |
454 | 454 | |
455 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
455 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
456 | 456 | exit; |
457 | 457 | } |
458 | 458 | |
@@ -461,16 +461,16 @@ discard block |
||
461 | 461 | * |
462 | 462 | * @param array $args |
463 | 463 | */ |
464 | - public function send_customer_payment_reminder( $args ) { |
|
465 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
464 | + public function send_customer_payment_reminder($args) { |
|
465 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
466 | 466 | |
467 | - if ( $sent ) { |
|
468 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
467 | + if ($sent) { |
|
468 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
469 | 469 | } else { |
470 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
470 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
471 | 471 | } |
472 | 472 | |
473 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
473 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
474 | 474 | exit; |
475 | 475 | } |
476 | 476 | |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | */ |
481 | 481 | public function admin_reset_tax_rates() { |
482 | 482 | |
483 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
484 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
483 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
484 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
485 | 485 | exit; |
486 | 486 | |
487 | 487 | } |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | public function admin_create_missing_pages() { |
494 | 494 | $installer = new GetPaid_Installer(); |
495 | 495 | $installer->create_pages(); |
496 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
497 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
496 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
497 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
498 | 498 | exit; |
499 | 499 | } |
500 | 500 | |
@@ -506,35 +506,35 @@ discard block |
||
506 | 506 | global $wpdb; |
507 | 507 | $installer = new GetPaid_Installer(); |
508 | 508 | |
509 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
509 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
510 | 510 | $installer->create_subscriptions_table(); |
511 | 511 | |
512 | - if ( $wpdb->last_error !== '' ) { |
|
513 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
512 | + if ($wpdb->last_error !== '') { |
|
513 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
517 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
518 | 518 | $installer->create_invoices_table(); |
519 | 519 | |
520 | - if ( $wpdb->last_error !== '' ) { |
|
521 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
520 | + if ($wpdb->last_error !== '') { |
|
521 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | |
525 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
525 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
526 | 526 | $installer->create_invoice_items_table(); |
527 | 527 | |
528 | - if ( $wpdb->last_error !== '' ) { |
|
529 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
528 | + if ($wpdb->last_error !== '') { |
|
529 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
530 | 530 | } |
531 | 531 | } |
532 | 532 | |
533 | - if ( ! $this->has_notices() ) { |
|
534 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
533 | + if (!$this->has_notices()) { |
|
534 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
535 | 535 | } |
536 | 536 | |
537 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
537 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
538 | 538 | exit; |
539 | 539 | } |
540 | 540 | |
@@ -549,10 +549,10 @@ discard block |
||
549 | 549 | $installer->migrate_old_invoices(); |
550 | 550 | |
551 | 551 | // Show an admin message. |
552 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
552 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
553 | 553 | |
554 | 554 | // Redirect the admin. |
555 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
555 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
556 | 556 | exit; |
557 | 557 | |
558 | 558 | } |
@@ -564,18 +564,18 @@ discard block |
||
564 | 564 | public function admin_download_customers() { |
565 | 565 | global $wpdb; |
566 | 566 | |
567 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
567 | + $output = fopen('php://output', 'w') or die(__('Unsupported server', 'invoicing')); |
|
568 | 568 | |
569 | - header( "Content-Type:text/csv" ); |
|
570 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
569 | + header("Content-Type:text/csv"); |
|
570 | + header("Content-Disposition:attachment;filename=customers.csv"); |
|
571 | 571 | |
572 | 572 | $post_types = ''; |
573 | 573 | |
574 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
575 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
574 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
575 | + $post_types .= $wpdb->prepare("post_type=%s OR ", $post_type); |
|
576 | 576 | } |
577 | 577 | |
578 | - $post_types = rtrim( $post_types, ' OR' ); |
|
578 | + $post_types = rtrim($post_types, ' OR'); |
|
579 | 579 | |
580 | 580 | $customers = $wpdb->get_col( |
581 | 581 | $wpdb->prepare( |
@@ -584,58 +584,58 @@ discard block |
||
584 | 584 | ); |
585 | 585 | |
586 | 586 | $columns = array( |
587 | - 'name' => __( 'Name', 'invoicing' ), |
|
588 | - 'email' => __( 'Email', 'invoicing' ), |
|
589 | - 'country' => __( 'Country', 'invoicing' ), |
|
590 | - 'state' => __( 'State', 'invoicing' ), |
|
591 | - 'city' => __( 'City', 'invoicing' ), |
|
592 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
593 | - 'address' => __( 'Address', 'invoicing' ), |
|
594 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
595 | - 'company' => __( 'Company', 'invoicing' ), |
|
596 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
597 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
598 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
599 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
587 | + 'name' => __('Name', 'invoicing'), |
|
588 | + 'email' => __('Email', 'invoicing'), |
|
589 | + 'country' => __('Country', 'invoicing'), |
|
590 | + 'state' => __('State', 'invoicing'), |
|
591 | + 'city' => __('City', 'invoicing'), |
|
592 | + 'zip' => __('ZIP', 'invoicing'), |
|
593 | + 'address' => __('Address', 'invoicing'), |
|
594 | + 'phone' => __('Phone', 'invoicing'), |
|
595 | + 'company' => __('Company', 'invoicing'), |
|
596 | + 'company_id' => __('Company ID', 'invoicing'), |
|
597 | + 'invoices' => __('Invoices', 'invoicing'), |
|
598 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
599 | + 'signup' => __('Date created', 'invoicing'), |
|
600 | 600 | ); |
601 | 601 | |
602 | 602 | // Output the csv column headers. |
603 | - fputcsv( $output, array_values( $columns ) ); |
|
603 | + fputcsv($output, array_values($columns)); |
|
604 | 604 | |
605 | 605 | // Loop through |
606 | 606 | $table = new WPInv_Customers_Table(); |
607 | - foreach ( $customers as $customer_id ) { |
|
607 | + foreach ($customers as $customer_id) { |
|
608 | 608 | |
609 | - $user = get_user_by( 'id', $customer_id ); |
|
609 | + $user = get_user_by('id', $customer_id); |
|
610 | 610 | $row = array(); |
611 | - if ( empty( $user ) ) { |
|
611 | + if (empty($user)) { |
|
612 | 612 | continue; |
613 | 613 | } |
614 | 614 | |
615 | - foreach ( array_keys( $columns ) as $column ) { |
|
615 | + foreach (array_keys($columns) as $column) { |
|
616 | 616 | |
617 | 617 | $method = 'column_' . $column; |
618 | 618 | |
619 | - if ( 'name' == $column ) { |
|
620 | - $value = esc_html( $user->display_name ); |
|
621 | - } else if( 'email' == $column ) { |
|
622 | - $value = sanitize_email( $user->user_email ); |
|
623 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
624 | - $value = strip_tags( $table->$method( $user ) ); |
|
619 | + if ('name' == $column) { |
|
620 | + $value = esc_html($user->display_name); |
|
621 | + } else if ('email' == $column) { |
|
622 | + $value = sanitize_email($user->user_email); |
|
623 | + } else if (is_callable(array($table, $method))) { |
|
624 | + $value = strip_tags($table->$method($user)); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( empty( $value ) ) { |
|
628 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
627 | + if (empty($value)) { |
|
628 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | $row[] = $value; |
632 | 632 | |
633 | 633 | } |
634 | 634 | |
635 | - fputcsv( $output, $row ); |
|
635 | + fputcsv($output, $row); |
|
636 | 636 | } |
637 | 637 | |
638 | - fclose( $output ); |
|
638 | + fclose($output); |
|
639 | 639 | exit; |
640 | 640 | |
641 | 641 | } |
@@ -645,29 +645,29 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @param array $data |
647 | 647 | */ |
648 | - public function admin_install_plugin( $data ) { |
|
648 | + public function admin_install_plugin($data) { |
|
649 | 649 | |
650 | - if ( ! empty( $data['plugins'] ) ) { |
|
650 | + if (!empty($data['plugins'])) { |
|
651 | 651 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
652 | 652 | wp_cache_flush(); |
653 | 653 | |
654 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
655 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
656 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
657 | - $installed = $upgrader->install( $plugin_zip ); |
|
654 | + foreach ($data['plugins'] as $slug => $file) { |
|
655 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
656 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
657 | + $installed = $upgrader->install($plugin_zip); |
|
658 | 658 | |
659 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
660 | - activate_plugin( $file, '', false, true ); |
|
659 | + if (!is_wp_error($installed) && $installed) { |
|
660 | + activate_plugin($file, '', false, true); |
|
661 | 661 | } else { |
662 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
662 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | } |
666 | 666 | |
667 | 667 | } |
668 | 668 | |
669 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
670 | - wp_safe_redirect( $redirect ); |
|
669 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
670 | + wp_safe_redirect($redirect); |
|
671 | 671 | exit; |
672 | 672 | |
673 | 673 | } |
@@ -677,42 +677,42 @@ discard block |
||
677 | 677 | * |
678 | 678 | * @param array $data |
679 | 679 | */ |
680 | - public function admin_connect_gateway( $data ) { |
|
680 | + public function admin_connect_gateway($data) { |
|
681 | 681 | |
682 | - if ( ! empty( $data['plugin'] ) ) { |
|
682 | + if (!empty($data['plugin'])) { |
|
683 | 683 | |
684 | - $gateway = sanitize_key( $data['plugin'] ); |
|
685 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
684 | + $gateway = sanitize_key($data['plugin']); |
|
685 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
686 | 686 | |
687 | - if ( ! empty( $connect_url ) ) { |
|
688 | - wp_redirect( $connect_url ); |
|
687 | + if (!empty($connect_url)) { |
|
688 | + wp_redirect($connect_url); |
|
689 | 689 | exit; |
690 | 690 | } |
691 | 691 | |
692 | - if ( 'stripe' == $data['plugin'] ) { |
|
692 | + if ('stripe' == $data['plugin']) { |
|
693 | 693 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
694 | 694 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
695 | 695 | wp_cache_flush(); |
696 | 696 | |
697 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
698 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
699 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
700 | - $upgrader->install( $plugin_zip ); |
|
697 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
698 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
699 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
700 | + $upgrader->install($plugin_zip); |
|
701 | 701 | } |
702 | 702 | |
703 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
703 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
704 | 704 | } |
705 | 705 | |
706 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
707 | - if ( ! empty( $connect_url ) ) { |
|
708 | - wp_redirect( $connect_url ); |
|
706 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
707 | + if (!empty($connect_url)) { |
|
708 | + wp_redirect($connect_url); |
|
709 | 709 | exit; |
710 | 710 | } |
711 | 711 | |
712 | 712 | } |
713 | 713 | |
714 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
715 | - wp_safe_redirect( $redirect ); |
|
714 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
715 | + wp_safe_redirect($redirect); |
|
716 | 716 | exit; |
717 | 717 | |
718 | 718 | } |
@@ -726,36 +726,36 @@ discard block |
||
726 | 726 | |
727 | 727 | // Fetch all invoices that have discount codes. |
728 | 728 | $table = $wpdb->prefix . 'getpaid_invoices'; |
729 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
729 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
730 | 730 | |
731 | - foreach ( $invoices as $invoice ) { |
|
731 | + foreach ($invoices as $invoice) { |
|
732 | 732 | |
733 | - $invoice = new WPInv_Invoice( $invoice ); |
|
733 | + $invoice = new WPInv_Invoice($invoice); |
|
734 | 734 | |
735 | - if ( ! $invoice->exists() ) { |
|
735 | + if (!$invoice->exists()) { |
|
736 | 736 | continue; |
737 | 737 | } |
738 | 738 | |
739 | 739 | // Abort if the discount does not exist or does not apply here. |
740 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
741 | - if ( ! $discount->exists() ) { |
|
740 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
741 | + if (!$discount->exists()) { |
|
742 | 742 | continue; |
743 | 743 | } |
744 | 744 | |
745 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
745 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
746 | 746 | $invoice->recalculate_total(); |
747 | 747 | |
748 | - if ( $invoice->get_total_discount() > 0 ) { |
|
748 | + if ($invoice->get_total_discount() > 0) { |
|
749 | 749 | $invoice->save(); |
750 | 750 | } |
751 | 751 | |
752 | 752 | } |
753 | 753 | |
754 | 754 | // Show an admin message. |
755 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
755 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
756 | 756 | |
757 | 757 | // Redirect the admin. |
758 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
758 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
759 | 759 | exit; |
760 | 760 | |
761 | 761 | } |
@@ -767,8 +767,8 @@ discard block |
||
767 | 767 | * @return array |
768 | 768 | */ |
769 | 769 | public function get_notices() { |
770 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
771 | - return is_array( $notices ) ? $notices : array(); |
|
770 | + $notices = get_option('wpinv_admin_notices'); |
|
771 | + return is_array($notices) ? $notices : array(); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | * @return array |
779 | 779 | */ |
780 | 780 | public function has_notices() { |
781 | - return count( $this->get_notices() ) > 0; |
|
781 | + return count($this->get_notices()) > 0; |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | * @since 1.0.19 |
789 | 789 | */ |
790 | 790 | public function clear_notices() { |
791 | - delete_option( 'wpinv_admin_notices' ); |
|
791 | + delete_option('wpinv_admin_notices'); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
@@ -797,16 +797,16 @@ discard block |
||
797 | 797 | * @access public |
798 | 798 | * @since 1.0.19 |
799 | 799 | */ |
800 | - public function save_notice( $type, $message ) { |
|
800 | + public function save_notice($type, $message) { |
|
801 | 801 | $notices = $this->get_notices(); |
802 | 802 | |
803 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
804 | - $notices[ $type ] = array(); |
|
803 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
804 | + $notices[$type] = array(); |
|
805 | 805 | } |
806 | 806 | |
807 | - $notices[ $type ][] = $message; |
|
807 | + $notices[$type][] = $message; |
|
808 | 808 | |
809 | - update_option( 'wpinv_admin_notices', $notices ); |
|
809 | + update_option('wpinv_admin_notices', $notices); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -816,8 +816,8 @@ discard block |
||
816 | 816 | * @access public |
817 | 817 | * @since 1.0.19 |
818 | 818 | */ |
819 | - public function show_success( $msg ) { |
|
820 | - $this->save_notice( 'success', $msg ); |
|
819 | + public function show_success($msg) { |
|
820 | + $this->save_notice('success', $msg); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
@@ -827,8 +827,8 @@ discard block |
||
827 | 827 | * @param string $msg The message to qeue. |
828 | 828 | * @since 1.0.19 |
829 | 829 | */ |
830 | - public function show_error( $msg ) { |
|
831 | - $this->save_notice( 'error', $msg ); |
|
830 | + public function show_error($msg) { |
|
831 | + $this->save_notice('error', $msg); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | /** |
@@ -838,8 +838,8 @@ discard block |
||
838 | 838 | * @param string $msg The message to qeue. |
839 | 839 | * @since 1.0.19 |
840 | 840 | */ |
841 | - public function show_warning( $msg ) { |
|
842 | - $this->save_notice( 'warning', $msg ); |
|
841 | + public function show_warning($msg) { |
|
842 | + $this->save_notice('warning', $msg); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -849,8 +849,8 @@ discard block |
||
849 | 849 | * @param string $msg The message to qeue. |
850 | 850 | * @since 1.0.19 |
851 | 851 | */ |
852 | - public function show_info( $msg ) { |
|
853 | - $this->save_notice( 'info', $msg ); |
|
852 | + public function show_info($msg) { |
|
853 | + $this->save_notice('info', $msg); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -864,30 +864,30 @@ discard block |
||
864 | 864 | $notices = $this->get_notices(); |
865 | 865 | $this->clear_notices(); |
866 | 866 | |
867 | - foreach ( $notices as $type => $messages ) { |
|
867 | + foreach ($notices as $type => $messages) { |
|
868 | 868 | |
869 | - if ( ! is_array( $messages ) ) { |
|
869 | + if (!is_array($messages)) { |
|
870 | 870 | continue; |
871 | 871 | } |
872 | 872 | |
873 | - $type = sanitize_key( $type ); |
|
874 | - foreach ( $messages as $message ) { |
|
875 | - $message = wp_kses_post( $message ); |
|
873 | + $type = sanitize_key($type); |
|
874 | + foreach ($messages as $message) { |
|
875 | + $message = wp_kses_post($message); |
|
876 | 876 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
877 | 877 | } |
878 | 878 | |
879 | 879 | } |
880 | 880 | |
881 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
881 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
882 | 882 | |
883 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
884 | - $url = wp_nonce_url( |
|
885 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
883 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
884 | + $url = wp_nonce_url( |
|
885 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
886 | 886 | 'getpaid-nonce', |
887 | 887 | 'getpaid-nonce' |
888 | 888 | ); |
889 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
890 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
889 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
890 | + $message2 = __('Generate Pages', 'invoicing'); |
|
891 | 891 | echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
892 | 892 | break; |
893 | 893 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
17 | 17 | |
18 | - /** |
|
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
23 | - public static function output( $post ) { |
|
18 | + /** |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | + public static function output( $post ) { |
|
24 | 24 | |
25 | - // Retrieve shipping address. |
|
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
25 | + // Retrieve shipping address. |
|
26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
27 | 27 | |
28 | - // Abort if it is invalid. |
|
29 | - if ( ! is_array( $shipping_address ) ) { |
|
30 | - return; |
|
31 | - } |
|
28 | + // Abort if it is invalid. |
|
29 | + if ( ! is_array( $shipping_address ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
@@ -55,31 +55,31 @@ discard block |
||
55 | 55 | |
56 | 56 | <?php |
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Prepares a value. |
|
62 | - * |
|
63 | - * @param array $address |
|
64 | - * @param string $key |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function prepare_for_display( $address, $key ) { |
|
60 | + /** |
|
61 | + * Prepares a value. |
|
62 | + * |
|
63 | + * @param array $address |
|
64 | + * @param string $key |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function prepare_for_display( $address, $key ) { |
|
68 | 68 | |
69 | - // Prepare the value. |
|
70 | - $value = $address[ $key ]; |
|
69 | + // Prepare the value. |
|
70 | + $value = $address[ $key ]; |
|
71 | 71 | |
72 | - if ( $key == 'country' ) { |
|
73 | - $value = wpinv_country_name( $value ); |
|
74 | - } |
|
72 | + if ( $key == 'country' ) { |
|
73 | + $value = wpinv_country_name( $value ); |
|
74 | + } |
|
75 | 75 | |
76 | - if ( $key == 'state' ) { |
|
77 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | - $value = wpinv_state_name( $value, $country ); |
|
79 | - } |
|
76 | + if ( $key == 'state' ) { |
|
77 | + $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | + $value = wpinv_state_name( $value, $country ); |
|
79 | + } |
|
80 | 80 | |
81 | - return esc_html( $value ); |
|
81 | + return esc_html( $value ); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | |
25 | 25 | // Retrieve shipping address. |
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
26 | + $shipping_address = get_post_meta($post->ID, 'shipping_address', true); |
|
27 | 27 | |
28 | 28 | // Abort if it is invalid. |
29 | - if ( ! is_array( $shipping_address ) ) { |
|
29 | + if (!is_array($shipping_address)) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
37 | - <?php foreach ( getpaid_user_address_fields() as $key => $label ) : ?> |
|
37 | + <?php foreach (getpaid_user_address_fields() as $key => $label) : ?> |
|
38 | 38 | |
39 | - <?php if ( ! empty( $shipping_address[ $key ] ) ) : ?> |
|
39 | + <?php if (!empty($shipping_address[$key])) : ?> |
|
40 | 40 | |
41 | 41 | <div class="form-group form-row"> |
42 | 42 | <div class="col"> |
43 | - <span style="font-weight: 600"><?php echo esc_html( $label ); ?>:</span> |
|
43 | + <span style="font-weight: 600"><?php echo esc_html($label); ?>:</span> |
|
44 | 44 | </div> |
45 | 45 | <div class="col"> |
46 | - <?php echo self::prepare_for_display( $shipping_address, $key ); ?> |
|
46 | + <?php echo self::prepare_for_display($shipping_address, $key); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | * @param string $key |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - public static function prepare_for_display( $address, $key ) { |
|
67 | + public static function prepare_for_display($address, $key) { |
|
68 | 68 | |
69 | 69 | // Prepare the value. |
70 | - $value = $address[ $key ]; |
|
70 | + $value = $address[$key]; |
|
71 | 71 | |
72 | - if ( $key == 'country' ) { |
|
73 | - $value = wpinv_country_name( $value ); |
|
72 | + if ($key == 'country') { |
|
73 | + $value = wpinv_country_name($value); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( $key == 'state' ) { |
|
77 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | - $value = wpinv_state_name( $value, $country ); |
|
76 | + if ($key == 'state') { |
|
77 | + $country = isset($address['country']) ? $address['country'] : wpinv_get_default_country(); |
|
78 | + $value = wpinv_state_name($value, $country); |
|
79 | 79 | } |
80 | 80 | |
81 | - return esc_html( $value ); |
|
81 | + return esc_html($value); |
|
82 | 82 | |
83 | 83 | } |
84 | 84 |