Passed
Push — master ( fce5e6...5d063b )
by Stiofan
01:08 queued 12s
created
includes/class-wpinv-item.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 class WPInv_Item {
6 8
     public $ID = 0;
Please login to merge, or discard this patch.
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
     public $filter;
48 48
 
49 49
 
50
-    public function __construct( $_id = false, $_args = array() ) {
51
-        $item = WP_Post::get_instance( $_id );
52
-        return $this->setup_item( $item );
50
+    public function __construct($_id = false, $_args = array()) {
51
+        $item = WP_Post::get_instance($_id);
52
+        return $this->setup_item($item);
53 53
     }
54 54
 
55
-    private function setup_item( $item ) {
56
-        if( ! is_object( $item ) ) {
55
+    private function setup_item($item) {
56
+        if (!is_object($item)) {
57 57
             return false;
58 58
         }
59 59
 
60
-        if( ! is_a( $item, 'WP_Post' ) ) {
60
+        if (!is_a($item, 'WP_Post')) {
61 61
             return false;
62 62
         }
63 63
 
64
-        if( 'wpi_item' !== $item->post_type ) {
64
+        if ('wpi_item' !== $item->post_type) {
65 65
             return false;
66 66
         }
67 67
 
68
-        foreach ( $item as $key => $value ) {
69
-            switch ( $key ) {
68
+        foreach ($item as $key => $value) {
69
+            switch ($key) {
70 70
                 default:
71 71
                     $this->$key = $value;
72 72
                     break;
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
         return true;
77 77
     }
78 78
 
79
-    public function __get( $key ) {
80
-        if ( method_exists( $this, 'get_' . $key ) ) {
81
-            return call_user_func( array( $this, 'get_' . $key ) );
79
+    public function __get($key) {
80
+        if (method_exists($this, 'get_' . $key)) {
81
+            return call_user_func(array($this, 'get_' . $key));
82 82
         } else {
83
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
83
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
84 84
         }
85 85
     }
86 86
 
87
-    public function create( $data = array(), $wp_error = false ) {
88
-        if ( $this->ID != 0 ) {
87
+    public function create($data = array(), $wp_error = false) {
88
+        if ($this->ID != 0) {
89 89
             return false;
90 90
         }
91 91
 
92 92
         $defaults = array(
93 93
             'post_type'   => 'wpi_item',
94 94
             'post_status' => 'draft',
95
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
95
+            'post_title'  => __('New Invoice Item', 'invoicing')
96 96
         );
97 97
 
98
-        $args = wp_parse_args( $data, $defaults );
98
+        $args = wp_parse_args($data, $defaults);
99 99
 
100
-        do_action( 'wpinv_item_pre_create', $args );
100
+        do_action('wpinv_item_pre_create', $args);
101 101
 
102
-        $id = wp_insert_post( $args, $wp_error );
102
+        $id = wp_insert_post($args, $wp_error);
103 103
         if ($wp_error && is_wp_error($id)) {
104 104
             return $id;
105 105
         }
106
-        if ( !$id ) {
106
+        if (!$id) {
107 107
             return false;
108 108
         }
109 109
         
110
-        $item = WP_Post::get_instance( $id );
110
+        $item = WP_Post::get_instance($id);
111 111
         
112 112
         if (!empty($item) && !empty($data['meta'])) {
113 113
             $this->ID = $item->ID;
@@ -115,47 +115,47 @@  discard block
 block discarded – undo
115 115
         }
116 116
         
117 117
         // Set custom id if not set.
118
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
119
-            $this->save_metas( array( 'custom_id' => $id ) );
118
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
119
+            $this->save_metas(array('custom_id' => $id));
120 120
         }
121 121
 
122
-        do_action( 'wpinv_item_create', $id, $args );
122
+        do_action('wpinv_item_create', $id, $args);
123 123
 
124
-        return $this->setup_item( $item );
124
+        return $this->setup_item($item);
125 125
     }
126 126
     
127
-    public function update( $data = array(), $wp_error = false ) {
128
-        if ( !$this->ID > 0 ) {
127
+    public function update($data = array(), $wp_error = false) {
128
+        if (!$this->ID > 0) {
129 129
             return false;
130 130
         }
131 131
         
132 132
         $data['ID'] = $this->ID;
133 133
 
134
-        do_action( 'wpinv_item_pre_update', $data );
134
+        do_action('wpinv_item_pre_update', $data);
135 135
         
136
-        $id = wp_update_post( $data, $wp_error );
136
+        $id = wp_update_post($data, $wp_error);
137 137
         if ($wp_error && is_wp_error($id)) {
138 138
             return $id;
139 139
         }
140 140
         
141
-        if ( !$id ) {
141
+        if (!$id) {
142 142
             return false;
143 143
         }
144 144
 
145
-        $item = WP_Post::get_instance( $id );
145
+        $item = WP_Post::get_instance($id);
146 146
         if (!empty($item) && !empty($data['meta'])) {
147 147
             $this->ID = $item->ID;
148 148
             $this->save_metas($data['meta']);
149 149
         }
150 150
         
151 151
         // Set custom id if not set.
152
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
153
-            $this->save_metas( array( 'custom_id' => $id ) );
152
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
153
+            $this->save_metas(array('custom_id' => $id));
154 154
         }
155 155
 
156
-        do_action( 'wpinv_item_update', $id, $data );
156
+        do_action('wpinv_item_update', $id, $data);
157 157
 
158
-        return $this->setup_item( $item );
158
+        return $this->setup_item($item);
159 159
     }
160 160
 
161 161
     public function get_ID() {
@@ -163,120 +163,120 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     public function get_name() {
166
-        return get_the_title( $this->ID );
166
+        return get_the_title($this->ID);
167 167
     }
168 168
     
169 169
     public function get_title() {
170
-        return get_the_title( $this->ID );
170
+        return get_the_title($this->ID);
171 171
     }
172 172
     
173 173
     public function get_status() {
174
-        return get_post_status( $this->ID );
174
+        return get_post_status($this->ID);
175 175
     }
176 176
     
177 177
     public function get_summary() {
178
-        $post = get_post( $this->ID );
179
-        return !empty( $post->post_excerpt ) ? $post->post_excerpt : '';
178
+        $post = get_post($this->ID);
179
+        return !empty($post->post_excerpt) ? $post->post_excerpt : '';
180 180
     }
181 181
 
182 182
     public function get_price() {
183
-        if ( ! isset( $this->price ) ) {
184
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
183
+        if (!isset($this->price)) {
184
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
185 185
             
186
-            if ( $this->price ) {
187
-                $this->price = wpinv_sanitize_amount( $this->price );
186
+            if ($this->price) {
187
+                $this->price = wpinv_sanitize_amount($this->price);
188 188
             } else {
189 189
                 $this->price = 0;
190 190
             }
191 191
         }
192 192
         
193
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
193
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
194 194
     }
195 195
     
196 196
     public function get_vat_rule() {
197 197
         global $wpinv_euvat;
198 198
         
199
-        if( !isset( $this->vat_rule ) ) {
200
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
199
+        if (!isset($this->vat_rule)) {
200
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
201 201
 
202
-            if ( empty( $this->vat_rule ) ) {        
202
+            if (empty($this->vat_rule)) {        
203 203
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
204 204
             }
205 205
         }
206 206
         
207
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
207
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
208 208
     }
209 209
     
210 210
     public function get_vat_class() {
211
-        if( !isset( $this->vat_class ) ) {
212
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
211
+        if (!isset($this->vat_class)) {
212
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
213 213
 
214
-            if ( empty( $this->vat_class ) ) {        
214
+            if (empty($this->vat_class)) {        
215 215
                 $this->vat_class = '_standard';
216 216
             }
217 217
         }
218 218
         
219
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
219
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
220 220
     }
221 221
 
222 222
     public function get_type() {
223
-        if( ! isset( $this->type ) ) {
224
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
223
+        if (!isset($this->type)) {
224
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
225 225
 
226
-            if ( empty( $this->type ) ) {
226
+            if (empty($this->type)) {
227 227
                 $this->type = 'custom';
228 228
             }
229 229
         }
230 230
 
231
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
231
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
232 232
     }
233 233
     
234 234
     public function get_custom_id() {
235
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
235
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
236 236
 
237
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
237
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
238 238
     }
239 239
     
240 240
     public function get_custom_name() {
241
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
241
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
242 242
 
243
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
243
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
244 244
     }
245 245
     
246 246
     public function get_custom_singular_name() {
247
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
247
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
248 248
 
249
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
249
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
250 250
     }
251 251
     
252 252
     public function get_editable() {
253
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
253
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
254 254
 
255
-        return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID );
255
+        return apply_filters('wpinv_item_get_editable', $editable, $this->ID);
256 256
     }
257 257
     
258 258
     public function get_excerpt() {
259
-        $excerpt = get_the_excerpt( $this->ID );
259
+        $excerpt = get_the_excerpt($this->ID);
260 260
         
261
-        return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID );
261
+        return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID);
262 262
     }
263 263
     
264 264
     public function get_is_recurring() {
265
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
265
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
266 266
 
267
-        return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID );
267
+        return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID);
268 268
 
269 269
     }
270 270
     
271
-    public function get_recurring_period( $full = false ) {
272
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
271
+    public function get_recurring_period($full = false) {
272
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
273 273
         
274
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
274
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
275 275
             $period = 'D';
276 276
         }
277 277
         
278
-        if ( $full ) {
279
-            switch( $period ) {
278
+        if ($full) {
279
+            switch ($period) {
280 280
                 case 'D':
281 281
                     $period = 'day';
282 282
                 break;
@@ -292,40 +292,40 @@  discard block
 block discarded – undo
292 292
             }
293 293
         }
294 294
 
295
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
295
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
296 296
     }
297 297
     
298 298
     public function get_recurring_interval() {
299
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
299
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
300 300
         
301
-        if ( !$interval > 0 ) {
301
+        if (!$interval > 0) {
302 302
             $interval = 1;
303 303
         }
304 304
 
305
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
305
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
306 306
     }
307 307
     
308 308
     public function get_recurring_limit() {
309
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
309
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
310 310
 
311
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
311
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
312 312
     }
313 313
     
314 314
     public function get_free_trial() {
315
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
315
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
316 316
 
317
-        return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID );
317
+        return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID);
318 318
     }
319 319
     
320
-    public function get_trial_period( $full = false ) {
321
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
320
+    public function get_trial_period($full = false) {
321
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
322 322
         
323
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
323
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
324 324
             $period = 'D';
325 325
         }
326 326
         
327
-        if ( $full ) {
328
-            switch( $period ) {
327
+        if ($full) {
328
+            switch ($period) {
329 329
                 case 'D':
330 330
                     $period = 'day';
331 331
                 break;
@@ -341,47 +341,47 @@  discard block
 block discarded – undo
341 341
             }
342 342
         }
343 343
 
344
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
344
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
345 345
     }
346 346
     
347 347
     public function get_trial_interval() {
348
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
348
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
349 349
         
350
-        if ( !$interval > 0 ) {
350
+        if (!$interval > 0) {
351 351
             $interval = 1;
352 352
         }
353 353
 
354
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
354
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
355 355
     }
356 356
     
357 357
     public function get_the_price() {
358
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
358
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
359 359
         
360
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
360
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
361 361
     }
362 362
     
363 363
     public function is_recurring() {
364 364
         $is_recurring = $this->get_is_recurring();
365 365
 
366
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
366
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
367 367
     }
368 368
     
369 369
     public function has_free_trial() {
370 370
         $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false;
371 371
 
372
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
372
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
373 373
     }
374 374
 
375 375
     public function is_free() {
376 376
         $is_free = false;
377 377
         
378
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
378
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
379 379
 
380
-        if ( (float)$price == 0 ) {
380
+        if ((float)$price == 0) {
381 381
             $is_free = true;
382 382
         }
383 383
 
384
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
384
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
385 385
 
386 386
     }
387 387
     
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 
391 391
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
392 392
 
393
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
393
+        return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
394 394
     }
395 395
     
396
-    public function save_metas( $metas = array() ) {
397
-        if ( empty( $metas ) ) {
396
+    public function save_metas($metas = array()) {
397
+        if (empty($metas)) {
398 398
             return false;
399 399
         }
400 400
         
401
-        foreach ( $metas as $meta_key => $meta_value ) {
401
+        foreach ($metas as $meta_key => $meta_value) {
402 402
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
403 403
             
404 404
             $this->update_meta($meta_key, $meta_value);
@@ -407,66 +407,66 @@  discard block
 block discarded – undo
407 407
         return true;
408 408
     }
409 409
 
410
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
411
-        if ( empty( $meta_key ) ) {
410
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
411
+        if (empty($meta_key)) {
412 412
             return false;
413 413
         }
414 414
         
415
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
415
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
416 416
 
417
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
417
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
418 418
     }
419 419
     
420
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
420
+    public function get_fees($type = 'fee', $item_id = 0) {
421 421
         global $wpi_session;
422 422
         
423
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
423
+        $fees = $wpi_session->get('wpi_cart_fees');
424 424
 
425
-        if ( ! wpinv_get_cart_contents() ) {
425
+        if (!wpinv_get_cart_contents()) {
426 426
             // We can only get item type fees when the cart is empty
427 427
             $type = 'custom';
428 428
         }
429 429
 
430
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
431
-            foreach( $fees as $key => $fee ) {
432
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
433
-                    unset( $fees[ $key ] );
430
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
431
+            foreach ($fees as $key => $fee) {
432
+                if (!empty($fee['type']) && $type != $fee['type']) {
433
+                    unset($fees[$key]);
434 434
                 }
435 435
             }
436 436
         }
437 437
 
438
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
438
+        if (!empty($fees) && !empty($item_id)) {
439 439
             // Remove fees that don't belong to the specified Item
440
-            foreach ( $fees as $key => $fee ) {
441
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
442
-                    unset( $fees[ $key ] );
440
+            foreach ($fees as $key => $fee) {
441
+                if ((int)$item_id !== (int)$fee['custom_id']) {
442
+                    unset($fees[$key]);
443 443
                 }
444 444
             }
445 445
         }
446 446
 
447
-        if ( ! empty( $fees ) ) {
447
+        if (!empty($fees)) {
448 448
             // Remove fees that belong to a specific item but are not in the cart
449
-            foreach( $fees as $key => $fee ) {
450
-                if( empty( $fee['custom_id'] ) ) {
449
+            foreach ($fees as $key => $fee) {
450
+                if (empty($fee['custom_id'])) {
451 451
                     continue;
452 452
                 }
453 453
 
454
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
455
-                    unset( $fees[ $key ] );
454
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
455
+                    unset($fees[$key]);
456 456
                 }
457 457
             }
458 458
         }
459 459
 
460
-        return ! empty( $fees ) ? $fees : array();
460
+        return !empty($fees) ? $fees : array();
461 461
     }
462 462
     
463 463
     public function can_purchase() {
464 464
         $can_purchase = true;
465 465
 
466
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
466
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
467 467
             $can_purchase = false;
468 468
         }
469 469
 
470
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
470
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
471 471
     }
472 472
 }
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_worldpay_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_worldpay_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
     
12 12
     // Collect payment data
@@ -24,132 +24,132 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Credit Card / Debit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Credit Card / Debit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
143
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
144 144
 
145 145
 function wpinv_is_worldpay_valid_for_use() {
146
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' )));
146
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR')));
147 147
 }
148 148
 
149
-function wpinv_check_worldpay_currency_support( $gateway_list ) {
150
-    if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) {
151
-        unset( $gateway_list['worldpay'] );
149
+function wpinv_check_worldpay_currency_support($gateway_list) {
150
+    if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) {
151
+        unset($gateway_list['worldpay']);
152 152
     }
153 153
     return $gateway_list;
154 154
 }
155
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 );
156 155
\ No newline at end of file
156
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1);
157 157
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetSIM.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@
 block discarded – undo
182 182
         $string = "";
183 183
         foreach ($array as $key => $value) {
184 184
             if ($value) {
185
-                $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'">';
185
+                $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '">';
186 186
             }
187 187
         }
188 188
         return $string;
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetARB.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -91,13 +91,13 @@
 block discarded – undo
91 91
         return $this->_sendRequest();
92 92
     }
93 93
     
94
-     /**
95
-     *
96
-     *
97
-     * @param string $response
98
-     * 
99
-     * @return AuthorizeNetARB_Response
100
-     */
94
+        /**
95
+         *
96
+         *
97
+         * @param string $response
98
+         * 
99
+         * @return AuthorizeNetARB_Response
100
+         */
101 101
     protected function _handleResponse($response)
102 102
     {
103 103
         return new AuthorizeNetARB_Response($response);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
      */
117 117
     protected function _setPostString()
118 118
     {
119
-        $this->_post_string =<<<XML
119
+        $this->_post_string = <<<XML
120 120
 <?xml version="1.0" encoding="utf-8"?>
121 121
 <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd">
122 122
     <merchantAuthentication>
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetTD.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
     {
65 65
         $month = ($month ? $month : date('m'));
66 66
         $year = ($year ? $year : date('Y'));
67
-        $firstSettlementDate = substr(date('c',mktime(0, 0, 0, $month, 1, $year)),0,-6);
68
-        $lastSettlementDate  = substr(date('c',mktime(0, 0, 0, $month+1, 0, $year)),0,-6);
67
+        $firstSettlementDate = substr(date('c', mktime(0, 0, 0, $month, 1, $year)), 0, -6);
68
+        $lastSettlementDate  = substr(date('c', mktime(0, 0, 0, $month + 1, 0, $year)), 0, -6);
69 69
         return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate);
70 70
     }
71 71
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
         $month = ($month ? $month : date('m'));
99 99
         $day = ($day ? $day : date('d'));
100 100
         $year = ($year ? $year : date('Y'));
101
-        $firstSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6);
102
-        $lastSettlementDate  = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6);
101
+        $firstSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6);
102
+        $lastSettlementDate  = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6);
103 103
         $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate);
104 104
         $batches = $response->xpath("batchList/batch");
105 105
         foreach ($batches as $batch) {
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
      */
188 188
     private function _constructXml($request_type)
189 189
     {
190
-        $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>';
190
+        $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>';
191 191
         $this->_xml = @new SimpleXMLElement($string);
192 192
         $merchant = $this->_xml->addChild('merchantAuthentication');
193
-        $merchant->addChild('name',$this->_api_login);
194
-        $merchant->addChild('transactionKey',$this->_transaction_key);
193
+        $merchant->addChild('name', $this->_api_login);
194
+        $merchant->addChild('transactionKey', $this->_transaction_key);
195 195
     }
196 196
     
197 197
 }
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetSOAP.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
         $string = "";
52 52
         $types = $this->__getTypes();
53 53
         foreach ($types as $type) {
54
-            if (preg_match("/struct /",$type)) {
55
-                $type = preg_replace("/struct /","class ",$type);
56
-                $type = preg_replace("/ (\w+) (\w+);/","    // $1\n    public \$$2;",$type);
57
-                $string .= $type ."\n";
54
+            if (preg_match("/struct /", $type)) {
55
+                $type = preg_replace("/struct /", "class ", $type);
56
+                $type = preg_replace("/ (\w+) (\w+);/", "    // $1\n    public \$$2;", $type);
57
+                $string .= $type . "\n";
58 58
             }
59 59
         }
60 60
         return $string;
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function saveSoapDocumentation($path)
86 86
     {
87
-        $string =  "<?php\n";
87
+        $string = "<?php\n";
88 88
         $string .= "/**\n";
89 89
         $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n";
90 90
         $string .= " * Generated " . date("m/d/Y") . "\n";
91 91
         $string .= " */\n";
92 92
         $string .= "class AuthorizeNetSOAP\n";
93
-        $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>";
93
+        $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() . "\n\n ?>";
94 94
         return file_put_contents($path, $string);
95 95
     }
96 96
     
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetDPM.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
             }
77 77
             else
78 78
             {
79
-              echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
79
+                echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
80 80
             }
81 81
         }
82 82
     }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
                 else
58 58
                 {
59 59
                     // Redirect to error page.
60
-                    $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
60
+                    $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text;
61 61
                 }
62 62
                 // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
63 63
                 echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
@@ -179,54 +179,54 @@  discard block
 block discarded – undo
179 179
             -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75);
180 180
             box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); }
181 181
         </style>
182
-        <form method="post" action="'.$post_url.'">
183
-                '.$hidden_fields.'
182
+        <form method="post" action="'.$post_url . '">
183
+                '.$hidden_fields . '
184 184
             <fieldset>
185 185
                 <div>
186 186
                     <label>Credit Card Number</label>
187
-                    <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input>
187
+                    <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '') . '"></input>
188 188
                 </div>
189 189
                 <div>
190 190
                     <label>Exp.</label>
191
-                    <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input>
191
+                    <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '') . '"></input>
192 192
                 </div>
193 193
                 <div>
194 194
                     <label>CCV</label>
195
-                    <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input>
195
+                    <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '') . '"></input>
196 196
                 </div>
197 197
             </fieldset>
198 198
             <fieldset>
199 199
                 <div>
200 200
                     <label>First Name</label>
201
-                    <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input>
201
+                    <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '') . '"></input>
202 202
                 </div>
203 203
                 <div>
204 204
                     <label>Last Name</label>
205
-                    <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input>
205
+                    <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '') . '"></input>
206 206
                 </div>
207 207
             </fieldset>
208 208
             <fieldset>
209 209
                 <div>
210 210
                     <label>Address</label>
211
-                    <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input>
211
+                    <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '') . '"></input>
212 212
                 </div>
213 213
                 <div>
214 214
                     <label>City</label>
215
-                    <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input>
215
+                    <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '') . '"></input>
216 216
                 </div>
217 217
             </fieldset>
218 218
             <fieldset>
219 219
                 <div>
220 220
                     <label>State</label>
221
-                    <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input>
221
+                    <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '') . '"></input>
222 222
                 </div>
223 223
                 <div>
224 224
                     <label>Zip Code</label>
225
-                    <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input>
225
+                    <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '') . '"></input>
226 226
                 </div>
227 227
                 <div>
228 228
                     <label>Country</label>
229
-                    <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input>
229
+                    <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '') . '"></input>
230 230
                 </div>
231 231
             </fieldset>
232 232
             <input type="submit" value="BUY" class="submit buy">
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -53,16 +53,14 @@  discard block
 block discarded – undo
53 53
                 {
54 54
                     // Do your processing here.
55 55
                     $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; 
56
-                }
57
-                else
56
+                } else
58 57
                 {
59 58
                     // Redirect to error page.
60 59
                     $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
61 60
                 }
62 61
                 // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
63 62
                 echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
64
-            }
65
-            else
63
+            } else
66 64
             {
67 65
                 echo "Error -- not AuthorizeNet. Check your MD5 Setting.";
68 66
             }
@@ -73,8 +71,7 @@  discard block
 block discarded – undo
73 71
             if ($_GET['response_code'] == 1)
74 72
             {
75 73
                 echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']);
76
-            }
77
-            else
74
+            } else
78 75
             {
79 76
               echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
80 77
             }
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
6 8
 
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -648,6 +648,9 @@
 block discarded – undo
648 648
 }
649 649
 add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
650 650
 
651
+/**
652
+ * @param WPInv_Invoice $invoice
653
+ */
651 654
 function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
652 655
     if ( $transaction_id == $invoice_id ) {
653 656
         $link = $transaction_id;
Please login to merge, or discard this patch.
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-5">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-5">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-3">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-5">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,192 +83,192 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
 
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
 
104 104
         $errors = wpinv_get_errors();
105 105
 
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
 
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
 
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
 
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
 
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
 
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
 
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
 
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
 
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
 
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
 
160 160
             try {
161 161
 
162
-                if ( $is_recurring ) {
162
+                if ($is_recurring) {
163 163
                     $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only');
164
-                    if('authorize_capture' == $trx_type){
164
+                    if ('authorize_capture' == $trx_type) {
165 165
                         $response = $authorizeAIM->authorizeAndCapture();
166 166
                     } else {
167 167
                         $response = $authorizeAIM->authorizeOnly();
168 168
                     }
169 169
                 } else {
170 170
                     $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture');
171
-                    if('authorize_capture' == $trx_type){
171
+                    if ('authorize_capture' == $trx_type) {
172 172
                         $response = $authorizeAIM->authorizeAndCapture();
173 173
                     } else {
174 174
                         $response = $authorizeAIM->authorizeOnly();
175 175
                     }
176 176
                 }
177 177
 
178
-                if ( $response->approved || $response->held ) {
179
-                    if ( $response->approved ) {
180
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
178
+                if ($response->approved || $response->held) {
179
+                    if ($response->approved) {
180
+                        wpinv_update_payment_status($invoice_id, 'publish');
181 181
                     }
182
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
182
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
183 183
 
184
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true );
185
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true );
184
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true);
185
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true);
186 186
 
187
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
187
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
188 188
 
189 189
                     wpinv_clear_errors();
190 190
                     wpinv_empty_cart();
191 191
 
192
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
192
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
193 193
                 } else {
194
-                    if ( !empty( $response->response_reason_text ) ) {
195
-                        $error = __( $response->response_reason_text, 'invoicing' );
196
-                    } else if ( !empty( $response->error_message ) ) {
197
-                        $error = __( $response->error_message, 'invoicing' );
194
+                    if (!empty($response->response_reason_text)) {
195
+                        $error = __($response->response_reason_text, 'invoicing');
196
+                    } else if (!empty($response->error_message)) {
197
+                        $error = __($response->error_message, 'invoicing');
198 198
                     } else {
199
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
199
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
200 200
                     } 
201 201
 
202
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
202
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
203 203
 
204
-                    wpinv_set_error( 'payment_error', $error );
205
-                    wpinv_record_gateway_error( $error, $response );
206
-                    wpinv_insert_payment_note( $invoice_id, $error, '', '', true );
204
+                    wpinv_set_error('payment_error', $error);
205
+                    wpinv_record_gateway_error($error, $response);
206
+                    wpinv_insert_payment_note($invoice_id, $error, '', '', true);
207 207
 
208
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
208
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
209 209
                 }
210
-            } catch ( AuthorizeNetException $e ) {
211
-                wpinv_set_error( 'request_error', $e->getMessage() );
212
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
213
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
210
+            } catch (AuthorizeNetException $e) {
211
+                wpinv_set_error('request_error', $e->getMessage());
212
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
213
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
214 214
             }
215 215
         } else {
216
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
216
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
217 217
         }
218 218
     } else {
219
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
220
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
219
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
220
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
221 221
     }
222 222
 }
223
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
223
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
224 224
 
225
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
226
-    if ( empty( $subscription_id ) ) {
225
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
226
+    if (empty($subscription_id)) {
227 227
         return false;
228 228
     }
229 229
 
230 230
     try {
231 231
         $authnetXML = wpinv_authorizenet_XML();
232
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
232
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
233 233
         return $authnetXML->isSuccessful();
234
-    } catch( Exception $e ) {
235
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
234
+    } catch (Exception $e) {
235
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
236 236
     }
237 237
 
238 238
     return false;
239 239
 }
240 240
 
241
-function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) {
242
-    if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) {
243
-        return wpinv_authorizenet_cancel_subscription( $subscription->profile_id );
241
+function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) {
242
+    if (!empty($valid) && !empty($subscription->profile_id)) {
243
+        return wpinv_authorizenet_cancel_subscription($subscription->profile_id);
244 244
     }
245 245
     
246 246
     return false;
247 247
 }
248
-add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 );
248
+add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2);
249 249
 
