Passed
Push — master ( dc6e8d...ffa28a )
by Brian
05:03
created
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 1 patch
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.
includes/wpinv-email-functions.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
     $css = getpaid_get_email_css();
111 111
 
112 112
     // include css inliner
113
-	if ( ! class_exists( 'Emogrifier' ) ) {
114
-		include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
113
+    if ( ! class_exists( 'Emogrifier' ) ) {
114
+        include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
115 115
     }
116 116
 
117 117
     // Inline the css.
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
     $message = wpinv_email_style_body( $message );
191 191
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
192 192
 
193
-	return $mailer->send(
193
+    return $mailer->send(
194 194
         $to,
195 195
         $subject,
196 196
         $message,
Please login to merge, or discard this patch.
includes/error-functions.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -117,14 +117,14 @@
 block discarded – undo
117 117
  */
118 118
 function getpaid_doing_it_wrong( $function, $message, $version ) {
119 119
 
120
-	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121
-
122
-	if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
125
-	} else {
126
-		_doing_it_wrong( $function, $message, $version );
127
-	}
120
+    $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121
+
122
+    if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
123
+        do_action( 'doing_it_wrong_run', $function, $message, $version );
124
+        error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
125
+    } else {
126
+        _doing_it_wrong( $function, $message, $version );
127
+    }
128 128
 
129 129
 }
130 130
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-forms.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -13,128 +13,128 @@
 block discarded – undo
13 13
 class GetPaid_Payment_Forms {
14 14
 
15 15
     /**
16
-	 * Class constructor
17
-	 *
18
-	 */
19
-	public function __construct() {
20
-
21
-		// Update a payment form's revenue whenever an invoice is paid for or refunded.
22
-		add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) );
23
-		add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) );
24
-
25
-		// Sync form amount whenever invoice statuses change.
26
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 );
27
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 );
28
-		add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 );
29
-
30
-	}
31
-
32
-	/**
33
-	 * Increments a form's revenue whenever there is a payment.
34
-	 *
35
-	 * @param WPInv_Invoice $invoice
36
-	 */
37
-	public function increment_form_revenue( $invoice ) {
38
-
39
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
40
-		if ( $form->get_id() ) {
41
-			$form->set_earned( $form->get_earned() + $invoice->get_total() );
42
-			$form->save();
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Decreases form revenue whenever invoice payment changes.
49
-	 *
50
-	 * @param WPInv_Invoice $invoice
51
-	 */
52
-	public function decrease_form_revenue( $invoice ) {
53
-
54
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
55
-		if ( $form->get_id() ) {
56
-			$form->set_earned( $form->get_earned() - $invoice->get_total() );
57
-			$form->save();
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Updates a form's failed amount.
64
-	 *
65
-	 * @param WPInv_Invoice $invoice
66
-	 * @param string $from
67
-	 * @param string $to
68
-	 */
69
-	public function update_form_failed_amount( $invoice, $from, $to ) {
70
-
71
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
72
-		if ( $form->get_id() ) {
73
-			return;
74
-		}
75
-
76
-		if ( 'wpi-failed' == $from ) {
77
-			$form->set_failed( $form->get_failed() - $invoice->get_total() );
78
-			$form->save();
79
-		}
80
-
81
-		if ( 'wpi-failed' == $to ) {
82
-			$form->set_failed( $form->get_failed() + $invoice->get_total() );
83
-			$form->save();
84
-		}
85
-
86
-	}
87
-
88
-	/**
89
-	 * Updates a form's refunded amount.
90
-	 *
91
-	 * @param WPInv_Invoice $invoice
92
-	 * @param string $from
93
-	 * @param string $to
94
-	 */
95
-	public function update_form_refunded_amount( $invoice, $from, $to ) {
96
-
97
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
98
-		if ( $form->get_id() ) {
99
-			return;
100
-		}
101
-
102
-		if ( 'wpi-refunded' == $from ) {
103
-			$form->set_refunded( $form->get_refunded() - $invoice->get_total() );
104
-			$form->save();
105
-		}
106
-
107
-		if ( 'wpi-refunded' == $to ) {
108
-			$form->set_refunded( $form->get_refunded() + $invoice->get_total() );
109
-			$form->save();
110
-		}
111
-
112
-	}
113
-
114
-	/**
115
-	 * Updates a form's cancelled amount.
116
-	 *
117
-	 * @param WPInv_Invoice $invoice
118
-	 * @param string $from
119
-	 * @param string $to
120
-	 */
121
-	public function update_form_cancelled_amount( $invoice, $from, $to ) {
122
-
123
-		$form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
124
-		if ( $form->get_id() ) {
125
-			return;
126
-		}
127
-
128
-		if ( 'wpi-cancelled' == $from ) {
129
-			$form->set_cancelled( $form->get_cancelled() - $invoice->get_total() );
130
-			$form->save();
131
-		}
132
-
133
-		if ( 'wpi-cancelled' == $to ) {
134
-			$form->set_cancelled( $form->get_cancelled() + $invoice->get_total() );
135
-			$form->save();
136
-		}
137
-
138
-	}
16
+     * Class constructor
17
+     *
18
+     */
19
+    public function __construct() {
20
+
21
+        // Update a payment form's revenue whenever an invoice is paid for or refunded.
22
+        add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) );
23
+        add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) );
24
+
25
+        // Sync form amount whenever invoice statuses change.
26
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 );
27
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 );
28
+        add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 );
29
+
30
+    }
31
+
32
+    /**
33
+     * Increments a form's revenue whenever there is a payment.
34
+     *
35
+     * @param WPInv_Invoice $invoice
36
+     */
37
+    public function increment_form_revenue( $invoice ) {
38
+
39
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
40
+        if ( $form->get_id() ) {
41
+            $form->set_earned( $form->get_earned() + $invoice->get_total() );
42
+            $form->save();
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Decreases form revenue whenever invoice payment changes.
49
+     *
50
+     * @param WPInv_Invoice $invoice
51
+     */
52
+    public function decrease_form_revenue( $invoice ) {
53
+
54
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
55
+        if ( $form->get_id() ) {
56
+            $form->set_earned( $form->get_earned() - $invoice->get_total() );
57
+            $form->save();
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Updates a form's failed amount.
64
+     *
65
+     * @param WPInv_Invoice $invoice
66
+     * @param string $from
67
+     * @param string $to
68
+     */
69
+    public function update_form_failed_amount( $invoice, $from, $to ) {
70
+
71
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
72
+        if ( $form->get_id() ) {
73
+            return;
74
+        }
75
+
76
+        if ( 'wpi-failed' == $from ) {
77
+            $form->set_failed( $form->get_failed() - $invoice->get_total() );
78
+            $form->save();
79
+        }
80
+
81
+        if ( 'wpi-failed' == $to ) {
82
+            $form->set_failed( $form->get_failed() + $invoice->get_total() );
83
+            $form->save();
84
+        }
85
+
86
+    }
87
+
88
+    /**
89
+     * Updates a form's refunded amount.
90
+     *
91
+     * @param WPInv_Invoice $invoice
92
+     * @param string $from
93
+     * @param string $to
94
+     */
95
+    public function update_form_refunded_amount( $invoice, $from, $to ) {
96
+
97
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
98
+        if ( $form->get_id() ) {
99
+            return;
100
+        }
101
+
102
+        if ( 'wpi-refunded' == $from ) {
103
+            $form->set_refunded( $form->get_refunded() - $invoice->get_total() );
104
+            $form->save();
105
+        }
106
+
107
+        if ( 'wpi-refunded' == $to ) {
108
+            $form->set_refunded( $form->get_refunded() + $invoice->get_total() );
109
+            $form->save();
110
+        }
111
+
112
+    }
113
+
114
+    /**
115
+     * Updates a form's cancelled amount.
116
+     *
117
+     * @param WPInv_Invoice $invoice
118
+     * @param string $from
119
+     * @param string $to
120
+     */
121
+    public function update_form_cancelled_amount( $invoice, $from, $to ) {
122
+
123
+        $form = new GetPaid_Payment_Form( $invoice->get_payment_form() );
124
+        if ( $form->get_id() ) {
125
+            return;
126
+        }
127
+
128
+        if ( 'wpi-cancelled' == $from ) {
129
+            $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() );
130
+            $form->save();
131
+        }
132
+
133
+        if ( 'wpi-cancelled' == $to ) {
134
+            $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() );
135
+            $form->save();
136
+        }
137
+
138
+    }
139 139
 
140 140
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-payment-form.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 class GetPaid_Meta_Box_Payment_Form {
17 17
 
18 18
     /**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23 23
     public static function output( $post ) {
24 24
         ?>
25 25
         <div id="wpinv-form-builder" class="bsui">
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
     }
87 87
 
88 88
     /**
89
-	 * Save meta box data.
90
-	 *
91
-	 * @param int $post_id
92
-	 */
93
-	public static function save( $post_id ) {
89
+     * Save meta box data.
90
+     *
91
+     * @param int $post_id
92
+     */
93
+    public static function save( $post_id ) {
94 94
 
95 95
         // Prepare the form.
96 96
         $form = new GetPaid_Payment_Form( $post_id );
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
     }
122 122
 
123 123
     /**
124
-	 * Converts an array fo form items to objects.
125
-	 *
126
-	 * @param array $items
127
-	 */
128
-	public static function item_to_objects( $items ) {
124
+     * Converts an array fo form items to objects.
125
+     *
126
+     * @param array $items
127
+     */
128
+    public static function item_to_objects( $items ) {
129 129
 
130 130
         $objects = array();
131 131
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-discount-details.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Discount_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the discount.
@@ -368,34 +368,34 @@  discard block
 block discarded – undo
368 368
     }
369 369
 
370 370
     /**
371
-	 * Save meta box data.
372
-	 *
373
-	 * @param int $post_id
374
-	 */
375
-	public static function save( $post_id ) {
371
+     * Save meta box data.
372
+     *
373
+     * @param int $post_id
374
+     */
375
+    public static function save( $post_id ) {
376 376
 
377 377
         // Prepare the discount.
378 378
         $discount = new WPInv_Discount( $post_id );
379 379
 
380 380
         // Load new data.
381 381
         $discount->set_props(
382
-			array(
383
-				'code'                 => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null,
384
-				'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null,
385
-				'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
-				'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
-				'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
382
+            array(
383
+                'code'                 => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null,
384
+                'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null,
385
+                'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
+                'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
+                'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
388 388
                 'type'                 => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null,
389
-				'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
-				'items'                => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(),
391
-				'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(),
392
-				'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null,
393
-				'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null,
394
-				'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null,
395
-			)
389
+                'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
+                'items'                => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(),
391
+                'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(),
392
+                'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null,
393
+                'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null,
394
+                'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null,
395
+            )
396 396
         );
397 397
 
398
-		$discount->save();
399
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
-	}
398
+        $discount->save();
399
+        do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
+    }
401 401
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-fees.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Fees {
14 14
 
15
-	/**
16
-	 * The fee validation error.
17
-	 * @var string
18
-	 */
19
-	public $fee_error;
20
-
21
-	/**
22
-	 * Submission fees.
23
-	 * @var array
24
-	 */
25
-	public $fees = array();
15
+    /**
16
+     * The fee validation error.
17
+     * @var string
18
+     */
19
+    public $fee_error;
20
+
21
+    /**
22
+     * Submission fees.
23
+     * @var array
24
+     */
25
+    public $fees = array();
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Process any existing invoice fees.
35
+        if ( $submission->has_invoice() ) {
36
+            $this->fees = $submission->get_invoice()->get_fees();
37
+        }
38
+
39
+        // Process price fields.
40
+        $data         = $submission->get_data();
41
+        $payment_form = $submission->get_payment_form();
42
+
43
+        foreach ( $payment_form->get_elements() as $element ) {
44
+
45
+            if ( 'price_input' == $element['type'] ) {
46
+                $this->process_price_input( $element, $data );
47
+            }
48
+
49
+            if ( 'price_select' == $element['type'] ) {
50
+                $this->process_price_select( $element, $data );
51
+            }
52
+
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Process a price input field.
59
+     *
60
+     * @param array $element
61
+     * @param array $data
62
+     */
63
+    public function process_price_input( $element, $data ) {
64
+
65
+        // Abort if not passed.
66
+        if ( empty( $data[ $element['id'] ] ) ) {
67
+            return;
68
+        }
69
+
70
+        $amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
+        $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
72
+
73
+        if ( $amount < $minimum ) {
74
+            throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
+        }
76
+
77
+        $this->fees[ $element['label'] ] = array(
78
+            'name'          => $element['label'],
79
+            'initial_fee'   => $amount,
80
+            'recurring_fee' => 0,
81
+        );
82
+
83
+    }
26 84
 
27 85
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
36
-			$this->fees = $submission->get_invoice()->get_fees();
37
-		}
38
-
39
-		// Process price fields.
40
-		$data         = $submission->get_data();
41
-		$payment_form = $submission->get_payment_form();
42
-
43
-		foreach ( $payment_form->get_elements() as $element ) {
44
-
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data );
47
-			}
48
-
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
51
-			}
52
-
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Process a price input field.
59
-	 *
60
-	 * @param array $element
61
-	 * @param array $data
62
-	 */
63
-	public function process_price_input( $element, $data ) {
64
-
65
-		// Abort if not passed.
66
-		if ( empty( $data[ $element['id'] ] ) ) {
67
-			return;
68
-		}
69
-
70
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
-		$minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
72
-
73
-		if ( $amount < $minimum ) {
74
-			throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
-		}
76
-
77
-		$this->fees[ $element['label'] ] = array(
78
-			'name'          => $element['label'],
79
-			'initial_fee'   => $amount,
80
-			'recurring_fee' => 0,
81
-		);
82
-
83
-	}
84
-
85
-	/**
86
-	 * Process a price select field.
87
-	 *
88
-	 * @param array $element
89
-	 * @param array $data
90
-	 */
91
-	public function process_price_select( $element, $data ) {
92
-
93
-		// Abort if not passed.
94
-		if ( empty( $data[ $element['id'] ] ) ) {
95
-			return;
96
-		}
97
-
98
-		$options  = getpaid_convert_price_string_to_options( $element['options'] );
99
-		$selected = wpinv_parse_list( $data[ $element['id'] ] );
100
-		$total    = 0;
101
-
102
-		foreach ( $selected as $price ) {
103
-
104
-			if ( ! isset( $options[ $price ] ) ) {
105
-				throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
106
-			}
107
-
108
-			$total += (float) wpinv_sanitize_amount( $price );
109
-		}
110
-
111
-		$this->fees[ $element['label'] ] = array(
112
-			'name'          => $element['label'],
113
-			'initial_fee'   => $total,
114
-			'recurring_fee' => 0,
115
-		);
116
-
117
-	}
86
+     * Process a price select field.
87
+     *
88
+     * @param array $element
89
+     * @param array $data
90
+     */
91
+    public function process_price_select( $element, $data ) {
92
+
93
+        // Abort if not passed.
94
+        if ( empty( $data[ $element['id'] ] ) ) {
95
+            return;
96
+        }
97
+
98
+        $options  = getpaid_convert_price_string_to_options( $element['options'] );
99
+        $selected = wpinv_parse_list( $data[ $element['id'] ] );
100
+        $total    = 0;
101
+
102
+        foreach ( $selected as $price ) {
103
+
104
+            if ( ! isset( $options[ $price ] ) ) {
105
+                throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
106
+            }
107
+
108
+            $total += (float) wpinv_sanitize_amount( $price );
109
+        }
110
+
111
+        $this->fees[ $element['label'] ] = array(
112
+            'name'          => $element['label'],
113
+            'initial_fee'   => $total,
114
+            'recurring_fee' => 0,
115
+        );
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -12,189 +12,189 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Discount {
14 14
 
15
-	/**
16
-	 * Submission discounts.
17
-	 * @var array
18
-	 */
19
-	public $discounts = array();
15
+    /**
16
+     * Submission discounts.
17
+     * @var array
18
+     */
19
+    public $discounts = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     * @param float                           $initial_total
26
+     * @param float                           $recurring_total
27
+     */
28
+    public function __construct( $submission, $initial_total, $recurring_total ) {
29
+
30
+        // Process any existing invoice discounts.
31
+        if ( $submission->has_invoice() ) {
32
+            $this->discounts = $submission->get_invoice()->get_discounts();
33
+        }
34
+
35
+        // Do we have a discount?
36
+        $discount = $submission->get_field( 'discount' );
37
+
38
+        if ( empty( $discount ) ) {
39
+
40
+            if ( isset( $this->discounts['discount_code'] ) ) {
41
+                unset( $this->discounts['discount_code'] );
42
+            }
43
+
44
+            return;
45
+        }
46
+
47
+        // Processes the discount code.
48
+        $amount = max( $initial_total, $recurring_total );
49
+        $this->process_discount( $submission, $discount, $amount );
50
+
51
+    }
20 52
 
21 53
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 * @param float                           $initial_total
26
-	 * @param float                           $recurring_total
27
-	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
29
-
30
-		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
32
-			$this->discounts = $submission->get_invoice()->get_discounts();
33
-		}
34
-
35
-		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
37
-
38
-		if ( empty( $discount ) ) {
39
-
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
42
-			}
43
-
44
-			return;
45
-		}
46
-
47
-		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Processes a submission discount.
55
-	 *
56
-	 * @param GetPaid_Payment_Form_Submission $submission
57
-	 * @param string                          $discount
58
-	 * @param float                           $amount
59
-	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
61
-
62
-		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
64
-
65
-		// Ensure it is active.
54
+     * Processes a submission discount.
55
+     *
56
+     * @param GetPaid_Payment_Form_Submission $submission
57
+     * @param string                          $discount
58
+     * @param float                           $amount
59
+     */
60
+    public function process_discount( $submission, $discount, $amount ) {
61
+
62
+        // Fetch the discount.
63
+        $discount = new WPInv_Discount( $discount );
64
+
65
+        // Ensure it is active.
66 66
         if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) );
68
-		}
69
-
70
-		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
-		}
74
-
75
-		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
77
-
78
-		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
80
-
81
-		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
-	}
84
-
85
-	/**
86
-	 * Validates a single use discount.
87
-	 *
88
-	 * @param WPInv_Discount                  $discount
89
-	 * @return bool
90
-	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
-	}
94
-
95
-	/**
96
-	 * Returns a user's id or email.
97
-	 *
98
-	 * @param string $email
99
-	 * @return int|string|false
100
-	 */
101
-	public function get_user_id_or_email( $email ) {
102
-
103
-		if ( is_user_logged_in() ) {
104
-			return get_current_user_id();
105
-		}
106
-
107
-		return empty( $email ) ? false : sanitize_email( $email );
108
-	}
109
-
110
-	/**
111
-	 * Validates a single use discount.
112
-	 *
113
-	 * @param GetPaid_Payment_Form_Submission $submission
114
-	 * @param WPInv_Discount                  $discount
115
-	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
117
-
118
-		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
120
-			return;
121
-		}
122
-
123
-		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
-
126
-		if ( empty( $user ) ) {
127
-			throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
-		}
129
-
130
-		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
-		}
134
-
135
-	}
136
-
137
-	/**
138
-	 * Validates the discount's amount.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 * @param WPInv_Discount         $discount
142
-	 * @param float                  $amount
143
-	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
145
-
146
-		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
-		}
151
-
152
-		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * Calculates the discount code's amount.
162
-	 *
163
-	 * Ensure that the discount exists and has been validated before calling this method.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 * @param WPInv_Discount                  $discount
167
-	 * @return array
168
-	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-
171
-		$initial_discount   = 0;
172
-		$recurring_discount = 0;
173
-
174
-		foreach ( $submission->get_items() as $item ) {
175
-
176
-			// Abort if it is not valid for this item.
177
-			if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
178
-				continue;
179
-			}
180
-
181
-			// Calculate the initial amount...
182
-			$initial_discount += $discount->get_discounted_amount( $item->get_sub_total() );
183
-
184
-			// ... and maybe the recurring amount.
185
-			if ( $item->is_recurring() && $discount->is_recurring() ) {
186
-				$recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() );
187
-			}
188
-
189
-		}
190
-
191
-		return array(
192
-			'name'               => 'discount_code',
193
-			'discount_code'      => $discount->get_code(),
194
-			'initial_discount'   => $initial_discount,
195
-			'recurring_discount' => $recurring_discount,
196
-		);
197
-
198
-	}
67
+            throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Exceeded limit.
71
+        if ( $discount->has_exceeded_limit() ) {
72
+            throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
+        }
74
+
75
+        // Validate usages.
76
+        $this->validate_single_use_discount( $submission, $discount );
77
+
78
+        // Validate amount.
79
+        $this->validate_discount_amount( $submission, $discount, $amount );
80
+
81
+        // Save the discount.
82
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
+    }
84
+
85
+    /**
86
+     * Validates a single use discount.
87
+     *
88
+     * @param WPInv_Discount                  $discount
89
+     * @return bool
90
+     */
91
+    public function is_discount_active(  $discount ) {
92
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
+    }
94
+
95
+    /**
96
+     * Returns a user's id or email.
97
+     *
98
+     * @param string $email
99
+     * @return int|string|false
100
+     */
101
+    public function get_user_id_or_email( $email ) {
102
+
103
+        if ( is_user_logged_in() ) {
104
+            return get_current_user_id();
105
+        }
106
+
107
+        return empty( $email ) ? false : sanitize_email( $email );
108
+    }
109
+
110
+    /**
111
+     * Validates a single use discount.
112
+     *
113
+     * @param GetPaid_Payment_Form_Submission $submission
114
+     * @param WPInv_Discount                  $discount
115
+     */
116
+    public function validate_single_use_discount( $submission, $discount ) {
117
+
118
+        // Abort if it is not a single use discount.
119
+        if ( ! $discount->is_single_use() ) {
120
+            return;
121
+        }
122
+
123
+        // Ensure there is a valid billing email.
124
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
+
126
+        if ( empty( $user ) ) {
127
+            throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
+        }
129
+
130
+        // Has the user used this discount code before?
131
+        if ( ! $discount->is_valid_for_user( $user ) ) {
132
+            throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
+        }
134
+
135
+    }
136
+
137
+    /**
138
+     * Validates the discount's amount.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     * @param WPInv_Discount         $discount
142
+     * @param float                  $amount
143
+     */
144
+    public function validate_discount_amount( $submission, $discount, $amount ) {
145
+
146
+        // Validate minimum amount.
147
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
+            throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
+        }
151
+
152
+        // Validate the maximum amount.
153
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
+            throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * Calculates the discount code's amount.
162
+     *
163
+     * Ensure that the discount exists and has been validated before calling this method.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     * @param WPInv_Discount                  $discount
167
+     * @return array
168
+     */
169
+    public function calculate_discount( $submission, $discount ) {
170
+
171
+        $initial_discount   = 0;
172
+        $recurring_discount = 0;
173
+
174
+        foreach ( $submission->get_items() as $item ) {
175
+
176
+            // Abort if it is not valid for this item.
177
+            if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
178
+                continue;
179
+            }
180
+
181
+            // Calculate the initial amount...
182
+            $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() );
183
+
184
+            // ... and maybe the recurring amount.
185
+            if ( $item->is_recurring() && $discount->is_recurring() ) {
186
+                $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() );
187
+            }
188
+
189
+        }
190
+
191
+        return array(
192
+            'name'               => 'discount_code',
193
+            'discount_code'      => $discount->get_code(),
194
+            'initial_discount'   => $initial_discount,
195
+            'recurring_discount' => $recurring_discount,
196
+        );
197
+
198
+    }
199 199
 
