You are here

function mollie_payment_configuration in Mollie Payment 7

Same name and namespace in other branches
  1. 7.2 mollie_payment.module \mollie_payment_configuration()

Payment method configuration form elements callback.

Parameters

array $form: A Drupal form array.

array $form_state: The current state of the form.

Return value

array A Drupal form array.

File

./mollie_payment.module, line 383
Provides Mollie integration for the Payment platform.

Code

function mollie_payment_configuration(array $form, array &$form_state) {
  $controller_data = $form_state['payment']->method->controller_data;
  if ($controller_data['advanced']) {
    $payment = $form_state['payment'];
    $client = mollie_payment_get_client($payment);
    if ($client) {
      if (module_exists('payment_recurring') && isset($payment->recurring)) {

        // We can only use methods that support a first payment.
        $methods_list = $client->methods
          ->all(0, 0, array(
          'recurringType' => 'first',
        ));
      }
      else {
        $methods_list = $client->methods
          ->all();
      }
      $methods = array();
      foreach ($methods_list as $method) {
        $methods[$method->id] = $method->description;
      }
      $form['mollie_payment_method'] = array(
        '#type' => 'select',
        '#title' => t('Method'),
        '#options' => $methods,
      );

      // Do not bother users with a form element if there is nothing to choose.
      if (count($methods) < 2) {
        $form['mollie_payment_method']['#type'] = 'hidden';
        reset($methods);
        $form['mollie_payment_method']['#value'] = key($methods);
      }
      $issuer_list = $client->issuers
        ->all();
      $issuers = array(
        '' => t('Choose your issuer'),
      );
      foreach ($issuer_list as $issuer) {
        $issuers[$issuer->id] = $issuer->name;
      }

      // Show the issuers but only if the selected method is 'ideal'.
      $form['mollie_payment_issuer'] = array(
        '#type' => 'select',
        '#title' => t('Issuer'),
        '#options' => $issuers,
        '#states' => array(
          'visible' => array(
            ':input[name="payment_method[payment_method_controller_payment_configuration][mollie_payment_method]"]' => array(
              'value' => 'ideal',
            ),
          ),
        ),
      );
    }
  }
  if ($controller_data['test_mode']) {
    $form['test_mode'] = array(
      '#type' => 'markup',
      '#markup' => theme('html_tag', array(
        'element' => array(
          '#tag' => 'pre',
          '#value' => t('Mollie is in test mode. No real money is being transfered. Be sure to switch off test mode on production websites.'),
        ),
      )),
    );
  }
  return $form;
}