250
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
251
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
252
-    if ( empty( $authorizenet_md5_hash ) ) {
250
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
251
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
252
+    if (empty($authorizenet_md5_hash)) {
253 253
         return true;
254 254
     }
255 255
 
256
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
256
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
257 257
 
258
-    return hash_equals( $compare_md5, $md5_hash );
258
+    return hash_equals($compare_md5, $md5_hash);
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_AIM() {
262
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
262
+    if (!class_exists('AuthorizeNetException')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
264 264
     }
265 265
 
266
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
266
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
267 267
 
268
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
269
-        $authorizeAIM->setSandbox( true );
268
+    if (wpinv_is_test_mode('authorizenet')) {
269
+        $authorizeAIM->setSandbox(true);
270 270
     } else {
271
-        $authorizeAIM->setSandbox( false );
271
+        $authorizeAIM->setSandbox(false);
272 272
     }
273 273
 
274 274
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -277,250 +277,250 @@  discard block
 block discarded – undo
277 277
 }
278 278
 
279 279
 function wpinv_authorizenet_XML() {
280
-    if ( !class_exists( 'AuthnetXML' ) ) {
281
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
280
+    if (!class_exists('AuthnetXML')) {
281
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
282 282
     }
283 283
     
284
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
284
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
285 285
     
286 286
     return $authnetXML;
287 287
 }
288 288
 
289
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
290
-    if ( empty( $response ) || empty( $invoice ) ) {
289
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
290
+    if (empty($response) || empty($invoice)) {
291 291
         return false;
292 292
     }
293 293
 
294
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
295
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
294
+    if ($invoice->is_recurring() && !empty($response->approved)) {
295
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
296 296
         $success = false;
297
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
297
+        if (wpinv_is_test_mode('authorizenet')) {
298 298
             $success = true;
299 299
         } else {
300 300
             $success = $subscription->isSuccessful();
301 301
         }
302 302
 
303
-        if ( !empty( $subscription ) && $success ) {
304
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
303
+        if (!empty($subscription) && $success) {
304
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
305 305
 
306
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
306
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
307 307
 
308
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
308
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
309 309
         } else {
310
-            if ( isset( $subscription->messages->message ) ) {
310
+            if (isset($subscription->messages->message)) {
311 311
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
312
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
312
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
313 313
             } else {
314
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
315
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
314
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
315
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
316 316
             }
317 317
 
318
-            wpinv_record_gateway_error( $error, $subscription );
318
+            wpinv_record_gateway_error($error, $subscription);
319 319
 
320
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true );
320
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true);
321 321
         }
322 322
     }
323 323
 }
324
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
324
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
325 325
 
326
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
327
-    if ( empty( $invoice ) ) {
326
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
327
+    if (empty($invoice)) {
328 328
         return false;
329 329
     }
330 330
 
331
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
331
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
332 332
 
333 333
     try {
334 334
         $authnetXML = wpinv_authorizenet_XML();
335
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
336
-    } catch( Exception $e ) {
335
+        $authnetXML->ARBCreateSubscriptionRequest($params);
336
+    } catch (Exception $e) {
337 337
         $authnetXML = array();
338
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
338
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
339 339
     }
340 340
 
341 341
     return $authnetXML;
342 342
 }
343 343
 
344
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
345
-    if ( empty( $invoice ) ) {
344
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
345
+    if (empty($invoice)) {
346 346
         return false;
347 347
     }
348 348
 
349
-    $subscription_item = $invoice->get_recurring( true );
350
-    if ( empty( $subscription_item->ID ) ) {
349
+    $subscription_item = $invoice->get_recurring(true);
350
+    if (empty($subscription_item->ID)) {
351 351
         return false;
352 352
     }
353 353
 
354
-    $item = $invoice->get_recurring( true );
354
+    $item = $invoice->get_recurring(true);
355 355
 
356
-    if ( empty( $item ) ) {
356
+    if (empty($item)) {
357 357
         $name = '';
358 358
     }
359 359
 
360
-    if ( !( $name = $item->get_name() ) ) {
360
+    if (!($name = $item->get_name())) {
361 361
         $name = $item->post_name;
362 362
     }
363 363
 
364
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
364
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
365 365
     $subscription_name  = $invoice->get_subscription_name();
366
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
367
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
366
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
367
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
368 368
     $interval           = $subscription_item->get_recurring_interval();
369 369
     $period             = $subscription_item->get_recurring_period();
370 370
     $bill_times         = (int)$subscription_item->get_recurring_limit();
371 371
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
372 372
 
373
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
373
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
374 374
     $interval           = $time_period['interval'];
375 375
     $period             = $time_period['period'];
376 376
 
377 377
     $current_tz = date_default_timezone_get();
378
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
-    $today = date( 'Y-m-d' );
380
-    date_default_timezone_set( $current_tz );
378
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
+    $today = date('Y-m-d');
380
+    date_default_timezone_set($current_tz);
381 381
 
382 382
     $free_trial = $invoice->is_free_trial();
383
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
383
+    if ($free_trial && $subscription_item->has_free_trial()) {
384 384
         $trial_interval    = $subscription_item->get_trial_interval();
385
-        $trial_period      = $subscription_item->get_trial_period( true );
385
+        $trial_period      = $subscription_item->get_trial_period(true);
386 386
     }
387 387
 
388 388
     $subscription = array();
389 389
     $subscription['name'] = $subscription_name;
390 390
 
391 391
     $subscription['paymentSchedule'] = array(
392
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
392
+        'interval'         => array('length' => $interval, 'unit' => $period),
393 393
         'startDate'        => $today,
394 394
         'totalOccurrences' => $bill_times,
395
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
395
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
396 396
     );
397 397
 
398 398
     $subscription['amount'] = $recurring_amount;
399 399
     $subscription['trialAmount'] = $initial_amount;
400
-    $subscription['payment'] = array( 'creditCard' => $card_details );
401
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
402
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
400
+    $subscription['payment'] = array('creditCard' => $card_details);
401
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
402
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
403 403
 
404 404
     $subscription['billTo'] = array(
405 405
         'firstName' => $invoice->get_first_name(),
406 406
         'lastName'  => $invoice->get_last_name(),
407 407
         'company'   => $invoice->company,
408
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
408
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
409 409
         'city'      => $invoice->city,
410 410
         'state'     => $invoice->state,
411 411
         'zip'       => $invoice->zip,
412 412
         'country'   => $invoice->country,
413 413
     );
414 414
 
415
-    $params = array( 'subscription' => $subscription );
415
+    $params = array('subscription' => $subscription);
416 416
 
417
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
417
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
418 418
 }
419 419
 
420
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
421
-    $card_defaults      = array(
420
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
421
+    $card_defaults = array(
422 422
         'cc_owner'          => null,
423 423
         'cc_number'         => null,
424 424
         'cc_expire_month'   => null,
425 425
         'cc_expire_year'    => null,
426 426
         'cc_cvv2'           => null,
427 427
     );
428
-    $card_info = wp_parse_args( $card_info, $card_defaults );
428
+    $card_info = wp_parse_args($card_info, $card_defaults);
429 429
 
430 430
     $card_details = array(
431
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
432
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
433
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
431
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
432
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
433
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
434 434
     );
435 435
 
436 436
     return $card_details;
437 437
 }
438 438
 
439
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
440
-    $parent_invoice_id = absint( $invoice->ID );
439
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
440
+    $parent_invoice_id = absint($invoice->ID);
441 441
 
442
-    if( empty( $parent_invoice_id ) ) {
442
+    if (empty($parent_invoice_id)) {
443 443
         return;
444 444
     }
445 445
 
446
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
447
-    if ( empty( $invoice ) ) {
446
+    $invoice = wpinv_get_invoice($parent_invoice_id);
447
+    if (empty($invoice)) {
448 448
         return;
449 449
     }
450 450
 
451 451
     $subscriptionId     = (array)$subscription->subscriptionId;
452
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
452
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
453 453
 
454
-    $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id );
454
+    $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id);
455 455
 
456
-    if ( false === $subscription ) {
456
+    if (false === $subscription) {
457 457
         return;
458 458
     }
459 459
 
460 460
     // Set payment to complete
461
-    wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' );
461
+    wpinv_update_payment_status($subscription->parent_payment_id, 'publish');
462 462
     sleep(1);
463
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true );
464
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id);
463
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true);
464
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id);
465 465
 
466 466
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
467
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
468
-    $created    = date_i18n( 'Y-m-d H:i:s' );
469
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
467
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
468
+    $created    = date_i18n('Y-m-d H:i:s');
469
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
470 470
 
471 471
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
472
-    $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
472
+    $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration));
473 473
 }
