You are here

public function EcheckAddForm::buildEcheckForm in Commerce Authorize.Net 8

Builds the eCheck form.

1 call to EcheckAddForm::buildEcheckForm()
EcheckAddForm::buildConfigurationForm in src/PluginForm/EcheckAddForm.php
Form constructor.

File

src/PluginForm/EcheckAddForm.php, line 23

Class

EcheckAddForm

Namespace

Drupal\commerce_authnet\PluginForm

Code

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;
}