200 200
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,373 +14,373 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	public function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
-
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
-	}
234
-
235
-	/**
236
-	 * Renewal date column
237
-	 *
238
-	 * @param WPInv_Subscription $item
239
-	 * @since       1.0.0
240
-	 * @return      string
241
-	 */
242
-	public function column_renewal_date( $item ) {
243
-		return getpaid_format_date_value( $item->get_expiration() );
244
-	}
245
-
246
-	/**
247
-	 * Start date column
248
-	 *
249
-	 * @param WPInv_Subscription $item
250
-	 * @since       1.0.0
251
-	 * @return      string
252
-	 */
253
-	public function column_start_date( $item ) {
254
-		return getpaid_format_date_value( $item->get_date_created() );
255
-	}
256
-
257
-	/**
258
-	 * Amount column
259
-	 *
260
-	 * @param WPInv_Subscription $item
261
-	 * @since       1.0.19
262
-	 * @return      string
263
-	 */
264
-	public function column_amount( $item ) {
265
-		$amount = getpaid_get_formatted_subscription_amount( $item );
266
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267
-	}
268
-
269
-	/**
270
-	 * Billing Times column
271
-	 *
272
-	 * @param WPInv_Subscription $item
273
-	 * @since       1.0.0
274
-	 * @return      string
275
-	 */
276
-	public function column_renewals( $item ) {
277
-		$max_bills = $item->get_bill_times();
278
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
279
-	}
280
-
281
-	/**
282
-	 * Product ID column
283
-	 *
284
-	 * @param WPInv_Subscription $item
285
-	 * @since       1.0.0
286
-	 * @return      string
287
-	 */
288
-	public function column_item( $item ) {
289
-		$_item = get_post( $item->get_product_id() );
290
-
291
-		if ( ! empty( $_item ) ) {
292
-			$link = get_edit_post_link( $_item );
293
-			$link = esc_url( $link );
294
-			$name = esc_html( get_the_title( $_item ) );
295
-			return "<a href='$link'>$name</a>";
296
-		} else {
297
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
298
-		}
299
-
300
-	}
301
-
302
-	/**
303
-	 * Retrieve the current page number
304
-	 *
305
-	 * @return      int
306
-	 */
307
-	public function get_paged() {
308
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
309
-	}
310
-
311
-	/**
312
-	 * Setup the final data for the table
313
-	 *
314
-	 */
315
-	public function prepare_items() {
316
-
317
-		$columns  = $this->get_columns();
318
-		$hidden   = array();
319
-		$sortable = $this->get_sortable_columns();
320
-
321
-		$this->_column_headers = array( $columns, $hidden, $sortable );
322
-
323
-		$this->set_pagination_args(
324
-			array(
325
-			'total_items' => $this->current_total_count,
326
-			'per_page'    => $this->per_page,
327
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
328
-			)
329
-		);
330
-	}
331
-
332
-	/**
333
-	 * Table columns
334
-	 *
335
-	 * @return array
336
-	 */
337
-	public function get_columns(){
338
-		$columns = array(
339
-			'cb'                => '<input type="checkbox" />',
340
-			'subscription'      => __( 'Subscription', 'invoicing' ),
341
-			'start_date'        => __( 'Start Date', 'invoicing' ),
342
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
-			'renewals'          => __( 'Payments', 'invoicing' ),
344
-			'item'              => __( 'Item', 'invoicing' ),
345
-			'status'            => __( 'Status', 'invoicing' ),
346
-		);
347
-
348
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
349
-	}
350
-
351
-	/**
352
-	 * Sortable table columns.
353
-	 *
354
-	 * @return array
355
-	 */
356
-	public function get_sortable_columns() {
357
-		$sortable = array(
358
-			'subscription' => array( 'id', true ),
359
-			'start_date'   => array( 'created', true ),
360
-			'renewal_date' => array( 'expiration', true ),
361
-			'renewals'     => array( 'bill_times', true ),
362
-			'item'         => array( 'product_id', true ),
363
-			'status'       => array( 'status', true ),
364
-		);
365
-
366
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
367
-	}
368
-
369
-	/**
370
-	 * Whether the table has items to display or not
371
-	 *
372
-	 * @return bool
373
-	 */
374
-	public function has_items() {
375
-		return ! empty( $this->current_total_count );
376
-	}
377
-
378
-	/**
379
-	 * Processes bulk actions.
380
-	 *
381
-	 */
382
-	public function process_bulk_action() {
383
-
384
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    public function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $view_url    = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
+
232
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
+    }
234
+
235
+    /**
236
+     * Renewal date column
237
+     *
238
+     * @param WPInv_Subscription $item
239
+     * @since       1.0.0
240
+     * @return      string
241
+     */
242
+    public function column_renewal_date( $item ) {
243
+        return getpaid_format_date_value( $item->get_expiration() );
244
+    }
245
+
246
+    /**
247
+     * Start date column
248
+     *
249
+     * @param WPInv_Subscription $item
250
+     * @since       1.0.0
251
+     * @return      string
252
+     */
253
+    public function column_start_date( $item ) {
254
+        return getpaid_format_date_value( $item->get_date_created() );
255
+    }
256
+
257
+    /**
258
+     * Amount column
259
+     *
260
+     * @param WPInv_Subscription $item
261
+     * @since       1.0.19
262
+     * @return      string
263
+     */
264
+    public function column_amount( $item ) {
265
+        $amount = getpaid_get_formatted_subscription_amount( $item );
266
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267
+    }
268
+
269
+    /**
270
+     * Billing Times column
271
+     *
272
+     * @param WPInv_Subscription $item
273
+     * @since       1.0.0
274
+     * @return      string
275
+     */
276
+    public function column_renewals( $item ) {
277
+        $max_bills = $item->get_bill_times();
278
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
279
+    }
280
+
281
+    /**
282
+     * Product ID column
283
+     *
284
+     * @param WPInv_Subscription $item
285
+     * @since       1.0.0
286
+     * @return      string
287
+     */
288
+    public function column_item( $item ) {
289
+        $_item = get_post( $item->get_product_id() );
290
+
291
+        if ( ! empty( $_item ) ) {
292
+            $link = get_edit_post_link( $_item );
293
+            $link = esc_url( $link );
294
+            $name = esc_html( get_the_title( $_item ) );
295
+            return "<a href='$link'>$name</a>";
296
+        } else {
297
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
298
+        }
299
+
300
+    }
301
+
302
+    /**
303
+     * Retrieve the current page number
304
+     *
305
+     * @return      int
306
+     */
307
+    public function get_paged() {
308
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
309
+    }
310
+
311
+    /**
312
+     * Setup the final data for the table
313
+     *
314
+     */
315
+    public function prepare_items() {
316
+
317
+        $columns  = $this->get_columns();
318
+        $hidden   = array();
319
+        $sortable = $this->get_sortable_columns();
320
+
321
+        $this->_column_headers = array( $columns, $hidden, $sortable );
322
+
323
+        $this->set_pagination_args(
324
+            array(
325
+            'total_items' => $this->current_total_count,
326
+            'per_page'    => $this->per_page,
327
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
328
+            )
329
+        );
330
+    }
331
+
332
+    /**
333
+     * Table columns
334
+     *
335
+     * @return array
336
+     */
337
+    public function get_columns(){
338
+        $columns = array(
339
+            'cb'                => '<input type="checkbox" />',
340
+            'subscription'      => __( 'Subscription', 'invoicing' ),
341
+            'start_date'        => __( 'Start Date', 'invoicing' ),
342
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
+            'renewals'          => __( 'Payments', 'invoicing' ),
344
+            'item'              => __( 'Item', 'invoicing' ),
345
+            'status'            => __( 'Status', 'invoicing' ),
346
+        );
347
+
348
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
349
+    }
350
+
351
+    /**
352
+     * Sortable table columns.
353
+     *
354
+     * @return array
355
+     */
356
+    public function get_sortable_columns() {
357
+        $sortable = array(
358
+            'subscription' => array( 'id', true ),
359
+            'start_date'   => array( 'created', true ),
360
+            'renewal_date' => array( 'expiration', true ),
361
+            'renewals'     => array( 'bill_times', true ),
362
+            'item'         => array( 'product_id', true ),
363
+            'status'       => array( 'status', true ),
364
+        );
365
+
366
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
367
+    }
368
+
369
+    /**
370
+     * Whether the table has items to display or not
371
+     *
372
+     * @return bool
373
+     */
374
+    public function has_items() {
375
+        return ! empty( $this->current_total_count );
376
+    }
377
+
378
+    /**
379
+     * Processes bulk actions.
380
+     *
381
+     */
382
+    public function process_bulk_action() {
383
+
384
+    }
385 385
 
386 386
 }
Please login to merge, or discard this patch.