474 474
 
475
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
476
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
475
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
476
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
477 477
         $error = false;
478 478
         
479
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
479
+        if (empty($post['authorizenet']['cc_owner'])) {
480 480
             $error = true;
481
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
481
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
482 482
         }
483
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
483
+        if (empty($post['authorizenet']['cc_number'])) {
484 484
             $error = true;
485
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
485
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
486 486
         }
487
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
487
+        if (empty($post['authorizenet']['cc_expire_month'])) {
488 488
             $error = true;
489
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
489
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
490 490
         }
491
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
491
+        if (empty($post['authorizenet']['cc_expire_year'])) {
492 492
             $error = true;
493
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
493
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
494 494
         }
495
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
495
+        if (empty($post['authorizenet']['cc_cvv2'])) {
496 496
             $error = true;
497
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
497
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
498 498
         }
499 499
 
500
-        if ( $error ) {
500
+        if ($error) {
501 501
             return;
502 502
         }
503 503
 
504 504
         $invoice = wpinv_get_invoice_cart();
505 505
 
506
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
507
-            $subscription_item = $invoice->get_recurring( true );
506
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
507
+            $subscription_item = $invoice->get_recurring(true);
508 508
 
509 509
             $interval   = $subscription_item->get_recurring_interval();
510 510
             $period     = $subscription_item->get_recurring_period();
511 511
 
512
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
513
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
512
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
513
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
514 514
             }
