You are here

function commerce_worldpay_bg_submit_form in Commerce Worldpay 7

Payment method callback: submit form.

This is the form the user sees when they choose the payment provider in checkout.

Here we add the card selection stuff if it is enabled.

@todo Attach a help box for aiding the user in payment method choice.

File

./commerce_worldpay_bg.module, line 495
Provides a Worldpay Business Gateway payment method for Drupal Commerce.

Code

function commerce_worldpay_bg_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
  $form = array();

  // Merge in values from the order.
  if (!empty($order->data['commerce_worldpay_bg'])) {
    $pane_values += $order->data['commerce_worldpay_bg'];
  }

  // Merge in default values.
  $pane_values += array(
    'paymentType' => 'not_selected',
  );
  $card_options = array(
    'not_selected' => '-- Please select a payment method --',
  );
  $cards = _commerce_worldpay_bg_payment_card_types();
  foreach ($payment_method['settings']['payment_choices'] as $card_code) {
    if ($card_code) {
      $card_options[$card_code] = $cards[$card_code];
    }
  }

  // Card selection
  if ($payment_method['settings']['payment_parameters']['pm_select_localy']) {
    $form['paymentType'] = array(
      '#type' => 'select',
      '#title' => t('Pay using'),
      '#options' => $card_options,
      '#required' => TRUE,
      '#default_value' => $pane_values['paymentType'],
    );
  }
  if (!$payment_method['settings']['payment_parameters']['edit_contact']) {
    $form['bill_address_help'] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'commerce-worldpay-bg-bill-address-help',
          'messages',
          'warning',
        ),
      ),
      'content' => array(
        '#markup' => t('Before proceeding to the next step, please verify that the billing address is the one that belongs to your chosen payment method.'),
      ),
    );
  }
  return $form;
}