Passed
Push — master ( c5e685...72070d )
by Brian
15:09
created
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Initial tax.
23
-	 * @var float
24
-	 */
25
-	protected $initial_tax = 0;
26
-
27
-	/**
28
-	 * Recurring tax.
29
-	 * @var float
30
-	 */
31
-	protected $recurring_tax = 0;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Initial tax.
23
+     * @var float
24
+     */
25
+    protected $initial_tax = 0;
26
+
27
+    /**
28
+     * Recurring tax.
29
+     * @var float
30
+     */
31
+    protected $recurring_tax = 0;
32
+
33
+    /**
34
+     * Class constructor
35
+     *
36
+     * @param GetPaid_Payment_Form_Submission $submission
37
+     */
38
+    public function __construct( $submission ) {
39
+
40
+        // Validate VAT number.
41
+        $this->validate_vat( $submission );
42
+
43
+        foreach ( $submission->get_items() as $item ) {
44
+            $this->process_item_tax( $item, $submission );
45
+        }
46
+
47
+        // Process any existing invoice taxes.
48
+        if ( $submission->has_invoice() ) {
49
+            $this->taxes = $submission->get_invoice()->get_taxes();
50
+        }
51
+
52
+        // Add VAT.
53
+        $this->taxes['vat'] = array(
54
+            'name'          => 'vat',
55
+            'initial_tax'   => $this->initial_tax,
56
+            'recurring_tax' => $this->recurring_tax,
57
+        );
58
+
59
+    }
60
+
61
+    /**
62
+     * Maybe process tax.
63
+     *
64
+     * @since 1.0.19
65
+     * @param GetPaid_Form_Item $item
66
+     * @param GetPaid_Payment_Form_Submission $submission
67
+     */
68
+    public function process_item_tax( $item, $submission ) {
69
+
70
+        $rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
+        $price    = $item->get_sub_total();
72
+        $item_tax = $price * $rate * 0.01;
73
+
74
+        if ( wpinv_prices_include_tax() ) {
75
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
76
+        }
77
+
78
+        $this->initial_tax += $item_tax;
79
+
80
+        if ( $item->is_recurring() ) {
81
+            $this->recurring_tax += $item_tax;
82
+        }
83
+
84
+    }
85
+
86
+    /**
87
+     * Checks if the submission has a digital item.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     * @since 1.0.19
91
+     * @return bool
92
+     */
93
+    public function has_digital_item( $submission ) {
94
+
95
+        foreach ( $submission->get_items() as $item ) {
96
+
97
+            if ( 'digital' == $item->get_vat_rule() ) {
98
+                return true;
99
+            }
100
+
101
+        }
102
+
103
+        return false;
104
+    }
105
+
106
+    /**
107
+     * Checks if this is an eu store.
108
+     *
109
+     * @since 1.0.19
110
+     * @return bool
111
+     */
112
+    public function is_eu_store() {
113
+        return $this->is_eu_country( wpinv_get_default_country() );
114
+    }
115
+
116
+    /**
117
+     * Checks if this is an eu country.
118
+     *
119
+     * @param string $country
120
+     * @since 1.0.19
121
+     * @return bool
122
+     */
123
+    public function is_eu_country( $country ) {
124
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
+    }
126
+
127
+    /**
128
+     * Checks if this is an eu purchase.
129
+     *
130
+     * @param string $customer_country
131
+     * @since 1.0.19
132
+     * @return bool
133
+     */
134
+    public function is_eu_transaction( $customer_country ) {
135
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
+    }
137
+
138
+    /**
139
+     * Retrieves the vat number.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     * @since 1.0.19
143
+     * @return string
144
+     */
145
+    public function get_vat_number( $submission ) {
146
+
147
+        // Retrieve from the posted number.
148
+        $vat_number = $submission->get_field( 'wpinv_vat_number' );
149
+        if ( ! empty( $vat_number ) ) {
150
+            return wpinv_clean( $vat_number );
151
+        }
152
+
153
+        // Retrieve from the invoice.
154
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
+    }
156
+
157
+    /**
158
+     * Retrieves the company.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     * @since 1.0.19
162
+     * @return string
163
+     */
164
+    public function get_company( $submission ) {
165
+
166
+        // Retrieve from the posted data.
167
+        $company = $submission->get_field( 'wpinv_company' );
168
+        if ( ! empty( $company ) ) {
169
+            return wpinv_clean( $company );
170
+        }
171
+
172
+        // Retrieve from the invoice.
173
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
+    }
175
+
176
+    /**
177
+     * Checks if we requires a VAT number.
178
+     *
179
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
180
+     * @param bool $country_in_eu Whether the customer country is from the EU
181
+     * @since 1.0.19
182
+     * @return string
183
+     */
184
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
+
186
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
+        $prevent_b2c = ! empty( $prevent_b2c );
188
+        $is_eu       = $ip_in_eu || $country_in_eu;
189
+
190
+        return $prevent_b2c && $is_eu;
191
+    }
32 192
 
33 193
     /**
34
-	 * Class constructor
35
-	 *
36
-	 * @param GetPaid_Payment_Form_Submission $submission
37
-	 */
38
-	public function __construct( $submission ) {
39
-
40
-		// Validate VAT number.
41
-		$this->validate_vat( $submission );
42
-
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
45
-		}
46
-
47
-		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
49
-			$this->taxes = $submission->get_invoice()->get_taxes();
50
-		}
51
-
52
-		// Add VAT.
53
-		$this->taxes['vat'] = array(
54
-			'name'          => 'vat',
55
-			'initial_tax'   => $this->initial_tax,
56
-			'recurring_tax' => $this->recurring_tax,
57
-		);
58
-
59
-	}
60
-
61
-	/**
62
-	 * Maybe process tax.
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @param GetPaid_Form_Item $item
66
-	 * @param GetPaid_Payment_Form_Submission $submission
67
-	 */
68
-	public function process_item_tax( $item, $submission ) {
69
-
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
-		$price    = $item->get_sub_total();
72
-		$item_tax = $price * $rate * 0.01;
73
-
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
76
-		}
77
-
78
-		$this->initial_tax += $item_tax;
79
-
80
-		if ( $item->is_recurring() ) {
81
-			$this->recurring_tax += $item_tax;
82
-		}
83
-
84
-	}
85
-
86
-	/**
87
-	 * Checks if the submission has a digital item.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 * @since 1.0.19
91
-	 * @return bool
92
-	 */
93
-	public function has_digital_item( $submission ) {
94
-
95
-		foreach ( $submission->get_items() as $item ) {
96
-
97
-			if ( 'digital' == $item->get_vat_rule() ) {
98
-				return true;
99
-			}
100
-
101
-		}
102
-
103
-		return false;
104
-	}
105
-
106
-	/**
107
-	 * Checks if this is an eu store.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @return bool
111
-	 */
112
-	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
114
-	}
115
-
116
-	/**
117
-	 * Checks if this is an eu country.
118
-	 *
119
-	 * @param string $country
120
-	 * @since 1.0.19
121
-	 * @return bool
122
-	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
-	}
126
-
127
-	/**
128
-	 * Checks if this is an eu purchase.
129
-	 *
130
-	 * @param string $customer_country
131
-	 * @since 1.0.19
132
-	 * @return bool
133
-	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
-	}
137
-
138
-	/**
139
-	 * Retrieves the vat number.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 * @since 1.0.19
143
-	 * @return string
144
-	 */
145
-	public function get_vat_number( $submission ) {
146
-
147
-		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
151
-		}
152
-
153
-		// Retrieve from the invoice.
154
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
-	}
156
-
157
-	/**
158
-	 * Retrieves the company.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 * @since 1.0.19
162
-	 * @return string
163
-	 */
164
-	public function get_company( $submission ) {
165
-
166
-		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
170
-		}
171
-
172
-		// Retrieve from the invoice.
173
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
-	}
175
-
176
-	/**
177
-	 * Checks if we requires a VAT number.
178
-	 *
179
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
180
-	 * @param bool $country_in_eu Whether the customer country is from the EU
181
-	 * @since 1.0.19
182
-	 * @return string
183
-	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
-
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
188
-		$is_eu       = $ip_in_eu || $country_in_eu;
189
-
190
-		return $prevent_b2c && $is_eu;
191
-	}
192
-
193
-	/**
194
-	 * Validate VAT data.
195
-	 *
196
-	 * @param GetPaid_Payment_Form_Submission $submission
197
-	 * @since 1.0.19
198
-	 */
199
-	public function validate_vat( $submission ) {
200
-
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
203
-
204
-		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
194
+     * Validate VAT data.
195
+     *
196
+     * @param GetPaid_Payment_Form_Submission $submission
197
+     * @since 1.0.19
198
+     */
199
+    public function validate_vat( $submission ) {
200
+
201
+        $has_digital = $this->has_digital_item( $submission );
202
+        $in_eu       = $this->is_eu_transaction( $submission->country );
203
+
204
+        // Abort if we are not validating vat numbers.
205
+        if ( ! $has_digital && ! $in_eu ) {
206 206
             return;
207
-		}
207
+        }
208 208
 
209
-		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
212
-		$ip_country  = WPInv_EUVat::get_country_by_ip();
209
+        // Prepare variables.
210
+        $vat_number  = $this->get_vat_number( $submission );
211
+        $company     = $this->get_company( $submission );
212
+        $ip_country  = WPInv_EUVat::get_country_by_ip();
213 213
         $is_eu       = $this->is_eu_country( $submission->country );
214 214
         $is_ip_eu    = $this->is_eu_country( $ip_country );
215 215
 
216
-		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases, ensure
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
-					getpaid_vat_name()
224
-				)
225
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                wp_sprintf(
222
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
+                    getpaid_vat_name()
224
+                )
225
+            );
226 226
 
227
-		}
227
+        }
228 228
 
229
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
229
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
231 231
             return;
232
-		}
232
+        }
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
238
-		}
236
+        if ( is_string( $is_valid ) ) {
237
+            throw new Exception( $is_valid );
238
+        }
239 239
 
240
-	}
240
+    }
241 241
 
242 242
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 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
  * Payment form submission taxes class
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param GetPaid_Payment_Form_Submission $submission
37 37
 	 */
38
-	public function __construct( $submission ) {
38
+	public function __construct($submission) {
39 39
 
40 40
 		// Validate VAT number.
41
-		$this->validate_vat( $submission );
41
+		$this->validate_vat($submission);
42 42
 
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
43
+		foreach ($submission->get_items() as $item) {
44
+			$this->process_item_tax($item, $submission);
45 45
 		}
46 46
 
47 47
 		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
48
+		if ($submission->has_invoice()) {
49 49
 			$this->taxes = $submission->get_invoice()->get_taxes();
50 50
 		}
51 51
 
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 	 * @param GetPaid_Form_Item $item
66 66
 	 * @param GetPaid_Payment_Form_Submission $submission
67 67
 	 */
68
-	public function process_item_tax( $item, $submission ) {
68
+	public function process_item_tax($item, $submission) {
69 69
 
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
70
+		$rate     = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id());
71 71
 		$price    = $item->get_sub_total();
72 72
 		$item_tax = $price * $rate * 0.01;
73 73
 
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
74
+		if (wpinv_prices_include_tax()) {
75
+			$item_tax = $price - ($price - $price * $rate * 0.01);
76 76
 		}
77 77
 
78 78
 		$this->initial_tax += $item_tax;
79 79
 
80
-		if ( $item->is_recurring() ) {
80
+		if ($item->is_recurring()) {
81 81
 			$this->recurring_tax += $item_tax;
82 82
 		}
83 83
 
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 * @since 1.0.19
91 91
 	 * @return bool
92 92
 	 */
93
-	public function has_digital_item( $submission ) {
93
+	public function has_digital_item($submission) {
94 94
 
95
-		foreach ( $submission->get_items() as $item ) {
95
+		foreach ($submission->get_items() as $item) {
96 96
 
97
-			if ( 'digital' == $item->get_vat_rule() ) {
97
+			if ('digital' == $item->get_vat_rule()) {
98 98
 				return true;
99 99
 			}
100 100
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @return bool
111 111
 	 */
112 112
 	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
113
+		return $this->is_eu_country(wpinv_get_default_country());
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @since 1.0.19
121 121
 	 * @return bool
122 122
 	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
123
+	public function is_eu_country($country) {
124
+		return getpaid_is_eu_state($country) || getpaid_is_gst_country($country);
125 125
 	}
126 126
 
127 127
 	/**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @since 1.0.19
132 132
 	 * @return bool
133 133
 	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
134
+	public function is_eu_transaction($customer_country) {
135
+		return $this->is_eu_country($customer_country) && $this->is_eu_store();
136 136
 	}
137 137
 
138 138
 	/**
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
 	 * @since 1.0.19
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_vat_number( $submission ) {
145
+	public function get_vat_number($submission) {
146 146
 
147 147
 		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
148
+		$vat_number = $submission->get_field('wpinv_vat_number');
149
+		if (!empty($vat_number)) {
150
+			return wpinv_clean($vat_number);
151 151
 		}
152 152
 
153 153
 		// Retrieve from the invoice.
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 	 * @since 1.0.19
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_company( $submission ) {
164
+	public function get_company($submission) {
165 165
 
166 166
 		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
167
+		$company = $submission->get_field('wpinv_company');
168
+		if (!empty($company)) {
169
+			return wpinv_clean($company);
170 170
 		}
171 171
 
172 172
 		// Retrieve from the invoice.
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 	 * @since 1.0.19
182 182
 	 * @return string
183 183
 	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
184
+	public function requires_vat($ip_in_eu, $country_in_eu) {
185 185
 
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
186
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
187
+		$prevent_b2c = !empty($prevent_b2c);
188 188
 		$is_eu       = $ip_in_eu || $country_in_eu;
189 189
 
190 190
 		return $prevent_b2c && $is_eu;
@@ -196,30 +196,30 @@  discard block
 block discarded – undo
196 196
 	 * @param GetPaid_Payment_Form_Submission $submission
197 197
 	 * @since 1.0.19
198 198
 	 */
199
-	public function validate_vat( $submission ) {
199
+	public function validate_vat($submission) {
200 200
 
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
201
+		$has_digital = $this->has_digital_item($submission);
202
+		$in_eu       = $this->is_eu_transaction($submission->country);
203 203
 
204 204
 		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
205
+		if (!$has_digital && !$in_eu) {
206 206
             return;
207 207
 		}
208 208
 
209 209
 		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
210
+		$vat_number  = $this->get_vat_number($submission);
211
+		$company     = $this->get_company($submission);
212 212
 		$ip_country  = WPInv_EUVat::get_country_by_ip();
213
-        $is_eu       = $this->is_eu_country( $submission->country );
214
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
213
+        $is_eu       = $this->is_eu_country($submission->country);
214
+        $is_ip_eu    = $this->is_eu_country($ip_country);
215 215
 
216 216
 		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220 220
 			throw new Exception(
221 221
 				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
222
+					__('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'),
223 223
 					getpaid_vat_name()
224 224
 				)
225 225
 			);
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
230
+		if (!$is_eu || !$in_eu || empty($vat_number)) {
231 231
             return;
232 232
 		}
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+		$is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country);
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
236
+		if (is_string($is_valid)) {
237
+			throw new Exception($is_valid);
238 238
 		}
239 239
 
240 240
 	}
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,77 +12,77 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27 27
 
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30 30
 
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36 36
 
37
-		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ! $submission->has_invoice() ) {
39
-			$payment_form->set_items( $selected_items );
40
-		}
37
+        // For default forms, ensure that an item has been set.
38
+        if ( $payment_form->is_default() && ! $submission->has_invoice() ) {
39
+            $payment_form->set_items( $selected_items );
40
+        }
41 41
 
42
-		// Process each individual item.
43
-		foreach ( $payment_form->get_items() as $item ) {
44
-			$this->process_item( $item, $selected_items );
45
-		}
42
+        // Process each individual item.
43
+        foreach ( $payment_form->get_items() as $item ) {
44
+            $this->process_item( $item, $selected_items );
45
+        }
46 46
 
47
-	}
47
+    }
48 48
 
49
-	/**
50
-	 * Process a single item.
51
-	 *
52
-	 * @param GetPaid_Form_Item $item
53
-	 * @param array $selected_items
54
-	 */
55
-	public function process_item( $item, $selected_items ) {
49
+    /**
50
+     * Process a single item.
51
+     *
52
+     * @param GetPaid_Form_Item $item
53
+     * @param array $selected_items
54
+     */
55
+    public function process_item( $item, $selected_items ) {
56 56
 
57
-		// Abort if this is an optional item and it has not been selected.
58
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
59
-			return;
60
-		}
57
+        // Abort if this is an optional item and it has not been selected.
58
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
59
+            return;
60
+        }
61 61
 
62
-		// (maybe) let customers change the quantities and prices.
63
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
62
+        // (maybe) let customers change the quantities and prices.
63
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
64 64
 
65
-			// Maybe change the quantities.
66
-			if ( $item->allows_quantities() ) {
67
-				$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
68
-			}
65
+            // Maybe change the quantities.
66
+            if ( $item->allows_quantities() ) {
67
+                $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
68
+            }
69 69
 
70
-			// Maybe change the price.
71
-			if ( $item->user_can_set_their_price() ) {
72
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
70
+            // Maybe change the price.
71
+            if ( $item->user_can_set_their_price() ) {
72
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
73 73
 
74
-				// But don't get lower than the minimum price.
75
-				$price = max( $price, $item->get_minimum_price() );
74
+                // But don't get lower than the minimum price.
75
+                $price = max( $price, $item->get_minimum_price() );
76 76
 
77
-				$item->set_price( $price );
77
+                $item->set_price( $price );
78 78
 
79
-			}
79
+            }
80 80
 
81
-		}
81
+        }
82 82
 
83
-		// Save the item.
84
-		$this->items[] = $item;
83
+        // Save the item.
84
+        $this->items[] = $item;
85 85
 
86
-	}
86
+    }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 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
  * Payment form submission itemss class
@@ -23,25 +23,25 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
30 30
 
31 31
 		// Prepare the selected items.
32 32
 		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
33
+		if (!empty($data['getpaid-items'])) {
34
+			$selected_items = wpinv_clean($data['getpaid-items']);
35 35
 		}
36 36
 
37 37
 		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ! $submission->has_invoice() ) {
39
-			$payment_form->set_items( $selected_items );
38
+		if ($payment_form->is_default() && !$submission->has_invoice()) {
39
+			$payment_form->set_items($selected_items);
40 40
 		}
41 41
 
42 42
 		// Process each individual item.
43
-		foreach ( $payment_form->get_items() as $item ) {
44
-			$this->process_item( $item, $selected_items );
43
+		foreach ($payment_form->get_items() as $item) {
44
+			$this->process_item($item, $selected_items);
45 45
 		}
46 46
 
47 47
 	}
@@ -52,29 +52,29 @@  discard block
 block discarded – undo
52 52
 	 * @param GetPaid_Form_Item $item
53 53
 	 * @param array $selected_items
54 54
 	 */
55
-	public function process_item( $item, $selected_items ) {
55
+	public function process_item($item, $selected_items) {
56 56
 
57 57
 		// Abort if this is an optional item and it has not been selected.
58
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
58
+		if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
59 59
 			return;
60 60
 		}
61 61
 
62 62
 		// (maybe) let customers change the quantities and prices.
63
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
63
+		if (isset($selected_items[$item->get_id()])) {
64 64
 
65 65
 			// Maybe change the quantities.
66
-			if ( $item->allows_quantities() ) {
67
-				$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
66
+			if ($item->allows_quantities()) {
67
+				$item->set_quantity((int) $selected_items[$item->get_id()]['quantity']);
68 68
 			}
69 69
 
70 70
 			// Maybe change the price.
71
-			if ( $item->user_can_set_their_price() ) {
72
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
71
+			if ($item->user_can_set_their_price()) {
72
+				$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
73 73
 
74 74
 				// But don't get lower than the minimum price.
75
-				$price = max( $price, $item->get_minimum_price() );
75
+				$price = max($price, $item->get_minimum_price());
76 76
 
77
-				$item->set_price( $price );
77
+				$item->set_price($price);
78 78
 
79 79
 			}
80 80
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,351 +114,351 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
288
+                    $item->set_quantity( $value );
289
+                    $prepared[] = $item;
290
+                }
286 291
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
289
-					$prepared[] = $item;
290
-				}
292
+                continue;
293
+            }
291 294
 
292
-				continue;
293
-			}
295
+            // Items saved via payment forms editor.
296
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
294 297
 
295
-			// Items saved via payment forms editor.
296
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
298
+                $item = new GetPaid_Form_Item( $value['id'] );
297 299
 
298
-				$item = new GetPaid_Form_Item( $value['id'] );
300
+                if ( ! $item->can_purchase() ) {
301
+                    continue;
302
+                }
299 303
 
300
-				if ( ! $item->can_purchase() ) {
301
-					continue;
302
-				}
304
+                // Sub-total (Cart items).
305
+                if ( isset( $value['subtotal'] ) ) {
306
+                    $item->set_price( $value['subtotal'] );
307
+                }
303 308
 
304
-				// Sub-total (Cart items).
305
-				if ( isset( $value['subtotal'] ) ) {
306
-					$item->set_price( $value['subtotal'] );
307
-				}
309
+                if ( isset( $value['quantity'] ) ) {
310
+                    $item->set_quantity( $value['quantity'] );
311
+                }
308 312
 
309
-				if ( isset( $value['quantity'] ) ) {
310
-					$item->set_quantity( $value['quantity'] );
311
-				}
313
+                if ( isset( $value['allow_quantities'] ) ) {
314
+                    $item->set_allow_quantities( $value['allow_quantities'] );
315
+                }
312 316
 
313
-				if ( isset( $value['allow_quantities'] ) ) {
314
-					$item->set_allow_quantities( $value['allow_quantities'] );
315
-				}
317
+                if ( isset( $value['required'] ) ) {
318
+                    $item->set_is_required( $value['required'] );
319
+                }
316 320
 
317
-				if ( isset( $value['required'] ) ) {
318
-					$item->set_is_required( $value['required'] );
319
-				}
321
+                if ( isset( $value['description'] ) ) {
322
+                    $item->set_custom_description( $value['description'] );
323
+                }
320 324
 
321
-				if ( isset( $value['description'] ) ) {
322
-					$item->set_custom_description( $value['description'] );
323
-				}
325
+                $prepared[] = $item;
326
+                continue;
324 327
 
325
-				$prepared[] = $item;
326
-				continue;
328
+            }
329
+
330
+            // $item_id => array( 'price' => 10 ) (item variations)
331
+            if ( is_numeric( $key ) && is_array( $value ) ) {
332
+                $item = new GetPaid_Form_Item( $key );
333
+
334
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
335
+                    $item->set_price( $value['price'] );
336
+                }
337
+
338
+                if ( $item->can_purchase() ) {
339
+                    $prepared[] = $item;
340
+                }
341
+
342
+                continue;
343
+            }
344
+
345
+        }
346
+
347
+        if ( 'objects' == $return && 'view' == $context ) {
348
+            return $prepared;
349
+        }
350
+
351
+        $items = array();
352
+        foreach ( $prepared as $item ) {
353
+            $items[] = $item->prepare_data_for_use();
354
+        }
355
+
356
+        return $items;
357
+    }
358
+
359
+    /**
360
+     * Get a single item belonging to the form.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  int $item_id The item id to return.
364
+     * @return GetPaid_Form_Item|bool
365
+     */
366
+    public function get_item( $item_id ) {
367
+
368
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
369
+            return false;
370
+        }
371
+
372
+        foreach( $this->get_items() as $item ) {
373
+            if ( $item->get_id() == (int) $item_id ) {
374
+                return $item;
375
+            }
376
+        }
377
+
378
+        return false;
379
+
380
+    }
381
+
382
+    /**
383
+     * Gets a single element.
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $element_type The element type to return.
387
+     * @return array|bool
388
+     */
389
+    public function get_element_type( $element_type ) {
390
+
391
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
392
+            return false;
393
+        }
394
+
395
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
396
+
397
+            if ( $element['type'] == $element_type ) {
398
+                return $element;
399
+            }
400
+
401
+        }
402
+
403
+        return false;
404
+
405
+    }
406
+
407
+    /**
408
+     * Get the total amount earned via this form.
409
+     *
410
+     * @since 1.0.19
411
+     * @param  string $context View or edit context.
412
+     * @return array
413
+     */
414
+    public function get_earned( $context = 'view' ) {
415
+        return $this->get_prop( 'earned', $context );
416
+    }
417
+
418
+    /**
419
+     * Get the total amount refunded via this form.
420
+     *
421
+     * @since 1.0.19
422
+     * @param  string $context View or edit context.
423
+     * @return array
424
+     */
425
+    public function get_refunded( $context = 'view' ) {
426
+        return $this->get_prop( 'refunded', $context );
427
+    }
327 428
 