515 515
         }
516 516
     }
517 517
 }
518
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
518
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
519 519
 
520
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
521
-    $subscription_interval = absint( $subscription_interval );
520
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
521
+    $subscription_interval = absint($subscription_interval);
522 522
 
523
-    switch( $subscription_period ) {
523
+    switch ($subscription_period) {
524 524
         case 'W':
525 525
         case 'week':
526 526
         case 'weeks':
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
         case 'M':
531 531
         case 'month':
532 532
         case 'months':
533
-            if ( $subscription_interval > 12 ) {
533
+            if ($subscription_interval > 12) {
534 534
                 $subscription_interval = 12;
535 535
             }
536 536
 
537 537
             $interval = $subscription_interval;
538 538
             $period   = 'months';
539 539
             
540
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
540
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
541 541
                 $interval = $subscription_interval * 30;
542 542
                 $period   = 'days';
543 543
             }
@@ -554,30 +554,30 @@  discard block
 block discarded – undo
554 554
             break;
555 555
     }
556 556
 
557
-    return compact( 'interval', 'period' );
557
+    return compact('interval', 'period');
558 558
 }
559 559
 
560 560
 function wpinv_authorizenet_process_ipn() {
561
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
561
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
562 562
         return;
563 563
     }
564 564
 
565
-    $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false;
565
+    $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false;
566 566
 
