Passed
Push — master ( bcec86...2e6a31 )
by Brian
04:08
created
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Spacing   +96 added lines, -96 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
 
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 		$this->state = wpinv_get_default_state();
162 162
 
163 163
 		// Do we have an actual submission?
164
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
165
-			$this->load_data( $_POST );
164
+		if (isset($_POST['getpaid_payment_form_submission'])) {
165
+			$this->load_data($_POST);
166 166
 		}
167 167
 
168 168
 	}
@@ -172,29 +172,29 @@  discard block
 block discarded – undo
172 172
 	 *
173 173
 	 * @param array $data
174 174
 	 */
175
-	public function load_data( $data ) {
175
+	public function load_data($data) {
176 176
 
177 177
 		// Prepare submitted data...
178
-		$data = wp_unslash( $data );
178
+		$data = wp_unslash($data);
179 179
 
180 180
 		// Filter the data.
181
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
181
+		$data = apply_filters('getpaid_submission_data', $data, $this);
182 182
 
183 183
 		$this->data = $data;
184 184
 
185
-		$this->id = md5( wp_json_encode( $data ) );
185
+		$this->id = md5(wp_json_encode($data));
186 186
 
187 187
 		// Every submission needs an active payment form.
188
-		if ( empty( $data['form_id'] ) ) {
189
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
188
+		if (empty($data['form_id'])) {
189
+			$this->last_error = __('Missing payment form', 'invoicing');
190 190
             return;
191 191
 		}
192 192
 
193 193
 		// Fetch the payment form.
194
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
194
+		$form = new GetPaid_Payment_Form($data['form_id']);
195 195
 
196
-		if ( ! $form->is_active() ) {
197
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
196
+		if (!$form->is_active()) {
197
+			$this->last_error = __('Payment form not active', 'invoicing');
198 198
 			return;
199 199
 		}
200 200
 
@@ -202,83 +202,83 @@  discard block
 block discarded – undo
202 202
 		$this->payment_form = $form;
203 203
 
204 204
 		// For existing invoices, make sure that it is valid.
205
-        if ( ! empty( $data['invoice_id'] ) ) {
206
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
205
+        if (!empty($data['invoice_id'])) {
206
+            $invoice = wpinv_get_invoice($data['invoice_id']);
207 207
 
208
-            if ( empty( $invoice ) ) {
209
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
208
+            if (empty($invoice)) {
209
+				$this->last_error = __('Invalid invoice', 'invoicing');
210 210
                 return;
211 211
 			}
212 212
 
213
-			if ( $invoice->is_paid() ) {
214
-				$this->last_error = __( 'This invoice is already paid for.', 'invoicing' );
213
+			if ($invoice->is_paid()) {
214
+				$this->last_error = __('This invoice is already paid for.', 'invoicing');
215 215
                 return;
216 216
 			}
217 217
 
218
-			$this->payment_form->set_items( $invoice->get_items() );
218
+			$this->payment_form->set_items($invoice->get_items());
219 219
 
220 220
 			$this->country = $invoice->get_country();
221 221
 			$this->state   = $invoice->get_state();
222 222
 			$this->invoice = $invoice;
223 223
 
224 224
 		// Default forms do not have items.
225
-        } else if ( $form->is_default() && isset( $data['getpaid-items'] ) ) {
226
-			$this->payment_form->set_items( wpinv_clean( $data['getpaid-items'] ) );
225
+        } else if ($form->is_default() && isset($data['getpaid-items'])) {
226
+			$this->payment_form->set_items(wpinv_clean($data['getpaid-items']));
227 227
 		}
228 228
 
229 229
 		// User's country.
230
-		if ( ! empty( $data['wpinv_country'] ) ) {
230
+		if (!empty($data['wpinv_country'])) {
231 231
 			$this->country = $data['wpinv_country'];
232 232
 		}
233 233
 
234 234
 		// User's state.
235
-		if ( ! empty( $data['wpinv_state'] ) ) {
235
+		if (!empty($data['wpinv_state'])) {
236 236
 			$this->country = $data['wpinv_state'];
237 237
 		}
238 238
 
239 239
 		// Handle items.
240 240
 		$selected_items = array();
241
-		if ( ! empty( $data['getpaid-items'] ) ) {
242
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
241
+		if (!empty($data['getpaid-items'])) {
242
+			$selected_items = wpinv_clean($data['getpaid-items']);
243 243
 		}
244 244
 
245
-		foreach ( $this->payment_form->get_items() as $item ) {
245
+		foreach ($this->payment_form->get_items() as $item) {
246 246
 
247 247
 			// Continue if this is an optional item and it has not been selected.
248
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
248
+			if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
249 249
 				continue;
250 250
 			}
251 251
 
252 252
 			// (maybe) let customers change the quantities and prices.
253
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
253
+			if (isset($selected_items[$item->get_id()])) {
254 254
 
255 255
 				// Maybe change the quantities.
256
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
257
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
256
+				if ($item->allows_quantities() && is_numeric($selected_items[$item->get_id()]['quantity'])) {
257
+					$item->set_quantity((int) $selected_items[$item->get_id()]['quantity']);
258 258
 				}
259 259
 
260 260
 				// Maybe change the price.
261
-				if ( $item->user_can_set_their_price() ) {
262
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
261
+				if ($item->user_can_set_their_price()) {
262
+					$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
263 263
 
264 264
 					// But don't get lower than the minimum price.
265
-					if ( $price < $item->get_minimum_price() ) {
265
+					if ($price < $item->get_minimum_price()) {
266 266
 						$price = $item->get_minimum_price();
267 267
 					}
268 268
 
269
-					$item->set_price( $price );
269
+					$item->set_price($price);
270 270
 
271 271
 				}
272 272
 
273 273
 			}
274 274
 
275 275
 			// Add the item to the form.
276
-			$this->add_item( $item );
276
+			$this->add_item($item);
277 277
 
278 278
 		}
279 279
 
280 280
 		// Fired when we are done processing a submission.
281
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
281
+		do_action_ref_array('getpaid_process_submission', array(&$this));
282 282
 
283 283
 	}
284 284
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @return bool
310 310
 	 */
311 311
 	public function has_invoice() {
312
-		return ! empty( $this->invoice );
312
+		return !empty($this->invoice);
313 313
 	}
314 314
 
315 315
 	/**
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @return string
320 320
 	 */
321 321
 	public function get_currency() {
322
-		if ( $this->has_invoice() ) {
322
+		if ($this->has_invoice()) {
323 323
 			return $this->invoice->get_currency();
324 324
 		}
325 325
 		return wpinv_get_currency();
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 *
341 341
 	 * @since 1.0.19
342 342
 	 */
343
-	public function is_required_field_set( $field ) {
344
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
343
+	public function is_required_field_set($field) {
344
+		return empty($field['required']) || !empty($this->data[$field['id']]);
345 345
 	}
346 346
 
347 347
 	///////// Items //////////////
@@ -352,25 +352,25 @@  discard block
 block discarded – undo
352 352
 	 * @since 1.0.19
353 353
 	 * @param GetPaid_Form_Item $item
354 354
 	 */
355
-	public function add_item( $item ) {
355
+	public function add_item($item) {
356 356
 
357 357
 		// Make sure that it is available for purchase.
358
-		if ( ! $item->can_purchase() ) {
358
+		if (!$item->can_purchase()) {
359 359
 			return;
360 360
 		}
361 361
 
362 362
 		// Do we have a recurring item?
363
-		if ( $item->is_recurring() ) {
363
+		if ($item->is_recurring()) {
364 364
 
365
-			if ( $this->has_recurring ) {
366
-				$this->last_error = __( 'You can only buy one recurring item at a time.', 'invoicing' );
365
+			if ($this->has_recurring) {
366
+				$this->last_error = __('You can only buy one recurring item at a time.', 'invoicing');
367 367
 			}
368 368
 
369 369
 			$this->has_recurring = true;
370 370
 
371 371
 		}
372 372
 
373
-		$this->items[ $item->get_id() ] = $item;
373
+		$this->items[$item->get_id()] = $item;
374 374
 
375 375
 		$this->subtotal_amount += $item->get_sub_total();
376 376
 
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 	 *
382 382
 	 * @since 1.0.19
383 383
 	 */
384
-	public function get_item( $item_id ) {
385
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
384
+	public function get_item($item_id) {
385
+		return isset($this->items[$item_id]) ? $this->items[$item_id] : null;
386 386
 	}
387 387
 
388 388
 	/**
@@ -411,18 +411,18 @@  discard block
 block discarded – undo
411 411
 	 */
412 412
 	public function process_taxes() {
413 413
 
414
-		$tax_processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
414
+		$tax_processor = new GetPaid_Payment_Form_Submission_Taxes($this);
415 415
 
416
-		if ( ! empty( $tax_processor->tax_error) ) {
416
+		if (!empty($tax_processor->tax_error)) {
417 417
 			$this->last_error = $tax_processor->tax_error;
418 418
 			return;
419 419
 		}
420 420
 
421
-		foreach ( $tax_processor->taxes as $tax ) {
422
-			$this->add_tax( $tax );
421
+		foreach ($tax_processor->taxes as $tax) {
422
+			$this->add_tax($tax);
423 423
 		}
424 424
 
425
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
425
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
426 426
 	}
427 427
 
428 428
 	/**
@@ -431,11 +431,11 @@  discard block
 block discarded – undo
431 431
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
432 432
 	 * @since 1.0.19
433 433
 	 */
434
-	public function add_tax( $tax ) {
434
+	public function add_tax($tax) {
435 435
 
436
-		$this->total_tax_amount           += wpinv_sanitize_amount( $tax['initial_tax'] );
437
-		$this->total_recurring_tax_amount += wpinv_sanitize_amount( $tax['recurring_tax'] );
438
-		$this->taxes[ $tax['name'] ]       = $tax;
436
+		$this->total_tax_amount           += wpinv_sanitize_amount($tax['initial_tax']);
437
+		$this->total_recurring_tax_amount += wpinv_sanitize_amount($tax['recurring_tax']);
438
+		$this->taxes[$tax['name']]       = $tax;
439 439
 
440 440
 	}
441 441
 
@@ -448,11 +448,11 @@  discard block
 block discarded – undo
448 448
 
449 449
 		$use_taxes = wpinv_use_taxes();
450 450
 
451
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
451
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
452 452
 			$use_taxes = false;
453 453
 		}
454 454
 
455
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
455
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
456 456
 
457 457
 	}
458 458
 
@@ -500,28 +500,28 @@  discard block
 block discarded – undo
500 500
 	public function process_discount() {
501 501
 
502 502
 		$total            = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
503
-		$discount_handler = new GetPaid_Payment_Form_Submission_Discount( $this, $total );
503
+		$discount_handler = new GetPaid_Payment_Form_Submission_Discount($this, $total);
504 504
 
505
-		if ( ! $discount_handler->is_discount_valid ) {
505
+		if (!$discount_handler->is_discount_valid) {
506 506
 			$this->last_error = $discount_handler->discount_error;
507 507
 			return;
508 508
 		}
509 509
 
510 510
 		// Process any existing invoice discounts.
511
-		if ( $this->has_invoice() ) {
511
+		if ($this->has_invoice()) {
512 512
 			$discounts = $this->get_invoice()->get_discounts();
513 513
 
514
-			foreach ( $discounts as $discount ) {
515
-				$this->add_discount( $discount );
514
+			foreach ($discounts as $discount) {
515
+				$this->add_discount($discount);
516 516
 			}
517 517
 
518 518
 		}
519 519
 
520
-		if ( $discount_handler->has_discount ) {
521
-			$this->add_discount( $discount_handler->calculate_discount( $this ) );
520
+		if ($discount_handler->has_discount) {
521
+			$this->add_discount($discount_handler->calculate_discount($this));
522 522
 		}
523 523
 
524
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
524
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
525 525
 	}
526 526
 
527 527
 	/**
@@ -530,11 +530,11 @@  discard block
 block discarded – undo
530 530
 	 * @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.
531 531
 	 * @since 1.0.19
532 532
 	 */
533
-	public function add_discount( $discount ) {
533
+	public function add_discount($discount) {
534 534
 
535
-		$this->total_discount_amount           += wpinv_sanitize_amount( $discount['initial_discount'] );
536
-		$this->total_recurring_discount_amount += wpinv_sanitize_amount( $discount['recurring_discount'] );
537
-		$this->discounts[ $discount['name'] ]   = $discount;
535
+		$this->total_discount_amount           += wpinv_sanitize_amount($discount['initial_discount']);
536
+		$this->total_recurring_discount_amount += wpinv_sanitize_amount($discount['recurring_discount']);
537
+		$this->discounts[$discount['name']]   = $discount;
538 538
 
539 539
 	}
540 540
 
@@ -543,13 +543,13 @@  discard block
 block discarded – undo
543 543
 	 *
544 544
 	 * @since 1.0.19
545 545
 	 */
546
-	public function remove_discount( $name ) {
546
+	public function remove_discount($name) {
547 547
 
548
-		if ( isset( $this->discounts[ $name ] ) ) {
549
-			$discount                               = $this->discounts[ $name ];
548
+		if (isset($this->discounts[$name])) {
549
+			$discount                               = $this->discounts[$name];
550 550
 			$this->total_discount_amount           -= $discount['initial_discount'];
551 551
 			$this->total_recurring_discount_amount -= $discount['recurring_discount'];
552
-			unset( $this->discounts[ $name ] );
552
+			unset($this->discounts[$name]);
553 553
 		}
554 554
 
555 555
 	}
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 	 * @return bool
562 562
 	 */
563 563
 	public function has_discount_code() {
564
-		return ! empty( $this->discounts['discount_code'] );
564
+		return !empty($this->discounts['discount_code']);
565 565
 	}
566 566
 
567 567
 	/**
@@ -618,18 +618,18 @@  discard block
 block discarded – undo
618 618
 	 */
619 619
 	public function process_fees() {
620 620
 
621
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
621
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
622 622
 
623
-		if ( ! empty( $fees_processor->fee_error) ) {
623
+		if (!empty($fees_processor->fee_error)) {
624 624
 			$this->last_error = $fees_processor->fee_error;
625 625
 			return;
626 626
 		}
627 627
 
628
-		foreach ( $fees_processor->fees as $fee ) {
629
-			$this->add_fee( $fee );
628
+		foreach ($fees_processor->fees as $fee) {
629
+			$this->add_fee($fee);
630 630
 		}
631 631
 
632
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
632
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
633 633
 	}
634 634
 
635 635
 	/**
@@ -638,11 +638,11 @@  discard block
 block discarded – undo
638 638
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
639 639
 	 * @since 1.0.19
640 640
 	 */
641
-	public function add_fee( $fee ) {
641
+	public function add_fee($fee) {
642 642
 
643
-		$this->total_fees_amount           += wpinv_sanitize_amount( $fee['initial_fee'] );
644
-		$this->total_recurring_fees_amount += wpinv_sanitize_amount( $fee['recurring_fee'] );
645
-		$this->fees[ $fee['name'] ]         = $fee;
643
+		$this->total_fees_amount           += wpinv_sanitize_amount($fee['initial_fee']);
644
+		$this->total_recurring_fees_amount += wpinv_sanitize_amount($fee['recurring_fee']);
645
+		$this->fees[$fee['name']]         = $fee;
646 646
 
647 647
 	}
648 648
 
@@ -651,13 +651,13 @@  discard block
 block discarded – undo
651 651
 	 *
652 652
 	 * @since 1.0.19
653 653
 	 */
654
-	public function remove_fee( $name ) {
654
+	public function remove_fee($name) {
655 655
 
656
-		if ( isset( $this->fees[ $name ] ) ) {
657
-			$fee                                = $this->fees[ $name ];
656
+		if (isset($this->fees[$name])) {
657
+			$fee                                = $this->fees[$name];
658 658
 			$this->total_fees_amount           -= $fee['initial_fee'];
659 659
 			$this->total_recurring_fees_amount -= $fee['recurring_fee'];
660
-			unset( $this->fees[ $name ] );
660
+			unset($this->fees[$name]);
661 661
 		}
662 662
 
663 663
 	}
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 	 */
699 699
 	public function get_total() {
700 700
 		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
701
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
702
-		return wpinv_sanitize_amount( $total );
701
+		$total = apply_filters('getpaid_get_submission_total_amount', $total, $this);
702
+		return wpinv_sanitize_amount($total);
703 703
 	}
704 704
 
705 705
 	/**
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
 	public function get_payment_details() {
711 711
 		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
712 712
 
713
-		if ( $this->has_recurring ) {
713
+		if ($this->has_recurring) {
714 714
 			$collect = true;
715 715
 		}
716 716
 
717
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
717
+		$collect = apply_filters('getpaid_submission_collect_payment_details', $collect, $this);
718 718
 		return $collect;
719 719
 	}
720 720
 
@@ -724,8 +724,8 @@  discard block
 block discarded – undo
724 724
 	 * @since 1.0.19
725 725
 	 */
726 726
 	public function get_billing_email() {
727
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
728
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
727
+		$billing_email = empty($this->data['billing_email']) ? '' : $this->data['billing_email'];
728
+		return apply_filters('getpaid_get_submission_billing_email', $billing_email, $this);
729 729
 	}
730 730
 
731 731
 	/**
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 	 */
736 736
 	public function has_billing_email() {
737 737
 		$billing_email = $this->get_billing_email();
738
-		return ! empty( $billing_email );
738
+		return !empty($billing_email);
739 739
 	}
740 740
 
741 741
 }
Please login to merge, or discard this patch.