You are here

public function AuthorizeNet::buildConfigurationForm in Ubercart 8.4

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides CreditCardPaymentMethodBase::buildConfigurationForm

File

payment/uc_authorizenet/src/Plugin/Ubercart/PaymentMethod/AuthorizeNet.php, line 52

Class

AuthorizeNet
Defines the Authorize.net payment method.

Namespace

Drupal\uc_authorizenet\Plugin\Ubercart\PaymentMethod

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);

  // If CC encryption has been configured properly.
  if ($key = uc_credit_encryption_key()) {

    // Setup our encryption object.
    $crypt = \Drupal::service('uc_store.encryption');

    // Decrypt the MD5 Hash.
    $md5_hash = $this->configuration['arb']['md5_hash'];
    if (!empty($md5_hash)) {
      $md5_hash = $crypt
        ->decrypt($key, $md5_hash);
    }

    // Store any errors.
    uc_store_encryption_errors($crypt, 'uc_authorizenet');
  }
  else {

    // @todo Need to set a form error - can't configure Authorize.net without
    // CC encryption set up.
  }

  // Allow admin to set duplicate window.
  $intervals = [
    0,
    15,
    30,
    45,
    60,
    75,
    90,
    105,
    120,
  ];
  $form['duplicate_window'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Duplicate window'),
    '#description' => $this
      ->t('Blocks submission of duplicate transactions within the specified window. Defaults to 120 seconds.'),
    '#default_value' => $this->configuration['duplicate_window'],
    '#options' => array_combine($intervals, $intervals),
  ];
  $form['api'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('API Login ID and Transaction Key'),
    '#description' => $this
      ->t('This information is required for Ubercart to interact with your payment gateway account. It is different from your login ID and password and may be found through your account settings page. Do not change the gateway URLs unless you are using this module with an Authorize.net-compatible gateway that requires different URLs.'),
    '#open' => TRUE,
  ];
  $form['api']['login_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API Login ID'),
    '#default_value' => $this->configuration['api']['login_id'],
  ];
  $form['api']['transaction_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Transaction Key'),
    '#default_value' => $this->configuration['api']['transaction_key'],
  ];
  $form['api']['test_gateway_url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('Authorize.net Test Gateway URL'),
    '#default_value' => $this->configuration['api']['test_gateway_url'],
  ];
  $form['api']['live_gateway_url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('Authorize.net Live Gateway URL'),
    '#default_value' => $this->configuration['api']['live_gateway_url'],
  ];
  $form['aim'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('AIM settings'),
    '#description' => $this
      ->t('These settings pertain to the Authorize.Net AIM payment method for card not present transactions.'),
    '#open' => TRUE,
  ];
  $form['aim']['txn_mode'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Transaction mode'),
    '#description' => $this
      ->t('Only specify a developer test account if you login to your account through https://test.authorize.net.<br />Adjust to live transactions when you are ready to start processing real payments.'),
    '#options' => [
      'live' => $this
        ->t('Live transactions in a live account'),
      'live_test' => $this
        ->t('Test transactions in a live account'),
      'developer_test' => $this
        ->t('Developer test account transactions'),
    ],
    '#default_value' => $this->configuration['aim']['txn_mode'],
  ];
  $form['aim']['email_customer'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Tell Authorize.net to e-mail the customer a receipt based on your account settings.'),
    '#default_value' => $this->configuration['aim']['email_customer'],
  ];
  $form['aim']['response_debug'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Log full API response messages from Authorize.net for debugging.'),
    '#default_value' => $this->configuration['aim']['response_debug'],
  ];
  $form['arb'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('ARB settings'),
    '#description' => $this
      ->t('These settings pertain to the Authorize.Net Automated Recurring Billing service.'),
    '#open' => TRUE,
  ];
  $form['arb']['arb_mode'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Transaction mode'),
    '#description' => $this
      ->t('Only specify developer mode if you login to your account through https://test.authorize.net.<br />Adjust to production mode when you are ready to start processing real recurring fees.'),
    '#options' => [
      'production' => $this
        ->t('Production'),
      'developer' => $this
        ->t('Developer test'),
      'disabled' => $this
        ->t('Disabled'),
    ],
    '#default_value' => $this->configuration['arb']['arb_mode'],
  ];
  $form['arb']['md5_hash'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('MD5 Hash'),
    '#description' => $this
      ->t('<b>Note:</b> You must first configure credit card encryption before setting this.<br />Enter the value here you entered in your Auth.Net account settings.'),
    '#default_value' => $md5_hash,
    '#access' => \Drupal::currentUser()
      ->hasPermission('administer credit cards'),
  ];
  $form['arb']['report_arb_post'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Log reported ARB payments in watchdog.'),
    '#description' => $this
      ->t('Make sure you have set your Silent POST URL in Authorize.Net to :url.', [
      ':url' => Url::fromUri('base:authnet/silent-post', [
        'absolute' => TRUE,
      ])
        ->toString(),
    ]),
    '#default_value' => $this->configuration['arb']['report_arb_post'],
  ];
  $form['cim'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('CIM settings'),
    '#description' => $this
      ->t('These settings pertain to the Authorize.Net Customer Information Management service.'),
    '#open' => TRUE,
  ];
  $form['cim']['cim_profile'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Always create a CIM profile for securely storing CC info for later use.'),
    '#default_value' => $this->configuration['cim']['cim_profile'],
  ];
  $form['cim']['cim_mode'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Transaction mode'),
    '#description' => $this
      ->t('Only specify a developer test account if you login to your account through https://test.authorize.net.<br />Adjust to live transactions when you are ready to start processing real payments.'),
    '#options' => [
      'production' => $this
        ->t('Production'),
      'developer' => $this
        ->t('Developer test'),
      'disabled' => $this
        ->t('Disabled'),
    ],
    '#default_value' => $this->configuration['cim']['cim_mode'],
  ];
  return $form;
}