You are here

class EcheckAddForm in Commerce Authorize.Net 8

Hierarchy

Expanded class hierarchy of EcheckAddForm

File

src/PluginForm/EcheckAddForm.php, line 9

Namespace

Drupal\commerce_authnet\PluginForm
View source
class EcheckAddForm extends BasePaymentMethodAddForm {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['payment_details'] = $this
      ->buildEcheckForm($form['payment_details'], $form_state);
    return $form;
  }

  /**
   * Builds the eCheck form.
   */
  public function buildEcheckForm(array $element, FormStateInterface $form_state) {

    // Alter the form with AuthorizeNet Accept JS specific needs.
    $element['#attributes']['class'][] = 'authorize-net-accept-js-form';

    /** @var \Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\AuthorizeNetInterface $plugin */
    $plugin = $this->plugin;
    if ($plugin
      ->getMode() == 'test') {
      $element['#attached']['library'][] = 'commerce_authnet/accept-js-sandbox';
    }
    else {
      $element['#attached']['library'][] = 'commerce_authnet/accept-js-production';
    }
    $element['#attached']['library'][] = 'commerce_authnet/form-echeck';
    $element['#attached']['drupalSettings']['commerceAuthorizeNet'] = [
      'clientKey' => $plugin
        ->getConfiguration()['client_key'],
      'apiLoginID' => $plugin
        ->getConfiguration()['api_login'],
      'paymentMethodType' => 'authnet_echeck',
    ];

    // To display validation errors.
    $element['payment_errors'] = [
      '#type' => 'markup',
      '#markup' => '<div id="payment-errors"></div>',
      '#weight' => -200,
    ];
    $element['routing_number'] = [
      '#type' => 'textfield',
      '#title' => t('Routing number'),
      '#description' => t("The bank's routing number."),
      '#attributes' => [
        'class' => [
          'authnet-echeck-routing-number',
        ],
      ],
    ];
    $element['account_number'] = [
      '#type' => 'textfield',
      '#title' => t('Bank account'),
      '#description' => t('The bank account number.'),
      '#attributes' => [
        'class' => [
          'authnet-echeck-account-number',
        ],
      ],
    ];
    $element['name_on_account'] = [
      '#type' => 'textfield',
      '#title' => t('Name on account'),
      '#description' => t('The name of the person who holds the bank account.'),
      '#attributes' => [
        'class' => [
          'authnet-echeck-name-on-account',
        ],
      ],
    ];
    $element['account_type'] = [
      '#type' => 'select',
      '#title' => t('Account type'),
      '#description' => t('The type of bank account. Currently only WEB eCheck ACH transactions are supported.'),
      '#options' => AuthorizeNetEcheck::getAccountTypes(),
      '#attributes' => [
        'class' => [
          'authnet-echeck-account-type',
        ],
      ],
    ];

    // Populated by the JS library after receiving a response from AuthorizeNet.
    $element['data_descriptor'] = [
      '#type' => 'hidden',
      '#attributes' => [
        'class' => [
          'accept-js-data-descriptor',
        ],
      ],
    ];
    $element['data_value'] = [
      '#type' => 'hidden',
      '#attributes' => [
        'class' => [
          'accept-js-data-value',
        ],
      ],
    ];
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  protected function validateEcheckForm(array &$element, FormStateInterface $form_state) {

    // The JS library performs its own validation.
  }

  /**
   * {@inheritdoc}
   */
  public function submitEcheckForm(array $element, FormStateInterface $form_state) {

    // The payment gateway plugin will process the submitted payment details.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EcheckAddForm::buildConfigurationForm public function Form constructor. Overrides PaymentMethodAddForm::buildConfigurationForm
EcheckAddForm::buildEcheckForm public function Builds the eCheck form.
EcheckAddForm::submitEcheckForm public function
EcheckAddForm::validateEcheckForm protected function
PaymentGatewayFormBase::$entity protected property The form entity.
PaymentGatewayFormBase::getEntity public function Gets the form entity. Overrides PaymentGatewayFormInterface::getEntity
PaymentGatewayFormBase::setEntity public function Sets the form entity. Overrides PaymentGatewayFormInterface::setEntity
PaymentMethodAddForm::buildCreditCardForm protected function Builds the credit card form. 1
PaymentMethodAddForm::buildPayPalForm protected function Builds the PayPal form.
PaymentMethodAddForm::getErrorElement public function Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormBase::getErrorElement
PaymentMethodAddForm::submitConfigurationForm public function Form submission handler. Overrides PaymentMethodFormBase::submitConfigurationForm
PaymentMethodAddForm::submitCreditCardForm protected function Handles the submission of the credit card form.
PaymentMethodAddForm::submitPayPalForm protected function Handles the submission of the PayPal form.
PaymentMethodAddForm::validateConfigurationForm public function Form validation handler. Overrides PaymentMethodFormBase::validateConfigurationForm
PaymentMethodAddForm::validateCreditCardForm protected function Validates the credit card form.
PaymentMethodAddForm::validatePayPalForm protected function Validates the PayPal form.
PaymentMethodFormBase::$currentStore protected property The current store.
PaymentMethodFormBase::$entityTypeManager protected property The entity type manager.
PaymentMethodFormBase::$inlineFormManager protected property The inline form manager.
PaymentMethodFormBase::$logger protected property The logger.
PaymentMethodFormBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
PaymentMethodFormBase::__construct public function Constructs a new PaymentMethodFormBase.
PluginFormBase::$plugin protected property The plugin this form is for. 3
PluginFormBase::setPlugin public function Sets the plugin for this object. Overrides PluginAwareInterface::setPlugin 1
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.