567
-    if ( $subscription_id ) {
568
-        $response_code  = intval( $_POST['x_response_code'] );
569
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
567
+    if ($subscription_id) {
568
+        $response_code  = intval($_POST['x_response_code']);
569
+        $reason_code    = intval($_POST['x_response_reason_code']);
570 570
 
571
-        $subscription = new WPInv_Subscription( $subscription_id, true );
571
+        $subscription = new WPInv_Subscription($subscription_id, true);
572 572
 
573
-        if ( !$subscription->id ) {
573
+        if (!$subscription->id) {
574 574
             return;
575 575
         }
576 576
 
577
-        if ( 1 == $response_code ) {
577
+        if (1 == $response_code) {
578 578
             // Approved
579
-            $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
580
-            $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
579
+            $transaction_id = sanitize_text_field($_POST['x_trans_id']);
580
+            $renewal_amount = sanitize_text_field($_POST['x_amount']);
581 581
 
582 582
             $args = array(
583 583
                 'amount'         => $renewal_amount,
@@ -585,63 +585,63 @@  discard block
 block discarded – undo
585 585
                 'gateway'        => 'authorizenet'
586 586
             );
587 587
 
588
-            $subscription->add_payment( $args );
588
+            $subscription->add_payment($args);
589 589
             $subscription->renew();
590 590
 
591
-            do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription );
592
-            do_action( 'wpinv_authorizenet_renewal_payment', $subscription );
593
-        } else if ( 2 == $response_code ) {
591
+            do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription);
592
+            do_action('wpinv_authorizenet_renewal_payment', $subscription);
593
+        } else if (2 == $response_code) {
594 594
             // Declined
595 595
             $subscription->failing();
596
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
597
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
598
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
596
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
597
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
598
+        } else if (3 == $response_code || 8 == $reason_code) {
599 599
             // An expired card
600 600
             $subscription->failing();
601
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
602
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
601
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
602
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
603 603
         } else {
604 604
             // Other Error
605
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
605
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
606 606
         }
607 607
 
608 608
         exit;
609 609
     }
610 610
 }
