@@ -4,7 +4,7 @@ discard block |
||
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 |
@@ -23,18 +23,18 @@ discard block |
||
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 | // Validate VAT number. |
29 | - $this->validate_vat( $submission ); |
|
29 | + $this->validate_vat($submission); |
|
30 | 30 | |
31 | - foreach ( $submission->get_items() as $item ) { |
|
32 | - $this->process_item_tax( $item, $submission ); |
|
31 | + foreach ($submission->get_items() as $item) { |
|
32 | + $this->process_item_tax($item, $submission); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // Process any existing invoice taxes. |
36 | - if ( $submission->has_invoice() ) { |
|
37 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
36 | + if ($submission->has_invoice()) { |
|
37 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | } |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | * @param GetPaid_Form_Item $item |
47 | 47 | * @param GetPaid_Payment_Form_Submission $submission |
48 | 48 | */ |
49 | - public function process_item_tax( $item, $submission ) { |
|
49 | + public function process_item_tax($item, $submission) { |
|
50 | 50 | |
51 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
52 | - $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
53 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
51 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
52 | + $taxes = getpaid_calculate_item_taxes($item->get_sub_total(), $rates); |
|
53 | + $r_taxes = getpaid_calculate_item_taxes($item->get_recurring_sub_total(), $rates); |
|
54 | 54 | |
55 | - foreach ( $taxes as $name => $amount ) { |
|
56 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
57 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
55 | + foreach ($taxes as $name => $amount) { |
|
56 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
57 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
58 | 58 | |
59 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
60 | - $this->taxes[ $name ] = $tax; |
|
59 | + if (!isset($this->taxes[$name])) { |
|
60 | + $this->taxes[$name] = $tax; |
|
61 | 61 | continue; |
62 | 62 | } |
63 | 63 | |
64 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
65 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
64 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
65 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @since 1.0.19 |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function has_digital_item( $submission ) { |
|
78 | + public function has_digital_item($submission) { |
|
79 | 79 | |
80 | - foreach ( $submission->get_items() as $item ) { |
|
80 | + foreach ($submission->get_items() as $item) { |
|
81 | 81 | |
82 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
82 | + if ('digital' == $item->get_vat_rule()) { |
|
83 | 83 | return true; |
84 | 84 | } |
85 | 85 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return bool |
96 | 96 | */ |
97 | 97 | public function is_eu_store() { |
98 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
98 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @since 1.0.19 |
106 | 106 | * @return bool |
107 | 107 | */ |
108 | - public function is_eu_country( $country ) { |
|
109 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
108 | + public function is_eu_country($country) { |
|
109 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @since 1.0.19 |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public function is_eu_transaction( $customer_country ) { |
|
120 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
119 | + public function is_eu_transaction($customer_country) { |
|
120 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | * @since 1.0.19 |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - public function get_vat_number( $submission ) { |
|
130 | + public function get_vat_number($submission) { |
|
131 | 131 | |
132 | 132 | // Retrieve from the posted number. |
133 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
134 | - if ( ! empty( $vat_number ) ) { |
|
135 | - return wpinv_clean( $vat_number ); |
|
133 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
134 | + if (!empty($vat_number)) { |
|
135 | + return wpinv_clean($vat_number); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Retrieve from the invoice. |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @since 1.0.19 |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function get_company( $submission ) { |
|
149 | + public function get_company($submission) { |
|
150 | 150 | |
151 | 151 | // Retrieve from the posted data. |
152 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
153 | - if ( ! empty( $company ) ) { |
|
154 | - return wpinv_clean( $company ); |
|
152 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
153 | + if (!empty($company)) { |
|
154 | + return wpinv_clean($company); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | // Retrieve from the invoice. |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | * @since 1.0.19 |
167 | 167 | * @return string |
168 | 168 | */ |
169 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
169 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
170 | 170 | |
171 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
172 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
171 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
172 | + $prevent_b2c = !empty($prevent_b2c); |
|
173 | 173 | $is_eu = $ip_in_eu || $country_in_eu; |
174 | 174 | |
175 | 175 | return $prevent_b2c && $is_eu; |
@@ -181,30 +181,30 @@ discard block |
||
181 | 181 | * @param GetPaid_Payment_Form_Submission $submission |
182 | 182 | * @since 1.0.19 |
183 | 183 | */ |
184 | - public function validate_vat( $submission ) { |
|
184 | + public function validate_vat($submission) { |
|
185 | 185 | |
186 | - $has_digital = $this->has_digital_item( $submission ); |
|
187 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
186 | + $has_digital = $this->has_digital_item($submission); |
|
187 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
188 | 188 | |
189 | 189 | // Abort if we are not validating vat numbers. |
190 | - if ( ! $has_digital && ! $in_eu ) { |
|
190 | + if (!$has_digital && !$in_eu) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Prepare variables. |
195 | - $vat_number = $this->get_vat_number( $submission ); |
|
196 | - $company = $this->get_company( $submission ); |
|
195 | + $vat_number = $this->get_vat_number($submission); |
|
196 | + $company = $this->get_company($submission); |
|
197 | 197 | $ip_country = getpaid_get_ip_country(); |
198 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
199 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
198 | + $is_eu = $this->is_eu_country($submission->country); |
|
199 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
200 | 200 | |
201 | 201 | // If we're preventing business to consumer purchases, ensure |
202 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
202 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
203 | 203 | |
204 | 204 | // Ensure that a vat number has been specified. |
205 | 205 | throw new Exception( |
206 | 206 | wp_sprintf( |
207 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
207 | + __('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'), |
|
208 | 208 | getpaid_vat_name() |
209 | 209 | ) |
210 | 210 | ); |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
215 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
215 | + if (!$is_eu || !$in_eu || empty($vat_number)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | |
219 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
219 | + $is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country); |
|
220 | 220 | |
221 | - if ( is_string( $is_valid ) ) { |
|
222 | - throw new Exception( $is_valid ); |
|
221 | + if (is_string($is_valid)) { |
|
222 | + throw new Exception($is_valid); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $this->state = wpinv_get_default_state(); |
135 | 135 | |
136 | 136 | // Do we have an actual submission? |
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
138 | + $this->load_data($_POST); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $data |
147 | 147 | */ |
148 | - public function load_data( $data ) { |
|
148 | + public function load_data($data) { |
|
149 | 149 | |
150 | 150 | // Remove slashes from the submitted data... |
151 | - $data = wp_unslash( $data ); |
|
151 | + $data = wp_unslash($data); |
|
152 | 152 | |
153 | 153 | // Allow plugins to filter the data. |
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
155 | 155 | |
156 | 156 | // Cache it... |
157 | 157 | $this->data = $data; |
158 | 158 | |
159 | 159 | // Then generate a unique id from the data. |
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
160 | + $this->id = md5(wp_json_encode($data)); |
|
161 | 161 | |
162 | 162 | // Finally, process the submission. |
163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
167 | 167 | $processors = apply_filters( |
168 | 168 | 'getpaid_payment_form_submission_processors', |
169 | 169 | array( |
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
170 | + array($this, 'process_payment_form'), |
|
171 | + array($this, 'process_invoice'), |
|
172 | + array($this, 'process_fees'), |
|
173 | + array($this, 'process_items'), |
|
174 | + array($this, 'process_taxes'), |
|
175 | + array($this, 'process_discount'), |
|
176 | 176 | ), |
177 | 177 | $this |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
180 | + foreach ($processors as $processor) { |
|
181 | + call_user_func_array($processor, array(&$this)); |
|
182 | 182 | } |
183 | 183 | |
184 | - } catch ( Exception $e ) { |
|
184 | + } catch (Exception $e) { |
|
185 | 185 | $this->last_error = $e->getMessage(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Fired when we are done processing a submission. |
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | public function process_payment_form() { |
208 | 208 | |
209 | 209 | // Every submission needs an active payment form. |
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
210 | + if (empty($this->data['form_id'])) { |
|
211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // Fetch the payment form. |
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
217 | + if (!$this->payment_form->is_active()) { |
|
218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
248 | 248 | public function process_invoice() { |
249 | 249 | |
250 | 250 | // Abort if there is no invoice. |
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
251 | + if (empty($this->data['invoice_id'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
256 | 256 | // and that it is not paid for. |
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
258 | 258 | |
259 | - if ( empty( $invoice ) ) { |
|
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
259 | + if (empty($invoice)) { |
|
260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
263 | + if ($invoice->is_paid()) { |
|
264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
267 | + $this->payment_form->set_items($invoice->get_items()); |
|
268 | 268 | $this->payment_form->invoice = $invoice; |
269 | 269 | |
270 | 270 | $this->country = $invoice->get_country(); |
271 | 271 | $this->state = $invoice->get_state(); |
272 | 272 | $this->invoice = $invoice; |
273 | 273 | |
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | public function has_invoice() { |
294 | - return ! empty( $this->invoice ); |
|
294 | + return !empty($this->invoice); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function process_items() { |
312 | 312 | |
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
314 | 314 | |
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
315 | + foreach ($processor->items as $item) { |
|
316 | + $this->add_item($item); |
|
317 | 317 | } |
318 | 318 | |
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | * @since 1.0.19 |
326 | 326 | * @param GetPaid_Form_Item $item |
327 | 327 | */ |
328 | - public function add_item( $item ) { |
|
328 | + public function add_item($item) { |
|
329 | 329 | |
330 | 330 | // Make sure that it is available for purchase. |
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
331 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Each submission can only contain one recurring item. |
336 | - if ( $item->is_recurring() ) { |
|
336 | + if ($item->is_recurring()) { |
|
337 | 337 | |
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
338 | + if ($this->has_recurring != 0) { |
|
339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | // Update the items and totals. |
347 | - $this->items[ $item->get_id() ] = $item; |
|
347 | + $this->items[$item->get_id()] = $item; |
|
348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function remove_item( $item_id ) { |
|
361 | + public function remove_item($item_id) { |
|
362 | 362 | |
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
363 | + if (isset($this->items[$item_id])) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
366 | 366 | |
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
367 | + if ($this->items[$item_id]->is_recurring()) { |
|
368 | 368 | $this->has_recurring = 0; |
369 | 369 | } |
370 | 370 | |
371 | - unset( $this->items[ $item_id ] ); |
|
371 | + unset($this->items[$item_id]); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | */ |
381 | 381 | public function get_subtotal() { |
382 | 382 | |
383 | - if ( wpinv_prices_include_tax() ) { |
|
383 | + if (wpinv_prices_include_tax()) { |
|
384 | 384 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
385 | 385 | } |
386 | 386 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function get_recurring_subtotal() { |
396 | 396 | |
397 | - if ( wpinv_prices_include_tax() ) { |
|
397 | + if (wpinv_prices_include_tax()) { |
|
398 | 398 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
399 | 399 | } |
400 | 400 | |
@@ -428,28 +428,28 @@ discard block |
||
428 | 428 | public function process_taxes() { |
429 | 429 | |
430 | 430 | // Abort if we're not using taxes. |
431 | - if ( ! $this->use_taxes() ) { |
|
431 | + if (!$this->use_taxes()) { |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // If a custom country && state has been passed in, use it to calculate taxes. |
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
436 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
437 | + if (!empty($country)) { |
|
438 | 438 | $this->country = $country; |
439 | 439 | } |
440 | 440 | |
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
441 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
442 | + if (!empty($state)) { |
|
443 | 443 | $this->state = $state; |
444 | 444 | } |
445 | 445 | |
446 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
446 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
447 | 447 | |
448 | - foreach ( $processor->taxes as $tax ) { |
|
449 | - $this->add_tax( $tax ); |
|
448 | + foreach ($processor->taxes as $tax) { |
|
449 | + $this->add_tax($tax); |
|
450 | 450 | } |
451 | 451 | |
452 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
452 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -458,16 +458,16 @@ discard block |
||
458 | 458 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
459 | 459 | * @since 1.0.19 |
460 | 460 | */ |
461 | - public function add_tax( $tax ) { |
|
461 | + public function add_tax($tax) { |
|
462 | 462 | |
463 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
464 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
465 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
463 | + if (wpinv_round_tax_per_tax_rate()) { |
|
464 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
465 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
466 | 466 | } |
467 | 467 | |
468 | - $this->taxes[ $tax['name'] ] = $tax; |
|
469 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
470 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
468 | + $this->taxes[$tax['name']] = $tax; |
|
469 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
470 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
471 | 471 | |
472 | 472 | } |
473 | 473 | |
@@ -476,12 +476,12 @@ discard block |
||
476 | 476 | * |
477 | 477 | * @since 1.0.19 |
478 | 478 | */ |
479 | - public function remove_tax( $tax_name ) { |
|
479 | + public function remove_tax($tax_name) { |
|
480 | 480 | |
481 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
482 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
483 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
484 | - unset( $this->taxes[ $tax_name ] ); |
|
481 | + if (isset($this->taxes[$tax_name])) { |
|
482 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
483 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
484 | + unset($this->taxes[$tax_name]); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | } |
@@ -495,11 +495,11 @@ discard block |
||
495 | 495 | |
496 | 496 | $use_taxes = wpinv_use_taxes(); |
497 | 497 | |
498 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
498 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
499 | 499 | $use_taxes = false; |
500 | 500 | } |
501 | 501 | |
502 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
502 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
503 | 503 | |
504 | 504 | } |
505 | 505 | |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | |
549 | 549 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
550 | 550 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
551 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
551 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
552 | 552 | |
553 | - foreach ( $processor->discounts as $discount ) { |
|
554 | - $this->add_discount( $discount ); |
|
553 | + foreach ($processor->discounts as $discount) { |
|
554 | + $this->add_discount($discount); |
|
555 | 555 | } |
556 | 556 | |
557 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
557 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -563,10 +563,10 @@ discard block |
||
563 | 563 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
564 | 564 | * @since 1.0.19 |
565 | 565 | */ |
566 | - public function add_discount( $discount ) { |
|
567 | - $this->discounts[ $discount['name'] ] = $discount; |
|
568 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
569 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
566 | + public function add_discount($discount) { |
|
567 | + $this->discounts[$discount['name']] = $discount; |
|
568 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
569 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @since 1.0.19 |
576 | 576 | */ |
577 | - public function remove_discount( $name ) { |
|
577 | + public function remove_discount($name) { |
|
578 | 578 | |
579 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
580 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
581 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
582 | - unset( $this->discounts[ $name ] ); |
|
579 | + if (isset($this->discounts[$name])) { |
|
580 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
581 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
582 | + unset($this->discounts[$name]); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | } |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | * @return bool |
592 | 592 | */ |
593 | 593 | public function has_discount_code() { |
594 | - return ! empty( $this->discounts['discount_code'] ); |
|
594 | + return !empty($this->discounts['discount_code']); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | */ |
649 | 649 | public function process_fees() { |
650 | 650 | |
651 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
651 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
652 | 652 | |
653 | - foreach ( $fees_processor->fees as $fee ) { |
|
654 | - $this->add_fee( $fee ); |
|
653 | + foreach ($fees_processor->fees as $fee) { |
|
654 | + $this->add_fee($fee); |
|
655 | 655 | } |
656 | 656 | |
657 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
657 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
664 | 664 | * @since 1.0.19 |
665 | 665 | */ |
666 | - public function add_fee( $fee ) { |
|
666 | + public function add_fee($fee) { |
|
667 | 667 | |
668 | - $this->fees[ $fee['name'] ] = $fee; |
|
669 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
670 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
668 | + $this->fees[$fee['name']] = $fee; |
|
669 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
670 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
671 | 671 | |
672 | 672 | } |
673 | 673 | |
@@ -676,12 +676,12 @@ discard block |
||
676 | 676 | * |
677 | 677 | * @since 1.0.19 |
678 | 678 | */ |
679 | - public function remove_fee( $name ) { |
|
679 | + public function remove_fee($name) { |
|
680 | 680 | |
681 | - if ( isset( $this->fees[ $name ] ) ) { |
|
682 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
683 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
684 | - unset( $this->fees[ $name ] ); |
|
681 | + if (isset($this->fees[$name])) { |
|
682 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
683 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
684 | + unset($this->fees[$name]); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | } |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | * @since 1.0.19 |
721 | 721 | */ |
722 | 722 | public function has_fees() { |
723 | - return count( $this->fees ) !== 0; |
|
723 | + return count($this->fees) !== 0; |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | /* |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | */ |
739 | 739 | public function get_total() { |
740 | 740 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
741 | - return max( $total, 0 ); |
|
741 | + return max($total, 0); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | */ |
749 | 749 | public function get_recurring_total() { |
750 | 750 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
751 | - return max( $total, 0 ); |
|
751 | + return max($total, 0); |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | /** |
@@ -760,12 +760,12 @@ discard block |
||
760 | 760 | $initial = $this->get_total(); |
761 | 761 | $recurring = $this->get_recurring_total(); |
762 | 762 | |
763 | - if ( $this->has_recurring == 0 ) { |
|
763 | + if ($this->has_recurring == 0) { |
|
764 | 764 | $recurring = 0; |
765 | 765 | } |
766 | 766 | |
767 | 767 | $collect = $initial > 0 || $recurring > 0; |
768 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
768 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @since 1.0.19 |
775 | 775 | */ |
776 | 776 | public function get_billing_email() { |
777 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
777 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /** |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | */ |
785 | 785 | public function has_billing_email() { |
786 | 786 | $billing_email = $this->get_billing_email(); |
787 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
787 | + return !empty($billing_email) && is_email($billing_email); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | /** |
@@ -814,8 +814,8 @@ discard block |
||
814 | 814 | * @since 1.0.19 |
815 | 815 | * @return mixed|null |
816 | 816 | */ |
817 | - public function get_field( $field, $sub_array_key = null ) { |
|
818 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
817 | + public function get_field($field, $sub_array_key = null) { |
|
818 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /** |
@@ -823,8 +823,8 @@ discard block |
||
823 | 823 | * |
824 | 824 | * @since 1.0.19 |
825 | 825 | */ |
826 | - public function is_required_field_set( $field ) { |
|
827 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
826 | + public function is_required_field_set($field) { |
|
827 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -832,8 +832,8 @@ discard block |
||
832 | 832 | * |
833 | 833 | * @since 1.0.19 |
834 | 834 | */ |
835 | - public function format_amount( $amount ) { |
|
836 | - return wpinv_price( $amount, $this->get_currency() ); |
|
835 | + public function format_amount($amount) { |
|
836 | + return wpinv_price($amount, $this->get_currency()); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | } |