Completed
Push — master ( 378b1c...258987 )
by Brian
12:54 queued 12:51
created
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'wpinv_renew_authorizenet_subscription_profile', array( $this, 'renew_subscription' ) );
74
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
73
+        add_filter('wpinv_renew_authorizenet_subscription_profile', array($this, 'renew_subscription'));
74
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', 
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', 
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => $this->get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', 
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', 
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => $this->get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => $this->get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,24 +311,24 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319 319
                         'name'                 => getpaid_tax()->get_vat_name(),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330
-log_noptin_message( $args );
331
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
330
+log_noptin_message($args);
331
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
332 332
 
333 333
     }
334 334
 
@@ -338,43 +338,43 @@  discard block
 block discarded – undo
338 338
      * @param stdClass $result Api response.
339 339
 	 * @param WPInv_Invoice $invoice Invoice.
340 340
 	 */
341
-	public function process_charge_response( $result, $invoice ) {
341
+	public function process_charge_response($result, $invoice) {
342 342
 
343 343
         wpinv_clear_errors();
344 344
 
345
-        switch ( (int) $result->transactionResponse->responseCode ) {
345
+        switch ((int) $result->transactionResponse->responseCode) {
346 346
 
347 347
             case 1:
348 348
             case 4:
349 349
 
350
-                if ( ! empty( $result->transactionResponse->transId ) ) {
351
-                    $invoice->set_transaction_id( $result->transactionResponse->transId );
350
+                if (!empty($result->transactionResponse->transId)) {
351
+                    $invoice->set_transaction_id($result->transactionResponse->transId);
352 352
                 }
353 353
 
354
-                if ( 1 == (int) $result->transactionResponse->responseCode ) {
354
+                if (1 == (int) $result->transactionResponse->responseCode) {
355 355
                     $invoice->mark_paid();
356 356
                 } else {
357
-                    $invoice->set_status( 'wpi-onhold' );
357
+                    $invoice->set_status('wpi-onhold');
358 358
                     $invoice->add_note( 
359 359
                         sprintf(
360
-                            __( 'Held for review: %s', 'invoicing' ),
360
+                            __('Held for review: %s', 'invoicing'),
361 361
                             $result->transactionResponse->messages->message[0]->description
362 362
                         )
363 363
                     );
364 364
                 }
365 365
 
366
-                $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
366
+                $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
367 367
                 $invoice->save();
368 368
 
369 369
                 return;
370 370
 
371 371
             case 2:
372 372
             case 3:
373
-                wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
373
+                wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
374 374
 
375
-                if ( ! empty( $result->transactionResponse->errors ) ) {
375
+                if (!empty($result->transactionResponse->errors)) {
376 376
                     $errors = (object) $result->transactionResponse->errors;
377
-                    wpinv_set_error( $errors->error[0]->errorCode, $errors->error[0]->errorText );
377
+                    wpinv_set_error($errors->error[0]->errorCode, $errors->error[0]->errorText);
378 378
                 }
379 379
 
380 380
                 return;
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 	 * @param array $card Card details.
391 391
 	 * @return array
392 392
 	 */
393
-	public function get_payment_information( $card ) {
393
+	public function get_payment_information($card) {
394 394
         return array(
395 395
 
396
-            'creditCard'         => array (
396
+            'creditCard'         => array(
397 397
                 'cardNumber'     => $card['cc_number'],
398 398
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
399 399
                 'cardCode'       => $card['cc_cvv2'],
@@ -409,30 +409,30 @@  discard block
 block discarded – undo
409 409
 	 * @param string $card_number Card number.
410 410
 	 * @return string
411 411
 	 */
412
-	public function get_card_name( $card_number ) {
412
+	public function get_card_name($card_number) {
413 413
 
414
-        switch( $card_number ) {
414
+        switch ($card_number) {
415 415
 
416
-            case( preg_match ( '/^4/', $card_number ) >= 1 ):
417
-                return __( 'Visa', 'invoicing' );
416
+            case(preg_match('/^4/', $card_number) >= 1):
417
+                return __('Visa', 'invoicing');
418 418
 
419
-            case( preg_match ( '/^5[1-5]/', $card_number ) >= 1 ):
420
-                return __( 'Mastercard', 'invoicing' );
419
+            case(preg_match('/^5[1-5]/', $card_number) >= 1):
420
+                return __('Mastercard', 'invoicing');
421 421
 
422
-            case( preg_match ( '/^3[47]/', $card_number ) >= 1 ):
423
-                return __( 'Amex', 'invoicing' );
422
+            case(preg_match('/^3[47]/', $card_number) >= 1):
423
+                return __('Amex', 'invoicing');
424 424
 
425
-            case( preg_match ( '/^3(?:0[0-5]|[68])/', $card_number ) >= 1 ):
426
-                return __( 'Diners Club', 'invoicing' );
425
+            case(preg_match('/^3(?:0[0-5]|[68])/', $card_number) >= 1):
426
+                return __('Diners Club', 'invoicing');
427 427
 
428
-            case( preg_match ( '/^6(?:011|5)/', $card_number ) >= 1 ):
429
-                return __( 'Discover', 'invoicing' );
428
+            case(preg_match('/^6(?:011|5)/', $card_number) >= 1):
429
+                return __('Discover', 'invoicing');
430 430
 
431
-            case( preg_match ( '/^(?:2131|1800|35\d{3})/', $card_number ) >= 1 ):
432
-                return __( 'JCB', 'invoicing' );
431
+            case(preg_match('/^(?:2131|1800|35\d{3})/', $card_number) >= 1):
432
+                return __('JCB', 'invoicing');
433 433
 
434 434
             default:
435
-            return __( 'Card', 'invoicing' );
435
+            return __('Card', 'invoicing');
436 436
                 break;
437 437
         }
438 438
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	 * @param WPInv_Invoice $invoice Invoice.
446 446
 	 * @return string
447 447
 	 */
448
-	public function get_customer_profile_meta_name( $invoice ) {
449
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
448
+	public function get_customer_profile_meta_name($invoice) {
449
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
450 450
     }
451 451
 
452 452
     /**
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @param WPInv_Invoice $invoice Invoice.
457 457
 	 * @return string
458 458
 	 */
459
-	public function get_api_url( $invoice ) {
460
-        return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
459
+	public function get_api_url($invoice) {
460
+        return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
461 461
     }
462 462
 
463 463
     /**
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
 	public function get_auth_params() {
470 470
 
471 471
         return array(
472
-            'name'           => $this->get_option( 'login_id' ),
473
-            'transactionKey' => $this->get_option( 'transaction_key' ),
472
+            'name'           => $this->get_option('login_id'),
473
+            'transactionKey' => $this->get_option('transaction_key'),
474 474
         );
475 475
 
476 476
     }
@@ -483,34 +483,34 @@  discard block
 block discarded – undo
483 483
      * @param WPInv_Invoice $invoice
484 484
 	 * @return WP_Error|string The payment profile id
485 485
 	 */
486
-	public function validate_submission_data( $submission_data, $invoice ) {
486
+	public function validate_submission_data($submission_data, $invoice) {
487 487
 
488 488
         // Validate authentication details.
489 489
         $auth = $this->get_auth_params();
490 490
 
491
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
492
-            return new WP_Error( 'invalid_settings', __( 'This gateway has not been set up.', 'invoicing') );
491
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
492
+            return new WP_Error('invalid_settings', __('This gateway has not been set up.', 'invoicing'));
493 493
         }
494 494
 
495 495
         // Validate the payment method.
496
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
497
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
496
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
497
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
498 498
         }
499 499
 
500 500
         // Are we adding a new payment method?
501
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
501
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
502 502
             return $submission_data['getpaid-authorizenet-payment-method'];
503 503
         }
504 504
 
505 505
         // Retrieve the customer profile id.
506
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
506
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
507 507
 
508 508
         // Create payment method.
509
-        if ( empty( $profile_id ) ) {
510
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
509
+        if (empty($profile_id)) {
510
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
511 511
         }
512 512
 
513
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
513
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
514 514
 
515 515
     }
516 516
 
@@ -521,15 +521,15 @@  discard block
 block discarded – undo
521 521
 	 * @param WPInv_Invoice $invoice Invoice.
522 522
 	 * @return array
523 523
 	 */
524
-	public function get_line_items( $invoice ) {
524
+	public function get_line_items($invoice) {
525 525
         $items = array();
526 526
 
527
-        foreach ( $invoice->get_items() as $item ) {
527
+        foreach ($invoice->get_items() as $item) {
528 528
 
529 529
             $items[] = array(
530
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
531
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
532
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
530
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
531
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
532
+                'description' => getpaid_limit_length($item->get_description(), 255),
533 533
                 'quantity'    => (int) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
534 534
                 'unitPrice'   => (float) $item->get_price(),
535 535
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -548,40 +548,40 @@  discard block
 block discarded – undo
548 548
      * @param WPInv_Invoice $invoice Invoice.
549 549
 	 * @return stdClass|WP_Error
550 550
 	 */
551
-    public function post( $post, $invoice ){
551
+    public function post($post, $invoice) {
552 552
 
553
-        $url      = $this->get_api_url( $invoice );
553
+        $url      = $this->get_api_url($invoice);
554 554
         $response = wp_remote_post(
555 555
             $url,
556 556
             array(
557 557
                 'headers'          => array(
558 558
                     'Content-Type' => 'application/json; charset=utf-8'
559 559
                 ),
560
-                'body'             => json_encode( $post ),
560
+                'body'             => json_encode($post),
561 561
                 'method'           => 'POST'
562 562
             )
563 563
         );
564 564
 
565
-        if ( is_wp_error( $response ) ) {
565
+        if (is_wp_error($response)) {
566 566
             return $response;
567 567
         }
568 568
 
569
-        $response = wp_unslash( wp_remote_retrieve_body( $response ) );
569
+        $response = wp_unslash(wp_remote_retrieve_body($response));
570 570
         $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
571
-        $response = json_decode( $response );
571
+        $response = json_decode($response);
572 572
 
573
-        if ( empty( $response ) ) {
574
-            return new WP_Error( 'invalid_reponse', __( 'Invalid response', 'invoicing' ) );
573
+        if (empty($response)) {
574
+            return new WP_Error('invalid_reponse', __('Invalid response', 'invoicing'));
575 575
         }
576 576
 
577
-        if ( $response->messages->resultCode == 'Error' ) {
577
+        if ($response->messages->resultCode == 'Error') {
578 578
 
579
-            if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) {
579
+            if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) {
580 580
                 $error = $response->transactionResponse->errors[0];
581
-                return new WP_Error( $error->errorCode, $error->errorText );
581
+                return new WP_Error($error->errorCode, $error->errorText);
582 582
             }
583 583
 
584
-            return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text );
584
+            return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text);
585 585
         }
586 586
 
587 587
         return $response;
@@ -597,49 +597,49 @@  discard block
 block discarded – undo
597 597
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
598 598
 	 * @return array
599 599
 	 */
600
-	public function process_payment( $invoice, $submission_data, $submission ) {
600
+	public function process_payment($invoice, $submission_data, $submission) {
601 601
 
602 602
         // Validate the submitted data.
603
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
603
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
604 604
 
605 605
         // Do we have an error?
606
-        if ( is_wp_error( $payment_profile_id ) ) {
607
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
606
+        if (is_wp_error($payment_profile_id)) {
607
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
608 608
             wpinv_send_back_to_checkout();
609 609
         }
610 610
 
611 611
         // Save the payment method to the order.
612
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
612
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
613 613
 
614 614
         // Check if this is a subscription or not.
615
-        if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice ) ) {
616
-            $this->process_subscription( $invoice, $subscription );
615
+        if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice)) {
616
+            $this->process_subscription($invoice, $subscription);
617 617
         }
618 618
 
619 619
         // If it is free, send to the success page.
620
-        if ( ! $invoice->needs_payment() ) {
620
+        if (!$invoice->needs_payment()) {
621 621
             $invoice->mark_paid();
622
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
622
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
623 623
         }
624 624
 
625 625
         // Charge the payment profile.
626
-        $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
627
-        $result           = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
626
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
627
+        $result           = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
628 628
 
629 629
         // Do we have an error?
630
-        if ( is_wp_error( $result ) ) {
631
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
630
+        if (is_wp_error($result)) {
631
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
632 632
             wpinv_send_back_to_checkout();
633 633
         }
634 634
 
635 635
         // Process the response.
636
-        $this->process_charge_response( $result, $invoice );
636
+        $this->process_charge_response($result, $invoice);
637 637
 
638
-        if ( wpinv_get_errors() ) {
638
+        if (wpinv_get_errors()) {
639 639
             wpinv_send_back_to_checkout();
640 640
         }
641 641
 
642
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
642
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
643 643
 
644 644
         exit;
645 645
 
@@ -651,40 +651,40 @@  discard block
 block discarded – undo
651 651
      * @param WPInv_Invoice $invoice Invoice.
652 652
      * @param WPInv_Subscription $subscription Subscription.
653 653
 	 */
654
-	public function process_subscription( $invoice, $subscription ) {
654
+	public function process_subscription($invoice, $subscription) {
655 655
 
656 656
         // Check if there is an initial amount to charge.
657
-        if ( (float) $invoice->get_total() > 0 ) {
657
+        if ((float) $invoice->get_total() > 0) {
658 658
 
659 659
             // Retrieve the payment method.
660
-            $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
661
-            $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
662
-            $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
660
+            $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
661
+            $customer_profile   = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
662
+            $result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
663 663
 
664 664
             // Do we have an error?
665
-            if ( is_wp_error( $result ) ) {
666
-                wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
665
+            if (is_wp_error($result)) {
666
+                wpinv_set_error($result->get_error_code(), $result->get_error_message());
667 667
                 wpinv_send_back_to_checkout();
668 668
             }
669 669
 
670 670
             // Process the response.
671
-            $this->process_charge_response( $result, $invoice );
671
+            $this->process_charge_response($result, $invoice);
672 672
 
673
-            if ( wpinv_get_errors() ) {
673
+            if (wpinv_get_errors()) {
674 674
                 wpinv_send_back_to_checkout();
675 675
             }
676 676
 
677 677
         }
678 678
 
679 679
         // Recalculate the new subscription expiry.
680
-        $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created );
681
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
680
+        $duration = strtotime($subscription->expiration) - strtotime($subscription->created);
681
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
682 682
 
683 683
         // Schedule an action to run when the subscription expires.
684 684
         $action_id = as_schedule_single_action(
685
-            strtotime( $expiry ),
685
+            strtotime($expiry),
686 686
             'wpinv_renew_authorizenet_subscription_profile',
687
-            array( $invoice->get_id() ),
687
+            array($invoice->get_id()),
688 688
             'invoicing'
689 689
         );
690 690
 
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
             array(
694 694
                 'profile_id' => $action_id,
695 695
                 'status'     => 'trialling' == $subscription->status ? 'trialling' : 'active',
696
-                'created'    => current_time( 'mysql' ),
696
+                'created'    => current_time('mysql'),
697 697
                 'expiration' => $expiry,
698 698
             )
699 699
         );
700 700
 
701
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
701
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
702 702
 
703 703
     }
704 704
 
@@ -707,45 +707,45 @@  discard block
 block discarded – undo
707 707
 	 *
708 708
      * @param int $invoice Invoice id.
709 709
 	 */
710
-	public function renew_subscription( $invoice ) {
710
+	public function renew_subscription($invoice) {
711 711
 
712 712
         // Retrieve the subscription.
713
-        $subscription = wpinv_get_subscription( $invoice );
714
-        if ( empty( $subscription ) ) {
713
+        $subscription = wpinv_get_subscription($invoice);
714
+        if (empty($subscription)) {
715 715
             return;
716 716
         }
717 717
 
718 718
         // Abort if it is canceled or complete.
719
-        if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) {
719
+        if ($subscription->status == 'completed' || $subscription->status == 'cancelled') {
720 720
             return;
721 721
         }
722 722
 
723 723
         // Retrieve the invoice.
724
-        $invoice = new WPInv_Invoice( $invoice );
724
+        $invoice = new WPInv_Invoice($invoice);
725 725
 
726 726
         // If we have not maxed out on bill times...
727 727
         $times_billed = $subscription->get_times_billed();
728 728
         $max_bills    = $subscription->bill_times;
729 729
 
730
-        if ( empty( $max_bills ) || $max_bills > $times_billed ) {
730
+        if (empty($max_bills) || $max_bills > $times_billed) {
731 731
 
732 732
             $new_invoice = $subscription->create_payment();
733 733
 
734
-            if ( empty( $new_invoice ) ) {
735
-                $invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
734
+            if (empty($new_invoice)) {
735
+                $invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
736 736
                 $subscription->failing();
737 737
                 return;
738 738
             }
739 739
 
740 740
             // retrieve the payment method.
741
-            $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
742
-            $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
743
-            $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
741
+            $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
742
+            $customer_profile   = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
743
+            $result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
744 744
 
745 745
             // Do we have an error?
746
-            if ( is_wp_error( $result ) ) {
746
+            if (is_wp_error($result)) {
747 747
                 $invoice->add_note(
748
-                    sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
748
+                    sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
749 749
                     true,
750 750
                     false,
751 751
                     true
@@ -755,12 +755,12 @@  discard block
 block discarded – undo
755 755
             }
756 756
 
757 757
             // Process the response.
758
-            $this->process_charge_response( $result, $new_invoice );
758
+            $this->process_charge_response($result, $new_invoice);
759 759
 
760
-            if ( wpinv_get_errors() ) {
760
+            if (wpinv_get_errors()) {
761 761
 
762 762
                 $invoice->add_note(
763
-                    sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
763
+                    sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
764 764
                     true,
765 765
                     false,
766 766
                     true
@@ -782,17 +782,17 @@  discard block
 block discarded – undo
782 782
             // Renew/Complete the subscription.
783 783
             $subscription->renew();
784 784
 
785
-            if ( 'completed' != $subscription->status ) {
785
+            if ('completed' != $subscription->status) {
786 786
 
787 787
                 // Schedule an action to run when the subscription expires.
788 788
                 $action_id = as_schedule_single_action(
789
-                    strtotime( $subscription->expiration ),
789
+                    strtotime($subscription->expiration),
790 790
                     'wpinv_renew_authorizenet_subscription_profile',
791
-                    array( $invoice->get_id() ),
791
+                    array($invoice->get_id()),
792 792
                     'invoicing'
793 793
                 );
794 794
     
795
-                $subscription->update( array( 'profile_id' => $action_id, ) );
795
+                $subscription->update(array('profile_id' => $action_id,));
796 796
     
797 797
             }
798 798
 
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 	 * @param WPInv_Subscription $subscription Subscription.
807 807
      * @param WPInv_Invoice $invoice Invoice.
808 808
 	 */
809
-	public function cancel_subscription( $subscription, $invoice ) {
809
+	public function cancel_subscription($subscription, $invoice) {
810 810
 
811
-        if ( as_unschedule_action( 'wpinv_renew_authorizenet_subscription_profile', array( $invoice->get_id() ), 'invoicing' ) ) {
811
+        if (as_unschedule_action('wpinv_renew_authorizenet_subscription_profile', array($invoice->get_id()), 'invoicing')) {
812 812
             return;
813 813
         }
814 814
 
@@ -835,45 +835,45 @@  discard block
 block discarded – undo
835 835
         $this->maybe_process_old_ipn();
836 836
 
837 837
         // Validate the IPN.
838
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
839
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
838
+        if (empty($_POST) || !$this->validate_ipn()) {
839
+		    wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500));
840 840
         }
841 841
 
842 842
         // Event type.
843
-        $posted = json_decode( file_get_contents('php://input') );
844
-        if ( empty( $posted ) ) {
845
-            wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) );
843
+        $posted = json_decode(file_get_contents('php://input'));
844
+        if (empty($posted)) {
845
+            wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500));
846 846
         }
847 847
 
848 848
         // Process the IPN.
849
-        $posted = (object) wp_unslash( $posted );
849
+        $posted = (object) wp_unslash($posted);
850 850
 
851 851
         // Process refunds.
852
-        if ( 'net.authorize.payment.refund.created' == $posted->eventType ) {
853
-            $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId );
852
+        if ('net.authorize.payment.refund.created' == $posted->eventType) {
853
+            $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId);
854 854
 
855
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
855
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
856 856
                 $invoice->refund();
857 857
             }
858 858
 
859 859
         }
860 860
 
861 861
         // Held funds approved.
862
-        if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) {
863
-            $invoice = new WPInv_Invoice( $posted->payload->id );
862
+        if ('net.authorize.payment.fraud.approved' == $posted->eventType) {
863
+            $invoice = new WPInv_Invoice($posted->payload->id);
864 864
 
865
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
866
-                $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ));
865
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
866
+                $invoice->mark_paid(false, __('Payment released', 'invoicing'));
867 867
             }
868 868
 
869 869
         }
870 870
 
871 871
         // Held funds declined.
872
-        if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) {
873
-            $invoice = new WPInv_Invoice( $posted->payload->id );
872
+        if ('net.authorize.payment.fraud.declined' == $posted->eventType) {
873
+            $invoice = new WPInv_Invoice($posted->payload->id);
874 874
 
875
-            if ( $invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id() ) {
876
-                $invoice->set_status( 'wpi-failed', __( 'Payment desclined', 'invoicing' ) );
875
+            if ($invoice->get_id() && $posted->payload->id == $invoice->get_transaction_id()) {
876
+                $invoice->set_status('wpi-failed', __('Payment desclined', 'invoicing'));
877 877
                 $invoice->save();
878 878
             }
879 879
 
@@ -891,41 +891,41 @@  discard block
 block discarded – undo
891 891
 	public function maybe_process_old_ipn() {
892 892
 
893 893
         // Ensure that we are using the old subscriptions.
894
-        if ( empty( $_POST['x_subscription_id'] ) ) {
894
+        if (empty($_POST['x_subscription_id'])) {
895 895
             return;
896 896
         }
897 897
 
898 898
         // Check validity.
899
-        $signature = $this->get_option( 'signature_key' );
900
-        if ( ! empty( $signature ) ) {
901
-            $login_id  = $this->get_option( 'login_id' );
899
+        $signature = $this->get_option('signature_key');
900
+        if (!empty($signature)) {
901
+            $login_id  = $this->get_option('login_id');
902 902
             $trans_id  = $_POST['x_trans_id'];
903 903
             $amount    = $_POST['x_amount'];
904
-            $hash      = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) );
904
+            $hash      = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature));
905 905
 
906
-            if ( ! hash_equals( $hash, $_POST['x_SHA2_Hash'] ) ) {
906
+            if (!hash_equals($hash, $_POST['x_SHA2_Hash'])) {
907 907
                 exit;
908 908
             }
909 909
 
910 910
         }
911 911
 
912 912
         // Fetch the associated subscription.
913
-        $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $_POST['x_subscription_id'] );
914
-        $subscription    = new WPInv_Subscription( $subscription_id );
913
+        $subscription_id = WPInv_Subscription::get_subscription_id_by_field($_POST['x_subscription_id']);
914
+        $subscription    = new WPInv_Subscription($subscription_id);
915 915
 
916 916
         // Abort if it is missing or completed.
917
-        if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) {
917
+        if (!$subscription->get_id() || $subscription->has_status('completed')) {
918 918
             return;
919 919
         }
920 920
 
921 921
         // Payment status.
922
-        if ( 1 == $_POST['x_response_code'] ) {
922
+        if (1 == $_POST['x_response_code']) {
923 923
 
924 924
             $invoice = $subscription->create_payment();
925
-            $invoice->set_transaction_id( sanitize_text_field( $_POST['x_trans_id'] ) );
926
-            $invoice->set_status( 'wpi-renewal' );
925
+            $invoice->set_transaction_id(sanitize_text_field($_POST['x_trans_id']));
926
+            $invoice->set_status('wpi-renewal');
927 927
             $invoice->save();
928
-            $subscription->add_payment( $invoice );
928
+            $subscription->add_payment($invoice);
929 929
             $subscription->renew();
930 930
 
931 931
         } else {
@@ -941,28 +941,28 @@  discard block
 block discarded – undo
941 941
 	 */
942 942
 	public function validate_ipn() {
943 943
 
944
-        wpinv_error_log( 'Validating Authorize.NET IPN response' );
944
+        wpinv_error_log('Validating Authorize.NET IPN response');
945 945
 
946
-        if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
946
+        if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) {
947 947
             return false;
948 948
         }
949 949
 
950
-        $signature = $this->get_option( 'signature_key' );
950
+        $signature = $this->get_option('signature_key');
951 951
 
952
-        if ( empty( $signature ) ) {
953
-            wpinv_error_log( 'Error: You have not set a signature key' );
952
+        if (empty($signature)) {
953
+            wpinv_error_log('Error: You have not set a signature key');
954 954
             return false;
955 955
         }
956 956
 
957
-        $hash  = hash_hmac ( 'sha512', file_get_contents('php://input'), hex2bin( $signature ) );
957
+        $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature));
958 958
 
959
-        if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
960
-            wpinv_error_log( 'Successfully validated the IPN' );
959
+        if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) {
960
+            wpinv_error_log('Successfully validated the IPN');
961 961
             return true;
962 962
         }
963 963
 
964
-        wpinv_error_log( 'IPN hash is not valid' );
965
-        wpinv_error_log(  $_SERVER['HTTP_X_ANET_SIGNATURE']  );
964
+        wpinv_error_log('IPN hash is not valid');
965
+        wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']);
966 966
         return false;
967 967
 
968 968
     }
@@ -970,11 +970,11 @@  discard block
 block discarded – undo
970 970
     /**
971 971
      * Displays a notice on the checkout page if sandbox is enabled.
972 972
      */
973
-    public function sandbox_notice( $description, $gateway ) {
973
+    public function sandbox_notice($description, $gateway) {
974 974
 
975
-        if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) {
975
+        if ($this->id == $gateway && wpinv_is_test_mode($this->id)) {
976 976
             $description .= '<br>' . sprintf(
977
-                __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
977
+                __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
978 978
                 '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
979 979
                 '</a>'
980 980
             );
@@ -988,42 +988,42 @@  discard block
 block discarded – undo
988 988
 	 * 
989 989
 	 * @param array $admin_settings
990 990
 	 */
991
-	public function admin_settings( $admin_settings ) {
991
+	public function admin_settings($admin_settings) {
992 992
 
993 993
         $currencies = sprintf(
994
-            __( 'Supported Currencies: %s', 'invoicing' ),
995
-            implode( ', ', $this->currencies )
994
+            __('Supported Currencies: %s', 'invoicing'),
995
+            implode(', ', $this->currencies)
996 996
         );
997 997
 
998 998
         $admin_settings['authorizenet_active']['desc'] .= $admin_settings['authorizenet_active']['desc'] . " ($currencies)";
999
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
999
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
1000 1000
 
1001 1001
         $admin_settings['authorizenet_login_id'] = array(
1002 1002
             'type' => 'text',
1003 1003
             'id'   => 'authorizenet_login_id',
1004
-            'name' => __( 'API Login ID', 'invoicing' ),
1005
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
1004
+            'name' => __('API Login ID', 'invoicing'),
1005
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
1006 1006
         );
1007 1007
 
1008 1008
         $admin_settings['authorizenet_transaction_key'] = array(
1009 1009
             'type' => 'text',
1010 1010
             'id'   => 'authorizenet_transaction_key',
1011
-            'name' => __( 'Transaction Key', 'invoicing' ),
1011
+            'name' => __('Transaction Key', 'invoicing'),
1012 1012
         );
1013 1013
 
1014 1014
         $admin_settings['authorizenet_signature_key'] = array(
1015 1015
             'type' => 'text',
1016 1016
             'id'   => 'authorizenet_signature_key',
1017
-            'name' => __( 'Signature Key', 'invoicing' ),
1018
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
1017
+            'name' => __('Signature Key', 'invoicing'),
1018
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
1019 1019
         );
1020 1020
 
1021 1021
         $admin_settings['authorizenet_ipn_url'] = array(
1022 1022
             'type'     => 'ipn_url',
1023 1023
             'id'       => 'authorizenet_ipn_url',
1024
-            'name'     => __( 'Webhook URL', 'invoicing' ),
1024
+            'name'     => __('Webhook URL', 'invoicing'),
1025 1025
             'std'      => $this->notify_url,
1026
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
1026
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
1027 1027
             'custom'   => 'authorizenet',
1028 1028
             'readonly' => true,
1029 1029
         );
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92 92
 /**
@@ -95,32 +95,32 @@  discard block
 block discarded – undo
95 95
  * @since 1.0.19
96 96
  * @return array
97 97
  */
98
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
98
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
99 99
 	$invoice_statuses = array(
100
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
101
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
102
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
103
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
106
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
107
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
100
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
101
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
102
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
103
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
104
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
105
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
106
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
107
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
108 108
     );
109 109
 
110
-    if ( $draft ) {
111
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
110
+    if ($draft) {
111
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
112 112
     }
113 113
 
114
-    if ( $trashed ) {
115
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
114
+    if ($trashed) {
115
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
116 116
     }
117 117
 
118
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
118
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
119 119
 }
120 120
 
121
-function wpinv_status_nicename( $status ) {
122
-    $statuses = wpinv_get_invoice_statuses( true, true );
123
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
121
+function wpinv_status_nicename($status) {
122
+    $statuses = wpinv_get_invoice_statuses(true, true);
123
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
124 124
 
125 125
     return $status;
126 126
 }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
  * Retrieves the default currency code.
130 130
  */
131 131
 function wpinv_get_currency() {
132
-    return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
132
+    return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
133 133
 }
134 134
 
135 135
 /**
@@ -137,61 +137,61 @@  discard block
 block discarded – undo
137 137
  * 
138 138
  * @param string|null $currency The currency code. Defaults to the default currency.
139 139
  */
140
-function wpinv_currency_symbol( $currency = null ) {
140
+function wpinv_currency_symbol($currency = null) {
141 141
 
142 142
     // Prepare the currency.
143
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
143
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
144 144
 
145 145
     // Fetch all symbols.
146 146
     $symbols = wpinv_get_currency_symbols();
147 147
 
148 148
     // Fetch this currencies symbol.
149
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
149
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
150 150
 
151 151
     // Filter the symbol.
152
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
152
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
153 153
 }
154 154
 
155 155
 function wpinv_currency_position() {
156
-    $position = wpinv_get_option( 'currency_position', 'left' );
156
+    $position = wpinv_get_option('currency_position', 'left');
157 157
     
158
-    return apply_filters( 'wpinv_currency_position', $position );
158
+    return apply_filters('wpinv_currency_position', $position);
159 159
 }
160 160
 
161 161
 function wpinv_thousands_separator() {
162
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
162
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
163 163
     
164
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
164
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
165 165
 }
166 166
 
167 167
 function wpinv_decimal_separator() {
168
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
168
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
169 169
     
170
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
170
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
171 171
 }
172 172
 
173 173
 function wpinv_decimals() {
174
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
174
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
175 175
     
176
-    return absint( $decimals );
176
+    return absint($decimals);
177 177
 }
178 178
 
179 179
 /**
180 180
  * Retrieves a list of all supported currencies.
181 181
  */
182 182
 function wpinv_get_currencies() {
183
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
183
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
184 184
 }
185 185
 
186 186
 /**
187 187
  * Retrieves a list of all currency symbols.
188 188
  */
189 189
 function wpinv_get_currency_symbols() {
190
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
190
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
191 191
 }
192 192
 
193
-function wpinv_price( $amount = '', $currency = '' ) {
194
-    if( empty( $currency ) ) {
193
+function wpinv_price($amount = '', $currency = '') {
194
+    if (empty($currency)) {
195 195
         $currency = wpinv_get_currency();
196 196
     }
197 197
 
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 
200 200
     $negative = $amount < 0;
201 201
 
202
-    if ( $negative ) {
203
-        $amount = substr( $amount, 1 );
202
+    if ($negative) {
203
+        $amount = substr($amount, 1);
204 204
     }
205 205
 
206
-    $symbol = wpinv_currency_symbol( $currency );
206
+    $symbol = wpinv_currency_symbol($currency);
207 207
 
208
-    if ( $position == 'left' || $position == 'left_space' ) {
209
-        switch ( $currency ) {
208
+    if ($position == 'left' || $position == 'left_space') {
209
+        switch ($currency) {
210 210
             case "GBP" :
211 211
             case "BRL" :
212 212
             case "EUR" :
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
             case "NZD" :
219 219
             case "SGD" :
220 220
             case "JPY" :
221
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
221
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
222 222
                 break;
223 223
             default :
224 224
                 //$price = $currency . ' ' . $amount;
225
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
225
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
226 226
                 break;
227 227
         }
228 228
     } else {
229
-        switch ( $currency ) {
229
+        switch ($currency) {
230 230
             case "GBP" :
231 231
             case "BRL" :
232 232
             case "EUR" :
@@ -237,83 +237,83 @@  discard block
 block discarded – undo
237 237
             case "MXN" :
238 238
             case "SGD" :
239 239
             case "JPY" :
240
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
240
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
241 241
                 break;
242 242
             default :
243 243
                 //$price = $amount . ' ' . $currency;
244
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
244
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
245 245
                 break;
246 246
         }
247 247
     }
248 248
     
249
-    if ( $negative ) {
249
+    if ($negative) {
250 250
         $price = '-' . $price;
251 251
     }
252 252
     
253
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
253
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
254 254
 
255 255
     return $price;
256 256
 }
257 257
 
258
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
258
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
259 259
     $thousands_sep = wpinv_thousands_separator();
260 260
     $decimal_sep   = wpinv_decimal_separator();
261 261
 
262
-    if ( $decimals === NULL ) {
262
+    if ($decimals === NULL) {
263 263
         $decimals = wpinv_decimals();
264 264
     }
265 265
 
266
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
267
-        $whole = substr( $amount, 0, $sep_found );
268
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
266
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
267
+        $whole = substr($amount, 0, $sep_found);
268
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
269 269
         $amount = $whole . '.' . $part;
270 270
     }
271 271
 
272
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
273
-        $amount = str_replace( ',', '', $amount );
272
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
273
+        $amount = str_replace(',', '', $amount);
274 274
     }
275 275
 
276
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
277
-        $amount = str_replace( ' ', '', $amount );
276
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
277
+        $amount = str_replace(' ', '', $amount);
278 278
     }
279 279
 
280
-    if ( empty( $amount ) ) {
280
+    if (empty($amount)) {
281 281
         $amount = 0;
282 282
     }
283 283
     
284
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
285
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
284
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
285
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
286 286
     
287
-    if ( $calculate ) {
288
-        if ( $thousands_sep === "," ) {
289
-            $formatted = str_replace( ",", "", $formatted );
287
+    if ($calculate) {
288
+        if ($thousands_sep === ",") {
289
+            $formatted = str_replace(",", "", $formatted);
290 290
         }
291 291
         
292
-        if ( $decimal_sep === "," ) {
293
-            $formatted = str_replace( ",", ".", $formatted );
292
+        if ($decimal_sep === ",") {
293
+            $formatted = str_replace(",", ".", $formatted);
294 294
         }
295 295
     }
296 296
 
297
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
297
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
298 298
 }
299
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
299
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
300 300
 
301
-function wpinv_sanitize_key( $key ) {
301
+function wpinv_sanitize_key($key) {
302 302
     $raw_key = $key;
303
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
303
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
304 304
 
305
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
305
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
306 306
 }
307 307
 
308
-function wpinv_get_file_extension( $str ) {
309
-    $parts = explode( '.', $str );
310
-    return end( $parts );
308
+function wpinv_get_file_extension($str) {
309
+    $parts = explode('.', $str);
310
+    return end($parts);
311 311
 }
312 312
 
313
-function wpinv_string_is_image_url( $str ) {
314
-    $ext = wpinv_get_file_extension( $str );
313
+function wpinv_string_is_image_url($str) {
314
+    $ext = wpinv_get_file_extension($str);
315 315
 
316
-    switch ( strtolower( $ext ) ) {
316
+    switch (strtolower($ext)) {
317 317
         case 'jpeg';
318 318
         case 'jpg';
319 319
             $return = true;
@@ -329,33 +329,33 @@  discard block
 block discarded – undo
329 329
             break;
330 330
     }
331 331
 
332
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
332
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
333 333
 }
334 334
 
335
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
336
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
335
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
336
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
337 337
     
338
-    if ( true === $should_log ) {
338
+    if (true === $should_log) {
339 339
         $label = '';
340
-        if ( $file && $file !== '' ) {
341
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
340
+        if ($file && $file !== '') {
341
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
342 342
         }
343 343
         
344
-        if ( $title && $title !== '' ) {
344
+        if ($title && $title !== '') {
345 345
             $label = $label !== '' ? $label . ' ' : '';
346 346
             $label .= $title . ' ';
347 347
         }
348 348
         
349
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
349
+        $label = $label !== '' ? trim($label) . ' : ' : '';
350 350
         
351
-        if ( is_array( $log ) || is_object( $log ) ) {
352
-            error_log( $label . print_r( $log, true ) );
351
+        if (is_array($log) || is_object($log)) {
352
+            error_log($label . print_r($log, true));
353 353
         } else {
354
-            error_log( $label . $log );
354
+            error_log($label . $log);
355 355
         }
356 356
 
357
-        error_log( wp_debug_backtrace_summary() );
358
-        if ( $exit ) {
357
+        error_log(wp_debug_backtrace_summary());
358
+        if ($exit) {
359 359
             exit;
360 360
         }
361 361
     }
@@ -363,32 +363,32 @@  discard block
 block discarded – undo
363 363
 
364 364
 function wpinv_is_ajax_disabled() {
365 365
     $retval = false;
366
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
366
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
367 367
 }
368 368
 
369
-function wpinv_get_current_page_url( $nocache = false ) {
369
+function wpinv_get_current_page_url($nocache = false) {
370 370
     global $wp;
371 371
 
372
-    if ( get_option( 'permalink_structure' ) ) {
373
-        $base = trailingslashit( home_url( $wp->request ) );
372
+    if (get_option('permalink_structure')) {
373
+        $base = trailingslashit(home_url($wp->request));
374 374
     } else {
375
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
376
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
375
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
376
+        $base = remove_query_arg(array('post_type', 'name'), $base);
377 377
     }
378 378
 
379 379
     $scheme = is_ssl() ? 'https' : 'http';
380
-    $uri    = set_url_scheme( $base, $scheme );
380
+    $uri    = set_url_scheme($base, $scheme);
381 381
 
382
-    if ( is_front_page() ) {
383
-        $uri = home_url( '/' );
384
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
382
+    if (is_front_page()) {
383
+        $uri = home_url('/');
384
+    } elseif (wpinv_is_checkout(array(), false)) {
385 385
         $uri = wpinv_get_checkout_uri();
386 386
     }
387 387
 
388
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
388
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
389 389
 
390
-    if ( $nocache ) {
391
-        $uri = wpinv_add_cache_busting( $uri );
390
+    if ($nocache) {
391
+        $uri = wpinv_add_cache_busting($uri);
392 392
     }
393 393
 
394 394
     return $uri;
@@ -401,46 +401,46 @@  discard block
 block discarded – undo
401 401
  * @param string $name  Constant name.
402 402
  * @param mixed  $value Value.
403 403
  */
404
-function getpaid_maybe_define_constant( $name, $value ) {
405
-	if ( ! defined( $name ) ) {
406
-		define( $name, $value );
404
+function getpaid_maybe_define_constant($name, $value) {
405
+	if (!defined($name)) {
406
+		define($name, $value);
407 407
 	}
408 408
 }
409 409
 
410 410
 function wpinv_get_php_arg_separator_output() {
411
-	return ini_get( 'arg_separator.output' );
411
+	return ini_get('arg_separator.output');
412 412
 }
413 413
 
414
-function wpinv_rgb_from_hex( $color ) {
415
-    $color = str_replace( '#', '', $color );
414
+function wpinv_rgb_from_hex($color) {
415
+    $color = str_replace('#', '', $color);
416 416
 
417 417
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
418
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
419
-    if ( empty( $color ) ) {
418
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
419
+    if (empty($color)) {
420 420
         return NULL;
421 421
     }
422 422
 
423
-    $color = str_split( $color );
423
+    $color = str_split($color);
424 424
 
425 425
     $rgb      = array();
426
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
427
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
428
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
426
+    $rgb['R'] = hexdec($color[0] . $color[1]);
427
+    $rgb['G'] = hexdec($color[2] . $color[3]);
428
+    $rgb['B'] = hexdec($color[4] . $color[5]);
429 429
 
430 430
     return $rgb;
431 431
 }
432 432
 
433
-function wpinv_hex_darker( $color, $factor = 30 ) {
434
-    $base  = wpinv_rgb_from_hex( $color );
433
+function wpinv_hex_darker($color, $factor = 30) {
434
+    $base  = wpinv_rgb_from_hex($color);
435 435
     $color = '#';
436 436
 
437
-    foreach ( $base as $k => $v ) {
437
+    foreach ($base as $k => $v) {
438 438
         $amount      = $v / 100;
439
-        $amount      = round( $amount * $factor );
439
+        $amount      = round($amount * $factor);
440 440
         $new_decimal = $v - $amount;
441 441
 
442
-        $new_hex_component = dechex( $new_decimal );
443
-        if ( strlen( $new_hex_component ) < 2 ) {
442
+        $new_hex_component = dechex($new_decimal);
443
+        if (strlen($new_hex_component) < 2) {
444 444
             $new_hex_component = "0" . $new_hex_component;
445 445
         }
446 446
         $color .= $new_hex_component;
@@ -449,18 +449,18 @@  discard block
 block discarded – undo
449 449
     return $color;
450 450
 }
451 451
 
452
-function wpinv_hex_lighter( $color, $factor = 30 ) {
453
-    $base  = wpinv_rgb_from_hex( $color );
452
+function wpinv_hex_lighter($color, $factor = 30) {
453
+    $base  = wpinv_rgb_from_hex($color);
454 454
     $color = '#';
455 455
 
456
-    foreach ( $base as $k => $v ) {
456
+    foreach ($base as $k => $v) {
457 457
         $amount      = 255 - $v;
458 458
         $amount      = $amount / 100;
459
-        $amount      = round( $amount * $factor );
459
+        $amount      = round($amount * $factor);
460 460
         $new_decimal = $v + $amount;
461 461
 
462
-        $new_hex_component = dechex( $new_decimal );
463
-        if ( strlen( $new_hex_component ) < 2 ) {
462
+        $new_hex_component = dechex($new_decimal);
463
+        if (strlen($new_hex_component) < 2) {
464 464
             $new_hex_component = "0" . $new_hex_component;
465 465
         }
466 466
         $color .= $new_hex_component;
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
     return $color;
470 470
 }
471 471
 
472
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
473
-    $hex = str_replace( '#', '', $color );
472
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
473
+    $hex = str_replace('#', '', $color);
474 474
 
475
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
476
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
477
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
475
+    $c_r = hexdec(substr($hex, 0, 2));
476
+    $c_g = hexdec(substr($hex, 2, 2));
477
+    $c_b = hexdec(substr($hex, 4, 2));
478 478
 
479
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
479
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
480 480
 
481 481
     return $brightness > 155 ? $dark : $light;
482 482
 }
483 483
 
484
-function wpinv_format_hex( $hex ) {
485
-    $hex = trim( str_replace( '#', '', $hex ) );
484
+function wpinv_format_hex($hex) {
485
+    $hex = trim(str_replace('#', '', $hex));
486 486
 
487
-    if ( strlen( $hex ) == 3 ) {
487
+    if (strlen($hex) == 3) {
488 488
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
489 489
     }
490 490
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
505 505
  * @return string
506 506
  */
507
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
508
-    if ( function_exists( 'mb_strimwidth' ) ) {
509
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
507
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
508
+    if (function_exists('mb_strimwidth')) {
509
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
510 510
     }
511 511
     
512
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
512
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
513 513
 }
514 514
 
515 515
 /**
@@ -521,28 +521,28 @@  discard block
 block discarded – undo
521 521
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
522 522
  * @return int Returns the number of characters in string.
523 523
  */
524
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
525
-    if ( function_exists( 'mb_strlen' ) ) {
526
-        return mb_strlen( $str, $encoding );
524
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
525
+    if (function_exists('mb_strlen')) {
526
+        return mb_strlen($str, $encoding);
527 527
     }
528 528
         
529
-    return strlen( $str );
529
+    return strlen($str);
530 530
 }
531 531
 
532
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
533
-    if ( function_exists( 'mb_strtolower' ) ) {
534
-        return mb_strtolower( $str, $encoding );
532
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
533
+    if (function_exists('mb_strtolower')) {
534
+        return mb_strtolower($str, $encoding);
535 535
     }
536 536
     
537
-    return strtolower( $str );
537
+    return strtolower($str);
538 538
 }
539 539
 
540
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
541
-    if ( function_exists( 'mb_strtoupper' ) ) {
542
-        return mb_strtoupper( $str, $encoding );
540
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
541
+    if (function_exists('mb_strtoupper')) {
542
+        return mb_strtoupper($str, $encoding);
543 543
     }
544 544
     
545
-    return strtoupper( $str );
545
+    return strtoupper($str);
546 546
 }
547 547
 
548 548
 /**
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
557 557
  * @return int Returns the position of the first occurrence of search in the string.
558 558
  */
559
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
560
-    if ( function_exists( 'mb_strpos' ) ) {
561
-        return mb_strpos( $str, $find, $offset, $encoding );
559
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
560
+    if (function_exists('mb_strpos')) {
561
+        return mb_strpos($str, $find, $offset, $encoding);
562 562
     }
563 563
         
564
-    return strpos( $str, $find, $offset );
564
+    return strpos($str, $find, $offset);
565 565
 }
566 566
 
567 567
 /**
@@ -575,12 +575,12 @@  discard block
 block discarded – undo
575 575
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
576 576
  * @return int Returns the position of the last occurrence of search.
577 577
  */
578
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
579
-    if ( function_exists( 'mb_strrpos' ) ) {
580
-        return mb_strrpos( $str, $find, $offset, $encoding );
578
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
579
+    if (function_exists('mb_strrpos')) {
580
+        return mb_strrpos($str, $find, $offset, $encoding);
581 581
     }
582 582
         
583
-    return strrpos( $str, $find, $offset );
583
+    return strrpos($str, $find, $offset);
584 584
 }
585 585
 
586 586
 /**
@@ -595,16 +595,16 @@  discard block
 block discarded – undo
595 595
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
596 596
  * @return string
597 597
  */
598
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
599
-    if ( function_exists( 'mb_substr' ) ) {
600
-        if ( $length === null ) {
601
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
598
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
599
+    if (function_exists('mb_substr')) {
600
+        if ($length === null) {
601
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
602 602
         } else {
603
-            return mb_substr( $str, $start, $length, $encoding );
603
+            return mb_substr($str, $start, $length, $encoding);
604 604
         }
605 605
     }
606 606
         
607
-    return substr( $str, $start, $length );
607
+    return substr($str, $start, $length);
608 608
 }
609 609
 
610 610
 /**
@@ -616,48 +616,48 @@  discard block
 block discarded – undo
616 616
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
617 617
  * @return string The width of string.
618 618
  */
619
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
620
-    if ( function_exists( 'mb_strwidth' ) ) {
621
-        return mb_strwidth( $str, $encoding );
619
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
620
+    if (function_exists('mb_strwidth')) {
621
+        return mb_strwidth($str, $encoding);
622 622
     }
623 623
     
624
-    return wpinv_utf8_strlen( $str, $encoding );
624
+    return wpinv_utf8_strlen($str, $encoding);
625 625
 }
626 626
 
627
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
628
-    if ( function_exists( 'mb_strlen' ) ) {
629
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
627
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
628
+    if (function_exists('mb_strlen')) {
629
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
630 630
         $str_end = "";
631 631
         
632
-        if ( $lower_str_end ) {
633
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
632
+        if ($lower_str_end) {
633
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
634 634
         } else {
635
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
635
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
636 636
         }
637 637
 
638 638
         return $first_letter . $str_end;
639 639
     }
640 640
     
641
-    return ucfirst( $str );
641
+    return ucfirst($str);
642 642
 }
643 643
 
644
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
645
-    if ( function_exists( 'mb_convert_case' ) ) {
646
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
644
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
645
+    if (function_exists('mb_convert_case')) {
646
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
647 647
     }
648 648
     
649
-    return ucwords( $str );
649
+    return ucwords($str);
650 650
 }
651 651
 
652
-function wpinv_period_in_days( $period, $unit ) {
653
-    $period = absint( $period );
652
+function wpinv_period_in_days($period, $unit) {
653
+    $period = absint($period);
654 654
     
655
-    if ( $period > 0 ) {
656
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
655
+    if ($period > 0) {
656
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
657 657
             $period = $period * 7;
658
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
658
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
659 659
             $period = $period * 30;
660
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
660
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
661 661
             $period = $period * 365;
662 662
         }
663 663
     }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
     return $period;
666 666
 }
667 667
 
668
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
669
-    if ( function_exists( 'cal_days_in_month' ) ) {
670
-        return cal_days_in_month( $calendar, $month, $year );
668
+function wpinv_cal_days_in_month($calendar, $month, $year) {
669
+    if (function_exists('cal_days_in_month')) {
670
+        return cal_days_in_month($calendar, $month, $year);
671 671
     }
672 672
 
673 673
     // Fallback in case the calendar extension is not loaded in PHP
674 674
     // Only supports Gregorian calendar
675
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
675
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
676 676
 }
677 677
 
678 678
 /**
@@ -683,11 +683,11 @@  discard block
 block discarded – undo
683 683
  *
684 684
  * @return string
685 685
  */
686
-function wpi_help_tip( $tip, $allow_html = false ) {
687
-    if ( $allow_html ) {
688
-        $tip = wpi_sanitize_tooltip( $tip );
686
+function wpi_help_tip($tip, $allow_html = false) {
687
+    if ($allow_html) {
688
+        $tip = wpi_sanitize_tooltip($tip);
689 689
     } else {
690
-        $tip = esc_attr( $tip );
690
+        $tip = esc_attr($tip);
691 691
     }
692 692
 
693 693
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
  * @param string $var
702 702
  * @return string
703 703
  */
704
-function wpi_sanitize_tooltip( $var ) {
705
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
704
+function wpi_sanitize_tooltip($var) {
705
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
706 706
         'br'     => array(),
707 707
         'em'     => array(),
708 708
         'strong' => array(),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
         'li'     => array(),
713 713
         'ol'     => array(),
714 714
         'p'      => array(),
715
-    ) ) );
715
+    )));
716 716
 }
717 717
 
718 718
 /**
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
  */
723 723
 function wpinv_get_screen_ids() {
724 724
 
725
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
725
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
726 726
 
727 727
     $screen_ids = array(
728 728
         'toplevel_page_' . $screen_id,
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
         'invoicing_page_wpi-addons',
741 741
     );
742 742
 
743
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
743
+    return apply_filters('wpinv_screen_ids', $screen_ids);
744 744
 }
745 745
 
746 746
 /**
@@ -751,14 +751,14 @@  discard block
 block discarded – undo
751 751
  * @param array|string $list List of values.
752 752
  * @return array Sanitized array of values.
753 753
  */
754
-function wpinv_parse_list( $list ) {
754
+function wpinv_parse_list($list) {
755 755
 
756
-    if ( empty( $list ) ) {
756
+    if (empty($list)) {
757 757
         $list = array();
758 758
     }
759 759
 
760
-	if ( ! is_array( $list ) ) {
761
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
760
+	if (!is_array($list)) {
761
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
762 762
 	}
763 763
 
764 764
 	return $list;
@@ -772,16 +772,16 @@  discard block
 block discarded – undo
772 772
  * @param string $key Type of data to fetch.
773 773
  * @return mixed Fetched data.
774 774
  */
775
-function wpinv_get_data( $key ) {
775
+function wpinv_get_data($key) {
776 776
 
777 777
     // Try fetching it from the cache.
778
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
779
-    if( $data ) {
778
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
779
+    if ($data) {
780 780
         return $data;
781 781
     }
782 782
 
783
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
784
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
783
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
784
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
785 785
 
786 786
 	return $data;
787 787
 }
@@ -795,10 +795,10 @@  discard block
 block discarded – undo
795 795
  * @param bool $first_empty Whether or not the first item in the list should be empty
796 796
  * @return mixed Fetched data.
797 797
  */
798
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
798
+function wpinv_maybe_add_empty_option($options, $first_empty) {
799 799
 
800
-    if ( ! empty( $options ) && $first_empty ) {
801
-        return array_merge( array( '' => '' ), $options );
800
+    if (!empty($options) && $first_empty) {
801
+        return array_merge(array('' => ''), $options);
802 802
     }
803 803
     return $options;
804 804
 
@@ -810,21 +810,21 @@  discard block
 block discarded – undo
810 810
  * @param mixed $var Data to sanitize.
811 811
  * @return string|array
812 812
  */
813
-function wpinv_clean( $var ) {
813
+function wpinv_clean($var) {
814 814
 
815
-	if ( is_array( $var ) ) {
816
-		return array_map( 'wpinv_clean', $var );
815
+	if (is_array($var)) {
816
+		return array_map('wpinv_clean', $var);
817 817
     }
818 818
 
819
-    if ( is_object( $var ) ) {
820
-		$object_vars = get_object_vars( $var );
821
-		foreach ( $object_vars as $property_name => $property_value ) {
822
-			$var->$property_name = wpinv_clean( $property_value );
819
+    if (is_object($var)) {
820
+		$object_vars = get_object_vars($var);
821
+		foreach ($object_vars as $property_name => $property_value) {
822
+			$var->$property_name = wpinv_clean($property_value);
823 823
         }
824 824
         return $var;
825 825
 	}
826 826
     
827
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
827
+    return is_string($var) ? sanitize_text_field($var) : $var;
828 828
 }
829 829
 
830 830
 /**
@@ -833,43 +833,43 @@  discard block
 block discarded – undo
833 833
  * @param string $str Data to convert.
834 834
  * @return string|array
835 835
  */
836
-function getpaid_convert_price_string_to_options( $str ) {
836
+function getpaid_convert_price_string_to_options($str) {
837 837
 
838
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
839
-    $options     = array();
838
+	$raw_options = array_map('trim', explode(',', $str));
839
+    $options = array();
840 840
 
841
-    foreach ( $raw_options as $option ) {
841
+    foreach ($raw_options as $option) {
842 842
 
843
-        if ( '' == $option ) {
843
+        if ('' == $option) {
844 844
             continue;
845 845
         }
846 846
 
847
-        $option = array_map( 'trim', explode( '|', $option ) );
847
+        $option = array_map('trim', explode('|', $option));
848 848
 
849 849
         $price = null;
850 850
         $label = null;
851 851
 
852
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
853
-            $label  = $option[0];
852
+        if (isset($option[0]) && '' != $option[0]) {
853
+            $label = $option[0];
854 854
         }
855 855
 
856
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
856
+        if (isset($option[1]) && '' != $option[1]) {
857 857
             $price = $option[1];
858 858
         }
859 859
 
860
-        if ( ! isset( $price ) ) {
860
+        if (!isset($price)) {
861 861
             $price = $label;
862 862
         }
863 863
 
864
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
864
+        if (!isset($price) || !is_numeric($price)) {
865 865
             continue;
866 866
         }
867 867
 
868
-        if ( ! isset( $label ) ) {
868
+        if (!isset($label)) {
869 869
             $label = $price;
870 870
         }
871 871
 
872
-        $options[ $price ] = $label;
872
+        $options[$price] = $label;
873 873
     }
874 874
 
875 875
     return $options;
@@ -878,23 +878,23 @@  discard block
 block discarded – undo
878 878
 /**
879 879
  * Returns the help tip.
880 880
  */
881
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
882
-    $additional_classes = sanitize_html_class( $additional_classes );
883
-    $tip                = esc_attr__( $tip );
881
+function getpaid_get_help_tip($tip, $additional_classes = '') {
882
+    $additional_classes = sanitize_html_class($additional_classes);
883
+    $tip                = esc_attr__($tip);
884 884
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
885 885
 }
886 886
 
887 887
 /**
888 888
  * Formats a date
889 889
  */
890
-function getpaid_format_date( $date ) {
890
+function getpaid_format_date($date) {
891 891
 
892
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
892
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
893 893
         return '';
894 894
     }
895 895
 
896 896
 
897
-    return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) );
897
+    return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date));
898 898
 
899 899
 }
900 900
 
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
  * @param  integer $limit Limit size in characters.
906 906
  * @return string
907 907
  */
908
-function getpaid_limit_length( $string, $limit ) {
908
+function getpaid_limit_length($string, $limit) {
909 909
     $str_limit = $limit - 3;
910 910
 
911
-	if ( function_exists( 'mb_strimwidth' ) ) {
912
-		if ( mb_strlen( $string ) > $limit ) {
913
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
911
+	if (function_exists('mb_strimwidth')) {
912
+		if (mb_strlen($string) > $limit) {
913
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
914 914
 		}
915 915
 	} else {
916
-		if ( strlen( $string ) > $limit ) {
917
-			$string = substr( $string, 0, $str_limit ) . '...';
916
+		if (strlen($string) > $limit) {
917
+			$string = substr($string, 0, $str_limit) . '...';
918 918
 		}
919 919
 	}
920 920
     return $string;
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
  * @since 1.0.19
929 929
  */
930 930
 function getpaid_api() {
931
-    return getpaid()->get( 'api' );
931
+    return getpaid()->get('api');
932 932
 }
933 933
 
934 934
 /**
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
  * @since 1.0.19
939 939
  */
940 940
 function getpaid_post_types() {
941
-    return getpaid()->get( 'post_types' );
941
+    return getpaid()->get('post_types');
942 942
 }
943 943
 
944 944
 /**
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
  * @since 1.0.19
949 949
  */
950 950
 function getpaid_session() {
951
-    return getpaid()->get( 'session' );
951
+    return getpaid()->get('session');
952 952
 }
953 953
 
954 954
 /**
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
  * @since 1.0.19
959 959
  */
960 960
 function getpaid_notes() {
961
-    return getpaid()->get( 'notes' );
961
+    return getpaid()->get('notes');
962 962
 }
963 963
 
964 964
 /**
@@ -970,26 +970,26 @@  discard block
 block discarded – undo
970 970
  * 
971 971
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
972 972
  */
973
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
973
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
974 974
 
975 975
     // Do not retrieve all fields if we just want the count.
976
-    if ( 'count' == $return ) {
976
+    if ('count' == $return) {
977 977
         $args['fields'] = 'id';
978 978
         $args['number'] = 1;
979 979
     }
980 980
 
981 981
     // Do not count all matches if we just want the results.
982
-    if ( 'results' == $return ) {
982
+    if ('results' == $return) {
983 983
         $args['count_total'] = false;
984 984
     }
985 985
 
986
-    $query = new GetPaid_Subscriptions_Query( $args );
986
+    $query = new GetPaid_Subscriptions_Query($args);
987 987
 
988
-    if ( 'results' == $return ) {
988
+    if ('results' == $return) {
989 989
         return $query->get_results();
990 990
     }
991 991
 
992
-    if ( 'count' == $return ) {
992
+    if ('count' == $return) {
993 993
         return $query->get_total();
994 994
     }
995 995
 
@@ -1006,13 +1006,13 @@  discard block
 block discarded – undo
1006 1006
     return apply_filters(
1007 1007
         'getpaid_get_subscription_statuses',
1008 1008
         array(
1009
-            'pending'    => __( 'Pending', 'invoicing' ),
1010
-            'trialling'  => __( 'Trialing', 'invoicing' ),
1011
-            'active'     => __( 'Active', 'invoicing' ),
1012
-            'failing'    => __( 'Failing', 'invoicing' ),
1013
-            'expired'    => __( 'Expired', 'invoicing' ),
1014
-            'completed'  => __( 'Complete', 'invoicing' ),
1015
-            'cancelled'  =>__( 'Cancelled', 'invoicing' ),
1009
+            'pending'    => __('Pending', 'invoicing'),
1010
+            'trialling'  => __('Trialing', 'invoicing'),
1011
+            'active'     => __('Active', 'invoicing'),
1012
+            'failing'    => __('Failing', 'invoicing'),
1013
+            'expired'    => __('Expired', 'invoicing'),
1014
+            'completed'  => __('Complete', 'invoicing'),
1015
+            'cancelled'  =>__('Cancelled', 'invoicing'),
1016 1016
         )
1017 1017
     );
1018 1018
 
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
  * 
1024 1024
  * @return string
1025 1025
  */
1026
-function getpaid_get_subscription_status_label( $status ) {
1026
+function getpaid_get_subscription_status_label($status) {
1027 1027
     $statuses = getpaid_get_subscription_statuses();
1028
-    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( $status );
1028
+    return isset($statuses[$status]) ? $statuses[$status] : ucfirst($status);
1029 1029
 }
1030 1030
 
1031 1031
 /**
@@ -1055,14 +1055,14 @@  discard block
 block discarded – undo
1055 1055
  * 
1056 1056
  * @return array
1057 1057
  */
1058
-function getpaid_get_subscription_status_counts( $args = array() ) {
1058
+function getpaid_get_subscription_status_counts($args = array()) {
1059 1059
 
1060
-    $statuses = array_keys( getpaid_get_subscription_statuses() );
1060
+    $statuses = array_keys(getpaid_get_subscription_statuses());
1061 1061
     $counts   = array();
1062 1062
 
1063
-    foreach ( $statuses as $status ) {
1064
-        $_args             = wp_parse_args( "status=$status", $args );
1065
-        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
1063
+    foreach ($statuses as $status) {
1064
+        $_args             = wp_parse_args("status=$status", $args);
1065
+        $counts[$status] = getpaid_get_subscriptions($_args, 'count');
1066 1066
     }
1067 1067
 
1068 1068
     return $counts;
@@ -1074,20 +1074,20 @@  discard block
 block discarded – undo
1074 1074
  * 
1075 1075
  * @return string
1076 1076
  */
1077
-function getpaid_get_subscription_period_label( $period ) {
1077
+function getpaid_get_subscription_period_label($period) {
1078 1078
 
1079 1079
     $periods = array(
1080
-        'd'     => __( 'day', 'invoicing' ),
1081
-        'day'   => __( 'day', 'invoicing' ),
1082
-        'w'     => __( 'week', 'invoicing' ),
1083
-        'week'  => __( 'week', 'invoicing' ),
1084
-        'm'     => __( 'month', 'invoicing' ),
1085
-        'month' => __( 'month', 'invoicing' ),
1086
-        'y'     => __( 'year', 'invoicing' ),
1087
-        'year'  => __( 'year', 'invoicing' ),
1080
+        'd'     => __('day', 'invoicing'),
1081
+        'day'   => __('day', 'invoicing'),
1082
+        'w'     => __('week', 'invoicing'),
1083
+        'week'  => __('week', 'invoicing'),
1084
+        'm'     => __('month', 'invoicing'),
1085
+        'month' => __('month', 'invoicing'),
1086
+        'y'     => __('year', 'invoicing'),
1087
+        'year'  => __('year', 'invoicing'),
1088 1088
     );
1089 1089
 
1090
-    return isset( $periods[ $period ] ) ? strtolower( $periods[ $period ] ) : strtolower( $periods['d'] );
1090
+    return isset($periods[$period]) ? strtolower($periods[$period]) : strtolower($periods['d']);
1091 1091
 }
1092 1092
 
1093 1093
 /**
@@ -1096,5 +1096,5 @@  discard block
 block discarded – undo
1096 1096
  * @return GetPaid_Admin
1097 1097
  */
1098 1098
 function getpaid_admin() {
1099
-    return getpaid()->get( 'admin' );
1099
+    return getpaid()->get('admin');
1100 1100
 }
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 /**
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
  * 
19 19
  * @return bool
20 20
  */
21
-function getpaid_is_eu_state( $country ) {
22
-    return WPInv_EUVat::is_eu_state( $country );
21
+function getpaid_is_eu_state($country) {
22
+    return WPInv_EUVat::is_eu_state($country);
23 23
 }
24 24
 
25 25
 /**
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
  * 
28 28
  * @return bool
29 29
  */
30
-function getpaid_is_gst_country( $country ) {
31
-    return WPInv_EUVat::is_gst_country( $country );
30
+function getpaid_is_gst_country($country) {
31
+    return WPInv_EUVat::is_gst_country($country);
32 32
 }
33 33
 
34 34
 /**
@@ -42,117 +42,117 @@  discard block
 block discarded – undo
42 42
 
43 43
 
44 44
 function wpinv_use_taxes() {
45
-    $ret = wpinv_get_option( 'enable_taxes', false );
45
+    $ret = wpinv_get_option('enable_taxes', false);
46 46
     
47
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
47
+    return (bool) apply_filters('wpinv_use_taxes', $ret);
48 48
 }
49 49
 
50 50
 function wpinv_get_tax_rates() {
51
-    $rates = get_option( 'wpinv_tax_rates', array() );
51
+    $rates = get_option('wpinv_tax_rates', array());
52 52
     
53
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
53
+    return apply_filters('wpinv_get_tax_rates', $rates);
54 54
 }
55 55
 
56
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
56
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
57 57
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
58
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
58
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
59 59
     
60
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
60
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
61 61
         return $wpi_tax_rates[$item_id];
62 62
     }
63 63
     
64
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
64
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
65 65
         $wpi_tax_rates[$item_id] = 0;
66 66
         return 0;
67 67
     }
68 68
 
69 69
     $is_global = false;
70
-    if ( $item_id == 'global' ) {
70
+    if ($item_id == 'global') {
71 71
         $is_global = true;
72 72
         $item_id = 0;
73 73
     }
74 74
     
75
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
76
-    $user_address   = wpinv_get_user_address( $wpi_userID );
75
+    $rate           = (float) wpinv_get_option('tax_rate', 0);
76
+    $user_address   = wpinv_get_user_address($wpi_userID);
77 77
     
78
-    if( empty( $country ) ) {
79
-        if( !empty( $_POST['wpinv_country'] ) ) {
78
+    if (empty($country)) {
79
+        if (!empty($_POST['wpinv_country'])) {
80 80
             $country = $_POST['wpinv_country'];
81
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
81
+        } elseif (!empty($_POST['wpinv_country'])) {
82 82
             $country = $_POST['wpinv_country'];
83
-        } elseif( !empty( $_POST['country'] ) ) {
83
+        } elseif (!empty($_POST['country'])) {
84 84
             $country = $_POST['country'];
85
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
85
+        } elseif (is_user_logged_in() && !empty($user_address)) {
86 86
             $country = $user_address['country'];
87 87
         }
88
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
88
+        $country = !empty($country) ? $country : wpinv_get_default_country();
89 89
     }
90 90
 
91
-    if( empty( $state ) ) {
92
-        if( !empty( $_POST['wpinv_state'] ) ) {
91
+    if (empty($state)) {
92
+        if (!empty($_POST['wpinv_state'])) {
93 93
             $state = $_POST['wpinv_state'];
94
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
94
+        } elseif (!empty($_POST['wpinv_state'])) {
95 95
             $state = $_POST['wpinv_state'];
96
-        } elseif( !empty( $_POST['state'] ) ) {
96
+        } elseif (!empty($_POST['state'])) {
97 97
             $state = $_POST['state'];
98
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
98
+        } elseif (is_user_logged_in() && !empty($user_address)) {
99 99
             $state = $user_address['state'];
100 100
         }
101
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
101
+        $state = !empty($state) ? $state : wpinv_get_default_state();
102 102
     }
103 103
     
104
-    if( !empty( $country ) ) {
105
-        $tax_rates   = wpinv_get_tax_rates();
104
+    if (!empty($country)) {
105
+        $tax_rates = wpinv_get_tax_rates();
106 106
 
107
-        if( !empty( $tax_rates ) ) {
107
+        if (!empty($tax_rates)) {
108 108
             // Locate the tax rate for this country / state, if it exists
109
-            foreach( $tax_rates as $key => $tax_rate ) {
110
-                if( $country != $tax_rate['country'] )
109
+            foreach ($tax_rates as $key => $tax_rate) {
110
+                if ($country != $tax_rate['country'])
111 111
                     continue;
112 112
 
113
-                if( !empty( $tax_rate['global'] ) ) {
114
-                    if( !empty( $tax_rate['rate'] ) ) {
115
-                        $rate = number_format( $tax_rate['rate'], 4 );
113
+                if (!empty($tax_rate['global'])) {
114
+                    if (!empty($tax_rate['rate'])) {
115
+                        $rate = number_format($tax_rate['rate'], 4);
116 116
                     }
117 117
                 } else {
118 118
 
119
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
119
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
120 120
                         continue;
121 121
 
122 122
                     $state_rate = $tax_rate['rate'];
123
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
124
-                        $rate = number_format( $state_rate, 4 );
123
+                    if (0 !== $state_rate || !empty($state_rate)) {
124
+                        $rate = number_format($state_rate, 4);
125 125
                     }
126 126
                 }
127 127
             }
128 128
         }
129 129
     }
130 130
     
131
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
131
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
132 132
     
133
-    if ( !empty( $item_id ) ) {
133
+    if (!empty($item_id)) {
134 134
         $wpi_tax_rates[$item_id] = $rate;
135
-    } else if ( $is_global ) {
135
+    } else if ($is_global) {
136 136
         $wpi_tax_rates['global'] = $rate;
137 137
     }
138 138
     
139 139
     return $rate;
140 140
 }
141 141
 
142
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
143
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
144
-    $rate = round( $rate, 4 );
142
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
143
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
144
+    $rate = round($rate, 4);
145 145
     $formatted = $rate .= '%';
146
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
146
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
147 147
 }
148 148
 
149
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
150
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
149
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
150
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
151 151
     $tax  = 0.00;
152 152
 
153
-    if ( wpinv_use_taxes() ) {        
154
-        if ( wpinv_prices_include_tax() ) {
155
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
153
+    if (wpinv_use_taxes()) {        
154
+        if (wpinv_prices_include_tax()) {
155
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
156 156
             $tax     = $amount - $pre_tax;
157 157
         } else {
158 158
             $tax = $amount * $rate * 0.01;
@@ -160,46 +160,46 @@  discard block
 block discarded – undo
160 160
 
161 161
     }
162 162
 
163
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
163
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
164 164
 }
165 165
 
166 166
 function wpinv_prices_include_tax() {
167 167
     return false; // TODO
168
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
168
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
169 169
 
170
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
170
+    return apply_filters('wpinv_prices_include_tax', $ret);
171 171
 }
172 172
 
173
-function wpinv_sales_tax_for_year( $year = null ) {
174
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
173
+function wpinv_sales_tax_for_year($year = null) {
174
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
175 175
 }
176 176
 
177
-function wpinv_get_sales_tax_for_year( $year = null ) {
177
+function wpinv_get_sales_tax_for_year($year = null) {
178 178
     global $wpdb;
179 179
 
180 180
     // Start at zero
181 181
     $tax = 0;
182 182
 
183
-    if ( ! empty( $year ) ) {
183
+    if (!empty($year)) {
184 184
         $args = array(
185 185
             'post_type'      => 'wpi_invoice',
186
-            'post_status'    => array( 'publish' ),
186
+            'post_status'    => array('publish'),
187 187
             'posts_per_page' => -1,
188 188
             'year'           => $year,
189 189
             'fields'         => 'ids'
190 190
         );
191 191
 
192
-        $payments    = get_posts( $args );
193
-        $payment_ids = implode( ',', $payments );
192
+        $payments    = get_posts($args);
193
+        $payment_ids = implode(',', $payments);
194 194
 
195
-        if ( count( $payments ) > 0 ) {
195
+        if (count($payments) > 0) {
196 196
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
197
-            $tax = $wpdb->get_var( $sql );
197
+            $tax = $wpdb->get_var($sql);
198 198
         }
199 199
 
200 200
     }
201 201
 
202
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
202
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
203 203
 }
204 204
 
205 205
 function wpinv_is_cart_taxed() {
@@ -208,33 +208,33 @@  discard block
 block discarded – undo
208 208
 
209 209
 function wpinv_prices_show_tax_on_checkout() {
210 210
     return false; // TODO
211
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
211
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
212 212
 
213
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
213
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
214 214
 }
215 215
 
216 216
 function wpinv_display_tax_rate() {
217
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
217
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
218 218
 
219
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
219
+    return apply_filters('wpinv_display_tax_rate', $ret);
220 220
 }
221 221
 
222 222
 function wpinv_cart_needs_tax_address_fields() {
223
-    if( !wpinv_is_cart_taxed() )
223
+    if (!wpinv_is_cart_taxed())
224 224
         return false;
225 225
 
226
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
226
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
227 227
 }
228 228
 
229
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
230
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
231
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
229
+function wpinv_item_is_tax_exclusive($item_id = 0) {
230
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
231
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
232 232
 }
233 233
 
234
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
234
+function wpinv_currency_decimal_filter($decimals = 2) {
235 235
     $currency = wpinv_get_currency();
236 236
 
237
-    switch ( $currency ) {
237
+    switch ($currency) {
238 238
         case 'RIAL' :
239 239
         case 'JPY' :
240 240
         case 'TWD' :
@@ -243,50 +243,50 @@  discard block
 block discarded – undo
243 243
             break;
244 244
     }
245 245
 
246
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
246
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
247 247
 }
248 248
 
249 249
 function wpinv_tax_amount() {
250 250
     $output = 0.00;
251 251
     
252
-    return apply_filters( 'wpinv_tax_amount', $output );
252
+    return apply_filters('wpinv_tax_amount', $output);
253 253
 }
254 254
 
255 255
 // VAT Settings
256
-function wpinv_vat_rate_add_callback( $args ) {
256
+function wpinv_vat_rate_add_callback($args) {
257 257
     ?>
258
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
258
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
259 259
     <?php
260 260
 }
261 261
 
262
-function wpinv_vat_rate_delete_callback( $args ) {
262
+function wpinv_vat_rate_delete_callback($args) {
263 263
     global $wpinv_euvat;
264 264
     
265 265
     $vat_classes = $wpinv_euvat->get_rate_classes();
266
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
267
-    if ( isset( $vat_classes[$vat_class] ) ) {
266
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
267
+    if (isset($vat_classes[$vat_class])) {
268 268
     ?>
269
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
269
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
270 270
     <?php
271 271
     }
272 272
 }
273 273
 
274
-function wpinv_vat_rates_callback( $args ) {
274
+function wpinv_vat_rates_callback($args) {
275 275
     global $wpinv_euvat;
276 276
     
277 277
     $vat_classes    = $wpinv_euvat->get_rate_classes();
278
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
278
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
279 279
     
280 280
     $eu_states      = $wpinv_euvat->get_eu_states();
281 281
     $countries      = wpinv_get_country_list();
282 282
     $vat_groups     = $wpinv_euvat->get_vat_groups();
283
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
283
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
284 284
     ob_start();
285 285
 ?>
286 286
 </td><tr>
287 287
     <td colspan="2" class="wpinv_vat_tdbox">
288
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
289
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
288
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
289
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
290 290
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
291 291
         <colgroup>
292 292
             <col width="50px" />
@@ -298,43 +298,43 @@  discard block
 block discarded – undo
298 298
         </colgroup>
299 299
         <thead>
300 300
             <tr>
301
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
302
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
303
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
304
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
305
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
301
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
302
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
303
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
304
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
305
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
306 306
             </tr>
307 307
         </thead>
308 308
         <tbody>
309
-        <?php if( !empty( $eu_states ) ) { ?>
309
+        <?php if (!empty($eu_states)) { ?>
310 310
         <?php 
311
-        foreach ( $eu_states as $state ) { 
312
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
311
+        foreach ($eu_states as $state) { 
312
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
313 313
             
314 314
             // Filter the rate for each country
315
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
315
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
316 316
             
317 317
             // If one does not exist create a default
318
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
318
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
319 319
             
320
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
321
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
322
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
323
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
320
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
321
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
322
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
323
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
324 324
         ?>
325 325
         <tr>
326 326
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
327 327
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
328 328
             <td class="wpinv_vat_global">
329
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
330
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
331
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
329
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
330
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
331
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
332 332
             </td>
333
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
334
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
333
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
334
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
335 335
             <td class="wpinv_vat_group">
336 336
             <?php
337
-            echo wpinv_html_select( array(
337
+            echo wpinv_html_select(array(
338 338
                                         'name'             => 'vat_rates[' . $state . '][group]',
339 339
                                         'selected'         => $vat_group,
340 340
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
                                         'multiple'         => false,
344 344
                                         'show_option_all'  => false,
345 345
                                         'show_option_none' => false
346
-                                    ) );
346
+                                    ));
347 347
             ?>
348 348
             </td>
349 349
         </tr>
350 350
         <?php } ?>
351 351
         <tr>
352 352
             <td colspan="6" style="background-color:#fafafa;">
353
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
353
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
354 354
             </td>
355 355
         </tr>
356 356
         <?php } ?>
@@ -362,35 +362,35 @@  discard block
 block discarded – undo
362 362
     echo $content;
363 363
 }
364 364
 
365
-function wpinv_vat_number_callback( $args ) {
365
+function wpinv_vat_number_callback($args) {
366 366
     global $wpinv_euvat;
367 367
     
368 368
     $vat_number     = $wpinv_euvat->get_vat_number();
369 369
     $vat_valid      = $wpinv_euvat->is_vat_validated();
370 370
 
371
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
372
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
371
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
372
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
373 373
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
374 374
     
375
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
376
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
377
-    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
378
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
379
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
375
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
376
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
377
+    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
378
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
379
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
380 380
 
381 381
     echo $html;
382 382
 }
383 383
 
384
-function wpinv_eu_fallback_rate_callback( $args ) {
384
+function wpinv_eu_fallback_rate_callback($args) {
385 385
     global $wpinv_options;
386 386
 
387
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
388
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
387
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
388
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
389 389
     
390
-    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
391
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
392
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
393
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
390
+    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
391
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
392
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
393
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
394 394
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
395 395
     echo $html;
396 396
     ?>
@@ -398,36 +398,36 @@  discard block
 block discarded – undo
398 398
     <?php
399 399
 }
400 400
 
401
-function wpinv_vat_ip_lookup_callback( $args ) {
401
+function wpinv_vat_ip_lookup_callback($args) {
402 402
     global $wpinv_options, $wpinv_euvat;
403 403
 
404
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
404
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
405 405
     
406 406
     $options = array();
407
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
408
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
407
+    if (function_exists('geoip_country_code_by_name')) {
408
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
409 409
     }
410 410
     
411 411
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
412 412
     
413
-    if ( !function_exists( 'bcadd' ) ) {
414
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
413
+    if (!function_exists('bcadd')) {
414
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
415 415
     } else {
416
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
416
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
417 417
     }
418 418
     
419
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
420
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
419
+    if ($geoip2_database !== false && empty($geoip2_message)) {
420
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
421 421
     }
422 422
     
423
-    if ( function_exists( 'simplexml_load_file' ) ) {
424
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
423
+    if (function_exists('simplexml_load_file')) {
424
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
425 425
     }
426 426
     
427
-    $options['site']    = __( 'Use default country', 'invoicing' );
428
-    $options['default'] = __( 'Auto', 'invoicing' );
427
+    $options['site']    = __('Use default country', 'invoicing');
428
+    $options['default'] = __('Auto', 'invoicing');
429 429
 
430
-    $html = wpinv_html_select( array(
430
+    $html = wpinv_html_select(array(
431 431
         'name'             => "wpinv_settings[{$args['id']}]",
432 432
         'selected'         => $value,
433 433
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -439,23 +439,23 @@  discard block
 block discarded – undo
439 439
     ));
440 440
     
441 441
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
442
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
442
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
443 443
     $desc .= '<p>';
444
-    if ( empty( $geoip2_message ) ) {
445
-        if ( $geoip2_database ) {
444
+    if (empty($geoip2_message)) {
445
+        if ($geoip2_database) {
446 446
             $last_updated = '';
447
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
448
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
449
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
447
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
448
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
449
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
450 450
             }
451
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~30MB)', 'invoicing' ) . '"></input>';
451
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~30MB)', 'invoicing') . '"></input>';
452 452
         } else {
453
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~30MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
453
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~30MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
454 454
         }
455 455
     } else {
456 456
         $desc .= $geoip2_message;
457 457
     }
458
-    $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
458
+    $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
459 459
     $desc .= '</label>';
460 460
     
461 461
     $html .= $desc;
@@ -471,39 +471,39 @@  discard block
 block discarded – undo
471 471
  * 
472 472
  * @param string|bool|null $vat_rule
473 473
  */
474
-function getpaid_filter_vat_rule( $vat_rule ) {
474
+function getpaid_filter_vat_rule($vat_rule) {
475 475
 
476
-    if ( empty( $vat_rule ) ) {        
476
+    if (empty($vat_rule)) {        
477 477
         return getpaid_tax()->allow_vat_rules() ? 'digital' : 'physical';
478 478
     }
479 479
 
480 480
     return $vat_rule;
481 481
 }
482
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
482
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
483 483
 
484 484
 /**
485 485
  * Filters the VAT class to ensure that each item has a VAT class.
486 486
  * 
487 487
  * @param string|bool|null $vat_rule
488 488
  */
489
-function getpaid_filter_vat_class( $vat_class ) {
490
-    return empty( $vat_class ) ? '_standard' : $vat_class;
489
+function getpaid_filter_vat_class($vat_class) {
490
+    return empty($vat_class) ? '_standard' : $vat_class;
491 491
 }
492
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
492
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
493 493
 
494 494
 /**
495 495
  * Returns the ip address location url.
496 496
  * 
497 497
  */
498
-function getpaid_ip_location_url( $ip_address ) {
498
+function getpaid_ip_location_url($ip_address) {
499 499
 
500 500
     return add_query_arg(
501 501
         array(
502 502
             'action'   => 'wpinv_ip_geolocation',
503 503
             'ip'       => $ip_address,
504
-            '_wpnonce' => wp_create_nonce( 'getpaid-ip-location' )
504
+            '_wpnonce' => wp_create_nonce('getpaid-ip-location')
505 505
         ),
506
-        admin_url( 'admin-ajax.php' )
506
+        admin_url('admin-ajax.php')
507 507
     );
508 508
 
509 509
 }
@@ -513,55 +513,55 @@  discard block
 block discarded – undo
513 513
  * 
514 514
  * @return array|bool
515 515
  */
516
-function getpaid_geolocate_ip_address( $ip_address ) {
516
+function getpaid_geolocate_ip_address($ip_address) {
517 517
 
518 518
     // Do we have an ip address?
519
-    if ( empty( $ip_address ) ) {
519
+    if (empty($ip_address)) {
520 520
         return false;
521 521
     }
522 522
 
523 523
     /**
524 524
      * Retrieve ip address using max mind.
525 525
      */
526
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record( $ip_address ) ) {
526
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record($ip_address)) {
527 527
 
528 528
         try {
529 529
             $iso        = $geoip2_city->country->isoCode;
530 530
             $country    = $geoip2_city->country->name;
531
-            $region     = ! empty( $geoip2_city->subdivisions ) && ! empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
531
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
532 532
             $city       = $geoip2_city->city->name;
533 533
             $longitude  = $geoip2_city->location->longitude;
534 534
             $latitude   = $geoip2_city->location->latitude;
535
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
536
-        } catch( Exception $e ) { }
535
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
536
+        } catch (Exception $e) { }
537 537
 
538 538
     }
539 539
 
540 540
     // If that fails, GeoLocate using GeoPlugin.
541
-    if ( ( empty( $iso ) || empty( $longitude ) || empty( $latitude ) ) && function_exists( 'simplexml_load_file' ) ) {
541
+    if ((empty($iso) || empty($longitude) || empty($latitude)) && function_exists('simplexml_load_file')) {
542 542
 
543 543
         try {
544
-            $url      = esc_url( add_query_arg( 'ip', urlencode( $ip_address ), 'http://www.geoplugin.net/xml.gp' ) );
545
-            $load_xml = simplexml_load_file( $url );
544
+            $url      = esc_url(add_query_arg('ip', urlencode($ip_address), 'http://www.geoplugin.net/xml.gp'));
545
+            $load_xml = simplexml_load_file($url);
546 546
 
547
-            if ( ! empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && ! empty( $load_xml->geoplugin_latitude ) && ! empty( $load_xml->geoplugin_longitude ) ) {
547
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
548 548
                 $iso        = $load_xml->geoplugin_countryCode;
549 549
                 $country    = $load_xml->geoplugin_countryName;
550
-                $region     = ! empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
551
-                $city       = ! empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
550
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
551
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
552 552
                 $longitude  = $load_xml->geoplugin_longitude;
553 553
                 $latitude   = $load_xml->geoplugin_latitude;
554 554
                 $credit     = $load_xml->geoplugin_credit;
555
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
555
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
556 556
             }
557
-        } catch( Exception $e ) { }
557
+        } catch (Exception $e) { }
558 558
 
559 559
     }
560 560
 
561
-   if ( empty( $iso )  ) {
561
+   if (empty($iso)) {
562 562
        return false;
563 563
    }
564 564
 
565
-   return compact( 'iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit' );
565
+   return compact('iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit');
566 566
 
567 567
 }
Please login to merge, or discard this patch.