Passed
Push — master ( 60cf75...7ee9b2 )
by Brian
128:01 queued 122:23
created
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -259,15 +259,15 @@  discard block
 block discarded – undo
259 259
     }
260 260
 
261 261
     /**
262
-	 * Retrieves a customer payment profile.
263
-	 *
264
-	 *
265
-	 * @param string $customer_profile_id customer profile id.
262
+     * Retrieves a customer payment profile.
263
+     *
264
+     *
265
+     * @param string $customer_profile_id customer profile id.
266 266
      * @param string $payment_profile_id payment profile id.
267
-	 * @return string|WP_Error Profile id.
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
-	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
269
+     */
270
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
     }
284 284
 
285 285
     /**
286
-	 * Charges a customer payment profile.
287
-	 *
286
+     * Charges a customer payment profile.
287
+     *
288 288
      * @param string $customer_profile_id customer profile id.
289 289
      * @param string $payment_profile_id payment profile id.
290
-	 * @param WPInv_Invoice $invoice Invoice.
290
+     * @param WPInv_Invoice $invoice Invoice.
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292
-	 * @return WP_Error|object
293
-	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
292
+     * @return WP_Error|object
293
+     */
294
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -333,41 +333,41 @@  discard block
 block discarded – undo
333 333
     }
334 334
 
