You are here

PaymentVoidForm.php in Commerce Core 8.2

File

modules/payment/src/PluginForm/PaymentVoidForm.php
View source
<?php

namespace Drupal\commerce_payment\PluginForm;

use Drupal\Core\Form\FormStateInterface;
class PaymentVoidForm extends PaymentGatewayFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

    /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
    $payment = $this->entity;
    $form['#theme'] = 'confirm_form';
    $form['#attributes']['class'][] = 'confirmation';
    $form['#page_title'] = $this
      ->t('Are you sure you want to void the %label payment?', [
      '%label' => $payment
        ->label(),
    ]);
    $form['#success_message'] = $this
      ->t('Payment voided.');
    $form['description'] = [
      '#markup' => $this
        ->t('This action cannot be undone.'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {

    /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
    $payment = $this->entity;

    /** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsAuthorizationsInterface $payment_gateway_plugin */
    $payment_gateway_plugin = $this->plugin;
    $payment_gateway_plugin
      ->voidPayment($payment);
  }

}

Classes

Namesort descending Description
PaymentVoidForm