328
-			}
429
+    /**
430
+     * Get the total amount cancelled via this form.
431
+     *
432
+     * @since 1.0.19
433
+     * @param  string $context View or edit context.
434
+     * @return array
435
+     */
436
+    public function get_cancelled( $context = 'view' ) {
437
+        return $this->get_prop( 'cancelled', $context );
438
+    }
329 439
 
330
-			// $item_id => array( 'price' => 10 ) (item variations)
331
-			if ( is_numeric( $key ) && is_array( $value ) ) {
332
-				$item = new GetPaid_Form_Item( $key );
440
+    /**
441
+     * Get the total amount failed via this form.
442
+     *
443
+     * @since 1.0.19
444
+     * @param  string $context View or edit context.
445
+     * @return array
446
+     */
447
+    public function get_failed( $context = 'view' ) {
448
+        return $this->get_prop( 'failed', $context );
449
+    }
333 450
 
334
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
335
-					$item->set_price( $value['price'] );
336
-				}
337
-
338
-				if ( $item->can_purchase() ) {
339
-					$prepared[] = $item;
340
-				}
341
-
342
-				continue;
343
-			}
344
-
345
-		}
346
-
347
-		if ( 'objects' == $return && 'view' == $context ) {
348
-			return $prepared;
349
-		}
350
-
351
-		$items = array();
352
-		foreach ( $prepared as $item ) {
353
-			$items[] = $item->prepare_data_for_use();
354
-		}
355
-
356
-		return $items;
357
-	}
358
-
359
-	/**
360
-	 * Get a single item belonging to the form.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  int $item_id The item id to return.
364
-	 * @return GetPaid_Form_Item|bool
365
-	 */
366
-	public function get_item( $item_id ) {
367
-
368
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
369
-			return false;
370
-		}
371
-
372
-		foreach( $this->get_items() as $item ) {
373
-			if ( $item->get_id() == (int) $item_id ) {
374
-				return $item;
375
-			}
376
-		}
377
-
378
-		return false;
379
-
380
-	}
381
-
382
-	/**
383
-	 * Gets a single element.
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $element_type The element type to return.
387
-	 * @return array|bool
388
-	 */
389
-	public function get_element_type( $element_type ) {
390
-
391
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
392
-			return false;
393
-		}
394
-
395
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
396
-
397
-			if ( $element['type'] == $element_type ) {
398
-				return $element;
399
-			}
400
-
401
-		}
402
-
403
-		return false;
404
-
405
-	}
406
-
407
-	/**
408
-	 * Get the total amount earned via this form.
409
-	 *
410
-	 * @since 1.0.19
411
-	 * @param  string $context View or edit context.
412
-	 * @return array
413
-	 */
414
-	public function get_earned( $context = 'view' ) {
415
-		return $this->get_prop( 'earned', $context );
416
-	}
417
-
418
-	/**
419
-	 * Get the total amount refunded via this form.
420
-	 *
421
-	 * @since 1.0.19
422
-	 * @param  string $context View or edit context.
423
-	 * @return array
424
-	 */
425
-	public function get_refunded( $context = 'view' ) {
426
-		return $this->get_prop( 'refunded', $context );
427
-	}
428
-
429
-	/**
430
-	 * Get the total amount cancelled via this form.
431
-	 *
432
-	 * @since 1.0.19
433
-	 * @param  string $context View or edit context.
434
-	 * @return array
435
-	 */
436
-	public function get_cancelled( $context = 'view' ) {
437
-		return $this->get_prop( 'cancelled', $context );
438
-	}
439
-
440
-	/**
441
-	 * Get the total amount failed via this form.
442
-	 *
443
-	 * @since 1.0.19
444
-	 * @param  string $context View or edit context.
445
-	 * @return array
446
-	 */
447
-	public function get_failed( $context = 'view' ) {
448
-		return $this->get_prop( 'failed', $context );
449
-	}
450
-
451
-	/**
452
-	 * Get the currency.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_currency() {
459
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
460
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
-	}
451
+    /**
452
+     * Get the currency.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_currency() {
459
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
460
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
+    }
462 462
 
463 463
     /*
464 464
 	|--------------------------------------------------------------------------
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
     */
472 472
 
473 473
     /**
474
-	 * Set plugin version when the item was created.
475
-	 *
476
-	 * @since 1.0.19
477
-	 */
478
-	public function set_version( $value ) {
479
-		$this->set_prop( 'version', $value );
474
+     * Set plugin version when the item was created.
475
+     *
476
+     * @since 1.0.19
477
+     */
478
+    public function set_version( $value ) {
479
+        $this->set_prop( 'version', $value );
480 480
     }
481 481
 
482 482
     /**
483
-	 * Set date when the item was created.
484
-	 *
485
-	 * @since 1.0.19
486
-	 * @param string $value Value to set.
483
+     * Set date when the item was created.
484
+     *
485
+     * @since 1.0.19
486
+     * @param string $value Value to set.
487 487
      * @return bool Whether or not the date was set.
488
-	 */
489
-	public function set_date_created( $value ) {
488
+     */
489
+    public function set_date_created( $value ) {
490 490
         $date = strtotime( $value );
491 491
 
492 492
         if ( $date ) {
@@ -499,13 +499,13 @@  discard block
 block discarded – undo
499 499
     }
500 500
 
501 501
     /**
502
-	 * Set date when the item was last modified.
503
-	 *
504
-	 * @since 1.0.19
505
-	 * @param string $value Value to set.
502
+     * Set date when the item was last modified.
503
+     *
504
+     * @since 1.0.19
505
+     * @param string $value Value to set.
506 506
      * @return bool Whether or not the date was set.
507
-	 */
508
-	public function set_date_modified( $value ) {
507
+     */
508
+    public function set_date_modified( $value ) {
509 509
         $date = strtotime( $value );
510 510
 
511 511
         if ( $date ) {
@@ -518,118 +518,118 @@  discard block
 block discarded – undo
518 518
     }
519 519
 
520 520
     /**
521
-	 * Set the item name.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $value New name.
525
-	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
528
-    }
529
-
530
-    /**
531
-	 * Alias of self::set_name().
532
-	 *
533
-	 * @since 1.0.19
534
-	 * @param  string $value New name.
535
-	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
538
-    }
539
-
540
-    /**
541
-	 * Set the owner of the item.
542
-	 *
543
-	 * @since 1.0.19
544
-	 * @param  int $value New author.
545
-	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
548
-	}
549
-
550
-	/**
551
-	 * Set the form elements.
552
-	 *
553
-	 * @since 1.0.19
554
-	 * @param  array $value Form elements.
555
-	 */
556
-	public function set_elements( $value ) {
557
-		if ( is_array( $value ) ) {
558
-			$this->set_prop( 'elements', $value );
559
-		}
560
-	}
561
-
562
-	/**
563
-	 * Set the form items.
564
-	 *
565
-	 * @since 1.0.19
566
-	 * @param  array $value Form elements.
567
-	 */
568
-	public function set_items( $value ) {
569
-		if ( is_array( $value ) ) {
570
-			$this->set_prop( 'items', $value );
571
-		}
572
-	}
573
-
574
-	/**
575
-	 * Set the total amount earned via this form.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  float $value Amount earned.
579
-	 */
580
-	public function set_earned( $value ) {
581
-		$value = max( (float) $value, 0 );
582
-		$this->set_prop( 'earned', $value );
583
-	}
584
-
585
-	/**
586
-	 * Set the total amount refunded via this form.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param  float $value Amount refunded.
590
-	 */
591
-	public function set_refunded( $value ) {
592
-		$value = max( (float) $value, 0 );
593
-		$this->set_prop( 'refunded', $value );
594
-	}
595
-
596
-	/**
597
-	 * Set the total amount cancelled via this form.
598
-	 *
599
-	 * @since 1.0.19
600
-	 * @param  float $value Amount cancelled.
601
-	 */
602
-	public function set_cancelled( $value ) {
603
-		$value = max( (float) $value, 0 );
604
-		$this->set_prop( 'cancelled', $value );
605
-	}
606
-
607
-	/**
608
-	 * Set the total amount failed via this form.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param  float $value Amount cancelled.
612
-	 */
613
-	public function set_failed( $value ) {
614
-		$value = max( (float) $value, 0 );
615
-		$this->set_prop( 'failed', $value );
616
-	}
521
+     * Set the item name.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $value New name.
525
+     */
526
+    public function set_name( $value ) {
527
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
528
+    }
529
+
530
+    /**
531
+     * Alias of self::set_name().
532
+     *
533
+     * @since 1.0.19
534
+     * @param  string $value New name.
535
+     */
536
+    public function set_title( $value ) {
537
+        $this->set_name( $value );
538
+    }
539
+
540
+    /**
541
+     * Set the owner of the item.
542
+     *
543
+     * @since 1.0.19
544
+     * @param  int $value New author.
545
+     */
546
+    public function set_author( $value ) {
547
+        $this->set_prop( 'author', (int) $value );
548
+    }
549
+
550
+    /**
551
+     * Set the form elements.
552
+     *
553
+     * @since 1.0.19
554
+     * @param  array $value Form elements.
555
+     */
556
+    public function set_elements( $value ) {
557
+        if ( is_array( $value ) ) {
558
+            $this->set_prop( 'elements', $value );
559
+        }
560
+    }
561
+
562
+    /**
563
+     * Set the form items.
564
+     *
565
+     * @since 1.0.19
566
+     * @param  array $value Form elements.
567
+     */
568
+    public function set_items( $value ) {
569
+        if ( is_array( $value ) ) {
570
+            $this->set_prop( 'items', $value );
571
+        }
572
+    }
573
+
574
+    /**
575
+     * Set the total amount earned via this form.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  float $value Amount earned.
579
+     */
580
+    public function set_earned( $value ) {
581
+        $value = max( (float) $value, 0 );
582
+        $this->set_prop( 'earned', $value );
583
+    }
584
+
585
+    /**
586
+     * Set the total amount refunded via this form.
587
+     *
588
+     * @since 1.0.19
589
+     * @param  float $value Amount refunded.
590
+     */
591
+    public function set_refunded( $value ) {
592
+        $value = max( (float) $value, 0 );
593
+        $this->set_prop( 'refunded', $value );
594
+    }
595
+
596
+    /**
597
+     * Set the total amount cancelled via this form.
598
+     *
599
+     * @since 1.0.19
600
+     * @param  float $value Amount cancelled.
601
+     */
602
+    public function set_cancelled( $value ) {
603
+        $value = max( (float) $value, 0 );
604
+        $this->set_prop( 'cancelled', $value );
605
+    }
606
+
607
+    /**
608
+     * Set the total amount failed via this form.
609
+     *
610
+     * @since 1.0.19
611
+     * @param  float $value Amount cancelled.
612
+     */
613
+    public function set_failed( $value ) {
614
+        $value = max( (float) $value, 0 );
615
+        $this->set_prop( 'failed', $value );
616
+    }
617 617
 
618 618
     /**
619 619
      * Create an item. For backwards compatibilty.
620 620
      *
621 621
      * @deprecated
622
-	 * @return int item id
622
+     * @return int item id
623 623
      */
624 624
     public function create( $data = array() ) {
625 625
 
626
-		// Set the properties.
627
-		if ( is_array( $data ) ) {
628
-			$this->set_props( $data );
629
-		}
626
+        // Set the properties.
627
+        if ( is_array( $data ) ) {
628
+            $this->set_props( $data );
629
+        }
630 630
 
631
-		// Save the item.
632
-		return $this->save();
631
+        // Save the item.
632
+        return $this->save();
633 633
 
634 634
     }
635 635
 
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
      * Updates an item. For backwards compatibilty.
638 638
      *
639 639
      * @deprecated
640
-	 * @return int item id
640
+     * @return int item id
641 641
      */
642 642
     public function update( $data = array() ) {
643 643
         return $this->create( $data );
@@ -653,22 +653,22 @@  discard block
 block discarded – undo
653 653
 	*/
654 654
 
655 655
     /**
656
-	 * Checks whether this is the default payment form.
657
-	 *
658
-	 * @since 1.0.19
659
-	 * @return bool
660
-	 */
656
+     * Checks whether this is the default payment form.
657
+     *
658
+     * @since 1.0.19
659
+     * @return bool
660
+     */
661 661
     public function is_default() {
662 662
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
663 663
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
664
-	}
664
+    }
665 665
 
666 666
     /**
667
-	 * Checks whether the form is active.
668
-	 *
669
-	 * @since 1.0.19
670
-	 * @return bool
671
-	 */
667
+     * Checks whether the form is active.
668
+     *
669
+     * @since 1.0.19
670
+     * @return bool
671
+     */
672 672
     public function is_active() {
673 673
         $is_active = 0 !== (int) $this->get_id();
674 674
 
@@ -677,70 +677,70 @@  discard block
 block discarded – undo
677 677
         }
678 678
 
679 679
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
680
-	}
681
-
682
-	/**
683
-	 * Checks whether the form has a given item.
684
-	 *
685
-	 * @since 1.0.19
686
-	 * @return bool
687
-	 */
680
+    }
681
+
682
+    /**
683
+     * Checks whether the form has a given item.
684
+     *
685
+     * @since 1.0.19
686
+     * @return bool
687
+     */
688 688
     public function has_item( $item_id ) {
689 689
         return false !== $this->get_item( $item_id );
690
-	}
691
-
692
-	/**
693
-	 * Checks whether the form has a given element.
694
-	 *
695
-	 * @since 1.0.19
696
-	 * @return bool
697
-	 */
690
+    }
691
+
692
+    /**
693
+     * Checks whether the form has a given element.
694
+     *
695
+     * @since 1.0.19
696
+     * @return bool
697
+     */
698 698
     public function has_element_type( $element_type ) {
699 699
         return false !== $this->get_element_type( $element_type );
700
-	}
701
-
702
-	/**
703
-	 * Checks whether this form is recurring or not.
704
-	 *
705
-	 * @since 1.0.19
706
-	 * @return bool
707
-	 */
700
+    }
701
+
702
+    /**
703
+     * Checks whether this form is recurring or not.
704
+     *
705
+     * @since 1.0.19
706
+     * @return bool
707
+     */
708 708
     public function is_recurring() {
709 709
 
710
-		if ( ! empty( $this->invoice ) ) {
711
-			return $this->invoice->is_recurring();
712
-		}
710
+        if ( ! empty( $this->invoice ) ) {
711
+            return $this->invoice->is_recurring();
712
+        }
713 713
 
714
-		foreach ( $this->get_items() as $item ) {
714
+        foreach ( $this->get_items() as $item ) {
715 715
 
716
-			if ( $item->is_recurring() ) {
717
-				return true;
718
-			}
716
+            if ( $item->is_recurring() ) {
717
+                return true;
718
+            }
719 719
 
720
-		}
720
+        }
721 721
 
722 722
         return false;
723
-	}
723
+    }
724 724
 