335 335
     /**
336
-	 * Processes a customer charge.
337
-	 *
336
+     * Processes a customer charge.
337
+     *
338 338
      * @param stdClass $result Api response.
339
-	 * @param WPInv_Invoice $invoice Invoice.
340
-	 */
341
-	public function process_charge_response( $result, $invoice ) {
339
+     * @param WPInv_Invoice $invoice Invoice.
340
+     */
341
+    public function process_charge_response( $result, $invoice ) {
342 342
 
343 343
         wpinv_clear_errors();
344
-		$response_code = (int) $result->transactionResponse->responseCode;
344
+        $response_code = (int) $result->transactionResponse->responseCode;
345 345
 
346
-		// Succeeded.
347
-		if ( 1 == $response_code || 4 == $response_code ) {
346
+        // Succeeded.
347
+        if ( 1 == $response_code || 4 == $response_code ) {
348 348
 
349
-			// Maybe set a transaction id.
350
-			if ( ! empty( $result->transactionResponse->transId ) ) {
351
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
352
-			}
349
+            // Maybe set a transaction id.
350
+            if ( ! empty( $result->transactionResponse->transId ) ) {
351
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
352
+            }
353 353
 
354
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
354
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
355 355
 
356
-			if ( 1 == $response_code ) {
357
-				return $invoice->mark_paid();
358
-			}
356
+            if ( 1 == $response_code ) {
357
+                return $invoice->mark_paid();
358
+            }
359 359
 
360
-			$invoice->set_status( 'wpi-onhold' );
361
-        	$invoice->add_note(
360
+            $invoice->set_status( 'wpi-onhold' );
361
+            $invoice->add_note(
362 362
                 sprintf(
363 363
                     __( 'Held for review: %s', 'invoicing' ),
364 364
                     $result->transactionResponse->messages->message[0]->description
365 365
                 )
366
-			);
366
+            );
367 367
 
368
-			return $invoice->save();
368
+            return $invoice->save();
369 369
 
370
-		}
370
+        }
371 371
 
372 372
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
373 373
 
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
     }
380 380
 
381 381
     /**
382
-	 * Returns payment information.
383
-	 *
384
-	 *
385
-	 * @param array $card Card details.
386
-	 * @return array
387
-	 */
388
-	public function get_payment_information( $card ) {
382
+     * Returns payment information.
383
+     *
384
+     *
385
+     * @param array $card Card details.
386
+     * @return array
387
+     */
388
+    public function get_payment_information( $card ) {
389 389
         return array(
390 390
 
391 391
             'creditCard'         => array (
@@ -398,25 +398,25 @@  discard block
 block discarded – undo
398 398
     }
399 399
 
400 400
     /**
401
-	 * Returns the customer profile meta name.
402
-	 *
403
-	 *
404
-	 * @param WPInv_Invoice $invoice Invoice.
405
-	 * @return string
406
-	 */
407
-	public function get_customer_profile_meta_name( $invoice ) {
401
+     * Returns the customer profile meta name.
402
+     *
403
+     *
404
+     * @param WPInv_Invoice $invoice Invoice.
405
+     * @return string
406
+     */
407
+    public function get_customer_profile_meta_name( $invoice ) {
408 408
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
409 409
     }
410 410
 
411 411
     /**
412
-	 * Validates the submitted data.
413
-	 *
414
-	 *
415
-	 * @param array $submission_data Posted checkout fields.
412
+     * Validates the submitted data.
413
+     *
414
+     *
415
+     * @param array $submission_data Posted checkout fields.
416 416
      * @param WPInv_Invoice $invoice
417
-	 * @return WP_Error|string The payment profile id
418
-	 */
419
-	public function validate_submission_data( $submission_data, $invoice ) {
417
+     * @return WP_Error|string The payment profile id
418
+     */
419
+    public function validate_submission_data( $submission_data, $invoice ) {
420 420
 
421 421
         // Validate authentication details.
422 422
         $auth = $this->get_auth_params();
@@ -448,13 +448,13 @@  discard block
 block discarded – undo
448 448
     }
449 449
 
450 450
     /**
451
-	 * Returns invoice line items.
452
-	 *
453
-	 *
454
-	 * @param WPInv_Invoice $invoice Invoice.
455
-	 * @return array
456
-	 */
457
-	public function get_line_items( $invoice ) {
451
+     * Returns invoice line items.
452
+     *
453
+     *
454
+     * @param WPInv_Invoice $invoice Invoice.
455
+     * @return array
456
+     */
457
+    public function get_line_items( $invoice ) {
458 458
         $items = array();
459 459
 
460 460
         foreach ( $invoice->get_items() as $item ) {
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
     }
475 475
 
476 476
     /**
477
-	 * Process Payment.
478
-	 *
479
-	 *
480
-	 * @param WPInv_Invoice $invoice Invoice.
481
-	 * @param array $submission_data Posted checkout fields.
482
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
483
-	 * @return array
484
-	 */
485
-	public function process_payment( $invoice, $submission_data, $submission ) {
477
+     * Process Payment.
478
+     *
479
+     *
480
+     * @param WPInv_Invoice $invoice Invoice.
481
+     * @param array $submission_data Posted checkout fields.
482
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
483
+     * @return array
484
+     */
485
+    public function process_payment( $invoice, $submission_data, $submission ) {
486 486
 
487 487
         // Validate the submitted data.
488 488
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -515,69 +515,69 @@  discard block
 block discarded – undo
515 515
 
516 516
         exit;
517 517
 
518
-	}
518
+    }
519 519
 	
520
-	/**
521
-	 * Processes the initial payment.
522
-	 *
520
+    /**
521
+     * Processes the initial payment.
522
+     *
523 523
      * @param WPInv_Invoice $invoice Invoice.
524
-	 */
525
-	protected function process_initial_payment( $invoice ) {
524
+     */
525
+    protected function process_initial_payment( $invoice ) {
526 526
 
527
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
527
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
528 528
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
529
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
529
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
530 530
 
531
-		// Do we have an error?
532
-		if ( is_wp_error( $result ) ) {
533
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
534
-			wpinv_send_back_to_checkout();
535
-		}
531
+        // Do we have an error?
532
+        if ( is_wp_error( $result ) ) {
533
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
534
+            wpinv_send_back_to_checkout();
535
+        }
536 536
 
537
-		// Process the response.
538
-		$this->process_charge_response( $result, $invoice );
537
+        // Process the response.
538
+        $this->process_charge_response( $result, $invoice );
539 539
 
540
-		if ( wpinv_get_errors() ) {
541
-			wpinv_send_back_to_checkout();
542
-		}
540
+        if ( wpinv_get_errors() ) {
541
+            wpinv_send_back_to_checkout();
542
+        }
543 543
 
544
-	}
544
+    }
545 545
 
546 546
     /**
547
-	 * Processes recurring payments.
548
-	 *
547
+     * Processes recurring payments.
548
+     *
549 549
      * @param WPInv_Invoice $invoice Invoice.
550 550
      * @param WPInv_Subscription $subscription Subscription.
551
-	 */
552
-	public function process_subscription( $invoice, $subscription ) {
551
+     */
552
+    public function process_subscription( $invoice, $subscription ) {
553 553
 
554 554
         // Check if there is an initial amount to charge.
555 555
         if ( (float) $invoice->get_total() > 0 ) {
556
-			$this->process_initial_payment( $invoice );
556
+            $this->process_initial_payment( $invoice );
557 557
         }
558 558
 
559 559
         // Activate the subscription.
560 560
         $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
561 561
         $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
562 562
 
563
-		$subscription->set_next_renewal_date( $expiry );
564
-		$subscription->set_date_created( current_time( 'mysql' ) );
565
-		$subscription->set_profile_id( $invoice->generate_key() );
566
-		$subscription->activate();
563
+        $subscription->set_next_renewal_date( $expiry );
564
+        $subscription->set_date_created( current_time( 'mysql' ) );
565
+        $subscription->set_profile_id( $invoice->generate_key() );
566
+        $subscription->activate();
567 567
 
568
-		// Redirect to the success page.
568
+        // Redirect to the success page.
569 569
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
570 570
 
571 571
     }
572 572
 
573
-	/**
574
-	 * (Maybe) renews an authorize.net subscription profile.
575
-	 *
576
-	 *
577
-	 * @param bool $should_expire
573
+    /**
574
+     * (Maybe) renews an authorize.net subscription profile.
575
+     *
576
+     *
577
+     * @param bool $should_expire
578 578
      * @param WPInv_Subscription $subscription
579
-	 */
580
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
579
+     */
580
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
581 581
 
582 582
         // Ensure its our subscription && it's active.
583 583
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
             return false;
591 591
         }
592 592
 
593
-		$this->renew_subscription( $subscription );
593
+        $this->renew_subscription( $subscription );
594 594
         // Renew the subscription.
595 595
         $subscription->add_payment(
596 596
             array(
@@ -603,18 +603,18 @@  discard block
 block discarded – undo
603 603
 
604 604
         return false;
605 605
 
606
-	}
606
+    }
607 607
 
608 608
     /**
609
-	 * Renews a subscription.
610
-	 *
609
+     * Renews a subscription.
610
+     *
611 611
      * @param WPInv_Subscription $subscription
612
-	 */
613
-	public function renew_subscription( $subscription ) {
612
+     */
613
+    public function renew_subscription( $subscription ) {
614 614
 
615
-		// Generate the renewal invoice.
616
-		$new_invoice = $subscription->create_payment();
617
-		$old_invoice = $subscription->get_parent_payment();
615
+        // Generate the renewal invoice.
616
+        $new_invoice = $subscription->create_payment();
617
+        $old_invoice = $subscription->get_parent_payment();
618 618
 
619 619
         if ( empty( $new_invoice ) ) {
620 620
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -622,40 +622,40 @@  discard block
 block discarded – undo
622 622
             return;
623 623
         }
624 624
 
625
-		// Charge the payment method.
626
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
627
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
628
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
625
+        // Charge the payment method.
626
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
627
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
628
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
629 629
 
630
-		// Do we have an error?
631
-		if ( is_wp_error( $result ) ) {
630
+        // Do we have an error?
631
+        if ( is_wp_error( $result ) ) {
632 632
 
633
-			$old_invoice->add_note(
634
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
635
-				true,
636
-				false,
637
-				true
638
-			);
639
-			$subscription->failing();
640
-			return;
633
+            $old_invoice->add_note(
634
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
635
+                true,
636
+                false,
637
+                true
638
+            );
639
+            $subscription->failing();
640
+            return;
641 641
 
642
-		}
642
+        }
643 643
 
644
-		// Process the response.
645
-		$this->process_charge_response( $result, $new_invoice );
644
+        // Process the response.
645
+        $this->process_charge_response( $result, $new_invoice );
646 646
 
647
-		if ( wpinv_get_errors() ) {
647
+        if ( wpinv_get_errors() ) {
648 648
 
649
-			$old_invoice->add_note(
650
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
651
-				true,
652
-				false,
653
-				true
654
-			);
655
-			$subscription->failing();
656
-			return;
649
+            $old_invoice->add_note(
650
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
651
+                true,
652
+                false,
653
+                true
654
+            );
655
+            $subscription->failing();
656
+            return;
657 657
 
658
-		}
658
+        }
659 659
 
660 660
     }
661 661
 
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
     }
677 677
 
678 678
     /**
679
-	 * Filters the gateway settings.
680
-	 *
681
-	 * @param array $admin_settings
682
-	 */
683
-	public function admin_settings( $admin_settings ) {
679
+     * Filters the gateway settings.
680
+     *
681
+     * @param array $admin_settings
682
+     */
683
+    public function admin_settings( $admin_settings ) {
684 684
 
685 685
         $currencies = sprintf(
686 686
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
             'readonly' => true,
721 721
         );
722 722
 
723
-		return $admin_settings;
724
-	}
723
+        return $admin_settings;
724
+    }
725 725
 
726 726
 }
Please login to merge, or discard this patch.
Spacing   +146 added lines, -146 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( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
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'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_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'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_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 330
 
331
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
331
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
332 332
 
333 333
     }
334 334
 
@@ -338,29 +338,29 @@  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
 		$response_code = (int) $result->transactionResponse->responseCode;
345 345
 
346 346
 		// Succeeded.
347
-		if ( 1 == $response_code || 4 == $response_code ) {
347
+		if (1 == $response_code || 4 == $response_code) {
348 348
 
349 349
 			// Maybe set a transaction id.
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
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
354
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
355 355
 
356
-			if ( 1 == $response_code ) {
356
+			if (1 == $response_code) {
357 357
 				return $invoice->mark_paid();
358 358
 			}
359 359
 
360
-			$invoice->set_status( 'wpi-onhold' );
360
+			$invoice->set_status('wpi-onhold');
361 361
         	$invoice->add_note(
362 362
                 sprintf(
363
-                    __( 'Held for review: %s', 'invoicing' ),
363
+                    __('Held for review: %s', 'invoicing'),
364 364
                     $result->transactionResponse->messages->message[0]->description
365 365
                 )
366 366
 			);
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
 
370 370
 		}
371 371
 
372
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
372
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
373 373
 
374
-        if ( ! empty( $result->transactionResponse->errors ) ) {
374
+        if (!empty($result->transactionResponse->errors)) {
375 375
             $errors = (object) $result->transactionResponse->errors;
376
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
376
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
377 377
         }
378 378
 
379 379
     }
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 	 * @param array $card Card details.
386 386
 	 * @return array
387 387
 	 */
388
-	public function get_payment_information( $card ) {
388
+	public function get_payment_information($card) {
389 389
         return array(
390 390
 
391
-            'creditCard'         => array (
391
+            'creditCard'         => array(
392 392
                 'cardNumber'     => $card['cc_number'],
393 393
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
394 394
                 'cardCode'       => $card['cc_cvv2'],
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @param WPInv_Invoice $invoice Invoice.
405 405
 	 * @return string
406 406
 	 */
407
-	public function get_customer_profile_meta_name( $invoice ) {
408
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
407
+	public function get_customer_profile_meta_name($invoice) {
408
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
409 409
     }
410 410
 
411 411
     /**
@@ -416,34 +416,34 @@  discard block
 block discarded – undo
416 416
      * @param WPInv_Invoice $invoice
417 417
 	 * @return WP_Error|string The payment profile id
418 418
 	 */
419
-	public function validate_submission_data( $submission_data, $invoice ) {
419
+	public function validate_submission_data($submission_data, $invoice) {
420 420
 
421 421
         // Validate authentication details.
422 422
         $auth = $this->get_auth_params();
423 423
 
424
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
425
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
424
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
425
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
426 426
         }
427 427
 
428 428
         // Validate the payment method.
429
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
430
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
429
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
430
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
431 431
         }
432 432
 
433 433
         // Are we adding a new payment method?
434
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
434
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
435 435
             return $submission_data['getpaid-authorizenet-payment-method'];
436 436
         }
437 437
 
438 438
         // Retrieve the customer profile id.
439
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
439
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
440 440
 
441 441
         // Create payment method.
442
-        if ( empty( $profile_id ) ) {
443
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
442
+        if (empty($profile_id)) {
443
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
444 444
         }
445 445
 
446
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
447 447
 
448 448
     }
449 449
 
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
 	 * @param WPInv_Invoice $invoice Invoice.
455 455
 	 * @return array
456 456
 	 */
457
-	public function get_line_items( $invoice ) {
457
+	public function get_line_items($invoice) {
458 458
         $items = array();
459 459
 
460
-        foreach ( $invoice->get_items() as $item ) {
460
+        foreach ($invoice->get_items() as $item) {
461 461
 
462 462
             $items[] = array(
463
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
464
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
465
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
463
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
464
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
465
+                'description' => getpaid_limit_length($item->get_description(), 255),
466 466
                 'quantity'    => (int) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
467 467
                 'unitPrice'   => (float) $item->get_price(),
468 468
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -482,36 +482,36 @@  discard block
 block discarded – undo
482 482
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
483 483
 	 * @return array
484 484
 	 */
485
-	public function process_payment( $invoice, $submission_data, $submission ) {
485
+	public function process_payment($invoice, $submission_data, $submission) {
486 486
 
487 487
         // Validate the submitted data.
488
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
488
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
489 489
 
490 490
         // Do we have an error?
491
-        if ( is_wp_error( $payment_profile_id ) ) {
492
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
491
+        if (is_wp_error($payment_profile_id)) {
492
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
493 493
             wpinv_send_back_to_checkout();
494 494
         }
495 495
 
496 496
         // Save the payment method to the order.
497
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
497
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
498 498
 
499 499
         // Check if this is a subscription or not.
500
-        $subscription = getpaid_get_invoice_subscription( $invoice );
501
-        if ( ! empty( $subscription ) ) {
502
-            $this->process_subscription( $invoice, $subscription );
500
+        $subscription = getpaid_get_invoice_subscription($invoice);
501
+        if (!empty($subscription)) {
502
+            $this->process_subscription($invoice, $subscription);
503 503
         }
504 504
 
505 505
         // If it is free, send to the success page.
506
-        if ( ! $invoice->needs_payment() ) {
506
+        if (!$invoice->needs_payment()) {
507 507
             $invoice->mark_paid();
508
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
508
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
509 509
         }
510 510
 
511 511
         // Charge the payment profile.
512
-        $this->process_initial_payment( $invoice );
512
+        $this->process_initial_payment($invoice);
513 513
 
514
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
514
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
515 515
 
516 516
         exit;
517 517
 
@@ -522,22 +522,22 @@  discard block
 block discarded – undo
522 522
 	 *
523 523
      * @param WPInv_Invoice $invoice Invoice.
524 524
 	 */
525
-	protected function process_initial_payment( $invoice ) {
525
+	protected function process_initial_payment($invoice) {
526 526
 
527
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
528
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
529
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
527
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
528
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
529
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
530 530
 
531 531
 		// Do we have an error?
532
-		if ( is_wp_error( $result ) ) {
533
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
532
+		if (is_wp_error($result)) {
533
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
534 534
 			wpinv_send_back_to_checkout();
535 535
 		}
536 536
 
537 537
 		// Process the response.
538
-		$this->process_charge_response( $result, $invoice );
538
+		$this->process_charge_response($result, $invoice);
539 539
 
540
-		if ( wpinv_get_errors() ) {
540
+		if (wpinv_get_errors()) {
541 541
 			wpinv_send_back_to_checkout();
542 542
 		}
543 543
 
@@ -549,24 +549,24 @@  discard block
 block discarded – undo
549 549
      * @param WPInv_Invoice $invoice Invoice.
550 550
      * @param WPInv_Subscription $subscription Subscription.
551 551
 	 */
552
-	public function process_subscription( $invoice, $subscription ) {
552
+	public function process_subscription($invoice, $subscription) {
553 553
 
554 554
         // Check if there is an initial amount to charge.
555
-        if ( (float) $invoice->get_total() > 0 ) {
556
-			$this->process_initial_payment( $invoice );
555
+        if ((float) $invoice->get_total() > 0) {
556
+			$this->process_initial_payment($invoice);
557 557
         }
558 558
 
559 559
         // Activate the subscription.
560
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
561
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
560
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
561
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
562 562
 
563
-		$subscription->set_next_renewal_date( $expiry );
564
-		$subscription->set_date_created( current_time( 'mysql' ) );
565
-		$subscription->set_profile_id( $invoice->generate_key() );
563
+		$subscription->set_next_renewal_date($expiry);
564
+		$subscription->set_date_created(current_time('mysql'));
565
+		$subscription->set_profile_id($invoice->generate_key());
566 566
 		$subscription->activate();
567 567
 
568 568
 		// Redirect to the success page.
569
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
569
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
570 570
 
571 571
     }
572 572
 
@@ -577,20 +577,20 @@  discard block
 block discarded – undo
577 577
 	 * @param bool $should_expire
578 578
      * @param WPInv_Subscription $subscription
579 579
 	 */
580
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
580
+	public function maybe_renew_subscription($should_expire, $subscription) {
581 581
 
582 582
         // Ensure its our subscription && it's active.
583
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
583
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
584 584
             return $should_expire;
585 585
         }
586 586
 
587 587
         // If this is the last renewal, complete the subscription.
588
-        if ( $subscription->is_last_renewal() ) {
588
+        if ($subscription->is_last_renewal()) {
589 589
             $subscription->complete();
590 590
             return false;
591 591
         }
592 592
 
593
-		$this->renew_subscription( $subscription );
593
+		$this->renew_subscription($subscription);
594 594
         // Renew the subscription.
595 595
         $subscription->add_payment(
596 596
             array(
@@ -610,28 +610,28 @@  discard block
 block discarded – undo
610 610
 	 *
611 611
      * @param WPInv_Subscription $subscription
612 612
 	 */
613
-	public function renew_subscription( $subscription ) {
613
+	public function renew_subscription($subscription) {
614 614
 
615 615
 		// Generate the renewal invoice.
616 616
 		$new_invoice = $subscription->create_payment();
617 617
 		$old_invoice = $subscription->get_parent_payment();
618 618
 
619
-        if ( empty( $new_invoice ) ) {
620
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
619
+        if (empty($new_invoice)) {
620
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
621 621
             $subscription->failing();
622 622
             return;
623 623
         }
624 624
 
625 625
 		// Charge the payment method.
626
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
627
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
628
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
626
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
627
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
628
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
629 629
 
630 630
 		// Do we have an error?
631
-		if ( is_wp_error( $result ) ) {
631
+		if (is_wp_error($result)) {
632 632
 
633 633
 			$old_invoice->add_note(
634
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
634
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
635 635
 				true,
636 636
 				false,
637 637
 				true
@@ -642,12 +642,12 @@  discard block
 block discarded – undo
642 642
 		}
643 643
 
644 644
 		// Process the response.
645
-		$this->process_charge_response( $result, $new_invoice );
645
+		$this->process_charge_response($result, $new_invoice);
646 646
 
647
-		if ( wpinv_get_errors() ) {
647
+		if (wpinv_get_errors()) {
648 648
 
649 649
 			$old_invoice->add_note(
650
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
650
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
651 651
 				true,
652 652
 				false,
653 653
 				true
@@ -662,11 +662,11 @@  discard block
 block discarded – undo
662 662
     /**
663 663
      * Displays a notice on the checkout page if sandbox is enabled.
664 664
      */
665
-    public function sandbox_notice( $description, $gateway ) {
665
+    public function sandbox_notice($description, $gateway) {
666 666
 
667
-        if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) {
667
+        if ($this->id == $gateway && wpinv_is_test_mode($this->id)) {
668 668
             $description .= '<br>' . sprintf(
669
-                __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
669
+                __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
670 670
                 '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
671 671
                 '</a>'
672 672
             );
@@ -680,42 +680,42 @@  discard block
 block discarded – undo
680 680
 	 *
681 681
 	 * @param array $admin_settings
682 682
 	 */
683
-	public function admin_settings( $admin_settings ) {
683
+	public function admin_settings($admin_settings) {
684 684
 
685 685
         $currencies = sprintf(
686
-            __( 'Supported Currencies: %s', 'invoicing' ),
687
-            implode( ', ', $this->currencies )
686
+            __('Supported Currencies: %s', 'invoicing'),
687
+            implode(', ', $this->currencies)
688 688
         );
689 689
 
690 690
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
691
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
691
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
692 692
 
693 693
         $admin_settings['authorizenet_login_id'] = array(
694 694
             'type' => 'text',
695 695
             'id'   => 'authorizenet_login_id',
696
-            'name' => __( 'API Login ID', 'invoicing' ),
697
-            '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>',
696
+            'name' => __('API Login ID', 'invoicing'),
697
+            '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>',
698 698
         );
699 699
 
700 700
         $admin_settings['authorizenet_transaction_key'] = array(
701 701
             'type' => 'text',
702 702
             'id'   => 'authorizenet_transaction_key',
703
-            'name' => __( 'Transaction Key', 'invoicing' ),
703
+            'name' => __('Transaction Key', 'invoicing'),
704 704
         );
705 705
 
706 706
         $admin_settings['authorizenet_signature_key'] = array(
707 707
             'type' => 'text',
708 708
             'id'   => 'authorizenet_signature_key',
709
-            'name' => __( 'Signature Key', 'invoicing' ),
710
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
709
+            'name' => __('Signature Key', 'invoicing'),
710
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
711 711
         );
712 712
 
713 713
         $admin_settings['authorizenet_ipn_url'] = array(
714 714
             'type'     => 'ipn_url',
715 715
             'id'       => 'authorizenet_ipn_url',
716
-            'name'     => __( 'Webhook URL', 'invoicing' ),
716
+            'name'     => __('Webhook URL', 'invoicing'),
717 717
             'std'      => $this->notify_url,
718
-            '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>',
718
+            '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>',
719 719
             'custom'   => 'authorizenet',
720 720
             'readonly' => true,
721 721
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@  discard block
 block discarded – undo
15 15
 abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway {
16 16
 
17 17
     /**
18
-	 * Class constructor.
19
-	 */
20
-	public function __construct() {
18
+     * Class constructor.
19
+     */
20
+    public function __construct() {
21 21
         parent::__construct();
22 22
     }
23 23
 
24 24
     /**
25
-	 * Returns the API URL.
26
-	 *
27
-	 *
28
-	 * @param WPInv_Invoice $invoice Invoice.
29
-	 * @return string
30
-	 */
31
-	public function get_api_url( $invoice ) {
25
+     * Returns the API URL.
26
+     *
27
+     *
28
+     * @param WPInv_Invoice $invoice Invoice.
29
+     * @return string
30
+     */
31
+    public function get_api_url( $invoice ) {
32 32
         return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
36
-	 * Communicates with authorize.net
37
-	 *
38
-	 *
39
-	 * @param array $post Data to post.
36
+     * Communicates with authorize.net
37
+     *
38
+     *
39
+     * @param array $post Data to post.
40 40
      * @param WPInv_Invoice $invoice Invoice.
41
-	 * @return stdClass|WP_Error
42
-	 */
41
+     * @return stdClass|WP_Error
42
+     */
43 43
     public function post( $post, $invoice ){
44 44
 
45 45
         $url      = $this->get_api_url( $invoice );
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
     }
82 82
 
83 83
     /**
84
-	 * Returns the API authentication params.
85
-	 *
86
-	 *
87
-	 * @return array
88
-	 */
89
-	public function get_auth_params() {
84
+     * Returns the API authentication params.
85
+     *
86
+     *
87
+     * @return array
88
+     */
89
+    public function get_auth_params() {
90 90
 
91 91
         return array(
92 92
             'name'           => $this->get_option( 'login_id' ),
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
     }
97 97
 
98 98
     /**
99
-	 * Cancels a subscription remotely
100
-	 *
101
-	 *
102
-	 * @param WPInv_Subscription $subscription Subscription.
99
+     * Cancels a subscription remotely
100
+     *
101
+     *
102
+     * @param WPInv_Subscription $subscription Subscription.
103 103
      * @param WPInv_Invoice $invoice Invoice.
104
-	 */
105
-	public function cancel_subscription( $subscription, $invoice ) {
104
+     */
105
+    public function cancel_subscription( $subscription, $invoice ) {
106 106
 
107 107
         // Backwards compatibility. New version do not use authorize.net subscriptions.
108 108
         $this->post(
@@ -118,17 +118,17 @@  discard block
 block discarded – undo
118 118
     }
119 119
 
120 120
     /**
121
-	 * Processes ipns.
122
-	 *
123
-	 * @return void
124
-	 */
125
-	public function verify_ipn() {
121
+     * Processes ipns.
122
+     *
123
+     * @return void
124
+     */
125
+    public function verify_ipn() {
126 126
 
127 127
         $this->maybe_process_old_ipn();
128 128
 
129 129
         // Validate the IPN.
130 130
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
131
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
131
+            wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
132 132
         }
133 133
 
134 134
         // Event type.
@@ -167,24 +167,24 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Validates IPN invoices.
171
-	 *
170
+     * Validates IPN invoices.
171
+     *
172 172
      * @param WPInv_Invoice $invoice
173 173
      * @param object $payload
174
-	 * @return void
175
-	 */
176
-	public function validate_ipn_invoice( $invoice, $payload ) {
174
+     * @return void
175
+     */
176
+    public function validate_ipn_invoice( $invoice, $payload ) {
177 177
         if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
178 178
             exit;
179 179
         }
180 180
     }
181 181
 
182 182
     /**
183
-	 * Process subscriptio IPNS.
184
-	 *
185
-	 * @return void
186
-	 */
187
-	public function maybe_process_old_ipn() {
183
+     * Process subscriptio IPNS.
184
+     *
185
+     * @return void
186
+     */
187
+    public function maybe_process_old_ipn() {
188 188
 
189 189
         $data = wp_unslash( $_POST );
190 190
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
     }
227 227
 
228 228
     /**
229
-	 * Validates the old IPN signature.
229
+     * Validates the old IPN signature.
230 230
      *
231 231
      * @param array $posted
232
-	 */
233
-	public function validate_old_ipn_signature( $posted ) {
232
+     */
233
+    public function validate_old_ipn_signature( $posted ) {
234 234
 
235 235
         $signature = $this->get_option( 'signature_key' );
236 236
         if ( ! empty( $signature ) ) {
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
     }
250 250
 
251 251
     /**
252
-	 * Check Authorize.NET IPN validity.
253
-	 */
254
-	public function validate_ipn() {
252
+     * Check Authorize.NET IPN validity.
253
+     */
254
+    public function validate_ipn() {
255 255
 
256 256
         wpinv_error_log( 'Validating Authorize.NET IPN response' );
257 257
 
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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 Legacy Payment Gateway class.
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 	 * @param WPInv_Invoice $invoice Invoice.
29 29
 	 * @return string
30 30
 	 */
31
-	public function get_api_url( $invoice ) {
32
-        return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
31
+	public function get_api_url($invoice) {
32
+        return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
@@ -40,40 +40,40 @@  discard block
 block discarded – undo
40 40
      * @param WPInv_Invoice $invoice Invoice.
41 41
 	 * @return stdClass|WP_Error
42 42
 	 */
43
-    public function post( $post, $invoice ){
43
+    public function post($post, $invoice) {
44 44
 
45
-        $url      = $this->get_api_url( $invoice );
45
+        $url      = $this->get_api_url($invoice);
46 46
         $response = wp_remote_post(
47 47
             $url,
48 48
             array(
49 49
                 'headers'          => array(
50 50
                     'Content-Type' => 'application/json; charset=utf-8'
51 51
                 ),
52
-                'body'             => json_encode( $post ),
52
+                'body'             => json_encode($post),
53 53
                 'method'           => 'POST'
54 54
             )
55 55
         );
56 56
 
57
-        if ( is_wp_error( $response ) ) {
57
+        if (is_wp_error($response)) {
58 58
             return $response;
59 59
         }
60 60
 
61
-        $response = wp_unslash( wp_remote_retrieve_body( $response ) );
61
+        $response = wp_unslash(wp_remote_retrieve_body($response));
62 62
         $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
63
-        $response = json_decode( $response );
63
+        $response = json_decode($response);
64 64
 
65
-        if ( empty( $response ) ) {
66
-            return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) );
65
+        if (empty($response)) {
66
+            return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing'));
67 67
         }
68 68
 
69
-        if ( $response->messages->resultCode == 'Error' ) {
69
+        if ($response->messages->resultCode == 'Error') {
70 70
 
71
-            if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) {
71
+            if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) {
72 72
                 $error = $response->transactionResponse->errors[0];
73
-                return new WP_Error( $error->errorCode, $error->errorText );
73
+                return new WP_Error($error->errorCode, $error->errorText);
74 74
             }
75 75
 
76
-            return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text );
76
+            return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text);
77 77
         }
78 78
 
79 79
         return $response;
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	public function get_auth_params() {
90 90
 
91 91
         return array(
92
-            'name'           => $this->get_option( 'login_id' ),
93
-            'transactionKey' => $this->get_option( 'transaction_key' ),
92
+            'name'           => $this->get_option('login_id'),
93
+            'transactionKey' => $this->get_option('transaction_key'),
94 94
         );
95 95
 
96 96
     }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @param WPInv_Subscription $subscription Subscription.
103 103
      * @param WPInv_Invoice $invoice Invoice.
104 104
 	 */
105
-	public function cancel_subscription( $subscription, $invoice ) {
105
+	public function cancel_subscription($subscription, $invoice) {
106 106
 
107 107
         // Backwards compatibility. New version do not use authorize.net subscriptions.
108 108
         $this->post(
@@ -127,38 +127,38 @@  discard block
 block discarded – undo
127 127
         $this->maybe_process_old_ipn();
128 128
 
129 129
         // Validate the IPN.
130
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
131
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
130
+        if (empty($_POST) || !$this->validate_ipn()) {
131
+		    wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500));
132 132
         }
133 133
 
134 134
         // Event type.
135
-        $posted = json_decode( file_get_contents( 'php://input' ) );
136
-        if ( empty( $posted ) ) {
137
-            wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) );
135
+        $posted = json_decode(file_get_contents('php://input'));
136
+        if (empty($posted)) {
137
+            wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500));
138 138
         }
139 139
 
140 140
         // Process the IPN.
141
-        $posted = (object) wp_unslash( $posted );
141
+        $posted = (object) wp_unslash($posted);
142 142
 
143 143
         // Process refunds.
144
-        if ( 'net.authorize.payment.refund.created' == $posted->eventType ) {
145
-            $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId );
146
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
144
+        if ('net.authorize.payment.refund.created' == $posted->eventType) {
145
+            $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId);
146
+            $this->validate_ipn_invoice($invoice, $posted->payload);
147 147
             $invoice->refund();
148 148
         }
149 149
 
150 150
         // Held funds approved.
151
-        if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) {
152
-            $invoice = new WPInv_Invoice( $posted->payload->id );
153
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
154
-            $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) );
151
+        if ('net.authorize.payment.fraud.approved' == $posted->eventType) {
152
+            $invoice = new WPInv_Invoice($posted->payload->id);
153
+            $this->validate_ipn_invoice($invoice, $posted->payload);
154
+            $invoice->mark_paid(false, __('Payment released', 'invoicing'));
155 155
         }
156 156
 
157 157
         // Held funds declined.
158
-        if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) {
159
-            $invoice = new WPInv_Invoice( $posted->payload->id );
160
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
161
-            $invoice->set_status( 'wpi-failed', __( 'Payment desclined', 'invoicing' ) );
158
+        if ('net.authorize.payment.fraud.declined' == $posted->eventType) {
159
+            $invoice = new WPInv_Invoice($posted->payload->id);
160
+            $this->validate_ipn_invoice($invoice, $posted->payload);
161
+            $invoice->set_status('wpi-failed', __('Payment desclined', 'invoicing'));
162 162
             $invoice->save();
163 163
         }
164 164
 
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
      * @param object $payload
174 174
 	 * @return void
175 175
 	 */
176
-	public function validate_ipn_invoice( $invoice, $payload ) {
177
-        if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
176
+	public function validate_ipn_invoice($invoice, $payload) {
177
+        if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) {
178 178
             exit;
179 179
         }
180 180
     }
@@ -186,32 +186,32 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public function maybe_process_old_ipn() {
188 188
 
189
-        $data = wp_unslash( $_POST );
189
+        $data = wp_unslash($_POST);
190 190
 
191 191
         // Only process subscriptions subscriptions.
192
-        if ( empty( $_POST['x_subscription_id'] ) ) {
192
+        if (empty($_POST['x_subscription_id'])) {
193 193
             return;
194 194
         }
195 195
 
196 196
         // Check validity.
197
-        $this->validate_old_ipn_signature( $data );
197
+        $this->validate_old_ipn_signature($data);
198 198
 
199 199
         // Fetch the associated subscription.
200
-        $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $_POST['x_subscription_id'] );
201
-        $subscription    = new WPInv_Subscription( $subscription_id );
200
+        $subscription_id = WPInv_Subscription::get_subscription_id_by_field($_POST['x_subscription_id']);
201
+        $subscription    = new WPInv_Subscription($subscription_id);
202 202
 
203 203
         // Abort if it is missing or completed.
204
-        if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) {
204
+        if (!$subscription->get_id() || $subscription->has_status('completed')) {
205 205
             return;
206 206
         }
207 207
 
208 208
         // Payment status.
209
-        if ( 1 == $_POST['x_response_code'] ) {
209
+        if (1 == $_POST['x_response_code']) {
210 210
 
211 211
             // Renew the subscription.
212 212
             $subscription->add_payment(
213 213
                 array(
214
-                    'transaction_id' => sanitize_text_field( $data['x_trans_id'] ),
214
+                    'transaction_id' => sanitize_text_field($data['x_trans_id']),
215 215
                     'gateway'        => $this->id
216 216
                 )
217 217
             );
@@ -230,17 +230,17 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @param array $posted
232 232
 	 */
233
-	public function validate_old_ipn_signature( $posted ) {
233
+	public function validate_old_ipn_signature($posted) {
234 234
 
235
-        $signature = $this->get_option( 'signature_key' );
236
-        if ( ! empty( $signature ) ) {
237
-            $login_id  = $this->get_option( 'login_id' );
235
+        $signature = $this->get_option('signature_key');
236
+        if (!empty($signature)) {
237
+            $login_id  = $this->get_option('login_id');
238 238
             $trans_id  = $_POST['x_trans_id'];
239 239
             $amount    = $_POST['x_amount'];
240
-            $hash      = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) );
240
+            $hash      = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature));
241 241
 
242
-            if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) {
243
-                wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" );
242
+            if (!hash_equals($hash, $posted['x_SHA2_Hash'])) {
243
+                wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash");
244 244
                 exit;
245 245
             }
246 246
 
@@ -253,28 +253,28 @@  discard block
 block discarded – undo
253 253
 	 */
254 254
 	public function validate_ipn() {
255 255
 
256
-        wpinv_error_log( 'Validating Authorize.NET IPN response' );
256
+        wpinv_error_log('Validating Authorize.NET IPN response');
257 257
 
258
-        if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
258
+        if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) {
259 259
             return false;
260 260
         }
261 261
 
262
-        $signature = $this->get_option( 'signature_key' );
262
+        $signature = $this->get_option('signature_key');
263 263
 
264
-        if ( empty( $signature ) ) {
265
-            wpinv_error_log( 'Error: You have not set a signature key' );
264
+        if (empty($signature)) {
265
+            wpinv_error_log('Error: You have not set a signature key');
266 266
             return false;
267 267
         }
268 268
 
269
-        $hash  = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) );
269
+        $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature));
270 270
 
271
-        if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
272
-            wpinv_error_log( 'Successfully validated the IPN' );
271
+        if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) {
272
+            wpinv_error_log('Successfully validated the IPN');
273 273
             return true;
274 274
         }
275 275
 
276
-        wpinv_error_log( 'IPN hash is not valid' );
277
-        wpinv_error_log(  $_SERVER['HTTP_X_ANET_SIGNATURE']  );
276
+        wpinv_error_log('IPN hash is not valid');
277
+        wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']);
278 278
         return false;
279 279
 
280 280
     }
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
 
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
181
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
180
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
181
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196 196
 /**
@@ -200,26 +200,26 @@  discard block
 block discarded – undo
200 200
  * @param string $card_number Card number.
201 201
  * @return string
202 202
  */
203
-function getpaid_get_card_name( $card_number ) {
203
+function getpaid_get_card_name($card_number) {
204 204
 
205 205
     // Known regexes.
206 206
     $regexes = array(
207
-        '/^4/'                     => __( 'Visa', 'invoicing' ),
208
-        '/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-        '/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-        '/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-        '/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-        '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
207
+        '/^4/'                     => __('Visa', 'invoicing'),
208
+        '/^5[1-5]/'                => __('Mastercard', 'invoicing'),
209
+        '/^3[47]/'                 => __('Amex', 'invoicing'),
210
+        '/^3(?:0[0-5]|[68])/'      => __('Diners Club', 'invoicing'),
211
+        '/^6(?:011|5)/'            => __('Discover', 'invoicing'),
212
+        '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'),
213 213
     );
214 214
 
215 215
     // Confirm if one matches.
216
-    foreach ( $regexes as $regex => $card ) {
217
-        if ( preg_match ( $regex, $card_number ) >= 1 ) {
216
+    foreach ($regexes as $regex => $card) {
217
+        if (preg_match($regex, $card_number) >= 1) {
218 218
             return $card;
219 219
         }
220 220
     }
221 221
 
222 222
     // None matched.
223
-    return __( 'Card', 'invoicing' );
223
+    return __('Card', 'invoicing');
224 224
 
225 225
 }
Please login to merge, or discard this patch.