@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->exists() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | - $args = wp_parse_args( $args, array( |
|
58 | - 'status' => array( 'publish' ), |
|
59 | - 'limit' => get_option( 'posts_per_page' ), |
|
57 | + $args = wp_parse_args($args, array( |
|
58 | + 'status' => array('publish'), |
|
59 | + 'limit' => get_option('posts_per_page'), |
|
60 | 60 | 'page' => 1, |
61 | 61 | 'exclude' => array(), |
62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'meta_query' => array(), |
66 | 66 | 'return' => 'objects', |
67 | 67 | 'paginate' => false, |
68 | - ) ); |
|
68 | + )); |
|
69 | 69 | |
70 | 70 | $wp_query_args = array( |
71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | 'fields' => 'ids', |
76 | 76 | 'orderby' => $args['orderby'], |
77 | 77 | 'order' => $args['order'], |
78 | - 'paged' => absint( $args['page'] ), |
|
78 | + 'paged' => absint($args['page']), |
|
79 | 79 | ); |
80 | 80 | |
81 | - if ( ! empty( $args['exclude'] ) ) { |
|
82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
81 | + if (!empty($args['exclude'])) { |
|
82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( ! $args['paginate' ] ) { |
|
85 | + if (!$args['paginate']) { |
|
86 | 86 | $wp_query_args['no_found_rows'] = true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $args['search'] ) ) { |
|
89 | + if (!empty($args['search'])) { |
|
90 | 90 | $wp_query_args['s'] = $args['search']; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
94 | - $types = wpinv_parse_list( $args['type'] ); |
|
93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
94 | + $types = wpinv_parse_list($args['type']); |
|
95 | 95 | $wp_query_args['meta_query'][] = array( |
96 | 96 | 'key' => '_wpinv_type', |
97 | - 'value' => implode( ',', $types ), |
|
97 | + 'value' => implode(',', $types), |
|
98 | 98 | 'compare' => 'IN', |
99 | 99 | ); |
100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
103 | 103 | |
104 | 104 | // Get results. |
105 | - $items = new WP_Query( $wp_query_args ); |
|
105 | + $items = new WP_Query($wp_query_args); |
|
106 | 106 | |
107 | - if ( 'objects' === $args['return'] ) { |
|
108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
109 | - } elseif ( 'self' === $args['return'] ) { |
|
107 | + if ('objects' === $args['return']) { |
|
108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
109 | + } elseif ('self' === $args['return']) { |
|
110 | 110 | return $items; |
111 | 111 | } else { |
112 | 112 | $return = $items->posts; |
113 | 113 | } |
114 | 114 | |
115 | - if ( $args['paginate' ] ) { |
|
115 | + if ($args['paginate']) { |
|
116 | 116 | return (object) array( |
117 | 117 | 'items' => $return, |
118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
128 | - if( empty( $item_id ) ) { |
|
127 | +function wpinv_is_free_item($item_id = 0) { |
|
128 | + if (empty($item_id)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $item = new WPInv_Item( $item_id ); |
|
132 | + $item = new WPInv_Item($item_id); |
|
133 | 133 | |
134 | 134 | return $item->is_free(); |
135 | 135 | } |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
141 | 141 | */ |
142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
142 | +function wpinv_item_is_editable($item = 0) { |
|
143 | 143 | |
144 | 144 | // Fetch the item. |
145 | - $item = new WPInv_Item( $item ); |
|
145 | + $item = new WPInv_Item($item); |
|
146 | 146 | |
147 | 147 | // Check if it is editable. |
148 | 148 | return $item->is_editable(); |
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
152 | - if( empty( $item_id ) ) { |
|
151 | +function wpinv_get_item_price($item_id = 0) { |
|
152 | + if (empty($item_id)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $item = new WPInv_Item( $item_id ); |
|
156 | + $item = new WPInv_Item($item_id); |
|
157 | 157 | |
158 | 158 | return $item->get_price(); |
159 | 159 | } |
@@ -163,96 +163,96 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @param WPInv_Item|int $item |
165 | 165 | */ |
166 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
167 | - $item = new WPInv_Item( $item ); |
|
166 | +function wpinv_is_recurring_item($item = 0) { |
|
167 | + $item = new WPInv_Item($item); |
|
168 | 168 | return $item->is_recurring(); |
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_item_price( $item_id = 0 ) { |
|
172 | - if( empty( $item_id ) ) { |
|
171 | +function wpinv_item_price($item_id = 0) { |
|
172 | + if (empty($item_id)) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - $price = wpinv_get_item_price( $item_id ); |
|
177 | - $price = wpinv_price( $price ); |
|
176 | + $price = wpinv_get_item_price($item_id); |
|
177 | + $price = wpinv_price($price); |
|
178 | 178 | |
179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
180 | 180 | } |
181 | 181 | |
182 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
183 | - if ( is_null( $amount_override ) ) { |
|
184 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
182 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
183 | + if (is_null($amount_override)) { |
|
184 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
185 | 185 | } else { |
186 | 186 | $original_price = $amount_override; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $price = $original_price; |
190 | 190 | |
191 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
191 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
195 | - if( empty( $item_id ) ) { |
|
194 | +function wpinv_item_custom_singular_name($item_id) { |
|
195 | + if (empty($item_id)) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | - $item = new WPInv_Item( $item_id ); |
|
199 | + $item = new WPInv_Item($item_id); |
|
200 | 200 | |
201 | 201 | return $item->get_custom_singular_name(); |
202 | 202 | } |
203 | 203 | |
204 | 204 | function wpinv_get_item_types() { |
205 | 205 | $item_types = array( |
206 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
207 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
206 | + 'custom' => __('Standard', 'invoicing'), |
|
207 | + 'fee' => __('Fee', 'invoicing'), |
|
208 | 208 | ); |
209 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
209 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_item_types() { |
213 | 213 | $item_types = wpinv_get_item_types(); |
214 | 214 | |
215 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
215 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
216 | 216 | } |
217 | 217 | |
218 | -function wpinv_get_item_type( $item_id ) { |
|
219 | - if( empty( $item_id ) ) { |
|
218 | +function wpinv_get_item_type($item_id) { |
|
219 | + if (empty($item_id)) { |
|
220 | 220 | return false; |
221 | 221 | } |
222 | 222 | |
223 | - $item = new WPInv_Item( $item_id ); |
|
223 | + $item = new WPInv_Item($item_id); |
|
224 | 224 | |
225 | 225 | return $item->get_type(); |
226 | 226 | } |
227 | 227 | |
228 | -function wpinv_item_type( $item_id ) { |
|
228 | +function wpinv_item_type($item_id) { |
|
229 | 229 | $item_types = wpinv_get_item_types(); |
230 | 230 | |
231 | - $item_type = wpinv_get_item_type( $item_id ); |
|
231 | + $item_type = wpinv_get_item_type($item_id); |
|
232 | 232 | |
233 | - if ( empty( $item_type ) ) { |
|
233 | + if (empty($item_type)) { |
|
234 | 234 | $item_type = '-'; |
235 | 235 | } |
236 | 236 | |
237 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
237 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
238 | 238 | |
239 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
239 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
240 | 240 | } |
241 | 241 | |
242 | -function wpinv_get_random_item( $post_ids = true ) { |
|
243 | - wpinv_get_random_items( 1, $post_ids ); |
|
242 | +function wpinv_get_random_item($post_ids = true) { |
|
243 | + wpinv_get_random_items(1, $post_ids); |
|
244 | 244 | } |
245 | 245 | |
246 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
247 | - if ( $post_ids ) { |
|
248 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
246 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
247 | + if ($post_ids) { |
|
248 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
249 | 249 | } else { |
250 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
250 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
251 | 251 | } |
252 | 252 | |
253 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
253 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
254 | 254 | |
255 | - return get_posts( $args ); |
|
255 | + return get_posts($args); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -261,13 +261,13 @@ discard block |
||
261 | 261 | * @param WPInv_Item|int $item |
262 | 262 | * @param bool $html |
263 | 263 | */ |
264 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
264 | +function wpinv_get_item_suffix($item, $html = true) { |
|
265 | 265 | |
266 | - $item = new WPInv_Item( $item ); |
|
267 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
268 | - $suffix = $html ? $suffix : strip_tags( $suffix ); |
|
266 | + $item = new WPInv_Item($item); |
|
267 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
268 | + $suffix = $html ? $suffix : strip_tags($suffix); |
|
269 | 269 | |
270 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
270 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param WPInv_Item|int $item |
277 | 277 | * @param bool $force_delete |
278 | 278 | */ |
279 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
280 | - $item = new WPInv_Item( $item ); |
|
281 | - $item->delete( $force_delete ); |
|
279 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
280 | + $item = new WPInv_Item($item); |
|
281 | + $item->delete($force_delete); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -317,45 +317,45 @@ discard block |
||
317 | 317 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
318 | 318 | * @return bool|WP_Error|WPInv_Item |
319 | 319 | */ |
320 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
320 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
321 | 321 | |
322 | 322 | // Prepare the item. |
323 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
324 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
325 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
323 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
324 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
325 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
326 | 326 | |
327 | - if ( ! empty( $item ) ) { |
|
327 | + if (!empty($item)) { |
|
328 | 328 | $args['ID'] = $item->get_id(); |
329 | 329 | } |
330 | 330 | |
331 | 331 | } |
332 | 332 | |
333 | 333 | // Do we have an item? |
334 | - if ( ! empty( $args['ID'] ) ) { |
|
335 | - $item = new WPInv_Item( $args['ID'] ); |
|
334 | + if (!empty($args['ID'])) { |
|
335 | + $item = new WPInv_Item($args['ID']); |
|
336 | 336 | } else { |
337 | 337 | $item = new WPInv_Item(); |
338 | 338 | } |
339 | 339 | |
340 | 340 | // Do we have an error? |
341 | - if ( ! empty( $item->last_error ) ) { |
|
342 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
341 | + if (!empty($item->last_error)) { |
|
342 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // Update item props. |
346 | - $item->set_props( $args ); |
|
346 | + $item->set_props($args); |
|
347 | 347 | |
348 | 348 | // Save the item. |
349 | 349 | $item->save(); |
350 | 350 | |
351 | 351 | // Do we have an error? |
352 | - if ( ! empty( $item->last_error ) ) { |
|
353 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
352 | + if (!empty($item->last_error)) { |
|
353 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Was the item saved? |
357 | - if ( ! $item->get_id() ) { |
|
358 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
357 | + if (!$item->get_id()) { |
|
358 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $item; |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | * |
368 | 368 | * @see wpinv_create_item() |
369 | 369 | */ |
370 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
371 | - return wpinv_create_item( $args, $wp_error ); |
|
370 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
371 | + return wpinv_create_item($args, $wp_error); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
375 | 375 | * Sanitizes a recurring period |
376 | 376 | */ |
377 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
377 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
378 | 378 | |
379 | 379 | $periods = array( |
380 | 380 | 'D' => 'day', |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | 'Y' => 'year', |
384 | 384 | ); |
385 | 385 | |
386 | - if ( ! isset( $periods[ $period ] ) ) { |
|
386 | + if (!isset($periods[$period])) { |
|
387 | 387 | $period = 'D'; |
388 | 388 | } |
389 | 389 | |
390 | - return $full ? $periods[ $period ] : $period; |
|
390 | + return $full ? $periods[$period] : $period; |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | |
@@ -396,38 +396,38 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @param WPInv_Item|GetPaid_Form_Item $item |
398 | 398 | */ |
399 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
399 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
400 | 400 | |
401 | 401 | // Abort if it is not recurring. |
402 | - if ( ! $item->is_recurring() ) { |
|
402 | + if (!$item->is_recurring()) { |
|
403 | 403 | return ''; |
404 | 404 | } |
405 | 405 | |
406 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
407 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
408 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
406 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
407 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
408 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
409 | 409 | $initial_class = 'getpaid-item-initial-price'; |
410 | 410 | $recurring_class = 'getpaid-item-recurring-price'; |
411 | 411 | |
412 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
413 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
414 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
412 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
413 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
414 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
415 | 415 | } |
416 | 416 | |
417 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
418 | - return __( 'Free forever', 'invoicing' ); |
|
417 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
418 | + return __('Free forever', 'invoicing'); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | // For free trial items. |
422 | - if ( $item->has_free_trial() ) { |
|
423 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
422 | + if ($item->has_free_trial()) { |
|
423 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
424 | 424 | |
425 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
425 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
426 | 426 | |
427 | 427 | return sprintf( |
428 | 428 | |
429 | 429 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
430 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
430 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
431 | 431 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
432 | 432 | "<span class='$recurring_class'>$recurring_price</span>", |
433 | 433 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | return sprintf( |
440 | 440 | |
441 | 441 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
442 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
442 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
443 | 443 | "<span class='$initial_class'>$initial_price</span>", |
444 | 444 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
445 | 445 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -449,12 +449,12 @@ discard block |
||
449 | 449 | |
450 | 450 | } |
451 | 451 | |
452 | - if ( $initial_price == $recurring_price ) { |
|
452 | + if ($initial_price == $recurring_price) { |
|
453 | 453 | |
454 | 454 | return sprintf( |
455 | 455 | |
456 | 456 | // translators: $1: is the recurring price, $2: is the susbcription period |
457 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
457 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
458 | 458 | "<span class='$recurring_class'>$recurring_price</span>", |
459 | 459 | "<span class='getpaid-item-recurring-period'>$period</span>" |
460 | 460 | |
@@ -462,12 +462,12 @@ discard block |
||
462 | 462 | |
463 | 463 | } |
464 | 464 | |
465 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
465 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
466 | 466 | |
467 | 467 | return sprintf( |
468 | 468 | |
469 | 469 | // translators: $1: is the recurring period, $2: is the recurring price |
470 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
470 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
471 | 471 | "<span class='getpaid-item-recurring-period'>$period</span>", |
472 | 472 | "<span class='$recurring_class'>$recurring_price</span>" |
473 | 473 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | return sprintf( |
479 | 479 | |
480 | 480 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
481 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
481 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
482 | 482 | "<span class='$initial_class'>$initial_price</span>", |
483 | 483 | "<span class='$recurring_class'>$recurring_price</span>", |
484 | 484 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -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_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = 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', 500 ); |
|
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', 500); |
|
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.', 500 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 500); |
|
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_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = 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' ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data'); |
|
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( $response['body'], 'Received valid response from PayPal IPN' ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
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' ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency'); |
|
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' ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount'); |
|
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,68 +212,68 @@ 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 | 230 | // Process a refund. |
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
235 | + if (!$invoice->is_refunded()) { |
|
236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
237 | 237 | } |
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
239 | + return wpinv_error_log($posted['reason_code'], false); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Process payments. |
243 | - if ( $payment_status == 'completed' ) { |
|
243 | + if ($payment_status == 'completed') { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
247 | 247 | } |
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
250 | 250 | |
251 | 251 | $note = ''; |
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
253 | + if (!empty($posted['mc_fee'])) { |
|
254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
257 | + if (!empty($posted['payer_status'])) { |
|
258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
259 | 259 | } |
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
262 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Pending payments. |
267 | - if ( $payment_status == 'pending' ) { |
|
267 | + if ($payment_status == 'pending') { |
|
268 | 268 | |
269 | 269 | /* translators: %s: pending reason. */ |
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
272 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: %s: payment status. */ |
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
284 | 284 | * @param array $posted Posted data. |
285 | 285 | */ |
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,40 +293,40 @@ discard block |
||
293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
294 | 294 | * @param array $posted Posted data. |
295 | 295 | */ |
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
298 | + wpinv_error_log('Processing subscription signup', false); |
|
299 | 299 | |
300 | 300 | // Make sure the invoice has a subscription. |
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
303 | + if (empty($subscription)) { |
|
304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Validate the IPN. |
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
308 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
309 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
310 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
311 | 311 | |
312 | 312 | // Activate the subscription. |
313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
313 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
314 | + $subscription->set_date_created(current_time('mysql')); |
|
315 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
316 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
317 | 317 | $subscription->activate(); |
318 | 318 | |
319 | 319 | // Set the transaction id. |
320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
320 | + if (!empty($posted['txn_id'])) { |
|
321 | + $invoice->set_transaction_id($posted['txn_id']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | // Update the payment status. |
325 | 325 | $invoice->mark_paid(); |
326 | 326 | |
327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
327 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
328 | 328 | |
329 | - wpinv_error_log( 'Subscription started.', false ); |
|
329 | + wpinv_error_log('Subscription started.', false); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -335,20 +335,20 @@ discard block |
||
335 | 335 | * @param WPInv_Invoice $invoice Invoice object. |
336 | 336 | * @param array $posted Posted data. |
337 | 337 | */ |
338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
338 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
339 | 339 | |
340 | 340 | // Make sure the invoice has a subscription. |
341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
341 | + $subscription = wpinv_get_subscription($invoice); |
|
342 | 342 | |
343 | - if ( empty( $subscription ) ) { |
|
344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
343 | + if (empty($subscription)) { |
|
344 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // Abort if this is the first payment. |
348 | - if ( ( $invoice->is_paid() && date( 'Ynd', strtotime( $invoice->get_date_completed() ) ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) || date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
348 | + if (($invoice->is_paid() && date('Ynd', strtotime($invoice->get_date_completed())) == date('Ynd', strtotime($posted['payment_date']))) || date('Ynd', $subscription->get_time_created()) == date('Ynd', strtotime($posted['payment_date']))) { |
|
349 | 349 | |
350 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
351 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
350 | + if (!empty($posted['txn_id'])) { |
|
351 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
352 | 352 | $invoice->mark_paid(); |
353 | 353 | $invoice->save(); |
354 | 354 | } |
@@ -356,11 +356,11 @@ discard block |
||
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
359 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
360 | 360 | |
361 | 361 | // Abort if the payment is already recorded. |
362 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
363 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
362 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
363 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | $args = array( |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | 'gateway' => $this->id, |
369 | 369 | ); |
370 | 370 | |
371 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
371 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
372 | 372 | |
373 | - if ( empty( $invoice ) ) { |
|
373 | + if (empty($invoice)) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
378 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
377 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
378 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
379 | 379 | |
380 | 380 | $subscription->renew(); |
381 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
381 | + wpinv_error_log('Subscription renewed.', false); |
|
382 | 382 | |
383 | 383 | } |
384 | 384 | |
@@ -387,18 +387,18 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @param WPInv_Invoice $invoice Invoice object. |
389 | 389 | */ |
390 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
390 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
391 | 391 | |
392 | 392 | // Make sure the invoice has a subscription. |
393 | - $subscription = wpinv_get_subscription( $invoice ); |
|
393 | + $subscription = wpinv_get_subscription($invoice); |
|
394 | 394 | |
395 | - if ( empty( $subscription ) ) { |
|
396 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
395 | + if (empty($subscription)) { |
|
396 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
397 | 397 | } |
398 | 398 | |
399 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
399 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
400 | 400 | $subscription->cancel(); |
401 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
401 | + wpinv_error_log('Subscription cancelled.', false); |
|
402 | 402 | |
403 | 403 | } |
404 | 404 | |
@@ -408,18 +408,18 @@ discard block |
||
408 | 408 | * @param WPInv_Invoice $invoice Invoice object. |
409 | 409 | * @param array $posted Posted data. |
410 | 410 | */ |
411 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
411 | + protected function ipn_txn_subscr_eot($invoice) { |
|
412 | 412 | |
413 | 413 | // Make sure the invoice has a subscription. |
414 | - $subscription = wpinv_get_subscription( $invoice ); |
|
414 | + $subscription = wpinv_get_subscription($invoice); |
|
415 | 415 | |
416 | - if ( empty( $subscription ) ) { |
|
417 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
416 | + if (empty($subscription)) { |
|
417 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
418 | 418 | } |
419 | 419 | |
420 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
420 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
421 | 421 | $subscription->complete(); |
422 | - wpinv_error_log( 'Subscription completed.', false ); |
|
422 | + wpinv_error_log('Subscription completed.', false); |
|
423 | 423 | |
424 | 424 | } |
425 | 425 | |
@@ -429,18 +429,18 @@ discard block |
||
429 | 429 | * @param WPInv_Invoice $invoice Invoice object. |
430 | 430 | * @param array $posted Posted data. |
431 | 431 | */ |
432 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
432 | + protected function ipn_txn_subscr_failed($invoice) { |
|
433 | 433 | |
434 | 434 | // Make sure the invoice has a subscription. |
435 | - $subscription = wpinv_get_subscription( $invoice ); |
|
435 | + $subscription = wpinv_get_subscription($invoice); |
|
436 | 436 | |
437 | - if ( empty( $subscription ) ) { |
|
438 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
437 | + if (empty($subscription)) { |
|
438 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
439 | 439 | } |
440 | 440 | |
441 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
441 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
442 | 442 | $subscription->failing(); |
443 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
443 | + wpinv_error_log('Subscription marked as failing.', false); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | |
@@ -450,18 +450,18 @@ discard block |
||
450 | 450 | * @param WPInv_Invoice $invoice Invoice object. |
451 | 451 | * @param array $posted Posted data. |
452 | 452 | */ |
453 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
453 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
454 | 454 | |
455 | 455 | // Make sure the invoice has a subscription. |
456 | - $subscription = wpinv_get_subscription( $invoice ); |
|
456 | + $subscription = wpinv_get_subscription($invoice); |
|
457 | 457 | |
458 | - if ( empty( $subscription ) ) { |
|
459 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
458 | + if (empty($subscription)) { |
|
459 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
460 | 460 | } |
461 | 461 | |
462 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
462 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
463 | 463 | $subscription->cancel(); |
464 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
464 | + wpinv_error_log('Subscription cancelled.', false); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | } |