You are here

function pay_method_gateway::form in Pay 7

Same name and namespace in other branches
  1. 6 includes/handlers/pay_method_gateway.inc \pay_method_gateway::form()

Overrides pay::form

File

includes/handlers/pay_method_gateway.inc, line 419
The base class for credit card payment activities.

Class

pay_method_gateway
@file The base class for credit card payment activities.

Code

function form(&$form, &$form_state) {
  global $user;
  $group = $this->pay_form
    ->handler();
  if (isset($this->gateway_testmode) && $this->gateway_testmode) {
    drupal_set_message(t('The @name payment method is in test mode. This transaction will not be fully processed.', array(
      '@name' => $this
        ->title(),
    )), 'warning');
  }
  if (isset($form[$group]['pay_method'][$this->pmid])) {
    $method_form = $form[$group]['pay_method'][$this->pmid];
  }
  $method_form['#theme'] = 'pay_cc_form';
  $options = array();
  if ($this->gateway_supports_cc) {
    $options['cc'] = t('Credit or debit card');
  }

  // TODO should reflect 'bank account' input here, but it's unsupported.
  $method_form['payment_type'] = array(
    '#type' => 'select',
    '#title' => t('Payment type'),
    '#options' => $options,
    '#required' => TRUE,
    '#default_value' => 'cc',
    '#access' => count($options) > 1,
  );
  $method_form['first_name'] = array(
    '#type' => 'textfield',
    '#title' => t('First name'),
    '#pre_render' => array(
      'pay_element_set_required',
    ),
  );
  $method_form['last_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last name'),
    '#pre_render' => array(
      'pay_element_set_required',
    ),
  );
  if ($user->uid) {
    $method_form['mail'] = array(
      '#type' => 'value',
      '#value' => $user->mail,
    );
  }
  else {
    $method_form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('E-mail'),
      '#pre_render' => array(
        'pay_element_set_required',
      ),
    );
  }
  $method_form['billto'] = array(
    '#type' => 'postal',
    '#postal_user' => $user,
    '#title' => t('Billing address'),
    '#pre_render' => array(
      'pay_element_set_required',
    ),
  );
  $method_form['cc_type'] = array(
    '#type' => 'radios',
    '#title' => t('Card type'),
    '#options' => $this
      ->payment_types($this->payment_types),
  );
  $method_form['cc_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Card number'),
    '#size' => 19,
    '#maxlength' => 19,
    '#pre_render' => array(
      'pay_element_set_required',
    ),
    '#attributes' => array(
      'autocomplete' => 'off',
    ),
  );
  $method_form['cc_ccv2'] = array(
    '#type' => 'textfield',
    '#title' => t('Security code'),
    '#size' => 4,
    '#maxlength' => 4,
    '#attributes' => array(
      'autocomplete' => 'off',
    ),
  );
  if ($this
    ->cc_issue_number_required()) {
    $method_form['cc_issue_number'] = array(
      '#type' => 'textfield',
      '#title' => t('Issue number'),
      '#size' => 2,
      '#maxlength' => 2,
      '#attributes' => array(
        'autocomplete' => 'off',
      ),
    );
  }
  $months = array();
  foreach (range(1, 12) as $i) {
    $key = str_pad($i, 2, '0', STR_PAD_LEFT);
    $months[$key] = $key . '- ' . date('F', strtotime('1-' . $i . '-2000'));
  }
  $method_form['cc_exp_month'] = array(
    '#type' => 'select',
    '#options' => $months,
    '#pre_render' => array(
      'pay_element_set_required',
    ),
    '#attributes' => array(
      'title' => t('Expiration month'),
    ),
  );
  $years = array();
  foreach (range(0, 9) as $i) {
    $year = date('Y') + $i;
    $years[substr($year, 2)] = $year;
  }
  $method_form['cc_exp_year'] = array(
    '#type' => 'select',
    '#options' => $years,
    '#pre_render' => array(
      'pay_element_set_required',
    ),
    '#attributes' => array(
      'title' => t('Expiration year'),
    ),
  );

  // Add this method_form to the expected place on the parent form.
  $form[$group]['pay_method'][$this->pmid] = $method_form;
  $form[$group]['pay_method'][$this->pmid]['#prefix'] = '<div class="payment-method-form">';
  $form[$group]['pay_method'][$this->pmid]['#suffix'] = '</div>';
}