725
-	/**
726
-	 * Retrieves the form's html.
727
-	 *
728
-	 * @since 1.0.19
729
-	 */
725
+    /**
726
+     * Retrieves the form's html.
727
+     *
728
+     * @since 1.0.19
729
+     */
730 730
     public function get_html() {
731 731
 
732
-		// Return the HTML.
733
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
732
+        // Return the HTML.
733
+        return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
734 734
 
735
-	}
735
+    }
736 736
 
737
-	/**
738
-	 * Displays the payment form.
739
-	 *
740
-	 * @since 1.0.19
741
-	 */
737
+    /**
738
+     * Displays the payment form.
739
+     *
740
+     * @since 1.0.19
741
+     */
742 742
     public function display() {
743
-		echo $this->get_html();
743
+        echo $this->get_html();
744 744
     }
745 745
 
746 746
 }
Please login to merge, or discard this patch.
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 
99 99
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'        => __('Select Payment Method', 'invoicing'),
236 236
 					'id'          => 'gtscicd',
237 237
 					'name'        => 'gtscicd',
238 238
 					'type'        => 'gateway_select',
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
272 272
 			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
273
+			if ($value instanceof GetPaid_Form_Item) {
274 274
 
275
-				if ( $value->can_purchase() ) {
275
+				if ($value->can_purchase()) {
276 276
 					$prepared[] = $value;
277 277
 				}
278 278
 
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 
283 283
 			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
284
+			if (is_numeric($key) && is_numeric($value)) {
285
+				$item = new GetPaid_Form_Item($key);
286 286
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
287
+				if ($item->can_purchase()) {
288
+					$item->set_quantity($value);
289 289
 					$prepared[] = $item;
290 290
 				}
291 291
 
@@ -293,33 +293,33 @@  discard block
 block discarded – undo
293 293
 			}
294 294
 
295 295
 			// Items saved via payment forms editor.
296
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
296
+			if (is_array($value) && isset($value['id'])) {
297 297
 
298
-				$item = new GetPaid_Form_Item( $value['id'] );
298
+				$item = new GetPaid_Form_Item($value['id']);
299 299
 
300
-				if ( ! $item->can_purchase() ) {
300
+				if (!$item->can_purchase()) {
301 301
 					continue;
302 302
 				}
303 303
 
304 304
 				// Sub-total (Cart items).
305
-				if ( isset( $value['subtotal'] ) ) {
306
-					$item->set_price( $value['subtotal'] );
305
+				if (isset($value['subtotal'])) {
306
+					$item->set_price($value['subtotal']);
307 307
 				}
308 308
 
309
-				if ( isset( $value['quantity'] ) ) {
310
-					$item->set_quantity( $value['quantity'] );
309
+				if (isset($value['quantity'])) {
310
+					$item->set_quantity($value['quantity']);
311 311
 				}
312 312
 
313
-				if ( isset( $value['allow_quantities'] ) ) {
314
-					$item->set_allow_quantities( $value['allow_quantities'] );
313
+				if (isset($value['allow_quantities'])) {
314
+					$item->set_allow_quantities($value['allow_quantities']);
315 315
 				}
316 316
 
317
-				if ( isset( $value['required'] ) ) {
318
-					$item->set_is_required( $value['required'] );
317
+				if (isset($value['required'])) {
318
+					$item->set_is_required($value['required']);
319 319
 				}
320 320
 
321
-				if ( isset( $value['description'] ) ) {
322
-					$item->set_custom_description( $value['description'] );
321
+				if (isset($value['description'])) {
322
+					$item->set_custom_description($value['description']);
323 323
 				}
324 324
 
325 325
 				$prepared[] = $item;
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 			}
329 329
 
330 330
 			// $item_id => array( 'price' => 10 ) (item variations)
331
-			if ( is_numeric( $key ) && is_array( $value ) ) {
332
-				$item = new GetPaid_Form_Item( $key );
331
+			if (is_numeric($key) && is_array($value)) {
332
+				$item = new GetPaid_Form_Item($key);
333 333
 
334
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
335
-					$item->set_price( $value['price'] );
334
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
335
+					$item->set_price($value['price']);
336 336
 				}
337 337
 
338
-				if ( $item->can_purchase() ) {
338
+				if ($item->can_purchase()) {
339 339
 					$prepared[] = $item;
340 340
 				}
341 341
 
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
 
345 345
 		}
346 346
 
347
-		if ( 'objects' == $return && 'view' == $context ) {
347
+		if ('objects' == $return && 'view' == $context) {
348 348
 			return $prepared;
349 349
 		}
350 350
 
351 351
 		$items = array();
352
-		foreach ( $prepared as $item ) {
352
+		foreach ($prepared as $item) {
353 353
 			$items[] = $item->prepare_data_for_use();
354 354
 		}
355 355
 
@@ -363,14 +363,14 @@  discard block
 block discarded – undo
363 363
 	 * @param  int $item_id The item id to return.
364 364
 	 * @return GetPaid_Form_Item|bool
365 365
 	 */
366
-	public function get_item( $item_id ) {
366
+	public function get_item($item_id) {
367 367
 
368
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
368
+		if (empty($item_id) || !is_numeric($item_id)) {
369 369
 			return false;
370 370
 		}
371 371
 
372
-		foreach( $this->get_items() as $item ) {
373
-			if ( $item->get_id() == (int) $item_id ) {
372
+		foreach ($this->get_items() as $item) {
373
+			if ($item->get_id() == (int) $item_id) {
374 374
 				return $item;
375 375
 			}
376 376
 		}
@@ -386,15 +386,15 @@  discard block
 block discarded – undo
386 386
 	 * @param  string $element_type The element type to return.
387 387
 	 * @return array|bool
388 388
 	 */
389
-	public function get_element_type( $element_type ) {
389
+	public function get_element_type($element_type) {
390 390
 
391
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
391
+		if (empty($element_type) || !is_scalar($element_type)) {
392 392
 			return false;
393 393
 		}
394 394
 
395
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
395
+		foreach ($this->get_prop('elements') as $element) {
396 396
 
397
-			if ( $element['type'] == $element_type ) {
397
+			if ($element['type'] == $element_type) {
398 398
 				return $element;
399 399
 			}
400 400
 
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
 	 * @param  string $context View or edit context.
412 412
 	 * @return array
413 413
 	 */
414
-	public function get_earned( $context = 'view' ) {
415
-		return $this->get_prop( 'earned', $context );
414
+	public function get_earned($context = 'view') {
415
+		return $this->get_prop('earned', $context);
416 416
 	}
417 417
 
418 418
 	/**
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	 * @param  string $context View or edit context.
423 423
 	 * @return array
424 424
 	 */
425
-	public function get_refunded( $context = 'view' ) {
426
-		return $this->get_prop( 'refunded', $context );
425
+	public function get_refunded($context = 'view') {
426
+		return $this->get_prop('refunded', $context);
427 427
 	}
428 428
 
429 429
 	/**
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 	 * @param  string $context View or edit context.
434 434
 	 * @return array
435 435
 	 */
436
-	public function get_cancelled( $context = 'view' ) {
437
-		return $this->get_prop( 'cancelled', $context );
436
+	public function get_cancelled($context = 'view') {
437
+		return $this->get_prop('cancelled', $context);
438 438
 	}
439 439
 
440 440
 	/**
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 * @param  string $context View or edit context.
445 445
 	 * @return array
446 446
 	 */
447
-	public function get_failed( $context = 'view' ) {
448
-		return $this->get_prop( 'failed', $context );
447
+	public function get_failed($context = 'view') {
448
+		return $this->get_prop('failed', $context);
449 449
 	}
450 450
 
451 451
 	/**
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @return string
457 457
 	 */
458 458
 	public function get_currency() {
459
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
460
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
459
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
460
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
461 461
 	}
462 462
 
463 463
     /*
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
 	 *
476 476
 	 * @since 1.0.19
477 477
 	 */
478
-	public function set_version( $value ) {
479
-		$this->set_prop( 'version', $value );
478
+	public function set_version($value) {
479
+		$this->set_prop('version', $value);
480 480
     }
481 481
 
482 482
     /**
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
 	 * @param string $value Value to set.
487 487
      * @return bool Whether or not the date was set.
488 488
 	 */
489
-	public function set_date_created( $value ) {
490
-        $date = strtotime( $value );
489
+	public function set_date_created($value) {
490
+        $date = strtotime($value);
491 491
 
492
-        if ( $date ) {
493
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
492
+        if ($date) {
493
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
494 494
             return true;
495 495
         }
496 496
 
@@ -505,11 +505,11 @@  discard block
 block discarded – undo
505 505
 	 * @param string $value Value to set.
506 506
      * @return bool Whether or not the date was set.
507 507
 	 */
508
-	public function set_date_modified( $value ) {
509
-        $date = strtotime( $value );
508
+	public function set_date_modified($value) {
509
+        $date = strtotime($value);
510 510
 
511
-        if ( $date ) {
512
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
511
+        if ($date) {
512
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
513 513
             return true;
514 514
         }
515 515
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 * @param  string $value New name.
525 525
 	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
+	public function set_name($value) {
527
+		$this->set_prop('name', sanitize_text_field($value));
528 528
     }
529 529
 
530 530
     /**
@@ -533,8 +533,8 @@  discard block
 block discarded – undo
533 533
 	 * @since 1.0.19
534 534
 	 * @param  string $value New name.
535 535
 	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
536
+	public function set_title($value) {
537
+		$this->set_name($value);
538 538
     }
539 539
 
540 540
     /**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 	 * @since 1.0.19
544 544
 	 * @param  int $value New author.
545 545
 	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
546
+	public function set_author($value) {
547
+		$this->set_prop('author', (int) $value);
548 548
 	}
549 549
 
550 550
 	/**
@@ -553,9 +553,9 @@  discard block
 block discarded – undo
553 553
 	 * @since 1.0.19
554 554
 	 * @param  array $value Form elements.
555 555
 	 */
556
-	public function set_elements( $value ) {
557
-		if ( is_array( $value ) ) {
558
-			$this->set_prop( 'elements', $value );
556
+	public function set_elements($value) {
557
+		if (is_array($value)) {
558
+			$this->set_prop('elements', $value);
559 559
 		}
560 560
 	}
561 561
 
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 	 * @since 1.0.19
566 566
 	 * @param  array $value Form elements.
567 567
 	 */
568
-	public function set_items( $value ) {
569
-		if ( is_array( $value ) ) {
570
-			$this->set_prop( 'items', $value );
568
+	public function set_items($value) {
569
+		if (is_array($value)) {
570
+			$this->set_prop('items', $value);
571 571
 		}
572 572
 	}
573 573
 
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
 	 * @since 1.0.19
578 578
 	 * @param  float $value Amount earned.
579 579
 	 */
580
-	public function set_earned( $value ) {
581
-		$value = max( (float) $value, 0 );
582
-		$this->set_prop( 'earned', $value );
580
+	public function set_earned($value) {
581
+		$value = max((float) $value, 0);
582
+		$this->set_prop('earned', $value);
583 583
 	}
584 584
 
585 585
 	/**
@@ -588,9 +588,9 @@  discard block
 block discarded – undo
588 588
 	 * @since 1.0.19
589 589
 	 * @param  float $value Amount refunded.
590 590
 	 */
591
-	public function set_refunded( $value ) {
592
-		$value = max( (float) $value, 0 );
593
-		$this->set_prop( 'refunded', $value );
591
+	public function set_refunded($value) {
592
+		$value = max((float) $value, 0);
593
+		$this->set_prop('refunded', $value);
594 594
 	}
595 595
 
596 596
 	/**
@@ -599,9 +599,9 @@  discard block
 block discarded – undo
599 599
 	 * @since 1.0.19
600 600
 	 * @param  float $value Amount cancelled.
601 601
 	 */
602
-	public function set_cancelled( $value ) {
603
-		$value = max( (float) $value, 0 );
604
-		$this->set_prop( 'cancelled', $value );
602
+	public function set_cancelled($value) {
603
+		$value = max((float) $value, 0);
604
+		$this->set_prop('cancelled', $value);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,9 +610,9 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param  float $value Amount cancelled.
612 612
 	 */
613
-	public function set_failed( $value ) {
614
-		$value = max( (float) $value, 0 );
615
-		$this->set_prop( 'failed', $value );
613
+	public function set_failed($value) {
614
+		$value = max((float) $value, 0);
615
+		$this->set_prop('failed', $value);
616 616
 	}
617 617
 
618 618
     /**
@@ -621,11 +621,11 @@  discard block
 block discarded – undo
621 621
      * @deprecated
622 622
 	 * @return int item id
623 623
      */
624
-    public function create( $data = array() ) {
624
+    public function create($data = array()) {
625 625
 
626 626
 		// Set the properties.
627
-		if ( is_array( $data ) ) {
628
-			$this->set_props( $data );
627
+		if (is_array($data)) {
628
+			$this->set_props($data);
629 629
 		}
630 630
 
631 631
 		// Save the item.
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
      * @deprecated
640 640
 	 * @return int item id
641 641
      */
642
-    public function update( $data = array() ) {
643
-        return $this->create( $data );
642
+    public function update($data = array()) {
643
+        return $this->create($data);
644 644
     }
645 645
 
646 646
     /*
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 	 */
661 661
     public function is_default() {
662 662
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
663
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
663
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
664 664
 	}
665 665
 
666 666
     /**
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
     public function is_active() {
673 673
         $is_active = 0 !== (int) $this->get_id();
674 674
 
675
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
675
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
676 676
             $is_active = false;
677 677
         }
678 678
 
679
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
679
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
680 680
 	}
681 681
 
682 682
 	/**
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
 	 * @since 1.0.19
686 686
 	 * @return bool
687 687
 	 */
688
-    public function has_item( $item_id ) {
689
-        return false !== $this->get_item( $item_id );
688
+    public function has_item($item_id) {
689
+        return false !== $this->get_item($item_id);
690 690
 	}
691 691
 
692 692
 	/**
@@ -695,8 +695,8 @@  discard block
 block discarded – undo
695 695
 	 * @since 1.0.19
696 696
 	 * @return bool
697 697
 	 */
698
-    public function has_element_type( $element_type ) {
699
-        return false !== $this->get_element_type( $element_type );
698
+    public function has_element_type($element_type) {
699
+        return false !== $this->get_element_type($element_type);
700 700
 	}
701 701
 
702 702
 	/**
@@ -707,13 +707,13 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
     public function is_recurring() {
709 709
 
710
-		if ( ! empty( $this->invoice ) ) {
710
+		if (!empty($this->invoice)) {
711 711
 			return $this->invoice->is_recurring();
712 712
 		}
713 713
 
714
-		foreach ( $this->get_items() as $item ) {
714
+		foreach ($this->get_items() as $item) {
715 715
 
716
-			if ( $item->is_recurring() ) {
716
+			if ($item->is_recurring()) {
717 717
 				return true;
718 718
 			}
719 719
 
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
     public function get_html() {
731 731
 
732 732
 		// Return the HTML.
733
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
733
+		return wpinv_get_template_html('payment-forms/form.php', array('form' => $this));
734 734
 
735 735
 	}
736 736
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 2 patches
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.
Spacing   +43 added lines, -43 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
  * Payment form submission discount class
@@ -25,28 +25,28 @@  discard block
 block discarded – undo
25 25
 	 * @param float                           $initial_total
26 26
 	 * @param float                           $recurring_total
27 27
 	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
28
+	public function __construct($submission, $initial_total, $recurring_total) {
29 29
 
30 30
 		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
31
+		if ($submission->has_invoice()) {
32 32
 			$this->discounts = $submission->get_invoice()->get_discounts();
33 33
 		}
34 34
 
35 35
 		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
36
+		$discount = $submission->get_field('discount');
37 37
 
38
-		if ( empty( $discount ) ) {
38
+		if (empty($discount)) {
39 39
 
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
40
+			if (isset($this->discounts['discount_code'])) {
41
+				unset($this->discounts['discount_code']);
42 42
 			}
43 43
 
44 44
 			return;
45 45
 		}
46 46
 
47 47
 		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
48
+		$amount = max($initial_total, $recurring_total);
49
+		$this->process_discount($submission, $discount, $amount);
50 50
 
51 51
 	}
52 52
 
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 	 * @param string                          $discount
58 58
 	 * @param float                           $amount
59 59
 	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
60
+	public function process_discount($submission, $discount, $amount) {
61 61
 
62 62
 		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
63
+		$discount = new WPInv_Discount($discount);
64 64
 
65 65
 		// Ensure it is active.
66
-        if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) );
66
+        if (!$this->is_discount_active($discount)) {
67
+			throw new Exception(__('Invalid or expired discount code', 'invoicing'));
68 68
 		}
69 69
 
70 70
 		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
71
+		if ($discount->has_exceeded_limit()) {
72
+			throw new Exception(__('This discount code has been used up', 'invoicing'));
73 73
 		}
74 74
 
75 75
 		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
76
+		$this->validate_single_use_discount($submission, $discount);
77 77
 
78 78
 		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
79
+		$this->validate_discount_amount($submission, $discount, $amount);
80 80
 
81 81
 		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
82
+		$this->discounts['discount_code'] = $this->calculate_discount($submission, $discount);
83 83
 	}
84 84
 
85 85
 	/**
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 	 * @param WPInv_Discount                  $discount
89 89
 	 * @return bool
90 90
 	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
91
+	public function is_discount_active($discount) {
92
+		return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired();
93 93
 	}
94 94
 
95 95
 	/**
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 	 * @param string $email
99 99
 	 * @return int|string|false
100 100
 	 */
101
-	public function get_user_id_or_email( $email ) {
101
+	public function get_user_id_or_email($email) {
102 102
 
103
-		if ( is_user_logged_in() ) {
103
+		if (is_user_logged_in()) {
104 104
 			return get_current_user_id();
105 105
 		}
106 106
 
107
-		return empty( $email ) ? false : sanitize_email( $email );
107
+		return empty($email) ? false : sanitize_email($email);
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
 	 * @param GetPaid_Payment_Form_Submission $submission
114 114
 	 * @param WPInv_Discount                  $discount
115 115
 	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
116
+	public function validate_single_use_discount($submission, $discount) {
117 117
 
118 118
 		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
119
+		if (!$discount->is_single_use()) {
120 120
 			return;
121 121
 		}
122 122
 
123 123
 		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
124
+		$user = $this->get_user_id_or_email($submission->get_billing_email());
125 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' ) );
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 128
 		}
129 129
 
130 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' ) );
131
+		if (!$discount->is_valid_for_user($user)) {
132
+			throw new Exception(__('You have already used this discount', 'invoicing'));
133 133
 		}
134 134
 
135 135
 	}
@@ -141,18 +141,18 @@  discard block
 block discarded – undo
141 141
 	 * @param WPInv_Discount         $discount
142 142
 	 * @param float                  $amount
143 143
 	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
144
+	public function validate_discount_amount($submission, $discount, $amount) {
145 145
 
146 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 ) );
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 150
 		}
151 151
 
152 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 ) );
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 156
 		}
157 157
 
158 158
 	}
@@ -166,24 +166,24 @@  discard block
 block discarded – undo
166 166
 	 * @param WPInv_Discount                  $discount
167 167
 	 * @return array
168 168
 	 */
169
-	public function calculate_discount( $submission, $discount ) {
169
+	public function calculate_discount($submission, $discount) {
170 170
 
171 171
 		$initial_discount   = 0;
172 172
 		$recurring_discount = 0;
173 173
 
174
-		foreach ( $submission->get_items() as $item ) {
174
+		foreach ($submission->get_items() as $item) {
175 175
 
176 176
 			// Abort if it is not valid for this item.
177
-			if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
177
+			if (!$discount->is_valid_for_items(array($item->get_id()))) {
178 178
 				continue;
179 179
 			}
180 180
 
181 181
 			// Calculate the initial amount...
182
-			$initial_discount += $discount->get_discounted_amount( $item->get_sub_total() );
182
+			$initial_discount += $discount->get_discounted_amount($item->get_sub_total());
183 183
 
184 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() );
185
+			if ($item->is_recurring() && $discount->is_recurring()) {
186
+				$recurring_discount += $discount->get_discounted_amount($item->get_recurring_sub_total());
187 187
 			}
188 188
 
189 189
 		}
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/alert.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -7,33 +7,33 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
     <label class="d-block">
16
-        <span><?php esc_html_e( 'Alert Text', 'invoicing' ); ?></span>
16
+        <span><?php esc_html_e('Alert Text', 'invoicing'); ?></span>
17 17
         <textarea v-model='active_form_element.text' class='form-control' rows='3'></textarea>
18 18
     </label>
19 19
 </div>
20 20
 
21 21
 <div class='form-group form-check'>
22 22
     <input :id="active_form_element.id + '_edit_dismissible'" v-model='active_form_element.dismissible' type='checkbox' class='form-check-input' />
23
-    <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e( 'Is Dismissible?', 'invoicing' ); ?></label>
23
+    <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e('Is Dismissible?', 'invoicing'); ?></label>
24 24
 </div>
25 25
 
26 26
 <div class='form-group'>
27
-    <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Alert Type', 'invoicing' ) ?></label>
27
+    <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Alert Type', 'invoicing') ?></label>
28 28
     <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'>
29
-        <option value='alert-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option>
30
-        <option value='alert-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option>
31
-        <option value='alert-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option>
32
-        <option value='alert-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option>
33
-        <option value='alert-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option>
34
-        <option value='alert-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option>
35
-        <option value='alert-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option>
36
-        <option value='alert-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option>
37
-        <option value='alert-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option>
29
+        <option value='alert-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option>
30
+        <option value='alert-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option>
31
+        <option value='alert-success'><?php esc_html_e('Success', 'invoicing'); ?></option>
32
+        <option value='alert-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option>
33
+        <option value='alert-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option>
34
+        <option value='alert-info'><?php esc_html_e('Info', 'invoicing'); ?></option>
35
+        <option value='alert-light'><?php esc_html_e('Light', 'invoicing'); ?></option>
36
+        <option value='alert-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option>
37
+        <option value='alert-link'><?php esc_html_e('Link', 'invoicing'); ?></option>
38 38
     </select>
39 39
 </div>
Please login to merge, or discard this patch.
templates/payment-forms/elements/price_input.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,30 +7,30 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Set the currency position.
13 13
 $position = wpinv_currency_position();
14 14
 
15
-if ( $position == 'left_space' ) {
15
+if ($position == 'left_space') {
16 16
     $position = 'left';
17 17
 }
18 18
 
19
-if ( $position == 'right_space' ) {
19
+if ($position == 'right_space') {
20 20
     $position = 'right';
21 21
 }
22 22
 
23 23
 echo aui()->input(
24 24
     array(
25
-        'name'              => esc_attr( $id ),
26
-        'id'                => esc_attr( $id ) . uniqid( '_' ),
27
-        'placeholder'       => empty( $placeholder ) ? wpinv_format_amount(0) : wpinv_format_amount( $placeholder ),
28
-        'value'             => empty( $value ) ? wpinv_format_amount(0) : wpinv_format_amount( $value ),
29
-        'label'             => empty( $label ) ? '' : wp_kses_post( $label ),
25
+        'name'              => esc_attr($id),
26
+        'id'                => esc_attr($id) . uniqid('_'),
27
+        'placeholder'       => empty($placeholder) ? wpinv_format_amount(0) : wpinv_format_amount($placeholder),
28
+        'value'             => empty($value) ? wpinv_format_amount(0) : wpinv_format_amount($value),
29
+        'label'             => empty($label) ? '' : wp_kses_post($label),
30 30
         'label_type'        => 'vertical',
31
-        'help_text'         => empty( $description ) ? '' : wp_kses_post( $description ),
32
-        'input_group_right' => $position == 'right' ? wpinv_currency_symbol( $form->get_currency() ) : '',
33
-        'input_group_left'  => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '',
31
+        'help_text'         => empty($description) ? '' : wp_kses_post($description),
32
+        'input_group_right' => $position == 'right' ? wpinv_currency_symbol($form->get_currency()) : '',
33
+        'input_group_left'  => $position == 'left' ? wpinv_currency_symbol($form->get_currency()) : '',
34 34
         'class'             => 'getpaid-refresh-on-change',
35 35
     )
36 36
 );
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,616 +13,616 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
193 32
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = esc_attr( $invoice->get_created_date() );
138
+                $date      = getpaid_format_date_value( $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
192
+                        $fomatted = getpaid_format_date( $due_date );
222 193
 
223
-			case 'customer' :
194
+                        if ( ! empty( $fomatted ) ) {
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( $invoice->is_draft() ) {
244
+                    return;
245
+                }
246
+
247
+                $url    = esc_url( $invoice->get_view_url() );
248
+                $print  = esc_attr__( 'Print invoice', 'invoicing' );
249
+                echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250
+
251
+                $url    = esc_url(
252
+                    wp_nonce_url(
253
+                        add_query_arg(
254
+                            array(
255
+                                'getpaid-admin-action' => 'send_invoice',
256
+                                'invoice_id'           => $invoice->get_id()
257
+                            )
258
+                        ),
259
+                        'getpaid-nonce',
260
+                        'getpaid-nonce'
261
+                    )
262
+                );
263
+
264
+                $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
+                echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266
+
267
+                break;
268
+        }
238 269
 
239
-				break;
270
+    }
240 271
 
241
-			case 'wpi_actions' :
242
-
243
-				if ( $invoice->is_draft() ) {
244
-					return;
245
-				}
246
-
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
249
-				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
272
+    /**
273
+     * Returns an array of payment forms table columns.
274
+     */
275
+    public static function payment_form_columns( $columns ) {
250 276
 
251
-				$url    = esc_url(
252
-					wp_nonce_url(
253
-						add_query_arg(
254
-							array(
255
-								'getpaid-admin-action' => 'send_invoice',
256
-								'invoice_id'           => $invoice->get_id()
257
-							)
258
-						),
259
-						'getpaid-nonce',
260
-						'getpaid-nonce'
261
-					)
262
-				);
277
+        $columns = array(
278
+            'cb'                => $columns['cb'],
279
+            'title'             => __( 'Name', 'invoicing' ),
280
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
+            'earnings'          => __( 'Revenue', 'invoicing' ),
282
+            'refunds'           => __( 'Refunded', 'invoicing' ),
283
+            'items'             => __( 'Items', 'invoicing' ),
284
+            'date'              => __( 'Date', 'invoicing' ),
285
+        );
263 286
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
-				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
287
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
266 288
 
267
-				break;
268
-		}
289
+    }
269 290
 
270
-	}
291
+    /**
292
+     * Displays payment form table columns.
293
+     */
294
+    public static function display_payment_form_columns( $column_name, $post_id ) {
271 295
 
272
-	/**
273
-	 * Returns an array of payment forms table columns.
274
-	 */
275
-	public static function payment_form_columns( $columns ) {
296
+        // Retrieve the payment form.
297
+        $form = new GetPaid_Payment_Form( $post_id );
276 298
 
277
-		$columns = array(
278
-			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
285
-		);
299
+        switch ( $column_name ) {
286 300
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
301
+            case 'earnings' :
302
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
+                break;
288 304
 
289
-	}
305
+            case 'refunds' :
306
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
+                break;
290 308
 
291
-	/**
292
-	 * Displays payment form table columns.
293
-	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
309
+            case 'refunds' :
310
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
+                break;
295 312
 
296
-		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
313
+            case 'shortcode' :
298 314
 
299
-		switch ( $column_name ) {
315
+                if ( $form->is_default() ) {
316
+                    echo '&mdash;';
317
+                } else {
318
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
+                }
300 320
 
301
-			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
-				break;
321
+                break;
304 322
 
305
-			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
-				break;
323
+            case 'items' :
308 324
 
309
-			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
-				break;
325
+                $items = $form->get_items();
312 326
 
313
-			case 'shortcode' :
327
+                if ( $form->is_default() || empty( $items ) ) {
328
+                    echo '&mdash;';
329
+                    return;
330
+                }
314 331
 
315
-				if ( $form->is_default() ) {
316
-					echo '&mdash;';
317
-				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
-				}
332
+                $_items = array();
320 333
 
321
-				break;
334
+                foreach ( $items as $item ) {
335
+                    $url = $item->get_edit_url();
322 336
 
323
-			case 'items' :
337
+                    if ( empty( $url ) ) {
338
+                        $_items[] = sanitize_text_field( $item->get_name() );
339
+                    } else {
340
+                        $_items[] = sprintf(
341
+                            '<a href="%s">%s</a>',
342
+                            esc_url( $url ),
343
+                            sanitize_text_field( $item->get_name() )
344
+                        );
345
+                    }
324 346
 
325
-				$items = $form->get_items();
347
+                }
326 348
 
327
-				if ( $form->is_default() || empty( $items ) ) {
328
-					echo '&mdash;';
329
-					return;
330
-				}
349
+                echo implode( '<br>', $_items );
331 350
 
332
-				$_items = array();
351
+                break;
333 352
 
334
-				foreach ( $items as $item ) {
335
-					$url = $item->get_edit_url();
353
+        }
336 354
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
339
-					} else {
340
-						$_items[] = sprintf(
341
-							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
344
-						);
345
-					}
355
+    }
346 356
 
347
-				}
357
+    /**
358
+     * Filters post states.
359
+     */
360
+    public static function filter_payment_form_state( $post_states, $post ) {
348 361
 
349
-				echo implode( '<br>', $_items );
362
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
+        }
365
+	
366
+        return $post_states;
350 367
 
351
-				break;
368
+    }
352 369
 
353
-		}
370
+    /**
371
+     * Returns an array of coupon table columns.
372
+     */
373
+    public static function discount_columns( $columns ) {
374
+
375
+        $columns = array(
376
+            'cb'                => $columns['cb'],
377
+            'title'             => __( 'Name', 'invoicing' ),
378
+            'code'              => __( 'Code', 'invoicing' ),
379
+            'amount'            => __( 'Amount', 'invoicing' ),
380
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
+            'start_date'        => __( 'Start Date', 'invoicing' ),
382
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
+        );
384
+
385
+        return apply_filters( 'wpi_discount_table_columns', $columns );
386
+    }
354 387
 
355
-	}
388
+    /**
389
+     * Filters post states.
390
+     */
391
+    public static function filter_discount_state( $post_states, $post ) {
356 392
 
357
-	/**
358
-	 * Filters post states.
359
-	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
393
+        if ( 'wpi_discount' == $post->post_type ) {
361 394
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
-		}
365
-	
366
-		return $post_states;
395
+            $discount = new WPInv_Discount( $post );
367 396
 
368
-	}
397
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
369 398
 
370
-	/**
371
-	 * Returns an array of coupon table columns.
372
-	 */
373
-	public static function discount_columns( $columns ) {
399
+            if ( $status != 'publish' ) {
400
+                return array(
401
+                    'discount_status' => wpinv_discount_status( $status ),
402
+                );
403
+            }
374 404
 
375
-		$columns = array(
376
-			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
-		);
405
+            return array();
384 406
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
386
-	}
407
+        }
387 408
 
388
-	/**
389
-	 * Filters post states.
390
-	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
409
+        return $post_states;
392 410
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
411
+    }
394 412
 
395
-			$discount = new WPInv_Discount( $post );
413
+    /**
414
+     * Returns an array of items table columns.
415
+     */
416
+    public static function item_columns( $columns ) {
417
+        global $wpinv_euvat;
418
+
419
+        $columns = array(
420
+            'cb'                => $columns['cb'],
421
+            'title'             => __( 'Name', 'invoicing' ),
422
+            'price'             => __( 'Price', 'invoicing' ),
423
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
425
+            'type'              => __( 'Type', 'invoicing' ),
426
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
+        );
428
+
429
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
+            unset( $columns['vat_rule'] );
431
+        }
396 432
 
397
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
433
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
+            unset( $columns['vat_class'] );
435
+        }
398 436
 
399
-			if ( $status != 'publish' ) {
400
-				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
402
-				);
403
-			}
437
+        return apply_filters( 'wpi_item_table_columns', $columns );
438
+    }
404 439
 
405
-			return array();
440
+    /**
441
+     * Returns an array of sortable items table columns.
442
+     */
443
+    public static function sortable_item_columns( $columns ) {
444
+
445
+        return array_merge(
446
+            $columns,
447
+            array(
448
+                'price'     => 'price',
449
+                'vat_rule'  => 'vat_rule',
450
+                'vat_class' => 'vat_class',
451
+                'type'      => 'type',
452
+            )
453
+        );
454
+
455
+    }
406 456
 
407
-		}
457
+    /**
458
+     * Displays items table columns.
459
+     */
460
+    public static function display_item_columns( $column_name, $post_id ) {
461
+        global $wpinv_euvat;
408 462
 
409
-		return $post_states;
463
+        $item = new WPInv_Item( $post_id );
410 464
 
411
-	}
465
+        switch ( $column_name ) {
412 466
 
413
-	/**
414
-	 * Returns an array of items table columns.
415
-	 */
416
-	public static function item_columns( $columns ) {
417
-		global $wpinv_euvat;
467
+            case 'price' :
418 468
 
419
-		$columns = array(
420
-			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
-		);
469
+                if ( ! $item->is_recurring() ) {
470
+                    echo $item->get_the_price();
471
+                    break;
472
+                }
428 473
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
431
-		}
474
+                $price = wp_sprintf(
475
+                    __( '%s / %s', 'invoicing' ),
476
+                    $item->get_the_price(),
477
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
+                );
432 479
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
435
-		}
480
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
+                    echo $price;
482
+                    break;
483
+                }
436 484
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
438
-	}
485
+                echo $item->get_the_initial_price();
439 486
 
440
-	/**
441
-	 * Returns an array of sortable items table columns.
442
-	 */
443
-	public static function sortable_item_columns( $columns ) {
487
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
+                break;
444 489
 
445
-		return array_merge(
446
-			$columns,
447
-			array(
448
-				'price'     => 'price',
449
-				'vat_rule'  => 'vat_rule',
450
-				'vat_class' => 'vat_class',
451
-				'type'      => 'type',
452
-			)
453
-		);
490
+            case 'vat_rule' :
491
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
+                break;
454 493
 
455
-	}
494
+            case 'vat_class' :
495
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
496
+                break;
456 497
 
457
-	/**
458
-	 * Displays items table columns.
459
-	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
461
-		global $wpinv_euvat;
498
+            case 'shortcode' :
499
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
+                break;
462 501
 
463
-		$item = new WPInv_Item( $post_id );
502
+            case 'type' :
503
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
+                break;
464 505
 
465
-		switch ( $column_name ) {
506
+        }
466 507
 
467
-			case 'price' :
508
+    }
468 509
 
469
-				if ( ! $item->is_recurring() ) {
470
-					echo $item->get_the_price();
471
-					break;
472
-				}
510
+    /**
511
+     * Lets users filter items using taxes.
512
+     */
513
+    public static function add_item_filters( $post_type ) {
514
+        $wpinv_euvat = getpaid_tax();
515
+
516
+        // Abort if we're not dealing with items.
517
+        if ( $post_type != 'wpi_item' ) {
518
+            return;
519
+        }
520
+
521
+        // Filter by vat rules.
522
+        if ( $wpinv_euvat->allow_vat_rules() ) {
523
+	
524
+            // Sanitize selected vat rule.
525
+            $vat_rule   = '';
526
+            $vat_rules  = $wpinv_euvat->get_rules();
527
+            if ( isset( $_GET['vat_rule'] ) ) {
528
+                $vat_rule   =  $_GET['vat_rule'];
529
+            }
530
+
531
+            // Filter by VAT rule.
532
+            echo wpinv_html_select(
533
+                array(
534
+                    'options'          => array_merge(
535
+                        array(
536
+                            '' => __( 'All VAT rules', 'invoicing' )
537
+                        ),
538
+                        $vat_rules
539
+                    ),
540
+                    'name'             => 'vat_rule',
541
+                    'id'               => 'vat_rule',
542
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
+                    'show_option_all'  => false,
544
+                    'show_option_none' => false,
545
+                    'class'            => 'gdmbx2-text-medium',
546
+                )
547
+            );
548
+
549
+            // Filter by VAT class.
550
+        }
473 551
 
474
-				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
476
-					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
-				);
552
+        // Filter by vat class.
553
+        if ( $wpinv_euvat->allow_vat_classes() ) {
554
+	
555
+            // Sanitize selected vat rule.
556
+            $vat_class   = '';
557
+            $vat_classes = $wpinv_euvat->get_all_classes();
558
+            if ( isset( $_GET['vat_class'] ) ) {
559
+                $vat_class   =  $_GET['vat_class'];
560
+            }
561
+
562
+            echo wpinv_html_select(
563
+                array(
564
+                    'options'          => array_merge(
565
+                        array(
566
+                            '' => __( 'All VAT classes', 'invoicing' )
567
+                        ),
568
+                        $vat_classes
569
+                    ),
570
+                    'name'             => 'vat_class',
571
+                    'id'               => 'vat_class',
572
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
+                    'show_option_all'  => false,
574
+                    'show_option_none' => false,
575
+                    'class'            => 'gdmbx2-text-medium',
576
+                )
577
+            );
479 578
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
-					echo $price;
482
-					break;
483
-				}
579
+        }
484 580
 
485
-				echo $item->get_the_initial_price();
581
+        // Filter by item type.
582
+        $type   = '';
583
+        if ( isset( $_GET['type'] ) ) {
584
+            $type   =  $_GET['type'];
585
+        }
486 586
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
-				break;
587
+        echo wpinv_html_select(
588
+            array(
589
+                'options'          => array_merge(
590
+                    array(
591
+                        '' => __( 'All item types', 'invoicing' )
592
+                    ),
593
+                    wpinv_get_item_types()
594
+                ),
595
+                'name'             => 'type',
596
+                'id'               => 'type',
597
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
+                'show_option_all'  => false,
599
+                'show_option_none' => false,
600
+                'class'            => 'gdmbx2-text-medium',
601
+            )
602
+        );
603
+
604
+    }
489 605
 
490
-			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
-				break;
606
+    /**
607
+     * Filters the item query.
608
+     */
609
+    public static function filter_item_query( $query ) {
493 610
 
494
-			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
496
-				break;
611
+        // modify the query only if it admin and main query.
612
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
+            return $query;
614
+        }
497 615
 
498
-			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
-				break;
616
+        // we want to modify the query for our items.
617
+        if ( 'wpi_item' != $query->query['post_type'] ){
618
+            return $query;
619
+        }
501 620
 
502
-			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
-				break;
621
+        if ( empty( $query->query_vars['meta_query'] ) ) {
622
+            $query->query_vars['meta_query'] = array();
623
+        }
505 624
 
506
-		}
507
-
508
-	}
509
-
510
-	/**
511
-	 * Lets users filter items using taxes.
512
-	 */
513
-	public static function add_item_filters( $post_type ) {
514
-		$wpinv_euvat = getpaid_tax();
515
-
516
-		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
518
-			return;
519
-		}
520
-
521
-		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
523
-	
524
-			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
529
-			}
530
-
531
-			// Filter by VAT rule.
532
-			echo wpinv_html_select(
533
-				array(
534
-					'options'          => array_merge(
535
-						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
537
-						),
538
-						$vat_rules
539
-					),
540
-					'name'             => 'vat_rule',
541
-					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
-					'show_option_all'  => false,
544
-					'show_option_none' => false,
545
-					'class'            => 'gdmbx2-text-medium',
546
-				)
547
-			);
548
-
549
-			// Filter by VAT class.
550
-		}
551
-
552
-		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
554
-	
555
-			// Sanitize selected vat rule.
556
-			$vat_class   = '';
557
-			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
560
-			}
561
-
562
-			echo wpinv_html_select(
563
-				array(
564
-					'options'          => array_merge(
565
-						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
567
-						),
568
-						$vat_classes
569
-					),
570
-					'name'             => 'vat_class',
571
-					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
-					'show_option_all'  => false,
574
-					'show_option_none' => false,
575
-					'class'            => 'gdmbx2-text-medium',
576
-				)
577
-			);
578
-
579
-		}
580
-
581
-		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
585
-		}
586
-
587
-		echo wpinv_html_select(
588
-			array(
589
-				'options'          => array_merge(
590
-					array(
591
-						'' => __( 'All item types', 'invoicing' )
592
-					),
593
-					wpinv_get_item_types()
594
-				),
595
-				'name'             => 'type',
596
-				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
-				'show_option_all'  => false,
599
-				'show_option_none' => false,
600
-				'class'            => 'gdmbx2-text-medium',
601
-			)
602
-		);
603
-
604
-	}
605
-
606
-	/**
607
-	 * Filters the item query.
608
-	 */
609
-	public static function filter_item_query( $query ) {
610
-
611
-		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
-			return $query;
614
-		}
615
-
616
-		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
618
-			return $query;
619
-		}
620
-
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
622
-			$query->query_vars['meta_query'] = array();
623
-		}
624
-
625
-		// Filter vat rule type
625
+        // Filter vat rule type
626 626
         if ( ! empty( $_GET['vat_rule'] ) ) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
@@ -647,94 +647,94 @@  discard block
 block discarded – undo
647 647
                 'value'   => sanitize_text_field( $_GET['type'] ),
648 648
                 'compare' => '='
649 649
             );
650
-		}
651
-
652
-	}
653
-
654
-	/**
655
-	 * Reorders items.
656
-	 */
657
-	public static function reorder_items( $vars ) {
658
-		global $typenow;
659
-
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
-			return $vars;
662
-		}
663
-
664
-		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
666
-			return array_merge(
667
-				$vars,
668
-				array(
669
-					'meta_key' => '_wpinv_type',
670
-					'orderby'  => 'meta_value'
671
-				)
672
-			);
673
-		}
674
-
675
-		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
677
-			return array_merge(
678
-				$vars,
679
-				array(
680
-					'meta_key' => '_wpinv_vat_class',
681
-					'orderby'  => 'meta_value'
682
-				)
683
-			);
684
-		}
685
-
686
-		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
688
-			return array_merge(
689
-				$vars,
690
-				array(
691
-					'meta_key' => '_wpinv_vat_rule',
692
-					'orderby'  => 'meta_value'
693
-				)
694
-			);
695
-		}
696
-
697
-		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
699
-			return array_merge(
700
-				$vars,
701
-				array(
702
-					'meta_key' => '_wpinv_price',
703
-					'orderby'  => 'meta_value_num'
704
-				)
705
-			);
706
-		}
707
-
708
-		return $vars;
709
-
710
-	}
711
-
712
-	/**
713
-	 * Fired when deleting a post.
714
-	 */
715
-	public static function delete_post( $post_id ) {
716
-
717
-		switch ( get_post_type( $post_id ) ) {
718
-
719
-			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
-				break;
722
-
723
-			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
-				break;
726
-
727
-			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
-				break;
730
-
731
-			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
736
-				break;
737
-		}
738
-	}
650
+        }
651
+
652
+    }
653
+
654
+    /**
655
+     * Reorders items.
656
+     */
657
+    public static function reorder_items( $vars ) {
658
+        global $typenow;
659
+
660
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
+            return $vars;
662
+        }
663
+
664
+        // By item type.
665
+        if ( 'type' == $vars['orderby'] ) {
666
+            return array_merge(
667
+                $vars,
668
+                array(
669
+                    'meta_key' => '_wpinv_type',
670
+                    'orderby'  => 'meta_value'
671
+                )
672
+            );
673
+        }
674
+
675
+        // By vat class.
676
+        if ( 'vat_class' == $vars['orderby'] ) {
677
+            return array_merge(
678
+                $vars,
679
+                array(
680
+                    'meta_key' => '_wpinv_vat_class',
681
+                    'orderby'  => 'meta_value'
682
+                )
683
+            );
684
+        }
685
+
686
+        // By vat rule.
687
+        if ( 'vat_rule' == $vars['orderby'] ) {
688
+            return array_merge(
689
+                $vars,
690
+                array(
691
+                    'meta_key' => '_wpinv_vat_rule',
692
+                    'orderby'  => 'meta_value'
693
+                )
694
+            );
695
+        }
696
+
697
+        // By price.
698
+        if ( 'price' == $vars['orderby'] ) {
699
+            return array_merge(
700
+                $vars,
701
+                array(
702
+                    'meta_key' => '_wpinv_price',
703
+                    'orderby'  => 'meta_value_num'
704
+                )
705
+            );
706
+        }
707
+
708
+        return $vars;
709
+
710
+    }
711
+
712
+    /**
713
+     * Fired when deleting a post.
714
+     */
715
+    public static function delete_post( $post_id ) {
716
+
717
+        switch ( get_post_type( $post_id ) ) {
718
+
719
+            case 'wpi_item' :
720
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
+                break;
722
+
723
+            case 'wpi_payment_form' :
724
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
+                break;
726
+
727
+            case 'wpi_discount' :
728
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
+                break;
730
+
731
+            case 'wpi_invoice' :
732
+                $invoice = new WPInv_Invoice( $post_id );
733
+                do_action( "getpaid_before_delete_invoice", $invoice );
734
+                $invoice->get_data_store()->delete_items( $invoice );
735
+                $invoice->get_data_store()->delete_special_fields( $invoice );
736
+                break;
737
+        }
738
+    }
739 739
 
740 740
 }
Please login to merge, or discard this patch.
Spacing   +193 added lines, -193 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
  * Post types Admin Class
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28 28
 
29 29
 		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
30
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
31
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
32 32
 
33 33
 		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
34
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
35
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
36
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
37
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
38
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
39
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
40 40
 
41 41
 		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
42
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
43
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
44
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
45 45
 
46 46
 		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
47
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
48 48
 
49 49
 		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
50
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
51
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * Post updated messages.
56 56
 	 */
57
-	public static function post_updated_messages( $messages ) {
57
+	public static function post_updated_messages($messages) {
58 58
 		global $post;
59 59
 
60 60
 		$messages['wpi_discount'] = array(
61 61
 			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
62
+			1   => __('Discount updated.', 'invoicing'),
63
+			2   => __('Custom field updated.', 'invoicing'),
64
+			3   => __('Custom field deleted.', 'invoicing'),
65
+			4   => __('Discount updated.', 'invoicing'),
66
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
67
+			6   => __('Discount updated.', 'invoicing'),
68
+			7   => __('Discount saved.', 'invoicing'),
69
+			8   => __('Discount submitted.', 'invoicing'),
70
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
71
+			10  => __('Discount draft updated.', 'invoicing'),
72 72
 		);
73 73
 
74 74
 		$messages['wpi_payment_form'] = array(
75 75
 			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
76
+			1   => __('Payment Form updated.', 'invoicing'),
77
+			2   => __('Custom field updated.', 'invoicing'),
78
+			3   => __('Custom field deleted.', 'invoicing'),
79
+			4   => __('Payment Form updated.', 'invoicing'),
80
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
81
+			6   => __('Payment Form updated.', 'invoicing'),
82
+			7   => __('Payment Form saved.', 'invoicing'),
83
+			8   => __('Payment Form submitted.', 'invoicing'),
84
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
85
+			10  => __('Payment Form draft updated.', 'invoicing'),
86 86
 		);
87 87
 
88 88
 		return $messages;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	/**
93 93
 	 * Post row actions.
94 94
 	 */
95
-	public static function post_row_actions( $actions, $post ) {
95
+	public static function post_row_actions($actions, $post) {
96 96
 
97
-		$post = get_post( $post );
97
+		$post = get_post($post);
98 98
 
99 99
 		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
100
+		if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
101
+			unset($actions['trash']);
102
+			unset($actions['inline hide-if-no-js']);
103 103
 		}
104 104
 
105 105
 		return $actions;
@@ -108,51 +108,51 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * Returns an array of invoice table columns.
110 110
 	 */
111
-	public static function invoice_columns( $columns ) {
111
+	public static function invoice_columns($columns) {
112 112
 
113 113
 		$columns = array(
114 114
 			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
115
+			'number'            => __('Invoice', 'invoicing'),
116
+			'customer'          => __('Customer', 'invoicing'),
117
+			'invoice_date'      => __('Date', 'invoicing'),
118
+			'amount'            => __('Amount', 'invoicing'),
119
+			'recurring'         => __('Recurring', 'invoicing'),
120
+			'status'            => __('Status', 'invoicing'),
121
+			'wpi_actions'       => __('Actions', 'invoicing'),
122 122
 		);
123 123
 
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
124
+		return apply_filters('wpi_invoice_table_columns', $columns);
125 125
 	}
126 126
 
127 127
 	/**
128 128
 	 * Displays invoice table columns.
129 129
 	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
130
+	public static function display_invoice_columns($column_name, $post_id) {
131 131
 
132
-		$invoice = new WPInv_Invoice( $post_id );
132
+		$invoice = new WPInv_Invoice($post_id);
133 133
 
134
-		switch ( $column_name ) {
134
+		switch ($column_name) {
135 135
 
136 136
 			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
137
+				$date_time = esc_attr($invoice->get_created_date());
138
+				$date      = getpaid_format_date_value($date_time);
139 139
 				echo "<span title='$date_time'>$date</span>";
140 140
 				break;
141 141
 
142 142
 			case 'amount' :
143 143
 
144 144
 				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
145
+				$formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency());
146 146
 
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
147
+				if ($invoice->is_refunded()) {
148
+					$refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency());
149 149
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150 150
 				} else {
151 151
 
152 152
 					$discount = $invoice->get_total_discount();
153 153
 
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
154
+					if (!empty($discount)) {
155
+						$new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency());
156 156
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157 157
 					} else {
158 158
 						echo $formated_amount;
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 				break;
164 164
 
165 165
 			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
166
+				$status       = sanitize_text_field($invoice->get_status());
167
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
168 168
 
169 169
 				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
170
+				if ($invoice->is_paid()) {
171
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
172
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
173 173
 
174 174
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175 175
 				} else {
@@ -177,22 +177,22 @@  discard block
 block discarded – undo
177 177
 				}
178 178
 
179 179
 				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
180
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
181 181
 
182 182
 					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
183
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
184
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
185 185
 					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
186
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
187 187
 					}
188 188
 
189 189
 					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
190
+					if (wpinv_get_option('overdue_active')) {
191 191
 						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
192
+						$fomatted = getpaid_format_date($due_date);
193 193
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
194
+						if (!empty($fomatted)) {
195
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
196 196
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197 197
 						}
198 198
 					}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 			case 'recurring':
205 205
 
206
-				if ( $invoice->is_recurring() ) {
206
+				if ($invoice->is_recurring()) {
207 207
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208 208
 				} else {
209 209
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 
213 213
 			case 'number' :
214 214
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
215
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
216
+				$invoice_number  = sanitize_text_field($invoice->get_number());
217
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
218 218
 
219 219
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220 220
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	
225 225
 				$customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
227
+				if (empty($customer_name)) {
228 228
 					$customer_name = $invoice->get_email();
229 229
 				}
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
231
+				if (!empty($customer_name)) {
232
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
233
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
234 234
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235 235
 				} else {
236 236
 					echo '<div>&mdash;</div>';
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
 
241 241
 			case 'wpi_actions' :
242 242
 
243
-				if ( $invoice->is_draft() ) {
243
+				if ($invoice->is_draft()) {
244 244
 					return;
245 245
 				}
246 246
 
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
247
+				$url    = esc_url($invoice->get_view_url());
248
+				$print  = esc_attr__('Print invoice', 'invoicing');
249 249
 				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250 250
 
251 251
 				$url    = esc_url(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 					)
262 262
 				);
263 263
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
264
+				$send = esc_attr__('Send invoice to customer', 'invoicing');
265 265
 				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266 266
 
267 267
 				break;
@@ -272,50 +272,50 @@  discard block
 block discarded – undo
272 272
 	/**
273 273
 	 * Returns an array of payment forms table columns.
274 274
 	 */
275
-	public static function payment_form_columns( $columns ) {
275
+	public static function payment_form_columns($columns) {
276 276
 
277 277
 		$columns = array(
278 278
 			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
279
+			'title'             => __('Name', 'invoicing'),
280
+			'shortcode'         => __('Shortcode', 'invoicing'),
281
+			'earnings'          => __('Revenue', 'invoicing'),
282
+			'refunds'           => __('Refunded', 'invoicing'),
283
+			'items'             => __('Items', 'invoicing'),
284
+			'date'              => __('Date', 'invoicing'),
285 285
 		);
286 286
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
287
+		return apply_filters('wpi_payment_form_table_columns', $columns);
288 288
 
289 289
 	}
290 290
 
291 291
 	/**
292 292
 	 * Displays payment form table columns.
293 293
 	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
294
+	public static function display_payment_form_columns($column_name, $post_id) {
295 295
 
296 296
 		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
297
+		$form = new GetPaid_Payment_Form($post_id);
298 298
 
299
-		switch ( $column_name ) {
299
+		switch ($column_name) {
300 300
 
301 301
 			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
302
+				echo wpinv_price(wpinv_format_amount($form->get_earned()));
303 303
 				break;
304 304
 
305 305
 			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
306
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
307 307
 				break;
308 308
 
309 309
 			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
310
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
311 311
 				break;
312 312
 
313 313
 			case 'shortcode' :
314 314
 
315
-				if ( $form->is_default() ) {
315
+				if ($form->is_default()) {
316 316
 					echo '&mdash;';
317 317
 				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
318
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
319 319
 				}
320 320
 
321 321
 				break;
@@ -324,29 +324,29 @@  discard block
 block discarded – undo
324 324
 
325 325
 				$items = $form->get_items();
326 326
 
327
-				if ( $form->is_default() || empty( $items ) ) {
327
+				if ($form->is_default() || empty($items)) {
328 328
 					echo '&mdash;';
329 329
 					return;
330 330
 				}
331 331
 
332 332
 				$_items = array();
333 333
 
334
-				foreach ( $items as $item ) {
334
+				foreach ($items as $item) {
335 335
 					$url = $item->get_edit_url();
336 336
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
337
+					if (empty($url)) {
338
+						$_items[] = sanitize_text_field($item->get_name());
339 339
 					} else {
340 340
 						$_items[] = sprintf(
341 341
 							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
342
+							esc_url($url),
343
+							sanitize_text_field($item->get_name())
344 344
 						);
345 345
 					}
346 346
 
347 347
 				}
348 348
 
349
-				echo implode( '<br>', $_items );
349
+				echo implode('<br>', $_items);
350 350
 
351 351
 				break;
352 352
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	/**
358 358
 	 * Filters post states.
359 359
 	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
360
+	public static function filter_payment_form_state($post_states, $post) {
361 361
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
362
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
363
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
364 364
 		}
365 365
 	
366 366
 		return $post_states;
@@ -370,35 +370,35 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * Returns an array of coupon table columns.
372 372
 	 */
373
-	public static function discount_columns( $columns ) {
373
+	public static function discount_columns($columns) {
374 374
 
375 375
 		$columns = array(
376 376
 			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
377
+			'title'             => __('Name', 'invoicing'),
378
+			'code'              => __('Code', 'invoicing'),
379
+			'amount'            => __('Amount', 'invoicing'),
380
+			'usage'             => __('Usage / Limit', 'invoicing'),
381
+			'start_date'        => __('Start Date', 'invoicing'),
382
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
383 383
 		);
384 384
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
385
+		return apply_filters('wpi_discount_table_columns', $columns);
386 386
 	}
387 387
 
388 388
 	/**
389 389
 	 * Filters post states.
390 390
 	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
391
+	public static function filter_discount_state($post_states, $post) {
392 392
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
393
+		if ('wpi_discount' == $post->post_type) {
394 394
 
395
-			$discount = new WPInv_Discount( $post );
395
+			$discount = new WPInv_Discount($post);
396 396
 
397 397
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
398 398
 
399
-			if ( $status != 'publish' ) {
399
+			if ($status != 'publish') {
400 400
 				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
401
+					'discount_status' => wpinv_discount_status($status),
402 402
 				);
403 403
 			}
404 404
 
@@ -413,34 +413,34 @@  discard block
 block discarded – undo
413 413
 	/**
414 414
 	 * Returns an array of items table columns.
415 415
 	 */
416
-	public static function item_columns( $columns ) {
416
+	public static function item_columns($columns) {
417 417
 		global $wpinv_euvat;
418 418
 
419 419
 		$columns = array(
420 420
 			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
421
+			'title'             => __('Name', 'invoicing'),
422
+			'price'             => __('Price', 'invoicing'),
423
+			'vat_rule'          => __('VAT rule', 'invoicing'),
424
+			'vat_class'         => __('VAT class', 'invoicing'),
425
+			'type'              => __('Type', 'invoicing'),
426
+			'shortcode'         => __('Shortcode', 'invoicing'),
427 427
 		);
428 428
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
429
+		if (!$wpinv_euvat->allow_vat_rules()) {
430
+			unset($columns['vat_rule']);
431 431
 		}
432 432
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
433
+		if (!$wpinv_euvat->allow_vat_classes()) {
434
+			unset($columns['vat_class']);
435 435
 		}
436 436
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
437
+		return apply_filters('wpi_item_table_columns', $columns);
438 438
 	}
439 439
 
440 440
 	/**
441 441
 	 * Returns an array of sortable items table columns.
442 442
 	 */
443
-	public static function sortable_item_columns( $columns ) {
443
+	public static function sortable_item_columns($columns) {
444 444
 
445 445
 		return array_merge(
446 446
 			$columns,
@@ -457,50 +457,50 @@  discard block
 block discarded – undo
457 457
 	/**
458 458
 	 * Displays items table columns.
459 459
 	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
460
+	public static function display_item_columns($column_name, $post_id) {
461 461
 		global $wpinv_euvat;
462 462
 
463
-		$item = new WPInv_Item( $post_id );
463
+		$item = new WPInv_Item($post_id);
464 464
 
465
-		switch ( $column_name ) {
465
+		switch ($column_name) {
466 466
 
467 467
 			case 'price' :
468 468
 
469
-				if ( ! $item->is_recurring() ) {
469
+				if (!$item->is_recurring()) {
470 470
 					echo $item->get_the_price();
471 471
 					break;
472 472
 				}
473 473
 
474 474
 				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
475
+					__('%s / %s', 'invoicing'),
476 476
 					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
477
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
478 478
 				);
479 479
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
480
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
481 481
 					echo $price;
482 482
 					break;
483 483
 				}
484 484
 
485 485
 				echo $item->get_the_initial_price();
486 486
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
487
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
488 488
 				break;
489 489
 
490 490
 			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
491
+				echo $wpinv_euvat->item_rule_label($item->get_id());
492 492
 				break;
493 493
 
494 494
 			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
495
+				echo $wpinv_euvat->item_class_label($item->get_id());
496 496
 				break;
497 497
 
498 498
 			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
499
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500 500
 				break;
501 501
 
502 502
 			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
503
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504 504
 				break;
505 505
 
506 506
 		}
@@ -510,22 +510,22 @@  discard block
 block discarded – undo
510 510
 	/**
511 511
 	 * Lets users filter items using taxes.
512 512
 	 */
513
-	public static function add_item_filters( $post_type ) {
513
+	public static function add_item_filters($post_type) {
514 514
 		$wpinv_euvat = getpaid_tax();
515 515
 
516 516
 		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
517
+		if ($post_type != 'wpi_item') {
518 518
 			return;
519 519
 		}
520 520
 
521 521
 		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
522
+		if ($wpinv_euvat->allow_vat_rules()) {
523 523
 	
524 524
 			// Sanitize selected vat rule.
525 525
 			$vat_rule   = '';
526 526
 			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
527
+			if (isset($_GET['vat_rule'])) {
528
+				$vat_rule = $_GET['vat_rule'];
529 529
 			}
530 530
 
531 531
 			// Filter by VAT rule.
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
 				array(
534 534
 					'options'          => array_merge(
535 535
 						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
536
+							'' => __('All VAT rules', 'invoicing')
537 537
 						),
538 538
 						$vat_rules
539 539
 					),
540 540
 					'name'             => 'vat_rule',
541 541
 					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
542
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
543 543
 					'show_option_all'  => false,
544 544
 					'show_option_none' => false,
545 545
 					'class'            => 'gdmbx2-text-medium',
@@ -550,26 +550,26 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
553
+		if ($wpinv_euvat->allow_vat_classes()) {
554 554
 	
555 555
 			// Sanitize selected vat rule.
556 556
 			$vat_class   = '';
557 557
 			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
558
+			if (isset($_GET['vat_class'])) {
559
+				$vat_class = $_GET['vat_class'];
560 560
 			}
561 561
 
562 562
 			echo wpinv_html_select(
563 563
 				array(
564 564
 					'options'          => array_merge(
565 565
 						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
566
+							'' => __('All VAT classes', 'invoicing')
567 567
 						),
568 568
 						$vat_classes
569 569
 					),
570 570
 					'name'             => 'vat_class',
571 571
 					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
572
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
573 573
 					'show_option_all'  => false,
574 574
 					'show_option_none' => false,
575 575
 					'class'            => 'gdmbx2-text-medium',
@@ -579,22 +579,22 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 
581 581
 		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
582
+		$type = '';
583
+		if (isset($_GET['type'])) {
584
+			$type = $_GET['type'];
585 585
 		}
586 586
 
587 587
 		echo wpinv_html_select(
588 588
 			array(
589 589
 				'options'          => array_merge(
590 590
 					array(
591
-						'' => __( 'All item types', 'invoicing' )
591
+						'' => __('All item types', 'invoicing')
592 592
 					),
593 593
 					wpinv_get_item_types()
594 594
 				),
595 595
 				'name'             => 'type',
596 596
 				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
597
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
598 598
 				'show_option_all'  => false,
599 599
 				'show_option_none' => false,
600 600
 				'class'            => 'gdmbx2-text-medium',
@@ -606,45 +606,45 @@  discard block
 block discarded – undo
606 606
 	/**
607 607
 	 * Filters the item query.
608 608
 	 */
609
-	public static function filter_item_query( $query ) {
609
+	public static function filter_item_query($query) {
610 610
 
611 611
 		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
612
+		if (!(is_admin() && $query->is_main_query())) { 
613 613
 			return $query;
614 614
 		}
615 615
 
616 616
 		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
617
+		if ('wpi_item' != $query->query['post_type']) {
618 618
 			return $query;
619 619
 		}
620 620
 
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
621
+		if (empty($query->query_vars['meta_query'])) {
622 622
 			$query->query_vars['meta_query'] = array();
623 623
 		}
624 624
 
625 625
 		// Filter vat rule type
626
-        if ( ! empty( $_GET['vat_rule'] ) ) {
626
+        if (!empty($_GET['vat_rule'])) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
629
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
629
+                'value'   => sanitize_text_field($_GET['vat_rule']),
630 630
                 'compare' => '='
631 631
             );
632 632
         }
633 633
 
634 634
         // Filter vat class
635
-        if ( ! empty( $_GET['vat_class'] ) ) {
635
+        if (!empty($_GET['vat_class'])) {
636 636
             $query->query_vars['meta_query'][] = array(
637 637
                 'key'     => '_wpinv_vat_class',
638
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
638
+                'value'   => sanitize_text_field($_GET['vat_class']),
639 639
                 'compare' => '='
640 640
             );
641 641
         }
642 642
 
643 643
         // Filter item type
644
-        if ( ! empty( $_GET['type'] ) ) {
644
+        if (!empty($_GET['type'])) {
645 645
             $query->query_vars['meta_query'][] = array(
646 646
                 'key'     => '_wpinv_type',
647
-                'value'   => sanitize_text_field( $_GET['type'] ),
647
+                'value'   => sanitize_text_field($_GET['type']),
648 648
                 'compare' => '='
649 649
             );
650 650
 		}
@@ -654,15 +654,15 @@  discard block
 block discarded – undo
654 654
 	/**
655 655
 	 * Reorders items.
656 656
 	 */
657
-	public static function reorder_items( $vars ) {
657
+	public static function reorder_items($vars) {
658 658
 		global $typenow;
659 659
 
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
660
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
661 661
 			return $vars;
662 662
 		}
663 663
 
664 664
 		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
665
+		if ('type' == $vars['orderby']) {
666 666
 			return array_merge(
667 667
 				$vars,
668 668
 				array(
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 		}
674 674
 
675 675
 		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
676
+		if ('vat_class' == $vars['orderby']) {
677 677
 			return array_merge(
678 678
 				$vars,
679 679
 				array(
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 		}
685 685
 
686 686
 		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
687
+		if ('vat_rule' == $vars['orderby']) {
688 688
 			return array_merge(
689 689
 				$vars,
690 690
 				array(
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 		}
696 696
 
697 697
 		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
698
+		if ('price' == $vars['orderby']) {
699 699
 			return array_merge(
700 700
 				$vars,
701 701
 				array(
@@ -712,27 +712,27 @@  discard block
 block discarded – undo
712 712
 	/**
713 713
 	 * Fired when deleting a post.
714 714
 	 */
715
-	public static function delete_post( $post_id ) {
715
+	public static function delete_post($post_id) {
716 716
 
717
-		switch ( get_post_type( $post_id ) ) {
717
+		switch (get_post_type($post_id)) {
718 718
 
719 719
 			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
720
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
721 721
 				break;
722 722
 
723 723
 			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
724
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
725 725
 				break;
726 726
 
727 727
 			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
728
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
729 729
 				break;
730 730
 
731 731
 			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
732
+				$invoice = new WPInv_Invoice($post_id);
733
+				do_action("getpaid_before_delete_invoice", $invoice);
734
+				$invoice->get_data_store()->delete_items($invoice);
735
+				$invoice->get_data_store()->delete_special_fields($invoice);
736 736
 				break;
737 737
 		}
738 738
 	}
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -12,185 +12,185 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-
41
-	}
42
-
43
-	/**
44
-	 * Adds totals to a response for submission refresh prices.
45
-	 *
46
-	 * @param GetPaid_Payment_Form_Submission $submission
47
-	 */
48
-	public function add_totals( $submission ) {
49
-
50
-		$this->response = array_merge(
51
-			$this->response,
52
-			array(
53
-
54
-				'totals'        => array(
55
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
57
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
58
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
59
-					'total'     => $submission->format_amount( $submission->get_total() ),
60
-				),
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+
41
+    }
42
+
43
+    /**
44
+     * Adds totals to a response for submission refresh prices.
45
+     *
46
+     * @param GetPaid_Payment_Form_Submission $submission
47
+     */
48
+    public function add_totals( $submission ) {
49
+
50
+        $this->response = array_merge(
51
+            $this->response,
52
+            array(
53
+
54
+                'totals'        => array(
55
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
57
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
58
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
59
+                    'total'     => $submission->format_amount( $submission->get_total() ),
60
+                ),
61 61
 	
62
-				'recurring'     => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
-				),
62
+                'recurring'     => array(
63
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
+                ),
69 69
 
70
-			)
71
-		);
70
+            )
71
+        );
72 72
 
73
-	}
73
+    }
74 74
 
75
-	/**
76
-	 * Adds texts to a response for submission refresh prices.
77
-	 *
78
-	 * @param GetPaid_Payment_Form_Submission $submission
79
-	 */
80
-	public function add_texts( $submission ) {
75
+    /**
76
+     * Adds texts to a response for submission refresh prices.
77
+     *
78
+     * @param GetPaid_Payment_Form_Submission $submission
79
+     */
80
+    public function add_texts( $submission ) {
81 81
 
82
-		$payable = $submission->format_amount( $submission->get_total() );
82
+        $payable = $submission->format_amount( $submission->get_total() );
83 83
 
84
-		if ( $submission->has_recurring != 0 ) {
84
+        if ( $submission->has_recurring != 0 ) {
85 85
 
86
-			$recurring = new WPInv_Item( $submission->has_recurring );
87
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
86
+            $recurring = new WPInv_Item( $submission->has_recurring );
87
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
88 88
 
89
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
-				$payable = "$payable / $period";
91
-			} else {
92
-				$payable = sprintf(
93
-					__( '%1$s (renews at %2$s / %3$s)'),
94
-					$submission->format_amount( $submission->get_total() ),
95
-					$submission->format_amount( $submission->get_recurring_total() ),
96
-					$period
97
-				);
98
-			}
89
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
+                $payable = "$payable / $period";
91
+            } else {
92
+                $payable = sprintf(
93
+                    __( '%1$s (renews at %2$s / %3$s)'),
94
+                    $submission->format_amount( $submission->get_total() ),
95
+                    $submission->format_amount( $submission->get_recurring_total() ),
96
+                    $period
97
+                );
98
+            }
99 99
 
100
-		}
100
+        }
101 101
 
102
-		$texts = array(
103
-			'.getpaid-checkout-total-payable' => $payable,
104
-		);
102
+        $texts = array(
103
+            '.getpaid-checkout-total-payable' => $payable,
104
+        );
105 105
 
106
-		foreach ( $submission->get_items() as $item_id => $item ) {
107
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
-		}
106
+        foreach ( $submission->get_items() as $item_id => $item ) {
107
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
+        }
110 110
 
111
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
111
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112 112
 
113
-	}
113
+    }
114 114
 
115
-	/**
116
-	 * Adds items to a response for submission refresh prices.
117
-	 *
118
-	 * @param GetPaid_Payment_Form_Submission $submission
119
-	 */
120
-	public function add_items( $submission ) {
115
+    /**
116
+     * Adds items to a response for submission refresh prices.
117
+     *
118
+     * @param GetPaid_Payment_Form_Submission $submission
119
+     */
120
+    public function add_items( $submission ) {
121 121
 
122
-		// Add items.
123
-		$items = array();
122
+        // Add items.
123
+        $items = array();
124 124
 
125 125
         foreach ( $submission->get_items() as $item_id => $item ) {
126
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
-		}
126
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
+        }
128 128
 
129
-		$this->response = array_merge(
130
-			$this->response,
131
-			array( 'items' => $items )
132
-		);
129
+        $this->response = array_merge(
130
+            $this->response,
131
+            array( 'items' => $items )
132
+        );
133 133
 
134
-	}
134
+    }
135 135
 
136
-	/**
137
-	 * Adds fees to a response for submission refresh prices.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 */
141
-	public function add_fees( $submission ) {
136
+    /**
137
+     * Adds fees to a response for submission refresh prices.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     */
141
+    public function add_fees( $submission ) {
142 142
 
143
-		$fees = array();
143
+        $fees = array();
144 144
 
145 145
         foreach ( $submission->get_fees() as $name => $data ) {
146
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
-		}
146
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
+        }
148 148
 
149
-		$this->response = array_merge(
150
-			$this->response,
151
-			array( 'fees' => $fees )
152
-		);
149
+        $this->response = array_merge(
150
+            $this->response,
151
+            array( 'fees' => $fees )
152
+        );
153 153
 
154
-	}
154
+    }
155 155
 
156
-	/**
157
-	 * Adds discounts to a response for submission refresh prices.
158
-	 *
159
-	 * @param GetPaid_Payment_Form_Submission $submission
160
-	 */
161
-	public function add_discounts( $submission ) {
156
+    /**
157
+     * Adds discounts to a response for submission refresh prices.
158
+     *
159
+     * @param GetPaid_Payment_Form_Submission $submission
160
+     */
161
+    public function add_discounts( $submission ) {
162 162
 
163
-		$discounts = array();
163
+        $discounts = array();
164 164
 
165 165
         foreach ( $submission->get_discounts() as $name => $data ) {
166
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
-		}
166
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
+        }
168 168
 
169
-		$this->response = array_merge(
170
-			$this->response,
171
-			array( 'discounts' => $discounts )
172
-		);
169
+        $this->response = array_merge(
170
+            $this->response,
171
+            array( 'discounts' => $discounts )
172
+        );
173 173
 
174
-	}
174
+    }
175 175
 
176
-	/**
177
-	 * Adds taxes to a response for submission refresh prices.
178
-	 *
179
-	 * @param GetPaid_Payment_Form_Submission $submission
180
-	 */
181
-	public function add_taxes( $submission ) {
176
+    /**
177
+     * Adds taxes to a response for submission refresh prices.
178
+     *
179
+     * @param GetPaid_Payment_Form_Submission $submission
180
+     */
181
+    public function add_taxes( $submission ) {
182 182
 
183
-		$taxes = array();
183
+        $taxes = array();
184 184
 
185 185
         foreach ( $submission->get_taxes() as $name => $data ) {
186
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
-		}
186
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
+        }
188 188
 
189
-		$this->response = array_merge(
190
-			$this->response,
191
-			array( 'taxes' => $taxes )
192
-		);
189
+        $this->response = array_merge(
190
+            $this->response,
191
+            array( 'taxes' => $taxes )
192
+        );
193 193
 
194
-	}
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 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
  * Payment form submission refresh prices class
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31
-            'is_free'       => ! $submission->should_collect_payment_details(),
31
+            'is_free'       => !$submission->should_collect_payment_details(),
32 32
 		);
33 33
 
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
34
+		$this->add_totals($submission);
35
+		$this->add_texts($submission);
36
+		$this->add_items($submission);
37
+		$this->add_fees($submission);
38
+		$this->add_discounts($submission);
39
+		$this->add_taxes($submission);
40 40
 
41 41
 	}
42 42
 
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param GetPaid_Payment_Form_Submission $submission
47 47
 	 */
48
-	public function add_totals( $submission ) {
48
+	public function add_totals($submission) {
49 49
 
50 50
 		$this->response = array_merge(
51 51
 			$this->response,
52 52
 			array(
53 53
 
54 54
 				'totals'        => array(
55
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
57
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
58
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
59
-					'total'     => $submission->format_amount( $submission->get_total() ),
55
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
56
+					'discount'  => $submission->format_amount($submission->get_discount()),
57
+					'fees'      => $submission->format_amount($submission->get_fee()),
58
+					'tax'       => $submission->format_amount($submission->get_tax()),
59
+					'total'     => $submission->format_amount($submission->get_total()),
60 60
 				),
61 61
 	
62 62
 				'recurring'     => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
63
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
64
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
65
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
66
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
67
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
68 68
 				),
69 69
 
70 70
 			)
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @param GetPaid_Payment_Form_Submission $submission
79 79
 	 */
80
-	public function add_texts( $submission ) {
80
+	public function add_texts($submission) {
81 81
 
82
-		$payable = $submission->format_amount( $submission->get_total() );
82
+		$payable = $submission->format_amount($submission->get_total());
83 83
 
84
-		if ( $submission->has_recurring != 0 ) {
84
+		if ($submission->has_recurring != 0) {
85 85
 
86
-			$recurring = new WPInv_Item( $submission->has_recurring );
87
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
86
+			$recurring = new WPInv_Item($submission->has_recurring);
87
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
88 88
 
89
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
89
+			if ($submission->get_total() == $submission->get_recurring_total()) {
90 90
 				$payable = "$payable / $period";
91 91
 			} else {
92 92
 				$payable = sprintf(
93
-					__( '%1$s (renews at %2$s / %3$s)'),
94
-					$submission->format_amount( $submission->get_total() ),
95
-					$submission->format_amount( $submission->get_recurring_total() ),
93
+					__('%1$s (renews at %2$s / %3$s)'),
94
+					$submission->format_amount($submission->get_total()),
95
+					$submission->format_amount($submission->get_recurring_total()),
96 96
 					$period
97 97
 				);
98 98
 			}
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 			'.getpaid-checkout-total-payable' => $payable,
104 104
 		);
105 105
 
106
-		foreach ( $submission->get_items() as $item_id => $item ) {
107
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
106
+		foreach ($submission->get_items() as $item_id => $item) {
107
+			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount($item->get_sub_total());
108
+			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount($item->get_recurring_sub_total());
109 109
 		}
110 110
 
111
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
111
+		$this->response = array_merge($this->response, array('texts' => $texts));
112 112
 
113 113
 	}
114 114
 
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param GetPaid_Payment_Form_Submission $submission
119 119
 	 */
120
-	public function add_items( $submission ) {
120
+	public function add_items($submission) {
121 121
 
122 122
 		// Add items.
123 123
 		$items = array();
124 124
 
125
-        foreach ( $submission->get_items() as $item_id => $item ) {
126
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
125
+        foreach ($submission->get_items() as $item_id => $item) {
126
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
127 127
 		}
128 128
 
129 129
 		$this->response = array_merge(
130 130
 			$this->response,
131
-			array( 'items' => $items )
131
+			array('items' => $items)
132 132
 		);
133 133
 
134 134
 	}
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @param GetPaid_Payment_Form_Submission $submission
140 140
 	 */
141
-	public function add_fees( $submission ) {
141
+	public function add_fees($submission) {
142 142
 
143 143
 		$fees = array();
144 144
 
145
-        foreach ( $submission->get_fees() as $name => $data ) {
146
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
145
+        foreach ($submission->get_fees() as $name => $data) {
146
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
147 147
 		}
148 148
 
149 149
 		$this->response = array_merge(
150 150
 			$this->response,
151
-			array( 'fees' => $fees )
151
+			array('fees' => $fees)
152 152
 		);
153 153
 
154 154
 	}
@@ -158,17 +158,17 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @param GetPaid_Payment_Form_Submission $submission
160 160
 	 */
161
-	public function add_discounts( $submission ) {
161
+	public function add_discounts($submission) {
162 162
 
163 163
 		$discounts = array();
164 164
 
165
-        foreach ( $submission->get_discounts() as $name => $data ) {
166
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
165
+        foreach ($submission->get_discounts() as $name => $data) {
166
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
167 167
 		}
168 168
 
169 169
 		$this->response = array_merge(
170 170
 			$this->response,
171
-			array( 'discounts' => $discounts )
171
+			array('discounts' => $discounts)
172 172
 		);
173 173
 
174 174
 	}
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @param GetPaid_Payment_Form_Submission $submission
180 180
 	 */
181
-	public function add_taxes( $submission ) {
181
+	public function add_taxes($submission) {
182 182
 
183 183
 		$taxes = array();
184 184
 
185
-        foreach ( $submission->get_taxes() as $name => $data ) {
186
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
185
+        foreach ($submission->get_taxes() as $name => $data) {
186
+			$taxes[$name] = $submission->format_amount($data['initial_tax']);
187 187
 		}
188 188
 
189 189
 		$this->response = array_merge(
190 190
 			$this->response,
191
-			array( 'taxes' => $taxes )
191
+			array('taxes' => $taxes)
192 192
 		);
193 193
 
194 194
 	}
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -12,170 +12,170 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
43
-
44
-		// Save the invoice.
45
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving( $invoice );
43
+
44
+        // Save the invoice.
45
+        $invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48
-		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
50
-	}
48
+        // Send to the gateway.
49
+        $this->post_process_submission( $invoice, $prepared );
50
+    }
51 51
 
52
-	/**
53
-	 * Validates the submission.
54
-	 *
55
-	 */
56
-	protected function validate_submission() {
52
+    /**
53
+     * Validates the submission.
54
+     *
55
+     */
56
+    protected function validate_submission() {
57 57
 
58
-		$submission = $this->payment_form_submission;
59
-		$data       = $submission->get_data();
58
+        $submission = $this->payment_form_submission;
59
+        $data       = $submission->get_data();
60 60
 
61
-		// Do we have an error?
61
+        // Do we have an error?
62 62
         if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
63
+            wp_send_json_error( $submission->last_error );
64 64
         }
65 65
 
66
-		// We need a billing email.
66
+        // We need a billing email.
67 67
         if ( ! $submission->has_billing_email() ) {
68 68
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
69
-		}
69
+        }
70 70
 
71
-		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
74
-		}
71
+        // Non-recurring gateways should not be allowed to process recurring invoices.
72
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
74
+        }
75 75
 
76
-		// Ensure the gateway is active.
77
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
-		}
76
+        // Ensure the gateway is active.
77
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
+        }
80 80
 
81
-		// Clear any existing errors.
82
-		wpinv_clear_errors();
81
+        // Clear any existing errors.
82
+        wpinv_clear_errors();
83 83
 
84
-		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
84
+        // Allow themes and plugins to hook to errors
85
+        do_action( 'getpaid_checkout_error_checks', $submission );
86 86
 
87
-		// Do we have any errors?
87
+        // Do we have any errors?
88 88
         if ( wpinv_get_errors() ) {
89 89
             wp_send_json_error( getpaid_get_errors_html() );
90
-		}
90
+        }
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves submission items.
96
-	 *
97
-	 * @return GetPaid_Form_Item[]
98
-	 */
99
-	protected function get_submission_items() {
94
+    /**
95
+     * Retrieves submission items.
96
+     *
97
+     * @return GetPaid_Form_Item[]
98
+     */
99
+    protected function get_submission_items() {
100 100
 
101
-		$items = $this->payment_form_submission->get_items();
101
+        $items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104 104
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
105 105
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
106
-		}
107
-
108
-		return $items;
109
-	}
110
-
111
-	/**
112
-	 * Retrieves submission invoice.
113
-	 *
114
-	 * @return WPInv_Invoice
115
-	 */
116
-	protected function get_submission_invoice() {
117
-		$submission = $this->payment_form_submission;
118
-
119
-		if ( ! $submission->has_invoice() ) {
120
-			$invoice = new WPInv_Invoice();
121
-			$invoice->created_via( 'payment_form' );
122
-			return $invoice;
123 106
         }
124 107
 
125
-		$invoice = $submission->get_invoice();
108
+        return $items;
109
+    }
110
+
111
+    /**
112
+     * Retrieves submission invoice.
113
+     *
114
+     * @return WPInv_Invoice
115
+     */
116
+    protected function get_submission_invoice() {
117
+        $submission = $this->payment_form_submission;
126 118
 
127
-		// Make sure that it is neither paid or refunded.
128
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
129
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
130
-		}
119
+        if ( ! $submission->has_invoice() ) {
120
+            $invoice = new WPInv_Invoice();
121
+            $invoice->created_via( 'payment_form' );
122
+            return $invoice;
123
+        }
131 124
 
132
-		return $invoice;
133
-	}
125
+        $invoice = $submission->get_invoice();
134 126
 
135
-	/**
136
-	 * Processes the submission invoice.
137
-	 *
138
-	 * @param WPInv_Invoice $invoice
139
-	 * @param GetPaid_Form_Item[] $items
140
-	 * @return WPInv_Invoice
141
-	 */
142
-	protected function process_submission_invoice( $invoice, $items ) {
127
+        // Make sure that it is neither paid or refunded.
128
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
129
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
130
+        }
143 131
 
144
-		$submission = $this->payment_form_submission;
145
-		$data       = $submission->get_data();
132
+        return $invoice;
133
+    }
146 134
 
147
-		// Set-up the invoice details.
148
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
149
-		$invoice->set_user_id( $this->get_submission_customer() );
150
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
135
+    /**
136
+     * Processes the submission invoice.
137
+     *
138
+     * @param WPInv_Invoice $invoice
139
+     * @param GetPaid_Form_Item[] $items
140
+     * @return WPInv_Invoice
141
+     */
142
+    protected function process_submission_invoice( $invoice, $items ) {
143
+
144
+        $submission = $this->payment_form_submission;
145
+        $data       = $submission->get_data();
146
+
147
+        // Set-up the invoice details.
148
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
149
+        $invoice->set_user_id( $this->get_submission_customer() );
150
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151 151
         $invoice->set_items( $items );
152 152
         $invoice->set_fees( $submission->get_fees() );
153 153
         $invoice->set_taxes( $submission->get_taxes() );
154
-		$invoice->set_discounts( $submission->get_discounts() );
155
-		$invoice->set_gateway( $data['wpi-gateway'] );
154
+        $invoice->set_discounts( $submission->get_discounts() );
155
+        $invoice->set_gateway( $data['wpi-gateway'] );
156 156
 
157
-		if ( $submission->has_discount_code() ) {
157
+        if ( $submission->has_discount_code() ) {
158 158
             $invoice->set_discount_code( $submission->get_discount_code() );
159
-		}
160
-
161
-		getpaid_maybe_add_default_address( $invoice );
162
-		return $invoice;
163
-	}
164
-
165
-	/**
166
-	 * Retrieves the submission's customer.
167
-	 *
168
-	 * @return int The customer id.
169
-	 */
170
-	protected function get_submission_customer() {
171
-		$submission = $this->payment_form_submission;
172
-
173
-		// If this is an existing invoice...
174
-		if ( $submission->has_invoice() ) {
175
-			return $submission->get_invoice()->get_user_id();
176
-		}
177
-
178
-		// (Maybe) create the user.
159
+        }
160
+
161
+        getpaid_maybe_add_default_address( $invoice );
162
+        return $invoice;
163
+    }
164
+
165
+    /**
166
+     * Retrieves the submission's customer.
167
+     *
168
+     * @return int The customer id.
169
+     */
170
+    protected function get_submission_customer() {
171
+        $submission = $this->payment_form_submission;
172
+
173
+        // If this is an existing invoice...
174
+        if ( $submission->has_invoice() ) {
175
+            return $submission->get_invoice()->get_user_id();
176
+        }
177
+
178
+        // (Maybe) create the user.
179 179
         $user = get_current_user_id();
180 180
 
181 181
         if ( empty( $user ) ) {
@@ -192,31 +192,31 @@  discard block
 block discarded – undo
192 192
 
193 193
         if ( is_numeric( $user ) ) {
194 194
             return $user;
195
-		}
195
+        }
196 196
 
197
-		return $user->ID;
197
+        return $user->ID;
198 198
 
199
-	}
199
+    }
200 200
 
201
-	/**
201
+    /**
202 202
      * Prepares submission data for saving to the database.
203 203
      *
204
-	 * @param WPInv_Invoice $invoice
204
+     * @param WPInv_Invoice $invoice
205 205
      */
206 206
     public function prepare_submission_data_for_saving( &$invoice ) {
207 207
 
208
-		$submission = $this->payment_form_submission;
208
+        $submission = $this->payment_form_submission;
209 209
 
210
-		// Prepared submission details.
210
+        // Prepared submission details.
211 211
         $prepared = array();
212 212
 
213 213
         // Raw submission details.
214
-		$data = $submission->get_data();
214
+        $data = $submission->get_data();
215 215
 		
216
-		// Loop throught the submitted details.
216
+        // Loop throught the submitted details.
217 217
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
218 218
 
219
-			// Skip premade fields.
219
+            // Skip premade fields.
220 220
             if ( ! empty( $field['premade'] ) ) {
221 221
                 continue;
222 222
             }
@@ -259,21 +259,21 @@  discard block
 block discarded – undo
259 259
                 $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
260 260
             }
261 261
 
262
-		}
262
+        }
263 263
 		
264
-		return $prepared;
264
+        return $prepared;
265 265
 
266
-	}
266
+    }
267 267
 
268
-	/**
269
-	 * Confirms the submission is valid and send users to the gateway.
270
-	 *
271
-	 * @param WPInv_Invoice $invoice
272
-	 * @param array $prepared_payment_form_data
273
-	 */
274
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
268
+    /**
269
+     * Confirms the submission is valid and send users to the gateway.
270
+     *
271
+     * @param WPInv_Invoice $invoice
272
+     * @param array $prepared_payment_form_data
273
+     */
274
+    protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
275 275
 
276
-		// Ensure the invoice exists.
276
+        // Ensure the invoice exists.
277 277
         if ( ! $invoice->exists() ) {
278 278
             wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
279 279
         }
@@ -281,65 +281,65 @@  discard block
 block discarded – undo
281 281
         // Save payment form data.
282 282
         if ( ! empty( $prepared_payment_form_data ) ) {
283 283
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
284
-		}
284
+        }
285 285
 
286
-		// Backwards compatibility.
286
+        // Backwards compatibility.
287 287
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
288 288
 
289
-		$this->process_payment( $invoice );
289
+        $this->process_payment( $invoice );
290 290
 
291 291
         // If we are here, there was an error.
292
-		wpinv_send_back_to_checkout();
292
+        wpinv_send_back_to_checkout();
293 293
 
294
-	}
294
+    }
295 295
 
296
-	/**
297
-	 * Processes the actual payment.
298
-	 *
299
-	 * @param WPInv_Invoice $invoice
300
-	 */
301
-	protected function process_payment( $invoice ) {
296
+    /**
297
+     * Processes the actual payment.
298
+     *
299
+     * @param WPInv_Invoice $invoice
300
+     */
301
+    protected function process_payment( $invoice ) {
302 302
 
303
-		$submission = $this->payment_form_submission;
303
+        $submission = $this->payment_form_submission;
304 304
 
305
-		// No need to send free invoices to the gateway.
306
-		if ( $invoice->is_free() ) {
307
-			$invoice->set_gateway( 'none' );
308
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
309
-			$invoice->mark_paid();
310
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
311
-		}
305
+        // No need to send free invoices to the gateway.
306
+        if ( $invoice->is_free() ) {
307
+            $invoice->set_gateway( 'none' );
308
+            $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
309
+            $invoice->mark_paid();
310
+            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
311
+        }
312 312
 
313
-		// Clear any checkout errors.
314
-		wpinv_clear_errors();
313
+        // Clear any checkout errors.
314
+        wpinv_clear_errors();
315 315
 
316
-		// Fires before sending to the gateway.
317
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
316
+        // Fires before sending to the gateway.
317
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
318 318
 
319
-		// Allow the sumission data to be modified before it is sent to the gateway.
320
-		$submission_data    = $submission->get_data();
321
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
322
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
319
+        // Allow the sumission data to be modified before it is sent to the gateway.
320
+        $submission_data    = $submission->get_data();
321
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
322
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
323 323
 
324
-		// Validate the currency.
325
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
326
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
327
-		}
324
+        // Validate the currency.
325
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
326
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
327
+        }
328 328
 
329
-		// Check to see if we have any errors.
330
-		if ( wpinv_get_errors() ) {
331
-			wpinv_send_back_to_checkout();
332
-		}
329
+        // Check to see if we have any errors.
330
+        if ( wpinv_get_errors() ) {
331
+            wpinv_send_back_to_checkout();
332
+        }
333 333
 
334
-		// Send info to the gateway for payment processing
335
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
334
+        // Send info to the gateway for payment processing
335
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
336 336
 
337
-		// Backwards compatibility.
338
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
337
+        // Backwards compatibility.
338
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
339 339
 
340
-	}
340
+    }
341 341
 
342
-	/**
342
+    /**
343 343
      * Sends a redrect response to payment details.
344 344
      *
345 345
      */
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 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
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42
+		$prepared   = $this->prepare_submission_data_for_saving($invoice);
43 43
 
44 44
 		// Save the invoice.
45 45
 		$invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48 48
 		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
49
+		$this->post_process_submission($invoice, $prepared);
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,34 +59,34 @@  discard block
 block discarded – undo
59 59
 		$data       = $submission->get_data();
60 60
 
61 61
 		// Do we have an error?
62
-        if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
62
+        if (!empty($submission->last_error)) {
63
+			wp_send_json_error($submission->last_error);
64 64
         }
65 65
 
66 66
 		// We need a billing email.
67
-        if ( ! $submission->has_billing_email() ) {
68
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
67
+        if (!$submission->has_billing_email()) {
68
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
69 69
 		}
70 70
 
71 71
 		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
72
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
73
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
74 74
 		}
75 75
 
76 76
 		// Ensure the gateway is active.
77
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
77
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
78
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
79 79
 		}
80 80
 
81 81
 		// Clear any existing errors.
82 82
 		wpinv_clear_errors();
83 83
 
84 84
 		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
85
+		do_action('getpaid_checkout_error_checks', $submission);
86 86
 
87 87
 		// Do we have any errors?
88
-        if ( wpinv_get_errors() ) {
89
-            wp_send_json_error( getpaid_get_errors_html() );
88
+        if (wpinv_get_errors()) {
89
+            wp_send_json_error(getpaid_get_errors_html());
90 90
 		}
91 91
 
92 92
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
105
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
104
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
105
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
106 106
 		}
107 107
 
108 108
 		return $items;
@@ -116,17 +116,17 @@  discard block
 block discarded – undo
116 116
 	protected function get_submission_invoice() {
117 117
 		$submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
119
+		if (!$submission->has_invoice()) {
120 120
 			$invoice = new WPInv_Invoice();
121
-			$invoice->created_via( 'payment_form' );
121
+			$invoice->created_via('payment_form');
122 122
 			return $invoice;
123 123
         }
124 124
 
125 125
 		$invoice = $submission->get_invoice();
126 126
 
127 127
 		// Make sure that it is neither paid or refunded.
128
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
129
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
129
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
130 130
 		}
131 131
 
132 132
 		return $invoice;
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 	 * @param GetPaid_Form_Item[] $items
140 140
 	 * @return WPInv_Invoice
141 141
 	 */
142
-	protected function process_submission_invoice( $invoice, $items ) {
142
+	protected function process_submission_invoice($invoice, $items) {
143 143
 
144 144
 		$submission = $this->payment_form_submission;
145 145
 		$data       = $submission->get_data();
146 146
 
147 147
 		// Set-up the invoice details.
148
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
149
-		$invoice->set_user_id( $this->get_submission_customer() );
150
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151
-        $invoice->set_items( $items );
152
-        $invoice->set_fees( $submission->get_fees() );
153
-        $invoice->set_taxes( $submission->get_taxes() );
154
-		$invoice->set_discounts( $submission->get_discounts() );
155
-		$invoice->set_gateway( $data['wpi-gateway'] );
156
-
157
-		if ( $submission->has_discount_code() ) {
158
-            $invoice->set_discount_code( $submission->get_discount_code() );
148
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
149
+		$invoice->set_user_id($this->get_submission_customer());
150
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
151
+        $invoice->set_items($items);
152
+        $invoice->set_fees($submission->get_fees());
153
+        $invoice->set_taxes($submission->get_taxes());
154
+		$invoice->set_discounts($submission->get_discounts());
155
+		$invoice->set_gateway($data['wpi-gateway']);
156
+
157
+		if ($submission->has_discount_code()) {
158
+            $invoice->set_discount_code($submission->get_discount_code());
159 159
 		}
160 160
 
161
-		getpaid_maybe_add_default_address( $invoice );
161
+		getpaid_maybe_add_default_address($invoice);
162 162
 		return $invoice;
163 163
 	}
164 164
 
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 		$submission = $this->payment_form_submission;
172 172
 
173 173
 		// If this is an existing invoice...
174
-		if ( $submission->has_invoice() ) {
174
+		if ($submission->has_invoice()) {
175 175
 			return $submission->get_invoice()->get_user_id();
176 176
 		}
177 177
 
178 178
 		// (Maybe) create the user.
179 179
         $user = get_current_user_id();
180 180
 
181
-        if ( empty( $user ) ) {
182
-            $user = get_user_by( 'email', $submission->get_billing_email() );
181
+        if (empty($user)) {
182
+            $user = get_user_by('email', $submission->get_billing_email());
183 183
         }
184 184
 
185
-        if ( empty( $user ) ) {
186
-            $user = wpinv_create_user( $submission->get_billing_email() );
185
+        if (empty($user)) {
186
+            $user = wpinv_create_user($submission->get_billing_email());
187 187
         }
188 188
 
189
-        if ( is_wp_error( $user ) ) {
190
-            wp_send_json_error( $user->get_error_message() );
189
+        if (is_wp_error($user)) {
190
+            wp_send_json_error($user->get_error_message());
191 191
         }
192 192
 
193
-        if ( is_numeric( $user ) ) {
193
+        if (is_numeric($user)) {
194 194
             return $user;
195 195
 		}
196 196
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
 	 * @param WPInv_Invoice $invoice
205 205
      */
206
-    public function prepare_submission_data_for_saving( &$invoice ) {
206
+    public function prepare_submission_data_for_saving(&$invoice) {
207 207
 
208 208
 		$submission = $this->payment_form_submission;
209 209
 
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 		$data = $submission->get_data();
215 215
 		
216 216
 		// Loop throught the submitted details.
217
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
217
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
218 218
 
219 219
 			// Skip premade fields.
220
-            if ( ! empty( $field['premade'] ) ) {
220
+            if (!empty($field['premade'])) {
221 221
                 continue;
222 222
             }
223 223
 
224 224
             // If it is required and not set, abort.
225
-            if ( ! $submission->is_required_field_set( $field ) ) {
226
-                wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
225
+            if (!$submission->is_required_field_set($field)) {
226
+                wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
227 227
             }
228 228
 
229 229
             // Handle address fields.
230
-            if ( $field['type'] == 'address' ) {
230
+            if ($field['type'] == 'address') {
231 231
 
232
-                foreach ( $field['fields'] as $address_field ) {
232
+                foreach ($field['fields'] as $address_field) {
233 233
 
234 234
                     // skip if it is not visible.
235
-                    if ( empty( $address_field['visible'] ) ) {
235
+                    if (empty($address_field['visible'])) {
236 236
                         continue;
237 237
                     }
238 238
 
239 239
                     // If it is required and not set, abort
240
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
241
-                        wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
240
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
241
+                        wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
242 242
                     }
243 243
 
244
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
245
-                        $name   = str_replace( 'wpinv_', '', $address_field['name'] );
244
+                    if (isset($data[$address_field['name']])) {
245
+                        $name   = str_replace('wpinv_', '', $address_field['name']);
246 246
                         $method = "set_$name";
247
-                        $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) );
247
+                        $invoice->$method(wpinv_clean($data[$address_field['name']]));
248 248
                     }
249 249
 
250 250
                 }
251 251
 
252
-            } else if ( isset( $data[ $field['id'] ] ) ) {
252
+            } else if (isset($data[$field['id']])) {
253 253
                 $label = $field['id'];
254 254
 
255
-                if ( isset( $field['label'] ) ) {
255
+                if (isset($field['label'])) {
256 256
                     $label = $field['label'];
257 257
                 }
258 258
 
259
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
259
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
260 260
             }
261 261
 
262 262
 		}
@@ -271,22 +271,22 @@  discard block
 block discarded – undo
271 271
 	 * @param WPInv_Invoice $invoice
272 272
 	 * @param array $prepared_payment_form_data
273 273
 	 */
274
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
274
+	protected function post_process_submission($invoice, $prepared_payment_form_data) {
275 275
 
276 276
 		// Ensure the invoice exists.
277
-        if ( ! $invoice->exists() ) {
278
-            wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
277
+        if (!$invoice->exists()) {
278
+            wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing'));
279 279
         }
280 280
 
281 281
         // Save payment form data.
282
-        if ( ! empty( $prepared_payment_form_data ) ) {
283
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
282
+        if (!empty($prepared_payment_form_data)) {
283
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
284 284
 		}
285 285
 
286 286
 		// Backwards compatibility.
287
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
287
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
288 288
 
289
-		$this->process_payment( $invoice );
289
+		$this->process_payment($invoice);
290 290
 
291 291
         // If we are here, there was an error.
292 292
 		wpinv_send_back_to_checkout();
@@ -298,44 +298,44 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @param WPInv_Invoice $invoice
300 300
 	 */
301
-	protected function process_payment( $invoice ) {
301
+	protected function process_payment($invoice) {
302 302
 
303 303
 		$submission = $this->payment_form_submission;
304 304
 
305 305
 		// No need to send free invoices to the gateway.
306
-		if ( $invoice->is_free() ) {
307
-			$invoice->set_gateway( 'none' );
308
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
306
+		if ($invoice->is_free()) {
307
+			$invoice->set_gateway('none');
308
+			$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
309 309
 			$invoice->mark_paid();
310
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
310
+			wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
311 311
 		}
312 312
 
313 313
 		// Clear any checkout errors.
314 314
 		wpinv_clear_errors();
315 315
 
316 316
 		// Fires before sending to the gateway.
317
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
317
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
318 318
 
319 319
 		// Allow the sumission data to be modified before it is sent to the gateway.
320 320
 		$submission_data    = $submission->get_data();
321
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
322
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
321
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
322
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
323 323
 
324 324
 		// Validate the currency.
325
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
326
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
325
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
326
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing'));
327 327
 		}
328 328
 
329 329
 		// Check to see if we have any errors.
330
-		if ( wpinv_get_errors() ) {
330
+		if (wpinv_get_errors()) {
331 331
 			wpinv_send_back_to_checkout();
332 332
 		}
333 333
 
334 334
 		// Send info to the gateway for payment processing
335
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
335
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
336 336
 
337 337
 		// Backwards compatibility.
338
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
338
+		wpinv_send_to_gateway($submission_gateway, $invoice);
339 339
 
340 340
 	}
341 341
 
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
      * Sends a redrect response to payment details.
344 344
      *
345 345
      */
346
-    public function send_redirect_response( $url ) {
347
-        $url = urlencode( $url );
348
-        wp_send_json_success( $url );
346
+    public function send_redirect_response($url) {
347
+        $url = urlencode($url);
348
+        wp_send_json_success($url);
349 349
     }
350 350
 
351 351
 }
Please login to merge, or discard this patch.