You are here

public function InvoicePaymentForm::submitForm in Commerce Invoice 8.2

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/InvoicePaymentForm.php, line 69

Class

InvoicePaymentForm

Namespace

Drupal\commerce_invoice\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (!$this->invoice
    ->isPaid() && $this->invoice
    ->getTotalPrice()) {
    $this->invoice
      ->setTotalPaid($this->invoice
      ->getTotalPrice());
    $this->invoice
      ->save();
  }
  if ($this->invoice
    ->isPaid()) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Invoice %title has been successfully paid.', [
      '%title' => $this->invoice
        ->label(),
    ]));
  }
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}