611
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
611
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
612 612
 
613 613
 /**
614 614
  * Retrieve the subscription
615 615
  */
616
-function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) {
617
-    $parent_invoice_id = absint( $invoice_id );
616
+function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) {
617
+    $parent_invoice_id = absint($invoice_id);
618 618
 
619
-    if ( empty( $subscription_data ) ) {
619
+    if (empty($subscription_data)) {
620 620
         return false;
621 621
     }
622 622
 
623
-    if ( empty( $parent_invoice_id ) ) {
623
+    if (empty($parent_invoice_id)) {
624 624
         return false;
625 625
     }
626 626
 
627
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
628
-    if ( empty( $invoice ) ) {
627
+    $invoice = wpinv_get_invoice($parent_invoice_id);
628
+    if (empty($invoice)) {
629 629
         return false;
630 630
     }
631 631
 
632 632
     $subscriptionId     = (array)$subscription_data->subscriptionId;
633
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
633
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
634 634
 
635
-    $subscription = new WPInv_Subscription( $subscription_id, true );
635
+    $subscription = new WPInv_Subscription($subscription_id, true);
636 636
 
637
-    if ( ! $subscription || $subscription->id < 1 ) {
637
+    if (!$subscription || $subscription->id < 1) {
638 638
         $subs_db      = new WPInv_Subscriptions_DB;
639
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) );
640
-        $subscription = reset( $subs );
639
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1));
640
+        $subscription = reset($subs);
641 641
 
642
-        if ( $subscription && $subscription->id > 0 ) {
642
+        if ($subscription && $subscription->id > 0) {
643 643
             // Update the profile ID so it is set for future renewals
644
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) );
644
+            $subscription->update(array('profile_id' => sanitize_text_field($subscription_id)));
645 645
         } else {
646 646
             // No subscription found with a matching payment ID, bail
647 647
             return false;
@@ -652,67 +652,67 @@  discard block
 block discarded – undo
652 652
 }
653 653
 
654 654
 function wpinv_is_authorizenet_valid_for_use() {
655
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) );
655
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR')));
656 656
 }
