@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | $this->state = wpinv_get_default_state(); |
| 147 | 147 | |
| 148 | 148 | // Do we have an actual submission? |
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param array $data |
| 159 | 159 | */ |
| 160 | - public function load_data( $data ) { |
|
| 160 | + public function load_data($data) { |
|
| 161 | 161 | |
| 162 | 162 | // Allow plugins to filter the data. |
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 164 | 164 | |
| 165 | 165 | // Cache it... |
| 166 | 166 | $this->data = $data; |
| 167 | 167 | |
| 168 | 168 | // Then generate a unique id from the data. |
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 169 | + $this->id = md5(wp_json_encode($data)); |
|
| 170 | 170 | |
| 171 | 171 | // Finally, process the submission. |
| 172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
| 176 | 176 | $processors = apply_filters( |
| 177 | 177 | 'getpaid_payment_form_submission_processors', |
| 178 | 178 | array( |
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 179 | + array($this, 'process_payment_form'), |
|
| 180 | + array($this, 'process_invoice'), |
|
| 181 | + array($this, 'process_fees'), |
|
| 182 | + array($this, 'process_items'), |
|
| 183 | + array($this, 'process_discount'), |
|
| 184 | + array($this, 'process_taxes'), |
|
| 185 | 185 | ), |
| 186 | 186 | $this |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | + foreach ($processors as $processor) { |
|
| 190 | + call_user_func_array($processor, array(&$this)); |
|
| 191 | 191 | } |
| 192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
| 192 | + } catch (GetPaid_Payment_Exception $e) { |
|
| 193 | 193 | $this->last_error = $e->getMessage(); |
| 194 | 194 | $this->last_error_code = $e->getErrorCode(); |
| 195 | - } catch ( Exception $e ) { |
|
| 195 | + } catch (Exception $e) { |
|
| 196 | 196 | $this->last_error = $e->getMessage(); |
| 197 | 197 | $this->last_error_code = $e->getCode(); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Fired when we are done processing a submission. |
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | public function process_payment_form() { |
| 220 | 220 | |
| 221 | 221 | // Every submission needs an active payment form. |
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 222 | + if (empty($this->data['form_id'])) { |
|
| 223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Fetch the payment form. |
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 229 | + if (!$this->payment_form->is_active()) { |
|
| 230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -260,64 +260,64 @@ discard block |
||
| 260 | 260 | public function process_invoice() { |
| 261 | 261 | |
| 262 | 262 | // Abort if there is no invoice. |
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | + if (empty($this->data['invoice_id'])) { |
|
| 264 | 264 | |
| 265 | 265 | // Check if we are resuming a payment. |
| 266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
| 266 | + if (empty($this->data['maybe_use_invoice'])) { |
|
| 267 | 267 | return; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
| 271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
| 270 | + $invoice = wpinv_get_invoice($this->data['maybe_use_invoice']); |
|
| 271 | + if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) { |
|
| 272 | 272 | return; |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // If the submission is for an existing invoice, ensure that it exists |
| 277 | 277 | // and that it is not paid for. |
| 278 | - if ( empty( $invoice ) ) { |
|
| 279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 278 | + if (empty($invoice)) { |
|
| 279 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if ( empty( $invoice ) ) { |
|
| 283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 282 | + if (empty($invoice)) { |
|
| 283 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if ( $invoice->is_paid() ) { |
|
| 287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 286 | + if ($invoice->is_paid()) { |
|
| 287 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $this->payment_form->invoice = $invoice; |
| 291 | - if ( ! $this->payment_form->is_default() ) { |
|
| 291 | + if (!$this->payment_form->is_default()) { |
|
| 292 | 292 | |
| 293 | 293 | $items = array(); |
| 294 | 294 | $item_ids = array(); |
| 295 | 295 | |
| 296 | - foreach ( $invoice->get_items() as $item ) { |
|
| 297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 296 | + foreach ($invoice->get_items() as $item) { |
|
| 297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 298 | 298 | $item_ids[] = $item->get_id(); |
| 299 | 299 | $items[] = $item; |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 303 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 304 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 305 | 305 | $item_ids[] = $item->get_id(); |
| 306 | 306 | $items[] = $item; |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $this->payment_form->set_items( $items ); |
|
| 310 | + $this->payment_form->set_items($items); |
|
| 311 | 311 | |
| 312 | 312 | } else { |
| 313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 313 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | $this->country = $invoice->get_country(); |
| 317 | 317 | $this->state = $invoice->get_state(); |
| 318 | 318 | $this->invoice = $invoice; |
| 319 | 319 | |
| 320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 320 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @return bool |
| 338 | 338 | */ |
| 339 | 339 | public function has_invoice() { |
| 340 | - return ! empty( $this->invoice ); |
|
| 340 | + return !empty($this->invoice); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /* |
@@ -356,13 +356,13 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | public function process_items() { |
| 358 | 358 | |
| 359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 359 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 360 | 360 | |
| 361 | - foreach ( $processor->items as $item ) { |
|
| 362 | - $this->add_item( $item ); |
|
| 361 | + foreach ($processor->items as $item) { |
|
| 362 | + $this->add_item($item); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 365 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -371,20 +371,20 @@ discard block |
||
| 371 | 371 | * @since 1.0.19 |
| 372 | 372 | * @param GetPaid_Form_Item $item |
| 373 | 373 | */ |
| 374 | - public function add_item( $item ) { |
|
| 374 | + public function add_item($item) { |
|
| 375 | 375 | |
| 376 | 376 | // Make sure that it is available for purchase. |
| 377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 377 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 378 | 378 | return; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Each submission can only contain one recurring item. |
| 382 | - if ( $item->is_recurring() ) { |
|
| 382 | + if ($item->is_recurring()) { |
|
| 383 | 383 | $this->has_recurring = $item->get_id(); |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // Update the items and totals. |
| 387 | - $this->items[ $item->get_id() ] = $item; |
|
| 387 | + $this->items[$item->get_id()] = $item; |
|
| 388 | 388 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 389 | 389 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 390 | 390 | |
@@ -398,17 +398,17 @@ discard block |
||
| 398 | 398 | * |
| 399 | 399 | * @since 1.0.19 |
| 400 | 400 | */ |
| 401 | - public function remove_item( $item_id ) { |
|
| 401 | + public function remove_item($item_id) { |
|
| 402 | 402 | |
| 403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 403 | + if (isset($this->items[$item_id])) { |
|
| 404 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 405 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 406 | 406 | |
| 407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 407 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 408 | 408 | $this->has_recurring = 0; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - unset( $this->items[ $item_id ] ); |
|
| 411 | + unset($this->items[$item_id]); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | public function get_subtotal() { |
| 422 | 422 | |
| 423 | - if ( wpinv_prices_include_tax() ) { |
|
| 423 | + if (wpinv_prices_include_tax()) { |
|
| 424 | 424 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 425 | 425 | } |
| 426 | 426 | |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | */ |
| 435 | 435 | public function get_recurring_subtotal() { |
| 436 | 436 | |
| 437 | - if ( wpinv_prices_include_tax() ) { |
|
| 437 | + if (wpinv_prices_include_tax()) { |
|
| 438 | 438 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return bool |
| 459 | 459 | */ |
| 460 | 460 | public function has_subscription_group() { |
| 461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | * @return bool |
| 469 | 469 | */ |
| 470 | 470 | public function has_multiple_subscription_groups() { |
| 471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 471 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /* |
@@ -488,39 +488,39 @@ discard block |
||
| 488 | 488 | public function process_taxes() { |
| 489 | 489 | |
| 490 | 490 | // Abort if we're not using taxes. |
| 491 | - if ( ! $this->use_taxes() ) { |
|
| 491 | + if (!$this->use_taxes()) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 497 | - if ( ! empty( $country ) ) { |
|
| 496 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 497 | + if (!empty($country)) { |
|
| 498 | 498 | $this->country = $country; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 502 | - if ( ! empty( $state ) ) { |
|
| 501 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 502 | + if (!empty($state)) { |
|
| 503 | 503 | $this->state = $state; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | // Confirm if the provided country and the ip country are similar. |
| 507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 507 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 508 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 509 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // Abort if the country is not taxable. |
| 513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 513 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 514 | 514 | return; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 518 | 518 | |
| 519 | - foreach ( $processor->taxes as $tax ) { |
|
| 520 | - $this->add_tax( $tax ); |
|
| 519 | + foreach ($processor->taxes as $tax) { |
|
| 520 | + $this->add_tax($tax); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 523 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -529,16 +529,16 @@ discard block |
||
| 529 | 529 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 530 | 530 | * @since 1.0.19 |
| 531 | 531 | */ |
| 532 | - public function add_tax( $tax ) { |
|
| 532 | + public function add_tax($tax) { |
|
| 533 | 533 | |
| 534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 534 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 535 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 536 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 539 | + $this->taxes[$tax['name']] = $tax; |
|
| 540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 542 | 542 | |
| 543 | 543 | } |
| 544 | 544 | |
@@ -547,12 +547,12 @@ discard block |
||
| 547 | 547 | * |
| 548 | 548 | * @since 1.0.19 |
| 549 | 549 | */ |
| 550 | - public function remove_tax( $tax_name ) { |
|
| 550 | + public function remove_tax($tax_name) { |
|
| 551 | 551 | |
| 552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 555 | - unset( $this->taxes[ $tax_name ] ); |
|
| 552 | + if (isset($this->taxes[$tax_name])) { |
|
| 553 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 554 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 555 | + unset($this->taxes[$tax_name]); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | } |
@@ -566,11 +566,11 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | $use_taxes = wpinv_use_taxes(); |
| 568 | 568 | |
| 569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 569 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 570 | 570 | $use_taxes = false; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 573 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 574 | 574 | |
| 575 | 575 | } |
| 576 | 576 | |
@@ -619,13 +619,13 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 621 | 621 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 622 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 623 | 623 | |
| 624 | - foreach ( $processor->discounts as $discount ) { |
|
| 625 | - $this->add_discount( $discount ); |
|
| 624 | + foreach ($processor->discounts as $discount) { |
|
| 625 | + $this->add_discount($discount); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 628 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -634,10 +634,10 @@ discard block |
||
| 634 | 634 | * @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. |
| 635 | 635 | * @since 1.0.19 |
| 636 | 636 | */ |
| 637 | - public function add_discount( $discount ) { |
|
| 638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 637 | + public function add_discount($discount) { |
|
| 638 | + $this->discounts[$discount['name']] = $discount; |
|
| 639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -645,12 +645,12 @@ discard block |
||
| 645 | 645 | * |
| 646 | 646 | * @since 1.0.19 |
| 647 | 647 | */ |
| 648 | - public function remove_discount( $name ) { |
|
| 648 | + public function remove_discount($name) { |
|
| 649 | 649 | |
| 650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 653 | - unset( $this->discounts[ $name ] ); |
|
| 650 | + if (isset($this->discounts[$name])) { |
|
| 651 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 652 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 653 | + unset($this->discounts[$name]); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | } |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | * @return bool |
| 663 | 663 | */ |
| 664 | 664 | public function has_discount_code() { |
| 665 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 665 | + return !empty($this->discounts['discount_code']); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -719,13 +719,13 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | public function process_fees() { |
| 721 | 721 | |
| 722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 723 | 723 | |
| 724 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 725 | - $this->add_fee( $fee ); |
|
| 724 | + foreach ($fees_processor->fees as $fee) { |
|
| 725 | + $this->add_fee($fee); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 728 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -734,17 +734,17 @@ discard block |
||
| 734 | 734 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 735 | 735 | * @since 1.0.19 |
| 736 | 736 | */ |
| 737 | - public function add_fee( $fee ) { |
|
| 737 | + public function add_fee($fee) { |
|
| 738 | 738 | |
| 739 | - if ( $fee['name'] == 'shipping' ) { |
|
| 740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 739 | + if ($fee['name'] == 'shipping') { |
|
| 740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 742 | 742 | return; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 745 | + $this->fees[$fee['name']] = $fee; |
|
| 746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 748 | 748 | |
| 749 | 749 | } |
| 750 | 750 | |
@@ -753,15 +753,15 @@ discard block |
||
| 753 | 753 | * |
| 754 | 754 | * @since 1.0.19 |
| 755 | 755 | */ |
| 756 | - public function remove_fee( $name ) { |
|
| 756 | + public function remove_fee($name) { |
|
| 757 | 757 | |
| 758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 761 | - unset( $this->fees[ $name ] ); |
|
| 758 | + if (isset($this->fees[$name])) { |
|
| 759 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 760 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 761 | + unset($this->fees[$name]); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - if ( 'shipping' == $name ) { |
|
| 764 | + if ('shipping' == $name) { |
|
| 765 | 765 | $this->totals['shipping']['initial'] = 0; |
| 766 | 766 | $this->totals['shipping']['recurring'] = 0; |
| 767 | 767 | } |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * @since 1.0.19 |
| 803 | 803 | */ |
| 804 | 804 | public function has_fees() { |
| 805 | - return count( $this->fees ) !== 0; |
|
| 805 | + return count($this->fees) !== 0; |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | /* |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | * @since 1.0.19 |
| 839 | 839 | */ |
| 840 | 840 | public function has_shipping() { |
| 841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 841 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | /** |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | * @since 1.0.19 |
| 849 | 849 | */ |
| 850 | 850 | public function is_initial_fetch() { |
| 851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
| 851 | + return isset($this->data['initial_state']) && empty($this->data['initial_state']); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | public function get_total() { |
| 860 | 860 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
| 861 | - return max( $total, 0 ); |
|
| 861 | + return max($total, 0); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | /** |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | */ |
| 869 | 869 | public function get_recurring_total() { |
| 870 | 870 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
| 871 | - return max( $total, 0 ); |
|
| 871 | + return max($total, 0); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -880,12 +880,12 @@ discard block |
||
| 880 | 880 | $initial = $this->get_total(); |
| 881 | 881 | $recurring = $this->get_recurring_total(); |
| 882 | 882 | |
| 883 | - if ( $this->has_recurring == 0 ) { |
|
| 883 | + if ($this->has_recurring == 0) { |
|
| 884 | 884 | $recurring = 0; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | $collect = $initial > 0 || $recurring > 0; |
| 888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 888 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | /** |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | * @since 1.0.19 |
| 895 | 895 | */ |
| 896 | 896 | public function get_billing_email() { |
| 897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 897 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | */ |
| 905 | 905 | public function has_billing_email() { |
| 906 | 906 | $billing_email = $this->get_billing_email(); |
| 907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 907 | + return !empty($billing_email) && is_email($billing_email); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | * @since 1.0.19 |
| 935 | 935 | * @return mixed|null |
| 936 | 936 | */ |
| 937 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 937 | + public function get_field($field, $sub_array_key = null) { |
|
| 938 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -943,8 +943,8 @@ discard block |
||
| 943 | 943 | * |
| 944 | 944 | * @since 1.0.19 |
| 945 | 945 | */ |
| 946 | - public function is_required_field_set( $field ) { |
|
| 947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 946 | + public function is_required_field_set($field) { |
|
| 947 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | /** |
@@ -952,8 +952,8 @@ discard block |
||
| 952 | 952 | * |
| 953 | 953 | * @since 1.0.19 |
| 954 | 954 | */ |
| 955 | - public function format_amount( $amount ) { |
|
| 956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 955 | + public function format_amount($amount) { |
|
| 956 | + return wpinv_price($amount, $this->get_currency()); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | } |