@@ -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 | ); |
@@ -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 | } |
@@ -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 |
@@ -13,703 +13,703 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - } |
|
131 | - |
|
132 | - return $actions; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + } |
|
131 | + |
|
132 | + return $actions; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | 136 | * Remove bulk edit option from admin side quote listing |
137 | 137 | * |
138 | 138 | * @since 1.0.0 |
139 | 139 | * @param array $actions post actions |
140 | - * @param WP_Post $post |
|
140 | + * @param WP_Post $post |
|
141 | 141 | * @return array $actions actions without edit option |
142 | 142 | */ |
143 | 143 | public static function filter_invoice_row_actions( $actions, $post ) { |
144 | 144 | |
145 | 145 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
146 | 146 | |
147 | - $actions = array(); |
|
148 | - $invoice = new WPInv_Invoice( $post ); |
|
149 | - |
|
150 | - $actions['edit'] = sprintf( |
|
151 | - '<a href="%1$s">%2$s</a>', |
|
152 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
153 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
154 | - ); |
|
155 | - |
|
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - |
|
158 | - $actions['view'] = sprintf( |
|
159 | - '<a href="%1$s">%2$s</a>', |
|
160 | - esc_url( $invoice->get_view_url() ), |
|
161 | - sprintf( |
|
162 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
163 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
164 | - ) |
|
165 | - ); |
|
166 | - |
|
167 | - $actions['send'] = sprintf( |
|
168 | - '<a href="%1$s">%2$s</a>', |
|
169 | - esc_url( |
|
170 | - wp_nonce_url( |
|
171 | - add_query_arg( |
|
172 | - array( |
|
173 | - 'getpaid-admin-action' => 'send_invoice', |
|
174 | - 'invoice_id' => $invoice->get_id() |
|
175 | - ) |
|
176 | - ), |
|
177 | - 'getpaid-nonce', |
|
178 | - 'getpaid-nonce' |
|
179 | - ) |
|
180 | - ), |
|
181 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
182 | - ); |
|
183 | - |
|
184 | - } |
|
147 | + $actions = array(); |
|
148 | + $invoice = new WPInv_Invoice( $post ); |
|
149 | + |
|
150 | + $actions['edit'] = sprintf( |
|
151 | + '<a href="%1$s">%2$s</a>', |
|
152 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
153 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
154 | + ); |
|
155 | + |
|
156 | + if ( ! $invoice->is_draft() ) { |
|
157 | + |
|
158 | + $actions['view'] = sprintf( |
|
159 | + '<a href="%1$s">%2$s</a>', |
|
160 | + esc_url( $invoice->get_view_url() ), |
|
161 | + sprintf( |
|
162 | + esc_html( __( 'View %s', 'invoicing' ) ), |
|
163 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
164 | + ) |
|
165 | + ); |
|
166 | + |
|
167 | + $actions['send'] = sprintf( |
|
168 | + '<a href="%1$s">%2$s</a>', |
|
169 | + esc_url( |
|
170 | + wp_nonce_url( |
|
171 | + add_query_arg( |
|
172 | + array( |
|
173 | + 'getpaid-admin-action' => 'send_invoice', |
|
174 | + 'invoice_id' => $invoice->get_id() |
|
175 | + ) |
|
176 | + ), |
|
177 | + 'getpaid-nonce', |
|
178 | + 'getpaid-nonce' |
|
179 | + ) |
|
180 | + ), |
|
181 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
182 | + ); |
|
183 | + |
|
184 | + } |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | return $actions; |
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Returns an array of invoice table columns. |
|
193 | - */ |
|
194 | - public static function invoice_columns( $columns ) { |
|
195 | - |
|
196 | - $columns = array( |
|
197 | - 'cb' => $columns['cb'], |
|
198 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
199 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
200 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
201 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
202 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
203 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
204 | - 'status' => __( 'Status', 'invoicing' ), |
|
205 | - ); |
|
206 | - |
|
207 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Displays invoice table columns. |
|
212 | - */ |
|
213 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
214 | - |
|
215 | - $invoice = new WPInv_Invoice( $post_id ); |
|
216 | - |
|
217 | - switch ( $column_name ) { |
|
218 | - |
|
219 | - case 'invoice_date' : |
|
220 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
221 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
222 | - echo "<span title='$date_time'>$date</span>"; |
|
223 | - break; |
|
224 | - |
|
225 | - case 'payment_date' : |
|
226 | - |
|
227 | - if ( $invoice->is_paid() ) { |
|
228 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
229 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
230 | - echo "<span title='$date_time'>$date</span>"; |
|
231 | - } else { |
|
232 | - echo "—"; |
|
233 | - } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Returns an array of invoice table columns. |
|
193 | + */ |
|
194 | + public static function invoice_columns( $columns ) { |
|
195 | + |
|
196 | + $columns = array( |
|
197 | + 'cb' => $columns['cb'], |
|
198 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
199 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
200 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
201 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
202 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
203 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
204 | + 'status' => __( 'Status', 'invoicing' ), |
|
205 | + ); |
|
206 | + |
|
207 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Displays invoice table columns. |
|
212 | + */ |
|
213 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
214 | + |
|
215 | + $invoice = new WPInv_Invoice( $post_id ); |
|
216 | + |
|
217 | + switch ( $column_name ) { |
|
218 | + |
|
219 | + case 'invoice_date' : |
|
220 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
221 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
222 | + echo "<span title='$date_time'>$date</span>"; |
|
223 | + break; |
|
224 | + |
|
225 | + case 'payment_date' : |
|
226 | + |
|
227 | + if ( $invoice->is_paid() ) { |
|
228 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
229 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
230 | + echo "<span title='$date_time'>$date</span>"; |
|
231 | + } else { |
|
232 | + echo "—"; |
|
233 | + } |
|
234 | 234 | |
235 | - break; |
|
235 | + break; |
|
236 | 236 | |
237 | - case 'amount' : |
|
237 | + case 'amount' : |
|
238 | 238 | |
239 | - $amount = $invoice->get_total(); |
|
240 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
239 | + $amount = $invoice->get_total(); |
|
240 | + $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
241 | 241 | |
242 | - if ( $invoice->is_refunded() ) { |
|
243 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
244 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
245 | - } else { |
|
242 | + if ( $invoice->is_refunded() ) { |
|
243 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
244 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
245 | + } else { |
|
246 | 246 | |
247 | - $discount = $invoice->get_total_discount(); |
|
247 | + $discount = $invoice->get_total_discount(); |
|
248 | 248 | |
249 | - if ( ! empty( $discount ) ) { |
|
250 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
251 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
252 | - } else { |
|
253 | - echo $formated_amount; |
|
254 | - } |
|
249 | + if ( ! empty( $discount ) ) { |
|
250 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
251 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
252 | + } else { |
|
253 | + echo $formated_amount; |
|
254 | + } |
|
255 | 255 | |
256 | - } |
|
256 | + } |
|
257 | 257 | |
258 | - break; |
|
258 | + break; |
|
259 | 259 | |
260 | - case 'status' : |
|
261 | - $status = esc_html( $invoice->get_status() ); |
|
262 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
260 | + case 'status' : |
|
261 | + $status = esc_html( $invoice->get_status() ); |
|
262 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
263 | 263 | |
264 | - // If it is paid, show the gateway title. |
|
265 | - if ( $invoice->is_paid() ) { |
|
266 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
267 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
264 | + // If it is paid, show the gateway title. |
|
265 | + if ( $invoice->is_paid() ) { |
|
266 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
267 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
268 | 268 | |
269 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
270 | - } else { |
|
271 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
272 | - } |
|
269 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
270 | + } else { |
|
271 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
272 | + } |
|
273 | 273 | |
274 | - // If it is not paid, display the overdue and view status. |
|
275 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
274 | + // If it is not paid, display the overdue and view status. |
|
275 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
276 | 276 | |
277 | - // Invoice view status. |
|
278 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
279 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
280 | - } else { |
|
281 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
282 | - } |
|
277 | + // Invoice view status. |
|
278 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
279 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
280 | + } else { |
|
281 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
282 | + } |
|
283 | 283 | |
284 | - // Display the overview status. |
|
285 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
286 | - $due_date = $invoice->get_due_date(); |
|
287 | - $fomatted = getpaid_format_date( $due_date ); |
|
284 | + // Display the overview status. |
|
285 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
286 | + $due_date = $invoice->get_due_date(); |
|
287 | + $fomatted = getpaid_format_date( $due_date ); |
|
288 | 288 | |
289 | - if ( ! empty( $fomatted ) ) { |
|
290 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
291 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
292 | - } |
|
293 | - } |
|
289 | + if ( ! empty( $fomatted ) ) { |
|
290 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
291 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
292 | + } |
|
293 | + } |
|
294 | 294 | |
295 | - } |
|
295 | + } |
|
296 | 296 | |
297 | - break; |
|
297 | + break; |
|
298 | 298 | |
299 | - case 'recurring': |
|
299 | + case 'recurring': |
|
300 | 300 | |
301 | - if ( $invoice->is_recurring() ) { |
|
302 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
303 | - } else { |
|
304 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
305 | - } |
|
306 | - break; |
|
301 | + if ( $invoice->is_recurring() ) { |
|
302 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
303 | + } else { |
|
304 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
305 | + } |
|
306 | + break; |
|
307 | 307 | |
308 | - case 'number' : |
|
308 | + case 'number' : |
|
309 | 309 | |
310 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
311 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
312 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
310 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
311 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
312 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
313 | 313 | |
314 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
314 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
315 | 315 | |
316 | - break; |
|
316 | + break; |
|
317 | 317 | |
318 | - case 'customer' : |
|
318 | + case 'customer' : |
|
319 | 319 | |
320 | - $customer_name = $invoice->get_user_full_name(); |
|
320 | + $customer_name = $invoice->get_user_full_name(); |
|
321 | 321 | |
322 | - if ( empty( $customer_name ) ) { |
|
323 | - $customer_name = $invoice->get_email(); |
|
324 | - } |
|
322 | + if ( empty( $customer_name ) ) { |
|
323 | + $customer_name = $invoice->get_email(); |
|
324 | + } |
|
325 | 325 | |
326 | - if ( ! empty( $customer_name ) ) { |
|
327 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
328 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
329 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
330 | - } else { |
|
331 | - echo '<div>—</div>'; |
|
332 | - } |
|
326 | + if ( ! empty( $customer_name ) ) { |
|
327 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
328 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
329 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
330 | + } else { |
|
331 | + echo '<div>—</div>'; |
|
332 | + } |
|
333 | 333 | |
334 | - break; |
|
334 | + break; |
|
335 | 335 | |
336 | - } |
|
336 | + } |
|
337 | 337 | |
338 | - } |
|
338 | + } |
|
339 | 339 | |
340 | - /** |
|
341 | - * Displays invoice bulk actions. |
|
342 | - */ |
|
343 | - public static function invoice_bulk_actions( $actions ) { |
|
344 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
345 | - return $actions; |
|
346 | - } |
|
340 | + /** |
|
341 | + * Displays invoice bulk actions. |
|
342 | + */ |
|
343 | + public static function invoice_bulk_actions( $actions ) { |
|
344 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
345 | + return $actions; |
|
346 | + } |
|
347 | 347 | |
348 | - /** |
|
349 | - * Processes invoice bulk actions. |
|
350 | - */ |
|
351 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
348 | + /** |
|
349 | + * Processes invoice bulk actions. |
|
350 | + */ |
|
351 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
352 | 352 | |
353 | - if ( $action == 'resend-invoice' ) { |
|
353 | + if ( $action == 'resend-invoice' ) { |
|
354 | 354 | |
355 | - $success = false; |
|
356 | - foreach ( $post_ids as $post_id ) { |
|
357 | - $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
358 | - } |
|
355 | + $success = false; |
|
356 | + foreach ( $post_ids as $post_id ) { |
|
357 | + $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
358 | + } |
|
359 | 359 | |
360 | - if ( $success ) { |
|
361 | - getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
362 | - } else { |
|
363 | - getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
364 | - } |
|
360 | + if ( $success ) { |
|
361 | + getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
362 | + } else { |
|
363 | + getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
364 | + } |
|
365 | 365 | |
366 | - } |
|
366 | + } |
|
367 | 367 | |
368 | - return $redirect_url; |
|
368 | + return $redirect_url; |
|
369 | 369 | |
370 | - } |
|
370 | + } |
|
371 | 371 | |
372 | - /** |
|
373 | - * Returns an array of payment forms table columns. |
|
374 | - */ |
|
375 | - public static function payment_form_columns( $columns ) { |
|
372 | + /** |
|
373 | + * Returns an array of payment forms table columns. |
|
374 | + */ |
|
375 | + public static function payment_form_columns( $columns ) { |
|
376 | 376 | |
377 | - $columns = array( |
|
378 | - 'cb' => $columns['cb'], |
|
379 | - 'title' => __( 'Name', 'invoicing' ), |
|
380 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
381 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
382 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
383 | - 'items' => __( 'Items', 'invoicing' ), |
|
384 | - 'date' => __( 'Date', 'invoicing' ), |
|
385 | - ); |
|
377 | + $columns = array( |
|
378 | + 'cb' => $columns['cb'], |
|
379 | + 'title' => __( 'Name', 'invoicing' ), |
|
380 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
381 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
382 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
383 | + 'items' => __( 'Items', 'invoicing' ), |
|
384 | + 'date' => __( 'Date', 'invoicing' ), |
|
385 | + ); |
|
386 | 386 | |
387 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
387 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
388 | 388 | |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - /** |
|
392 | - * Displays payment form table columns. |
|
393 | - */ |
|
394 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
391 | + /** |
|
392 | + * Displays payment form table columns. |
|
393 | + */ |
|
394 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
395 | 395 | |
396 | - // Retrieve the payment form. |
|
397 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
396 | + // Retrieve the payment form. |
|
397 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
398 | 398 | |
399 | - switch ( $column_name ) { |
|
399 | + switch ( $column_name ) { |
|
400 | 400 | |
401 | - case 'earnings' : |
|
402 | - echo wpinv_price( $form->get_earned() ); |
|
403 | - break; |
|
401 | + case 'earnings' : |
|
402 | + echo wpinv_price( $form->get_earned() ); |
|
403 | + break; |
|
404 | 404 | |
405 | - case 'refunds' : |
|
406 | - echo wpinv_price( $form->get_refunded() ); |
|
407 | - break; |
|
405 | + case 'refunds' : |
|
406 | + echo wpinv_price( $form->get_refunded() ); |
|
407 | + break; |
|
408 | 408 | |
409 | - case 'refunds' : |
|
410 | - echo wpinv_price( $form->get_refunded() ); |
|
411 | - break; |
|
409 | + case 'refunds' : |
|
410 | + echo wpinv_price( $form->get_refunded() ); |
|
411 | + break; |
|
412 | 412 | |
413 | - case 'shortcode' : |
|
413 | + case 'shortcode' : |
|
414 | 414 | |
415 | - if ( $form->is_default() ) { |
|
416 | - echo '—'; |
|
417 | - } else { |
|
418 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
419 | - } |
|
415 | + if ( $form->is_default() ) { |
|
416 | + echo '—'; |
|
417 | + } else { |
|
418 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
419 | + } |
|
420 | 420 | |
421 | - break; |
|
421 | + break; |
|
422 | 422 | |
423 | - case 'items' : |
|
423 | + case 'items' : |
|
424 | 424 | |
425 | - $items = $form->get_items(); |
|
425 | + $items = $form->get_items(); |
|
426 | 426 | |
427 | - if ( $form->is_default() || empty( $items ) ) { |
|
428 | - echo '—'; |
|
429 | - return; |
|
430 | - } |
|
427 | + if ( $form->is_default() || empty( $items ) ) { |
|
428 | + echo '—'; |
|
429 | + return; |
|
430 | + } |
|
431 | 431 | |
432 | - $_items = array(); |
|
432 | + $_items = array(); |
|
433 | 433 | |
434 | - foreach ( $items as $item ) { |
|
435 | - $url = $item->get_edit_url(); |
|
434 | + foreach ( $items as $item ) { |
|
435 | + $url = $item->get_edit_url(); |
|
436 | 436 | |
437 | - if ( empty( $url ) ) { |
|
438 | - $_items[] = esc_html( $item->get_name() ); |
|
439 | - } else { |
|
440 | - $_items[] = sprintf( |
|
441 | - '<a href="%s">%s</a>', |
|
442 | - esc_url( $url ), |
|
443 | - esc_html( $item->get_name() ) |
|
444 | - ); |
|
445 | - } |
|
437 | + if ( empty( $url ) ) { |
|
438 | + $_items[] = esc_html( $item->get_name() ); |
|
439 | + } else { |
|
440 | + $_items[] = sprintf( |
|
441 | + '<a href="%s">%s</a>', |
|
442 | + esc_url( $url ), |
|
443 | + esc_html( $item->get_name() ) |
|
444 | + ); |
|
445 | + } |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - echo implode( '<br>', $_items ); |
|
449 | + echo implode( '<br>', $_items ); |
|
450 | 450 | |
451 | - break; |
|
451 | + break; |
|
452 | 452 | |
453 | - } |
|
453 | + } |
|
454 | 454 | |
455 | - } |
|
455 | + } |
|
456 | 456 | |
457 | - /** |
|
458 | - * Filters post states. |
|
459 | - */ |
|
460 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
457 | + /** |
|
458 | + * Filters post states. |
|
459 | + */ |
|
460 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
461 | 461 | |
462 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
463 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
464 | - } |
|
462 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
463 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
464 | + } |
|
465 | 465 | |
466 | - return $post_states; |
|
467 | - |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Returns an array of coupon table columns. |
|
472 | - */ |
|
473 | - public static function discount_columns( $columns ) { |
|
474 | - |
|
475 | - $columns = array( |
|
476 | - 'cb' => $columns['cb'], |
|
477 | - 'title' => __( 'Name', 'invoicing' ), |
|
478 | - 'code' => __( 'Code', 'invoicing' ), |
|
479 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
480 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
481 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
482 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
483 | - ); |
|
484 | - |
|
485 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Filters post states. |
|
490 | - */ |
|
491 | - public static function filter_discount_state( $post_states, $post ) { |
|
492 | - |
|
493 | - if ( 'wpi_discount' == $post->post_type ) { |
|
494 | - |
|
495 | - $discount = new WPInv_Discount( $post ); |
|
496 | - |
|
497 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
498 | - |
|
499 | - if ( $status != 'publish' ) { |
|
500 | - return array( |
|
501 | - 'discount_status' => wpinv_discount_status( $status ), |
|
502 | - ); |
|
503 | - } |
|
504 | - |
|
505 | - return array(); |
|
506 | - |
|
507 | - } |
|
508 | - |
|
509 | - return $post_states; |
|
510 | - |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Returns an array of items table columns. |
|
515 | - */ |
|
516 | - public static function item_columns( $columns ) { |
|
517 | - |
|
518 | - $columns = array( |
|
519 | - 'cb' => $columns['cb'], |
|
520 | - 'title' => __( 'Name', 'invoicing' ), |
|
521 | - 'price' => __( 'Price', 'invoicing' ), |
|
522 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
523 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
524 | - 'type' => __( 'Type', 'invoicing' ), |
|
525 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
526 | - ); |
|
527 | - |
|
528 | - if ( ! wpinv_use_taxes() ) { |
|
529 | - unset( $columns['vat_rule'] ); |
|
530 | - unset( $columns['vat_class'] ); |
|
531 | - } |
|
532 | - |
|
533 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
534 | - } |
|
535 | - |
|
536 | - /** |
|
537 | - * Returns an array of sortable items table columns. |
|
538 | - */ |
|
539 | - public static function sortable_item_columns( $columns ) { |
|
540 | - |
|
541 | - return array_merge( |
|
542 | - $columns, |
|
543 | - array( |
|
544 | - 'price' => 'price', |
|
545 | - 'vat_rule' => 'vat_rule', |
|
546 | - 'vat_class' => 'vat_class', |
|
547 | - 'type' => 'type', |
|
548 | - ) |
|
549 | - ); |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Displays items table columns. |
|
555 | - */ |
|
556 | - public static function display_item_columns( $column_name, $post_id ) { |
|
466 | + return $post_states; |
|
467 | + |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Returns an array of coupon table columns. |
|
472 | + */ |
|
473 | + public static function discount_columns( $columns ) { |
|
474 | + |
|
475 | + $columns = array( |
|
476 | + 'cb' => $columns['cb'], |
|
477 | + 'title' => __( 'Name', 'invoicing' ), |
|
478 | + 'code' => __( 'Code', 'invoicing' ), |
|
479 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
480 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
481 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
482 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
483 | + ); |
|
484 | + |
|
485 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Filters post states. |
|
490 | + */ |
|
491 | + public static function filter_discount_state( $post_states, $post ) { |
|
492 | + |
|
493 | + if ( 'wpi_discount' == $post->post_type ) { |
|
494 | + |
|
495 | + $discount = new WPInv_Discount( $post ); |
|
496 | + |
|
497 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
498 | + |
|
499 | + if ( $status != 'publish' ) { |
|
500 | + return array( |
|
501 | + 'discount_status' => wpinv_discount_status( $status ), |
|
502 | + ); |
|
503 | + } |
|
504 | + |
|
505 | + return array(); |
|
506 | + |
|
507 | + } |
|
508 | + |
|
509 | + return $post_states; |
|
510 | + |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Returns an array of items table columns. |
|
515 | + */ |
|
516 | + public static function item_columns( $columns ) { |
|
517 | + |
|
518 | + $columns = array( |
|
519 | + 'cb' => $columns['cb'], |
|
520 | + 'title' => __( 'Name', 'invoicing' ), |
|
521 | + 'price' => __( 'Price', 'invoicing' ), |
|
522 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
523 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
524 | + 'type' => __( 'Type', 'invoicing' ), |
|
525 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
526 | + ); |
|
527 | + |
|
528 | + if ( ! wpinv_use_taxes() ) { |
|
529 | + unset( $columns['vat_rule'] ); |
|
530 | + unset( $columns['vat_class'] ); |
|
531 | + } |
|
532 | + |
|
533 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Returns an array of sortable items table columns. |
|
538 | + */ |
|
539 | + public static function sortable_item_columns( $columns ) { |
|
540 | + |
|
541 | + return array_merge( |
|
542 | + $columns, |
|
543 | + array( |
|
544 | + 'price' => 'price', |
|
545 | + 'vat_rule' => 'vat_rule', |
|
546 | + 'vat_class' => 'vat_class', |
|
547 | + 'type' => 'type', |
|
548 | + ) |
|
549 | + ); |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Displays items table columns. |
|
555 | + */ |
|
556 | + public static function display_item_columns( $column_name, $post_id ) { |
|
557 | 557 | |
558 | - $item = new WPInv_Item( $post_id ); |
|
558 | + $item = new WPInv_Item( $post_id ); |
|
559 | 559 | |
560 | - switch ( $column_name ) { |
|
560 | + switch ( $column_name ) { |
|
561 | 561 | |
562 | - case 'price' : |
|
562 | + case 'price' : |
|
563 | 563 | |
564 | - if ( ! $item->is_recurring() ) { |
|
565 | - echo $item->get_the_price(); |
|
566 | - break; |
|
567 | - } |
|
564 | + if ( ! $item->is_recurring() ) { |
|
565 | + echo $item->get_the_price(); |
|
566 | + break; |
|
567 | + } |
|
568 | 568 | |
569 | - $price = wp_sprintf( |
|
570 | - __( '%s / %s', 'invoicing' ), |
|
571 | - $item->get_the_price(), |
|
572 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
573 | - ); |
|
569 | + $price = wp_sprintf( |
|
570 | + __( '%s / %s', 'invoicing' ), |
|
571 | + $item->get_the_price(), |
|
572 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
573 | + ); |
|
574 | 574 | |
575 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
576 | - echo $price; |
|
577 | - break; |
|
578 | - } |
|
575 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
576 | + echo $price; |
|
577 | + break; |
|
578 | + } |
|
579 | 579 | |
580 | - echo $item->get_the_initial_price(); |
|
580 | + echo $item->get_the_initial_price(); |
|
581 | 581 | |
582 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
583 | - break; |
|
582 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
583 | + break; |
|
584 | 584 | |
585 | - case 'vat_rule' : |
|
586 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
587 | - break; |
|
585 | + case 'vat_rule' : |
|
586 | + echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
587 | + break; |
|
588 | 588 | |
589 | - case 'vat_class' : |
|
590 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
591 | - break; |
|
589 | + case 'vat_class' : |
|
590 | + echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
591 | + break; |
|
592 | 592 | |
593 | - case 'shortcode' : |
|
594 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
595 | - break; |
|
593 | + case 'shortcode' : |
|
594 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
595 | + break; |
|
596 | 596 | |
597 | - case 'type' : |
|
598 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
599 | - break; |
|
597 | + case 'type' : |
|
598 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
599 | + break; |
|
600 | 600 | |
601 | - } |
|
601 | + } |
|
602 | 602 | |
603 | - } |
|
603 | + } |
|
604 | 604 | |
605 | - /** |
|
606 | - * Lets users filter items using taxes. |
|
607 | - */ |
|
608 | - public static function add_item_filters( $post_type ) { |
|
605 | + /** |
|
606 | + * Lets users filter items using taxes. |
|
607 | + */ |
|
608 | + public static function add_item_filters( $post_type ) { |
|
609 | 609 | |
610 | - // Abort if we're not dealing with items. |
|
611 | - if ( $post_type != 'wpi_item' ) { |
|
612 | - return; |
|
613 | - } |
|
610 | + // Abort if we're not dealing with items. |
|
611 | + if ( $post_type != 'wpi_item' ) { |
|
612 | + return; |
|
613 | + } |
|
614 | 614 | |
615 | - // Filter by vat rules. |
|
616 | - if ( wpinv_use_taxes() ) { |
|
615 | + // Filter by vat rules. |
|
616 | + if ( wpinv_use_taxes() ) { |
|
617 | 617 | |
618 | - // Sanitize selected vat rule. |
|
619 | - $vat_rule = ''; |
|
620 | - $vat_rules = getpaid_get_tax_rules(); |
|
621 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
622 | - $vat_rule = $_GET['vat_rule']; |
|
623 | - } |
|
624 | - |
|
625 | - // Filter by VAT rule. |
|
626 | - echo wpinv_html_select( |
|
627 | - array( |
|
628 | - 'options' => array_merge( |
|
629 | - array( |
|
630 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
631 | - ), |
|
632 | - $vat_rules |
|
633 | - ), |
|
634 | - 'name' => 'vat_rule', |
|
635 | - 'id' => 'vat_rule', |
|
636 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
637 | - 'show_option_all' => false, |
|
638 | - 'show_option_none' => false, |
|
639 | - ) |
|
640 | - ); |
|
641 | - |
|
642 | - // Filter by VAT class. |
|
618 | + // Sanitize selected vat rule. |
|
619 | + $vat_rule = ''; |
|
620 | + $vat_rules = getpaid_get_tax_rules(); |
|
621 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
622 | + $vat_rule = $_GET['vat_rule']; |
|
623 | + } |
|
624 | + |
|
625 | + // Filter by VAT rule. |
|
626 | + echo wpinv_html_select( |
|
627 | + array( |
|
628 | + 'options' => array_merge( |
|
629 | + array( |
|
630 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
631 | + ), |
|
632 | + $vat_rules |
|
633 | + ), |
|
634 | + 'name' => 'vat_rule', |
|
635 | + 'id' => 'vat_rule', |
|
636 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
637 | + 'show_option_all' => false, |
|
638 | + 'show_option_none' => false, |
|
639 | + ) |
|
640 | + ); |
|
641 | + |
|
642 | + // Filter by VAT class. |
|
643 | 643 | |
644 | - // Sanitize selected vat rule. |
|
645 | - $vat_class = ''; |
|
646 | - $vat_classes = getpaid_get_tax_classes(); |
|
647 | - if ( isset( $_GET['vat_class'] ) ) { |
|
648 | - $vat_class = $_GET['vat_class']; |
|
649 | - } |
|
650 | - |
|
651 | - echo wpinv_html_select( |
|
652 | - array( |
|
653 | - 'options' => array_merge( |
|
654 | - array( |
|
655 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
656 | - ), |
|
657 | - $vat_classes |
|
658 | - ), |
|
659 | - 'name' => 'vat_class', |
|
660 | - 'id' => 'vat_class', |
|
661 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
662 | - 'show_option_all' => false, |
|
663 | - 'show_option_none' => false, |
|
664 | - ) |
|
665 | - ); |
|
666 | - |
|
667 | - } |
|
668 | - |
|
669 | - // Filter by item type. |
|
670 | - $type = ''; |
|
671 | - if ( isset( $_GET['type'] ) ) { |
|
672 | - $type = $_GET['type']; |
|
673 | - } |
|
674 | - |
|
675 | - echo wpinv_html_select( |
|
676 | - array( |
|
677 | - 'options' => array_merge( |
|
678 | - array( |
|
679 | - '' => __( 'All item types', 'invoicing' ) |
|
680 | - ), |
|
681 | - wpinv_get_item_types() |
|
682 | - ), |
|
683 | - 'name' => 'type', |
|
684 | - 'id' => 'type', |
|
685 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
686 | - 'show_option_all' => false, |
|
687 | - 'show_option_none' => false, |
|
688 | - ) |
|
689 | - ); |
|
690 | - |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Filters the item query. |
|
695 | - */ |
|
696 | - public static function filter_item_query( $query ) { |
|
697 | - |
|
698 | - // modify the query only if it admin and main query. |
|
699 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
700 | - return $query; |
|
701 | - } |
|
702 | - |
|
703 | - // we want to modify the query for our items. |
|
704 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
705 | - return $query; |
|
706 | - } |
|
707 | - |
|
708 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
709 | - $query->query_vars['meta_query'] = array(); |
|
710 | - } |
|
711 | - |
|
712 | - // Filter vat rule type |
|
644 | + // Sanitize selected vat rule. |
|
645 | + $vat_class = ''; |
|
646 | + $vat_classes = getpaid_get_tax_classes(); |
|
647 | + if ( isset( $_GET['vat_class'] ) ) { |
|
648 | + $vat_class = $_GET['vat_class']; |
|
649 | + } |
|
650 | + |
|
651 | + echo wpinv_html_select( |
|
652 | + array( |
|
653 | + 'options' => array_merge( |
|
654 | + array( |
|
655 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
656 | + ), |
|
657 | + $vat_classes |
|
658 | + ), |
|
659 | + 'name' => 'vat_class', |
|
660 | + 'id' => 'vat_class', |
|
661 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
662 | + 'show_option_all' => false, |
|
663 | + 'show_option_none' => false, |
|
664 | + ) |
|
665 | + ); |
|
666 | + |
|
667 | + } |
|
668 | + |
|
669 | + // Filter by item type. |
|
670 | + $type = ''; |
|
671 | + if ( isset( $_GET['type'] ) ) { |
|
672 | + $type = $_GET['type']; |
|
673 | + } |
|
674 | + |
|
675 | + echo wpinv_html_select( |
|
676 | + array( |
|
677 | + 'options' => array_merge( |
|
678 | + array( |
|
679 | + '' => __( 'All item types', 'invoicing' ) |
|
680 | + ), |
|
681 | + wpinv_get_item_types() |
|
682 | + ), |
|
683 | + 'name' => 'type', |
|
684 | + 'id' => 'type', |
|
685 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
686 | + 'show_option_all' => false, |
|
687 | + 'show_option_none' => false, |
|
688 | + ) |
|
689 | + ); |
|
690 | + |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Filters the item query. |
|
695 | + */ |
|
696 | + public static function filter_item_query( $query ) { |
|
697 | + |
|
698 | + // modify the query only if it admin and main query. |
|
699 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
700 | + return $query; |
|
701 | + } |
|
702 | + |
|
703 | + // we want to modify the query for our items. |
|
704 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
705 | + return $query; |
|
706 | + } |
|
707 | + |
|
708 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
709 | + $query->query_vars['meta_query'] = array(); |
|
710 | + } |
|
711 | + |
|
712 | + // Filter vat rule type |
|
713 | 713 | if ( ! empty( $_GET['vat_rule'] ) ) { |
714 | 714 | $query->query_vars['meta_query'][] = array( |
715 | 715 | 'key' => '_wpinv_vat_rule', |
@@ -734,97 +734,97 @@ discard block |
||
734 | 734 | 'value' => sanitize_text_field( $_GET['type'] ), |
735 | 735 | 'compare' => '=' |
736 | 736 | ); |
737 | - } |
|
738 | - |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * Reorders items. |
|
743 | - */ |
|
744 | - public static function reorder_items( $vars ) { |
|
745 | - global $typenow; |
|
746 | - |
|
747 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
748 | - return $vars; |
|
749 | - } |
|
750 | - |
|
751 | - // By item type. |
|
752 | - if ( 'type' == $vars['orderby'] ) { |
|
753 | - return array_merge( |
|
754 | - $vars, |
|
755 | - array( |
|
756 | - 'meta_key' => '_wpinv_type', |
|
757 | - 'orderby' => 'meta_value' |
|
758 | - ) |
|
759 | - ); |
|
760 | - } |
|
761 | - |
|
762 | - // By vat class. |
|
763 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
764 | - return array_merge( |
|
765 | - $vars, |
|
766 | - array( |
|
767 | - 'meta_key' => '_wpinv_vat_class', |
|
768 | - 'orderby' => 'meta_value' |
|
769 | - ) |
|
770 | - ); |
|
771 | - } |
|
772 | - |
|
773 | - // By vat rule. |
|
774 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
775 | - return array_merge( |
|
776 | - $vars, |
|
777 | - array( |
|
778 | - 'meta_key' => '_wpinv_vat_rule', |
|
779 | - 'orderby' => 'meta_value' |
|
780 | - ) |
|
781 | - ); |
|
782 | - } |
|
783 | - |
|
784 | - // By price. |
|
785 | - if ( 'price' == $vars['orderby'] ) { |
|
786 | - return array_merge( |
|
787 | - $vars, |
|
788 | - array( |
|
789 | - 'meta_key' => '_wpinv_price', |
|
790 | - 'orderby' => 'meta_value_num' |
|
791 | - ) |
|
792 | - ); |
|
793 | - } |
|
794 | - |
|
795 | - return $vars; |
|
796 | - |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Fired when deleting a post. |
|
801 | - */ |
|
802 | - public static function delete_post( $post_id ) { |
|
803 | - |
|
804 | - switch ( get_post_type( $post_id ) ) { |
|
805 | - |
|
806 | - case 'wpi_item' : |
|
807 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
808 | - break; |
|
809 | - |
|
810 | - case 'wpi_payment_form' : |
|
811 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
812 | - break; |
|
813 | - |
|
814 | - case 'wpi_discount' : |
|
815 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
816 | - break; |
|
817 | - |
|
818 | - case 'wpi_invoice' : |
|
819 | - $invoice = new WPInv_Invoice( $post_id ); |
|
820 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
821 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
822 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
823 | - break; |
|
824 | - } |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
737 | + } |
|
738 | + |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Reorders items. |
|
743 | + */ |
|
744 | + public static function reorder_items( $vars ) { |
|
745 | + global $typenow; |
|
746 | + |
|
747 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
748 | + return $vars; |
|
749 | + } |
|
750 | + |
|
751 | + // By item type. |
|
752 | + if ( 'type' == $vars['orderby'] ) { |
|
753 | + return array_merge( |
|
754 | + $vars, |
|
755 | + array( |
|
756 | + 'meta_key' => '_wpinv_type', |
|
757 | + 'orderby' => 'meta_value' |
|
758 | + ) |
|
759 | + ); |
|
760 | + } |
|
761 | + |
|
762 | + // By vat class. |
|
763 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
764 | + return array_merge( |
|
765 | + $vars, |
|
766 | + array( |
|
767 | + 'meta_key' => '_wpinv_vat_class', |
|
768 | + 'orderby' => 'meta_value' |
|
769 | + ) |
|
770 | + ); |
|
771 | + } |
|
772 | + |
|
773 | + // By vat rule. |
|
774 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
775 | + return array_merge( |
|
776 | + $vars, |
|
777 | + array( |
|
778 | + 'meta_key' => '_wpinv_vat_rule', |
|
779 | + 'orderby' => 'meta_value' |
|
780 | + ) |
|
781 | + ); |
|
782 | + } |
|
783 | + |
|
784 | + // By price. |
|
785 | + if ( 'price' == $vars['orderby'] ) { |
|
786 | + return array_merge( |
|
787 | + $vars, |
|
788 | + array( |
|
789 | + 'meta_key' => '_wpinv_price', |
|
790 | + 'orderby' => 'meta_value_num' |
|
791 | + ) |
|
792 | + ); |
|
793 | + } |
|
794 | + |
|
795 | + return $vars; |
|
796 | + |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Fired when deleting a post. |
|
801 | + */ |
|
802 | + public static function delete_post( $post_id ) { |
|
803 | + |
|
804 | + switch ( get_post_type( $post_id ) ) { |
|
805 | + |
|
806 | + case 'wpi_item' : |
|
807 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
808 | + break; |
|
809 | + |
|
810 | + case 'wpi_payment_form' : |
|
811 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
812 | + break; |
|
813 | + |
|
814 | + case 'wpi_discount' : |
|
815 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
816 | + break; |
|
817 | + |
|
818 | + case 'wpi_invoice' : |
|
819 | + $invoice = new WPInv_Invoice( $post_id ); |
|
820 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
821 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
822 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
823 | + break; |
|
824 | + } |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | 828 | * Add a post display state for special GetPaid pages in the page list table. |
829 | 829 | * |
830 | 830 | * @param array $post_states An array of post display states. |
@@ -838,22 +838,22 @@ discard block |
||
838 | 838 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
839 | 839 | } |
840 | 840 | |
841 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
841 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
842 | 842 | |
843 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
844 | - $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
845 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
846 | - $label |
|
847 | - ); |
|
848 | - } |
|
843 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
844 | + $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
845 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
846 | + $label |
|
847 | + ); |
|
848 | + } |
|
849 | 849 | |
850 | - } |
|
850 | + } |
|
851 | 851 | |
852 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
852 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
853 | 853 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
854 | 854 | } |
855 | 855 | |
856 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
856 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
857 | 857 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
858 | 858 | } |
859 | 859 |
@@ -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 | * Post types Admin Class |
@@ -21,74 +21,74 @@ discard block |
||
21 | 21 | GetPaid_Metaboxes::init(); |
22 | 22 | |
23 | 23 | // Filter the post updated messages. |
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
25 | 25 | |
26 | 26 | // Filter post actions. |
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2); |
|
29 | 29 | |
30 | 30 | // Invoice table columns. |
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
31 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
32 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
33 | + add_filter('bulk_actions-edit-wpi_invoice', array(__CLASS__, 'invoice_bulk_actions')); |
|
34 | + add_filter('handle_bulk_actions-edit-wpi_invoice', array(__CLASS__, 'handle_invoice_bulk_actions'), 10, 3); |
|
35 | 35 | |
36 | 36 | // Items table columns. |
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
37 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
38 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
39 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
40 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
41 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
42 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
43 | 43 | |
44 | 44 | // Payment forms columns. |
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
46 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
47 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
48 | 48 | |
49 | 49 | // Discount table columns. |
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
50 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
51 | + add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100); |
|
52 | 52 | |
53 | 53 | // Deleting posts. |
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
54 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
55 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
56 | 56 | |
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
57 | + add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Post updated messages. |
62 | 62 | */ |
63 | - public static function post_updated_messages( $messages ) { |
|
63 | + public static function post_updated_messages($messages) { |
|
64 | 64 | global $post; |
65 | 65 | |
66 | 66 | $messages['wpi_discount'] = array( |
67 | 67 | 0 => '', |
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
68 | + 1 => __('Discount updated.', 'invoicing'), |
|
69 | + 2 => __('Custom field updated.', 'invoicing'), |
|
70 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
71 | + 4 => __('Discount updated.', 'invoicing'), |
|
72 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
73 | + 6 => __('Discount updated.', 'invoicing'), |
|
74 | + 7 => __('Discount saved.', 'invoicing'), |
|
75 | + 8 => __('Discount submitted.', 'invoicing'), |
|
76 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
77 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | $messages['wpi_payment_form'] = array( |
81 | 81 | 0 => '', |
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
82 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
83 | + 2 => __('Custom field updated.', 'invoicing'), |
|
84 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
85 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
86 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
87 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
88 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
89 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
90 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
91 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
92 | 92 | ); |
93 | 93 | |
94 | 94 | return $messages; |
@@ -98,19 +98,19 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * Post row actions. |
100 | 100 | */ |
101 | - public static function post_row_actions( $actions, $post ) { |
|
101 | + public static function post_row_actions($actions, $post) { |
|
102 | 102 | |
103 | - $post = get_post( $post ); |
|
103 | + $post = get_post($post); |
|
104 | 104 | |
105 | 105 | // We do not want to edit the default payment form. |
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
106 | + if ('wpi_payment_form' == $post->post_type) { |
|
107 | 107 | |
108 | - if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
108 | + if ($post->ID == wpinv_get_default_payment_form()) { |
|
109 | + unset($actions['trash']); |
|
110 | + unset($actions['inline hide-if-no-js']); |
|
111 | 111 | } |
112 | 112 | |
113 | - $actions['duplicate'] = sprintf( |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | 114 | '<a href="%1$s">%2$s</a>', |
115 | 115 | esc_url( |
116 | 116 | wp_nonce_url( |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'getpaid-nonce' |
125 | 125 | ) |
126 | 126 | ), |
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
127 | + esc_html(__('Duplicate', 'invoicing')) |
|
128 | 128 | ); |
129 | 129 | |
130 | 130 | } |
@@ -140,31 +140,31 @@ discard block |
||
140 | 140 | * @param WP_Post $post |
141 | 141 | * @return array $actions actions without edit option |
142 | 142 | */ |
143 | - public static function filter_invoice_row_actions( $actions, $post ) { |
|
143 | + public static function filter_invoice_row_actions($actions, $post) { |
|
144 | 144 | |
145 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
145 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
146 | 146 | |
147 | 147 | $actions = array(); |
148 | - $invoice = new WPInv_Invoice( $post ); |
|
148 | + $invoice = new WPInv_Invoice($post); |
|
149 | 149 | |
150 | - $actions['edit'] = sprintf( |
|
150 | + $actions['edit'] = sprintf( |
|
151 | 151 | '<a href="%1$s">%2$s</a>', |
152 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
153 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
152 | + esc_url(get_edit_post_link($invoice->get_id())), |
|
153 | + esc_html(__('Edit', 'invoicing')) |
|
154 | 154 | ); |
155 | 155 | |
156 | - if ( ! $invoice->is_draft() ) { |
|
156 | + if (!$invoice->is_draft()) { |
|
157 | 157 | |
158 | - $actions['view'] = sprintf( |
|
158 | + $actions['view'] = sprintf( |
|
159 | 159 | '<a href="%1$s">%2$s</a>', |
160 | - esc_url( $invoice->get_view_url() ), |
|
160 | + esc_url($invoice->get_view_url()), |
|
161 | 161 | sprintf( |
162 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
163 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
162 | + esc_html(__('View %s', 'invoicing')), |
|
163 | + getpaid_get_post_type_label($invoice->get_post_type(), false) |
|
164 | 164 | ) |
165 | 165 | ); |
166 | 166 | |
167 | - $actions['send'] = sprintf( |
|
167 | + $actions['send'] = sprintf( |
|
168 | 168 | '<a href="%1$s">%2$s</a>', |
169 | 169 | esc_url( |
170 | 170 | wp_nonce_url( |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | 'getpaid-nonce' |
179 | 179 | ) |
180 | 180 | ), |
181 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
181 | + esc_html(__('Send to Customer', 'invoicing')) |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | } |
@@ -191,42 +191,42 @@ discard block |
||
191 | 191 | /** |
192 | 192 | * Returns an array of invoice table columns. |
193 | 193 | */ |
194 | - public static function invoice_columns( $columns ) { |
|
194 | + public static function invoice_columns($columns) { |
|
195 | 195 | |
196 | 196 | $columns = array( |
197 | 197 | 'cb' => $columns['cb'], |
198 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
199 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
200 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
201 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
202 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
203 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
204 | - 'status' => __( 'Status', 'invoicing' ), |
|
198 | + 'number' => __('Invoice', 'invoicing'), |
|
199 | + 'customer' => __('Customer', 'invoicing'), |
|
200 | + 'invoice_date' => __('Created', 'invoicing'), |
|
201 | + 'payment_date' => __('Completed', 'invoicing'), |
|
202 | + 'amount' => __('Amount', 'invoicing'), |
|
203 | + 'recurring' => __('Recurring', 'invoicing'), |
|
204 | + 'status' => __('Status', 'invoicing'), |
|
205 | 205 | ); |
206 | 206 | |
207 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
207 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Displays invoice table columns. |
212 | 212 | */ |
213 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
213 | + public static function display_invoice_columns($column_name, $post_id) { |
|
214 | 214 | |
215 | - $invoice = new WPInv_Invoice( $post_id ); |
|
215 | + $invoice = new WPInv_Invoice($post_id); |
|
216 | 216 | |
217 | - switch ( $column_name ) { |
|
217 | + switch ($column_name) { |
|
218 | 218 | |
219 | 219 | case 'invoice_date' : |
220 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
221 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
220 | + $date_time = esc_attr($invoice->get_created_date()); |
|
221 | + $date = getpaid_format_date_value($date_time, "—", true); |
|
222 | 222 | echo "<span title='$date_time'>$date</span>"; |
223 | 223 | break; |
224 | 224 | |
225 | 225 | case 'payment_date' : |
226 | 226 | |
227 | - if ( $invoice->is_paid() ) { |
|
228 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
229 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
227 | + if ($invoice->is_paid()) { |
|
228 | + $date_time = esc_attr($invoice->get_completed_date()); |
|
229 | + $date = getpaid_format_date_value($date_time, "—", true); |
|
230 | 230 | echo "<span title='$date_time'>$date</span>"; |
231 | 231 | } else { |
232 | 232 | echo "—"; |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | case 'amount' : |
238 | 238 | |
239 | 239 | $amount = $invoice->get_total(); |
240 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
240 | + $formated_amount = wpinv_price($amount, $invoice->get_currency()); |
|
241 | 241 | |
242 | - if ( $invoice->is_refunded() ) { |
|
243 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
242 | + if ($invoice->is_refunded()) { |
|
243 | + $refunded_amount = wpinv_price(0, $invoice->get_currency()); |
|
244 | 244 | echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
245 | 245 | } else { |
246 | 246 | |
247 | 247 | $discount = $invoice->get_total_discount(); |
248 | 248 | |
249 | - if ( ! empty( $discount ) ) { |
|
250 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
249 | + if (!empty($discount)) { |
|
250 | + $new_amount = wpinv_price($amount + $discount, $invoice->get_currency()); |
|
251 | 251 | echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
252 | 252 | } else { |
253 | 253 | echo $formated_amount; |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | break; |
259 | 259 | |
260 | 260 | case 'status' : |
261 | - $status = esc_html( $invoice->get_status() ); |
|
262 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
261 | + $status = esc_html($invoice->get_status()); |
|
262 | + $status_label = esc_html($invoice->get_status_nicename()); |
|
263 | 263 | |
264 | 264 | // If it is paid, show the gateway title. |
265 | - if ( $invoice->is_paid() ) { |
|
266 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
267 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
265 | + if ($invoice->is_paid()) { |
|
266 | + $gateway = esc_html($invoice->get_gateway_title()); |
|
267 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
268 | 268 | |
269 | 269 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
270 | 270 | } else { |
@@ -272,22 +272,22 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | // If it is not paid, display the overdue and view status. |
275 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
275 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
276 | 276 | |
277 | 277 | // Invoice view status. |
278 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
279 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
278 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
279 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
280 | 280 | } else { |
281 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
281 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // Display the overview status. |
285 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
285 | + if (wpinv_get_option('overdue_active')) { |
|
286 | 286 | $due_date = $invoice->get_due_date(); |
287 | - $fomatted = getpaid_format_date( $due_date ); |
|
287 | + $fomatted = getpaid_format_date($due_date); |
|
288 | 288 | |
289 | - if ( ! empty( $fomatted ) ) { |
|
290 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
289 | + if (!empty($fomatted)) { |
|
290 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted); |
|
291 | 291 | echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
292 | 292 | } |
293 | 293 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | |
299 | 299 | case 'recurring': |
300 | 300 | |
301 | - if ( $invoice->is_recurring() ) { |
|
301 | + if ($invoice->is_recurring()) { |
|
302 | 302 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
303 | 303 | } else { |
304 | 304 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -307,9 +307,9 @@ discard block |
||
307 | 307 | |
308 | 308 | case 'number' : |
309 | 309 | |
310 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
311 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
312 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
310 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
311 | + $invoice_number = esc_html($invoice->get_number()); |
|
312 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
313 | 313 | |
314 | 314 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
315 | 315 | |
@@ -319,13 +319,13 @@ discard block |
||
319 | 319 | |
320 | 320 | $customer_name = $invoice->get_user_full_name(); |
321 | 321 | |
322 | - if ( empty( $customer_name ) ) { |
|
322 | + if (empty($customer_name)) { |
|
323 | 323 | $customer_name = $invoice->get_email(); |
324 | 324 | } |
325 | 325 | |
326 | - if ( ! empty( $customer_name ) ) { |
|
327 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
328 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
326 | + if (!empty($customer_name)) { |
|
327 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
328 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
329 | 329 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
330 | 330 | } else { |
331 | 331 | echo '<div>—</div>'; |
@@ -340,27 +340,27 @@ discard block |
||
340 | 340 | /** |
341 | 341 | * Displays invoice bulk actions. |
342 | 342 | */ |
343 | - public static function invoice_bulk_actions( $actions ) { |
|
344 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
343 | + public static function invoice_bulk_actions($actions) { |
|
344 | + $actions['resend-invoice'] = __('Send to Customer', 'invoicing'); |
|
345 | 345 | return $actions; |
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * Processes invoice bulk actions. |
350 | 350 | */ |
351 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
351 | + public static function handle_invoice_bulk_actions($redirect_url, $action, $post_ids) { |
|
352 | 352 | |
353 | - if ( $action == 'resend-invoice' ) { |
|
353 | + if ($action == 'resend-invoice') { |
|
354 | 354 | |
355 | 355 | $success = false; |
356 | - foreach ( $post_ids as $post_id ) { |
|
357 | - $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
356 | + foreach ($post_ids as $post_id) { |
|
357 | + $success = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($post_id), true); |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( $success ) { |
|
361 | - getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
360 | + if ($success) { |
|
361 | + getpaid_admin()->show_success(__('Invoices were successfully sent', 'invoicing')); |
|
362 | 362 | } else { |
363 | - getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
363 | + getpaid_admin()->show_error(__('Could not send some invoices', 'invoicing')); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | } |
@@ -372,50 +372,50 @@ discard block |
||
372 | 372 | /** |
373 | 373 | * Returns an array of payment forms table columns. |
374 | 374 | */ |
375 | - public static function payment_form_columns( $columns ) { |
|
375 | + public static function payment_form_columns($columns) { |
|
376 | 376 | |
377 | 377 | $columns = array( |
378 | 378 | 'cb' => $columns['cb'], |
379 | - 'title' => __( 'Name', 'invoicing' ), |
|
380 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
381 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
382 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
383 | - 'items' => __( 'Items', 'invoicing' ), |
|
384 | - 'date' => __( 'Date', 'invoicing' ), |
|
379 | + 'title' => __('Name', 'invoicing'), |
|
380 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
381 | + 'earnings' => __('Revenue', 'invoicing'), |
|
382 | + 'refunds' => __('Refunded', 'invoicing'), |
|
383 | + 'items' => __('Items', 'invoicing'), |
|
384 | + 'date' => __('Date', 'invoicing'), |
|
385 | 385 | ); |
386 | 386 | |
387 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
387 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
392 | 392 | * Displays payment form table columns. |
393 | 393 | */ |
394 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
394 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
395 | 395 | |
396 | 396 | // Retrieve the payment form. |
397 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
397 | + $form = new GetPaid_Payment_Form($post_id); |
|
398 | 398 | |
399 | - switch ( $column_name ) { |
|
399 | + switch ($column_name) { |
|
400 | 400 | |
401 | 401 | case 'earnings' : |
402 | - echo wpinv_price( $form->get_earned() ); |
|
402 | + echo wpinv_price($form->get_earned()); |
|
403 | 403 | break; |
404 | 404 | |
405 | 405 | case 'refunds' : |
406 | - echo wpinv_price( $form->get_refunded() ); |
|
406 | + echo wpinv_price($form->get_refunded()); |
|
407 | 407 | break; |
408 | 408 | |
409 | 409 | case 'refunds' : |
410 | - echo wpinv_price( $form->get_refunded() ); |
|
410 | + echo wpinv_price($form->get_refunded()); |
|
411 | 411 | break; |
412 | 412 | |
413 | 413 | case 'shortcode' : |
414 | 414 | |
415 | - if ( $form->is_default() ) { |
|
415 | + if ($form->is_default()) { |
|
416 | 416 | echo '—'; |
417 | 417 | } else { |
418 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
418 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | break; |
@@ -424,29 +424,29 @@ discard block |
||
424 | 424 | |
425 | 425 | $items = $form->get_items(); |
426 | 426 | |
427 | - if ( $form->is_default() || empty( $items ) ) { |
|
427 | + if ($form->is_default() || empty($items)) { |
|
428 | 428 | echo '—'; |
429 | 429 | return; |
430 | 430 | } |
431 | 431 | |
432 | 432 | $_items = array(); |
433 | 433 | |
434 | - foreach ( $items as $item ) { |
|
434 | + foreach ($items as $item) { |
|
435 | 435 | $url = $item->get_edit_url(); |
436 | 436 | |
437 | - if ( empty( $url ) ) { |
|
438 | - $_items[] = esc_html( $item->get_name() ); |
|
437 | + if (empty($url)) { |
|
438 | + $_items[] = esc_html($item->get_name()); |
|
439 | 439 | } else { |
440 | 440 | $_items[] = sprintf( |
441 | 441 | '<a href="%s">%s</a>', |
442 | - esc_url( $url ), |
|
443 | - esc_html( $item->get_name() ) |
|
442 | + esc_url($url), |
|
443 | + esc_html($item->get_name()) |
|
444 | 444 | ); |
445 | 445 | } |
446 | 446 | |
447 | 447 | } |
448 | 448 | |
449 | - echo implode( '<br>', $_items ); |
|
449 | + echo implode('<br>', $_items); |
|
450 | 450 | |
451 | 451 | break; |
452 | 452 | |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * Filters post states. |
459 | 459 | */ |
460 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
460 | + public static function filter_payment_form_state($post_states, $post) { |
|
461 | 461 | |
462 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
463 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
462 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
463 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | return $post_states; |
@@ -470,35 +470,35 @@ discard block |
||
470 | 470 | /** |
471 | 471 | * Returns an array of coupon table columns. |
472 | 472 | */ |
473 | - public static function discount_columns( $columns ) { |
|
473 | + public static function discount_columns($columns) { |
|
474 | 474 | |
475 | 475 | $columns = array( |
476 | 476 | 'cb' => $columns['cb'], |
477 | - 'title' => __( 'Name', 'invoicing' ), |
|
478 | - 'code' => __( 'Code', 'invoicing' ), |
|
479 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
480 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
481 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
482 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
477 | + 'title' => __('Name', 'invoicing'), |
|
478 | + 'code' => __('Code', 'invoicing'), |
|
479 | + 'amount' => __('Amount', 'invoicing'), |
|
480 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
481 | + 'start_date' => __('Start Date', 'invoicing'), |
|
482 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
483 | 483 | ); |
484 | 484 | |
485 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
485 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
489 | 489 | * Filters post states. |
490 | 490 | */ |
491 | - public static function filter_discount_state( $post_states, $post ) { |
|
491 | + public static function filter_discount_state($post_states, $post) { |
|
492 | 492 | |
493 | - if ( 'wpi_discount' == $post->post_type ) { |
|
493 | + if ('wpi_discount' == $post->post_type) { |
|
494 | 494 | |
495 | - $discount = new WPInv_Discount( $post ); |
|
495 | + $discount = new WPInv_Discount($post); |
|
496 | 496 | |
497 | 497 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
498 | 498 | |
499 | - if ( $status != 'publish' ) { |
|
499 | + if ($status != 'publish') { |
|
500 | 500 | return array( |
501 | - 'discount_status' => wpinv_discount_status( $status ), |
|
501 | + 'discount_status' => wpinv_discount_status($status), |
|
502 | 502 | ); |
503 | 503 | } |
504 | 504 | |
@@ -513,30 +513,30 @@ discard block |
||
513 | 513 | /** |
514 | 514 | * Returns an array of items table columns. |
515 | 515 | */ |
516 | - public static function item_columns( $columns ) { |
|
516 | + public static function item_columns($columns) { |
|
517 | 517 | |
518 | 518 | $columns = array( |
519 | 519 | 'cb' => $columns['cb'], |
520 | - 'title' => __( 'Name', 'invoicing' ), |
|
521 | - 'price' => __( 'Price', 'invoicing' ), |
|
522 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
523 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
524 | - 'type' => __( 'Type', 'invoicing' ), |
|
525 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
520 | + 'title' => __('Name', 'invoicing'), |
|
521 | + 'price' => __('Price', 'invoicing'), |
|
522 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
523 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
524 | + 'type' => __('Type', 'invoicing'), |
|
525 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
526 | 526 | ); |
527 | 527 | |
528 | - if ( ! wpinv_use_taxes() ) { |
|
529 | - unset( $columns['vat_rule'] ); |
|
530 | - unset( $columns['vat_class'] ); |
|
528 | + if (!wpinv_use_taxes()) { |
|
529 | + unset($columns['vat_rule']); |
|
530 | + unset($columns['vat_class']); |
|
531 | 531 | } |
532 | 532 | |
533 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
533 | + return apply_filters('wpi_item_table_columns', $columns); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | 537 | * Returns an array of sortable items table columns. |
538 | 538 | */ |
539 | - public static function sortable_item_columns( $columns ) { |
|
539 | + public static function sortable_item_columns($columns) { |
|
540 | 540 | |
541 | 541 | return array_merge( |
542 | 542 | $columns, |
@@ -553,49 +553,49 @@ discard block |
||
553 | 553 | /** |
554 | 554 | * Displays items table columns. |
555 | 555 | */ |
556 | - public static function display_item_columns( $column_name, $post_id ) { |
|
556 | + public static function display_item_columns($column_name, $post_id) { |
|
557 | 557 | |
558 | - $item = new WPInv_Item( $post_id ); |
|
558 | + $item = new WPInv_Item($post_id); |
|
559 | 559 | |
560 | - switch ( $column_name ) { |
|
560 | + switch ($column_name) { |
|
561 | 561 | |
562 | 562 | case 'price' : |
563 | 563 | |
564 | - if ( ! $item->is_recurring() ) { |
|
564 | + if (!$item->is_recurring()) { |
|
565 | 565 | echo $item->get_the_price(); |
566 | 566 | break; |
567 | 567 | } |
568 | 568 | |
569 | 569 | $price = wp_sprintf( |
570 | - __( '%s / %s', 'invoicing' ), |
|
570 | + __('%s / %s', 'invoicing'), |
|
571 | 571 | $item->get_the_price(), |
572 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
572 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
573 | 573 | ); |
574 | 574 | |
575 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
575 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
576 | 576 | echo $price; |
577 | 577 | break; |
578 | 578 | } |
579 | 579 | |
580 | 580 | echo $item->get_the_initial_price(); |
581 | 581 | |
582 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
582 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
583 | 583 | break; |
584 | 584 | |
585 | 585 | case 'vat_rule' : |
586 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
586 | + echo getpaid_get_tax_rule_label($item->get_vat_rule()); |
|
587 | 587 | break; |
588 | 588 | |
589 | 589 | case 'vat_class' : |
590 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
590 | + echo getpaid_get_tax_class_label($item->get_vat_class()); |
|
591 | 591 | break; |
592 | 592 | |
593 | 593 | case 'shortcode' : |
594 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
594 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
595 | 595 | break; |
596 | 596 | |
597 | 597 | case 'type' : |
598 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
598 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
599 | 599 | break; |
600 | 600 | |
601 | 601 | } |
@@ -605,21 +605,21 @@ discard block |
||
605 | 605 | /** |
606 | 606 | * Lets users filter items using taxes. |
607 | 607 | */ |
608 | - public static function add_item_filters( $post_type ) { |
|
608 | + public static function add_item_filters($post_type) { |
|
609 | 609 | |
610 | 610 | // Abort if we're not dealing with items. |
611 | - if ( $post_type != 'wpi_item' ) { |
|
611 | + if ($post_type != 'wpi_item') { |
|
612 | 612 | return; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Filter by vat rules. |
616 | - if ( wpinv_use_taxes() ) { |
|
616 | + if (wpinv_use_taxes()) { |
|
617 | 617 | |
618 | 618 | // Sanitize selected vat rule. |
619 | 619 | $vat_rule = ''; |
620 | 620 | $vat_rules = getpaid_get_tax_rules(); |
621 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
622 | - $vat_rule = $_GET['vat_rule']; |
|
621 | + if (isset($_GET['vat_rule'])) { |
|
622 | + $vat_rule = $_GET['vat_rule']; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // Filter by VAT rule. |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | array( |
628 | 628 | 'options' => array_merge( |
629 | 629 | array( |
630 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
630 | + '' => __('All VAT rules', 'invoicing') |
|
631 | 631 | ), |
632 | 632 | $vat_rules |
633 | 633 | ), |
634 | 634 | 'name' => 'vat_rule', |
635 | 635 | 'id' => 'vat_rule', |
636 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
636 | + 'selected' => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '', |
|
637 | 637 | 'show_option_all' => false, |
638 | 638 | 'show_option_none' => false, |
639 | 639 | ) |
@@ -644,21 +644,21 @@ discard block |
||
644 | 644 | // Sanitize selected vat rule. |
645 | 645 | $vat_class = ''; |
646 | 646 | $vat_classes = getpaid_get_tax_classes(); |
647 | - if ( isset( $_GET['vat_class'] ) ) { |
|
648 | - $vat_class = $_GET['vat_class']; |
|
647 | + if (isset($_GET['vat_class'])) { |
|
648 | + $vat_class = $_GET['vat_class']; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | echo wpinv_html_select( |
652 | 652 | array( |
653 | 653 | 'options' => array_merge( |
654 | 654 | array( |
655 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
655 | + '' => __('All VAT classes', 'invoicing') |
|
656 | 656 | ), |
657 | 657 | $vat_classes |
658 | 658 | ), |
659 | 659 | 'name' => 'vat_class', |
660 | 660 | 'id' => 'vat_class', |
661 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
661 | + 'selected' => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '', |
|
662 | 662 | 'show_option_all' => false, |
663 | 663 | 'show_option_none' => false, |
664 | 664 | ) |
@@ -667,22 +667,22 @@ discard block |
||
667 | 667 | } |
668 | 668 | |
669 | 669 | // Filter by item type. |
670 | - $type = ''; |
|
671 | - if ( isset( $_GET['type'] ) ) { |
|
672 | - $type = $_GET['type']; |
|
670 | + $type = ''; |
|
671 | + if (isset($_GET['type'])) { |
|
672 | + $type = $_GET['type']; |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | echo wpinv_html_select( |
676 | 676 | array( |
677 | 677 | 'options' => array_merge( |
678 | 678 | array( |
679 | - '' => __( 'All item types', 'invoicing' ) |
|
679 | + '' => __('All item types', 'invoicing') |
|
680 | 680 | ), |
681 | 681 | wpinv_get_item_types() |
682 | 682 | ), |
683 | 683 | 'name' => 'type', |
684 | 684 | 'id' => 'type', |
685 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
685 | + 'selected' => in_array($type, wpinv_item_types()) ? $type : '', |
|
686 | 686 | 'show_option_all' => false, |
687 | 687 | 'show_option_none' => false, |
688 | 688 | ) |
@@ -693,45 +693,45 @@ discard block |
||
693 | 693 | /** |
694 | 694 | * Filters the item query. |
695 | 695 | */ |
696 | - public static function filter_item_query( $query ) { |
|
696 | + public static function filter_item_query($query) { |
|
697 | 697 | |
698 | 698 | // modify the query only if it admin and main query. |
699 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
699 | + if (!(is_admin() && $query->is_main_query())) { |
|
700 | 700 | return $query; |
701 | 701 | } |
702 | 702 | |
703 | 703 | // we want to modify the query for our items. |
704 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
704 | + if (empty($query->query['post_type']) || 'wpi_item' != $query->query['post_type']) { |
|
705 | 705 | return $query; |
706 | 706 | } |
707 | 707 | |
708 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
708 | + if (empty($query->query_vars['meta_query'])) { |
|
709 | 709 | $query->query_vars['meta_query'] = array(); |
710 | 710 | } |
711 | 711 | |
712 | 712 | // Filter vat rule type |
713 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
713 | + if (!empty($_GET['vat_rule'])) { |
|
714 | 714 | $query->query_vars['meta_query'][] = array( |
715 | 715 | 'key' => '_wpinv_vat_rule', |
716 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
716 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
717 | 717 | 'compare' => '=' |
718 | 718 | ); |
719 | 719 | } |
720 | 720 | |
721 | 721 | // Filter vat class |
722 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
722 | + if (!empty($_GET['vat_class'])) { |
|
723 | 723 | $query->query_vars['meta_query'][] = array( |
724 | 724 | 'key' => '_wpinv_vat_class', |
725 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
725 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
726 | 726 | 'compare' => '=' |
727 | 727 | ); |
728 | 728 | } |
729 | 729 | |
730 | 730 | // Filter item type |
731 | - if ( ! empty( $_GET['type'] ) ) { |
|
731 | + if (!empty($_GET['type'])) { |
|
732 | 732 | $query->query_vars['meta_query'][] = array( |
733 | 733 | 'key' => '_wpinv_type', |
734 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
734 | + 'value' => sanitize_text_field($_GET['type']), |
|
735 | 735 | 'compare' => '=' |
736 | 736 | ); |
737 | 737 | } |
@@ -741,15 +741,15 @@ discard block |
||
741 | 741 | /** |
742 | 742 | * Reorders items. |
743 | 743 | */ |
744 | - public static function reorder_items( $vars ) { |
|
744 | + public static function reorder_items($vars) { |
|
745 | 745 | global $typenow; |
746 | 746 | |
747 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
747 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
748 | 748 | return $vars; |
749 | 749 | } |
750 | 750 | |
751 | 751 | // By item type. |
752 | - if ( 'type' == $vars['orderby'] ) { |
|
752 | + if ('type' == $vars['orderby']) { |
|
753 | 753 | return array_merge( |
754 | 754 | $vars, |
755 | 755 | array( |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | } |
761 | 761 | |
762 | 762 | // By vat class. |
763 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
763 | + if ('vat_class' == $vars['orderby']) { |
|
764 | 764 | return array_merge( |
765 | 765 | $vars, |
766 | 766 | array( |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | } |
772 | 772 | |
773 | 773 | // By vat rule. |
774 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
774 | + if ('vat_rule' == $vars['orderby']) { |
|
775 | 775 | return array_merge( |
776 | 776 | $vars, |
777 | 777 | array( |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | // By price. |
785 | - if ( 'price' == $vars['orderby'] ) { |
|
785 | + if ('price' == $vars['orderby']) { |
|
786 | 786 | return array_merge( |
787 | 787 | $vars, |
788 | 788 | array( |
@@ -799,27 +799,27 @@ discard block |
||
799 | 799 | /** |
800 | 800 | * Fired when deleting a post. |
801 | 801 | */ |
802 | - public static function delete_post( $post_id ) { |
|
802 | + public static function delete_post($post_id) { |
|
803 | 803 | |
804 | - switch ( get_post_type( $post_id ) ) { |
|
804 | + switch (get_post_type($post_id)) { |
|
805 | 805 | |
806 | 806 | case 'wpi_item' : |
807 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
807 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
808 | 808 | break; |
809 | 809 | |
810 | 810 | case 'wpi_payment_form' : |
811 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
811 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
812 | 812 | break; |
813 | 813 | |
814 | 814 | case 'wpi_discount' : |
815 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
815 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
816 | 816 | break; |
817 | 817 | |
818 | 818 | case 'wpi_invoice' : |
819 | - $invoice = new WPInv_Invoice( $post_id ); |
|
820 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
821 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
822 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
819 | + $invoice = new WPInv_Invoice($post_id); |
|
820 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
821 | + $invoice->get_data_store()->delete_items($invoice); |
|
822 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
823 | 823 | break; |
824 | 824 | } |
825 | 825 | } |
@@ -832,29 +832,29 @@ discard block |
||
832 | 832 | * |
833 | 833 | * @return mixed |
834 | 834 | */ |
835 | - public static function add_display_post_states( $post_states, $post ) { |
|
835 | + public static function add_display_post_states($post_states, $post) { |
|
836 | 836 | |
837 | - if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) { |
|
838 | - $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
|
837 | + if (wpinv_get_option('success_page', 0) == $post->ID) { |
|
838 | + $post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing'); |
|
839 | 839 | } |
840 | 840 | |
841 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
841 | + foreach (getpaid_get_invoice_post_types() as $post_type => $label) { |
|
842 | 842 | |
843 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
843 | + if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) { |
|
844 | 844 | $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
845 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
845 | + __('GetPaid %s History Page', 'invoicing'), |
|
846 | 846 | $label |
847 | 847 | ); |
848 | 848 | } |
849 | 849 | |
850 | 850 | } |
851 | 851 | |
852 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
853 | - $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
|
852 | + if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) { |
|
853 | + $post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscription Page', 'invoicing'); |
|
854 | 854 | } |
855 | 855 | |
856 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
857 | - $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
|
856 | + if (wpinv_get_option('checkout_page', 0) == $post->ID) { |
|
857 | + $post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing'); |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | return $post_states; |
@@ -4,29 +4,29 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | $gateways = wpinv_get_payment_gateways(); |
10 | -ksort( $gateways ); |
|
10 | +ksort($gateways); |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | <div class="table-responsive"> |
14 | 14 | <table id="wpinv_gateways_select" class="table border bg-white form-table"> |
15 | - <caption><?php echo esc_html_e( 'This table displays installed payment methods.', 'invoicing' ); ?></caption> |
|
15 | + <caption><?php echo esc_html_e('This table displays installed payment methods.', 'invoicing'); ?></caption> |
|
16 | 16 | |
17 | 17 | <thead> |
18 | 18 | <tr class="table-light"> |
19 | 19 | |
20 | 20 | <th scope="col" class="border-bottom border-top text-left"> |
21 | - <?php _e( 'Payment Method', 'invoicing' ); ?> |
|
21 | + <?php _e('Payment Method', 'invoicing'); ?> |
|
22 | 22 | </th> |
23 | 23 | |
24 | 24 | <th scope="col" class="border-bottom border-top text-center"> |
25 | - <?php _e( 'Enabled', 'invoicing' ); ?> |
|
25 | + <?php _e('Enabled', 'invoicing'); ?> |
|
26 | 26 | </th> |
27 | 27 | |
28 | 28 | <th scope="col" class="border-bottom border-top text-center"> |
29 | - <?php _e( 'Supports Subscriptions', 'invoicing' ); ?> |
|
29 | + <?php _e('Supports Subscriptions', 'invoicing'); ?> |
|
30 | 30 | </th> |
31 | 31 | |
32 | 32 | <th scope="col" class="border-bottom border-top text-right" style="width:32px"> </th> |
@@ -35,15 +35,15 @@ discard block |
||
35 | 35 | </thead> |
36 | 36 | |
37 | 37 | <tbody> |
38 | - <?php foreach ( $gateways as $id => $gateway ) : ?> |
|
38 | + <?php foreach ($gateways as $id => $gateway) : ?> |
|
39 | 39 | <tr> |
40 | 40 | <td class="getpaid-payment-method text-left"> |
41 | - <a style="color: #0073aa;" href="<?php echo esc_url( add_query_arg( 'section', $id ) ); ?>" class="font-weight-bold"><?php echo esc_html( $gateway['admin_label'] ); ?></a> |
|
41 | + <a style="color: #0073aa;" href="<?php echo esc_url(add_query_arg('section', $id)); ?>" class="font-weight-bold"><?php echo esc_html($gateway['admin_label']); ?></a> |
|
42 | 42 | </td> |
43 | 43 | <td class="getpaid-payment-method-enabled text-center"> |
44 | 44 | <?php |
45 | 45 | |
46 | - if ( wpinv_is_gateway_active( $id ) ) { |
|
46 | + if (wpinv_is_gateway_active($id)) { |
|
47 | 47 | echo "<i class='text-success fa fa-check'></i>"; |
48 | 48 | } else { |
49 | 49 | echo "<i class='text-dark fa fa-times'></i>"; |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | <td class="getpaid-payment-method-subscription text-center"> |
55 | 55 | <?php |
56 | 56 | |
57 | - $supports = apply_filters( "wpinv_{$id}_support_subscription", false ); |
|
58 | - $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $id ); |
|
57 | + $supports = apply_filters("wpinv_{$id}_support_subscription", false); |
|
58 | + $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $id); |
|
59 | 59 | |
60 | - if ( $supports ) { |
|
60 | + if ($supports) { |
|
61 | 61 | echo "<i class='text-success fa fa-check'></i>"; |
62 | 62 | } else { |
63 | 63 | echo "<i class='text-dark fa fa-times'></i>"; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | </td> |
68 | 68 | |
69 | 69 | <td class="getpaid-payment-method-action text-right"> |
70 | - <a class="button button-secondary" href="<?php echo esc_url( add_query_arg( 'section', $id ) ); ?>"><?php _e( 'Manage', 'invoicing' ); ?></a> |
|
70 | + <a class="button button-secondary" href="<?php echo esc_url(add_query_arg('section', $id)); ?>"><?php _e('Manage', 'invoicing'); ?></a> |
|
71 | 71 | </td> |
72 | 72 | |
73 | 73 | </tr> |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | <tfoot> |
78 | 78 | <tr class="table-light"> |
79 | 79 | <td colspan="4" class="border-top"> |
80 | - <a class="button button-secondary getpaid-install-gateways" href="<?php echo esc_url( admin_url( 'admin.php?page=wpi-addons&tab=gateways' ) ); ?>"> |
|
81 | - <span><?php _e( 'Add Payment Methods', 'invoicing' ); ?></span> |
|
80 | + <a class="button button-secondary getpaid-install-gateways" href="<?php echo esc_url(admin_url('admin.php?page=wpi-addons&tab=gateways')); ?>"> |
|
81 | + <span><?php _e('Add Payment Methods', 'invoicing'); ?></span> |
|
82 | 82 | </a> |
83 | 83 | </td> |
84 | 84 | </tr> |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @var array $tax_rate |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | ?> |
12 | 12 | |
@@ -18,54 +18,54 @@ discard block |
||
18 | 18 | $country = aui()->select( |
19 | 19 | array( |
20 | 20 | 'options' => array_merge( |
21 | - array( '' => __( 'All Countries', 'invoicing' ) ), |
|
21 | + array('' => __('All Countries', 'invoicing')), |
|
22 | 22 | wpinv_get_country_list() |
23 | 23 | ), |
24 | 24 | 'name' => "tax_rates[$key][country]", |
25 | - 'id' => uniqid( 'tax_rate_country' ), |
|
26 | - 'value' => esc_html( $tax_rate['country'] ), |
|
27 | - 'label' => __( 'Country', 'invoicing' ), |
|
25 | + 'id' => uniqid('tax_rate_country'), |
|
26 | + 'value' => esc_html($tax_rate['country']), |
|
27 | + 'label' => __('Country', 'invoicing'), |
|
28 | 28 | 'class' => 'wpinv_country', |
29 | 29 | 'no_wrap' => true, |
30 | 30 | ) |
31 | 31 | ); |
32 | 32 | |
33 | - echo str_replace( 'custom-select', '', $country ); |
|
33 | + echo str_replace('custom-select', '', $country); |
|
34 | 34 | ?> |
35 | 35 | </td> |
36 | 36 | |
37 | 37 | <td class="wpinv_tax_state"> |
38 | 38 | |
39 | 39 | <label class="w-100"> |
40 | - <span class="screen-reader-text"><?php _e( 'States', 'invoicing' ); ?></span> |
|
41 | - <input type="text" placeholder="<?php esc_attr_e( 'Apply to whole country', 'invoicing' ); ?>" name="tax_rates[<?php echo esc_attr( $key ) ?>][state]" value="<?php echo empty( $tax_rate['global'] ) ? esc_attr( $tax_rate['state'] ) : ''; ?>"/> |
|
40 | + <span class="screen-reader-text"><?php _e('States', 'invoicing'); ?></span> |
|
41 | + <input type="text" placeholder="<?php esc_attr_e('Apply to whole country', 'invoicing'); ?>" name="tax_rates[<?php echo esc_attr($key) ?>][state]" value="<?php echo empty($tax_rate['global']) ? esc_attr($tax_rate['state']) : ''; ?>"/> |
|
42 | 42 | </label> |
43 | 43 | |
44 | 44 | </td> |
45 | 45 | |
46 | 46 | <td class="wpinv_standard_rate"> |
47 | 47 | <label class="w-100"> |
48 | - <span class="screen-reader-text"><?php _e( 'Standard Rate', 'invoicing' ); ?></span> |
|
49 | - <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo esc_attr( $key ) ?>][rate]" value="<?php echo wpinv_sanitize_amount( $tax_rate['rate'] ); ?>"/> |
|
48 | + <span class="screen-reader-text"><?php _e('Standard Rate', 'invoicing'); ?></span> |
|
49 | + <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo esc_attr($key) ?>][rate]" value="<?php echo wpinv_sanitize_amount($tax_rate['rate']); ?>"/> |
|
50 | 50 | </label> |
51 | 51 | </td> |
52 | 52 | |
53 | 53 | <td class="wpinv_reduced_rate"> |
54 | 54 | <label class="w-100"> |
55 | - <span class="screen-reader-text"><?php _e( 'Reduced Rate', 'invoicing' ); ?></span> |
|
56 | - <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo esc_attr( $key ) ?>][reduced_rate]" value="<?php echo wpinv_sanitize_amount( $tax_rate['reduced_rate'] ); ?>"/> |
|
55 | + <span class="screen-reader-text"><?php _e('Reduced Rate', 'invoicing'); ?></span> |
|
56 | + <input type="number" step="any" min="0" max="99" name="tax_rates[<?php echo esc_attr($key) ?>][reduced_rate]" value="<?php echo wpinv_sanitize_amount($tax_rate['reduced_rate']); ?>"/> |
|
57 | 57 | </label> |
58 | 58 | </td> |
59 | 59 | |
60 | 60 | <td class="wpinv_tax_name"> |
61 | 61 | <label class="w-100"> |
62 | - <span class="screen-reader-text"><?php _e( 'Tax Name', 'invoicing' ); ?></span> |
|
63 | - <input type="text" name="tax_rates[<?php echo esc_attr( $key ) ?>][name]" value="<?php echo esc_attr( $tax_rate['name'] ); ?>"/> |
|
62 | + <span class="screen-reader-text"><?php _e('Tax Name', 'invoicing'); ?></span> |
|
63 | + <input type="text" name="tax_rates[<?php echo esc_attr($key) ?>][name]" value="<?php echo esc_attr($tax_rate['name']); ?>"/> |
|
64 | 64 | </label> |
65 | 65 | </td> |
66 | 66 | |
67 | 67 | <td class="wpinv_tax_remove"> |
68 | - <button type="button" class="close wpinv_remove_tax_rate" aria-label="<?php esc_attr_e( 'Delete', 'invoicing' ); ?>" title="<?php esc_attr_e( 'Delete', 'invoicing' ); ?>"> |
|
68 | + <button type="button" class="close wpinv_remove_tax_rate" aria-label="<?php esc_attr_e('Delete', 'invoicing'); ?>" title="<?php esc_attr_e('Delete', 'invoicing'); ?>"> |
|
69 | 69 | <span aria-hidden="true">×</span> |
70 | 70 | </button> |
71 | 71 | </td> |
@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Ensure that we have options. |
13 | -if ( empty( $options ) ) { |
|
13 | +if (empty($options)) { |
|
14 | 14 | return; |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Prepare price options. |
18 | -$options = getpaid_convert_price_string_to_options( $options ); |
|
19 | -$keys = array_keys( $options ); |
|
20 | -$value = empty( $options ) ? '' : $keys[0]; |
|
18 | +$options = getpaid_convert_price_string_to_options($options); |
|
19 | +$keys = array_keys($options); |
|
20 | +$value = empty($options) ? '' : $keys[0]; |
|
21 | 21 | |
22 | 22 | // Prepare id. |
23 | -$id = esc_attr( $id ); |
|
23 | +$id = esc_attr($id); |
|
24 | 24 | |
25 | -$select_type = empty( $select_type ) ? 'select' : $select_type; |
|
25 | +$select_type = empty($select_type) ? 'select' : $select_type; |
|
26 | 26 | |
27 | 27 | // Item select; |
28 | -if ( $select_type == 'select' ) { |
|
28 | +if ($select_type == 'select') { |
|
29 | 29 | echo aui()->select( |
30 | 30 | array( |
31 | 31 | 'name' => $id, |
32 | - 'id' => $id . uniqid( '_' ), |
|
33 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
32 | + 'id' => $id . uniqid('_'), |
|
33 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
34 | 34 | 'value' => $value, |
35 | - 'label' => empty( $label ) ? '' : esc_html( $label ), |
|
35 | + 'label' => empty($label) ? '' : esc_html($label), |
|
36 | 36 | 'label_type' => 'vertical', |
37 | 37 | 'class' => 'getpaid-price-select-dropdown getpaid-refresh-on-change', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'options' => $options, |
40 | 40 | ) |
41 | 41 | ); |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | // Item radios; |
46 | -if ( $select_type == 'radios' ) { |
|
46 | +if ($select_type == 'radios') { |
|
47 | 47 | echo aui()->radio( |
48 | 48 | array( |
49 | - 'name' => esc_attr( $id ), |
|
50 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
51 | - 'label' => empty( $label ) ? '' : esc_html( $label ), |
|
49 | + 'name' => esc_attr($id), |
|
50 | + 'id' => esc_attr($id) . uniqid('_'), |
|
51 | + 'label' => empty($label) ? '' : esc_html($label), |
|
52 | 52 | 'label_type' => 'vertical', |
53 | 53 | 'class' => 'getpaid-price-select-radio getpaid-refresh-on-change w-100', |
54 | 54 | 'value' => $value, |
55 | 55 | 'inline' => false, |
56 | 56 | 'options' => $options, |
57 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
57 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | return; |
@@ -62,30 +62,30 @@ discard block |
||
62 | 62 | |
63 | 63 | |
64 | 64 | // Display the label. |
65 | -if ( ! empty( $label ) ) { |
|
66 | - $label = esc_html( $label ); |
|
65 | +if (!empty($label)) { |
|
66 | + $label = esc_html($label); |
|
67 | 67 | echo "<label>$label</label>"; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Item buttons; |
71 | -if ( $select_type == 'buttons' || $select_type == 'circles' ) { |
|
71 | +if ($select_type == 'buttons' || $select_type == 'circles') { |
|
72 | 72 | |
73 | 73 | $class = 'getpaid-price-buttons'; |
74 | 74 | |
75 | - if ( $select_type == 'circles' ) { |
|
75 | + if ($select_type == 'circles') { |
|
76 | 76 | $class .= ' getpaid-price-circles'; |
77 | 77 | } |
78 | 78 | echo "<div class='$class'>"; |
79 | 79 | |
80 | - foreach ( $options as $price => $label ) { |
|
81 | - $label = esc_html( $label ); |
|
82 | - $price = esc_attr( $price ); |
|
83 | - $_id = $id . uniqid( '_' ); |
|
84 | - $checked = checked( $price, $value, false ); |
|
80 | + foreach ($options as $price => $label) { |
|
81 | + $label = esc_html($label); |
|
82 | + $price = esc_attr($price); |
|
83 | + $_id = $id . uniqid('_'); |
|
84 | + $checked = checked($price, $value, false); |
|
85 | 85 | |
86 | 86 | $class = 'rounded'; |
87 | 87 | |
88 | - if ( $select_type == 'circles' ) { |
|
88 | + if ($select_type == 'circles') { |
|
89 | 89 | $class = ''; |
90 | 90 | } |
91 | 91 | echo " |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | // Item checkboxes; |
104 | -if ( $select_type == 'checkboxes' ) { |
|
104 | +if ($select_type == 'checkboxes') { |
|
105 | 105 | echo '<div class="form-group">'; |
106 | 106 | |
107 | - foreach ( $options as $price => $label ) { |
|
108 | - $label = esc_html( $label ); |
|
109 | - $price = esc_attr( $price ); |
|
110 | - $checked = checked( $price, $value, false ); |
|
107 | + foreach ($options as $price => $label) { |
|
108 | + $label = esc_html($label); |
|
109 | + $price = esc_attr($price); |
|
110 | + $checked = checked($price, $value, false); |
|
111 | 111 | echo " |
112 | 112 | <label class='d-block'> |
113 | 113 | <input type='checkbox' class='getpaid-price-select-checkbox getpaid-refresh-on-change w-auto' name='{$id}[]' value='$price' $checked /> |
@@ -120,6 +120,6 @@ discard block |
||
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | -if ( ! empty( $description ) ) { |
|
123 | +if (!empty($description)) { |
|
124 | 124 | echo "<small class='form-text text-muted'>$description</small>"; |
125 | 125 | } |