657
-function wpinv_check_authorizenet_currency_support( $gateway_list ) {
658
-    if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) {
659
-        unset( $gateway_list['authorizenet'] );
657
+function wpinv_check_authorizenet_currency_support($gateway_list) {
658
+    if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) {
659
+        unset($gateway_list['authorizenet']);
660 660
     }
661 661
     return $gateway_list;
662 662
 }
663
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
663
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1);
664 664
 
665
-function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
666
-    if ( $transaction_id == $invoice_id ) {
665
+function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) {
666
+    if ($transaction_id == $invoice_id) {
667 667
         $link = $transaction_id;
668 668
     } else {
669
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
669
+        if (!empty($invoice) && !empty($invoice->mode)) {
670 670
             $mode = $invoice->mode;
671 671
         } else {
672
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
672
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
673 673
         }
674 674
 
675 675
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
676 676
         $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id;
677 677
 
678
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>';
678
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>';
679 679
     }
680 680
 
681
-    return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice );
681
+    return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice);
682 682
 }
683
-add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 );
683
+add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3);
684 684
 
685
-function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) {
686
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
687
-        $invoice = wpinv_get_invoice( $invoice_id );
685
+function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) {
686
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
687
+        $invoice = wpinv_get_invoice($invoice_id);
688 688
 
689
-        if ( ! empty( $invoice ) ) {
690
-            return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice );
689
+        if (!empty($invoice)) {
690
+            return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice);
691 691
         }        
692 692
     }
693 693
     
694 694
     return $transaction_id;
695 695
 }
696
-add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 );
696
+add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2);
697 697
 
698
-function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) {
698
+function wpinv_authorizenet_profile_id_link($profile_id, $subscription) {
699 699
     $link = $profile_id;
700 700
 
701
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
702
-        $invoice = wpinv_get_invoice( $invoice_id );
701
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
702
+        $invoice = wpinv_get_invoice($invoice_id);
703 703
 
704
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
704
+        if (!empty($invoice) && !empty($invoice->mode)) {
705 705
             $mode = $invoice->mode;
706 706
         } else {
707
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
707
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
708 708
         }
709 709
 
710 710
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
711 711
         $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id;
712 712
 
713
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
713
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
714 714
     }
715 715
     
716
-    return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription );
716
+    return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription);
717 717
 }
718
-add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 );
719 718
\ No newline at end of file
719
+add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2);
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/manual.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_manual_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_manual_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.