You are here

function commerce_worldpay_bg_settings_form in Commerce Worldpay 7

Settings form for Worldpay payment method.

Used to set vendor name and secret key within Rules settings.

File

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

Code

function commerce_worldpay_bg_settings_form($settings = NULL) {
  $form = array();

  // Merge default settings into the stored settings array.
  $settings = (array) $settings + array(
    'installation_id' => '',
    'txn_mode' => C_WORLDPAY_BG_TXN_MODE_TEST,
    'txn_type' => COMMERCE_CREDIT_AUTH_CAPTURE,
    'debug' => 'log',
    'payment_response_logging' => 'full_wppr',
    'site_id' => substr(drupal_clean_css_identifier($_SERVER['HTTP_HOST']), 0, 10),
    'payment_choices' => array_keys(_commerce_worldpay_bg_payment_card_types()),
    'confirmed_setup' => FALSE,
    'payment_parameters' => array(
      'test_mode' => TRUE,
      'test_result' => 'AUTHORISED',
      'pm_select_localy' => FALSE,
      'cart_in_desc' => FALSE,
      'cancel_order' => FALSE,
      'edit_contact' => TRUE,
      'show_contact' => TRUE,
      'lang' => 'en-GB',
    ),
    'payment_security' => array(
      'use_password' => TRUE,
      'password' => '',
      'md5_salt' => '',
    ),
    'payment_urls' => array(
      'live' => C_WORLDPAY_BG_DEF_SERVER_LIVE,
      'test' => C_WORLDPAY_BG_DEF_SERVER_TEST,
      'use_ssl' => FALSE,
      'force_non_ssl_links' => FALSE,
    ),
  );
  $url = url('commerce_worldpay/bg/response', array());

  // Remove language prefixes.
  if (!empty($GLOBALS['language']->prefix) && drupal_multilingual()) {
    $url = str_replace('/' . $GLOBALS['language']->prefix, '', $url);
  }
  $form['help_text']['worldpay_settings'] = array(
    '#type' => 'item',
    '#markup' => t('<h4>Installation instructions</h4>
      <p>For this module to work properly you must configure a few specific options in your RBS WorldPay account under <em>Installation Administration</em> settings:</p>
      <ul>
        <li><strong>Payment Response URL</strong> must be set to: <em>@response_url</em></li>
        <li><strong>Payment Response enabled?</strong> must be <em>enabled</em></li>
        <li><strong>Enable the Shopper Response</strong> should be <em>enabled</em> to get the Commerce response page.</li>
        <li><strong>Shopper Redirect URL</strong> and set the value to be <em>MC_callback</em>. !link.</li>
        <li><strong>SignatureFields must be set to</strong>: <em>@sig</em></li>
      </ul>', array(
      '@response_url' => '<wpdisplay item=' . C_WORLDPAY_BG_RESPONSE_URL_TOKEN . '-ppe empty="' . $url . '">',
      '@sig' => join(':', _commerce_worldpay_bg_md5_signature_fields()),
      '!link' => l(t('Worldpay help document'), 'http://www.worldpay.com/support/kb/bg/paymentresponse/pr5502.html', array(
        'absolute' => TRUE,
        'external' => TRUE,
      )),
    )),
    '#tree' => FALSE,
  );
  $form['help_text']['confirmed_setup'] = array(
    '#type' => 'checkbox',
    '#title' => t('I have completed the WorldPay installation setup (above).'),
    '#default_value' => $settings['confirmed_setup'],
    '#required' => TRUE,
    '#tree' => TRUE,
    // Make it more convieniant to access.
    '#parents' => array(
      'parameter',
      'payment_method',
      'settings',
      'payment_method',
      'settings',
      'confirmed_setup',
    ),
  );
  $form['installation_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Installation ID'),
    '#size' => 16,
    '#default_value' => $settings['installation_id'],
    '#required' => TRUE,
  );
  $form['debug'] = array(
    '#type' => 'select',
    '#title' => t('Debug mode'),
    '#multiple' => FALSE,
    '#options' => array(
      'log' => t('Log'),
      'screen' => t('Screen'),
      'both' => t('Both'),
      'none' => t('None'),
    ),
    '#default_value' => $settings['debug'],
  );
  $form['payment_response_logging'] = array(
    '#type' => 'radios',
    '#title' => t('Payment Response/Notificaton logging'),
    '#options' => array(
      'notification' => t('Log notifications during WorldPay Payment Notifications validation and processing.'),
      'full_wppr' => t('Log notifications with the full WorldPay Payment Notifications during validation and processing (used for debugging).'),
    ),
    '#default_value' => $settings['payment_response_logging'],
  );
  $form['site_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Site ID'),
    '#description' => t('A custom identifier that will be passed to WorldPay. This is useful for using one WorldPay account for multiple web sites.'),
    '#size' => 10,
    '#default_value' => $settings['site_id'],
    '#required' => FALSE,
  );
  $form['payment_methods_container'] = array(
    '#type' => 'fieldset',
    '#title' => t('Payment methods'),
    '#description' => t('Select the payment methods to display in checkout.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['payment_methods_container']['payment_choices'] = array(
    '#type' => 'checkboxes',
    '#default_value' => $settings['payment_choices'],
    '#options' => _commerce_worldpay_bg_payment_card_types(),
    '#parents' => array(
      'parameter',
      'payment_method',
      'settings',
      'payment_method',
      'settings',
      'payment_choices',
    ),
  );
  $form['payment_parameters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Payment parameters'),
    '#description' => t('These options control what parameters are sent to RBS WorldPay when the customer submits the order.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['payment_parameters']['pm_select_localy'] = array(
    '#type' => 'checkbox',
    '#title' => t('Select payment method locally'),
    '#default_value' => $settings['payment_parameters']['pm_select_localy'],
    '#description' => t('When checked the payment methods will be chosen on this website instead of on WorldPay\'s server.'),
  );
  $form['payment_parameters']['test_mode'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable test mode'),
    '#default_value' => $settings['payment_parameters']['test_mode'],
  );
  $form['payment_parameters']['test_result'] = array(
    '#type' => 'select',
    '#title' => t('Test mode result'),
    '#description' => t('Specify the required transaction result when working in test mode.'),
    '#default_value' => $settings['payment_parameters']['test_result'],
    '#options' => array(
      'AUTHORISED' => 'Authorised',
      'REFUSED' => 'Refused',
      'ERROR' => 'Error',
      'CAPTURED' => 'Captured',
    ),
    '#disabled' => !$settings['payment_parameters']['test_mode'] ? TRUE : FALSE,
  );
  $form['payment_parameters']['cart_in_desc'] = array(
    '#type' => 'checkbox',
    '#title' => t('Submit the cart contents as the order description'),
    '#description' => t('Setting this option to true will display the cart contents on the payment page. This could help to reassure customers of exactly what they are paying for.'),
    '#default_value' => $settings['payment_parameters']['cart_in_desc'],
  );
  $form['payment_parameters']['cancel_order'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cancel order in Commerce if cancelled during payment'),
    '#description' => t("If the customer cancels out of payment processing whilst on the RBS WorldPay server, remove the items from their cart and cancel their order in Commerce. N.B. This option is greyed out if it's not available."),
    '#default_value' => $settings['payment_parameters']['cancel_order'],
  );
  $form['payment_parameters']['edit_contact'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable editing of contact details on the WorldPay\'s payment page.'),
    '#default_value' => $settings['payment_parameters']['edit_contact'],
  );
  $form['payment_parameters']['show_contact'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the contact details on the payment page.'),
    '#default_value' => $settings['payment_parameters']['show_contact'],
  );
  $form['payment_parameters']['lang'] = array(
    '#type' => 'textfield',
    '#title' => t('Payment page language'),
    '#description' => t('Specify the payment page language. Enter a 2-character ISO 639 language code, with optional regionalisation using 2-character country code separated by hyphen. For example "en-GB" specifies UK English.'),
    '#size' => 8,
    '#maxlength' => 6,
    '#default_value' => $settings['payment_parameters']['lang'],
  );
  $form['payment_security'] = array(
    '#type' => 'fieldset',
    '#title' => t('Security'),
    '#description' => t('These options are for insuring a secure transaction to RBS WorldPay when the customer submits the order.'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['payment_security']['use_password'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use WorldPay installation password?'),
    '#description' => t('It is recomended that you set a password in your Worldpay Merchant Interface > Installation. Once done check this and enter the password.'),
    '#default_value' => $settings['payment_security']['use_password'],
  );
  $form['payment_security']['password'] = array(
    '#type' => 'textfield',
    '#title' => t('Installation password'),
    '#description' => t('This will only be used if you have checked "Use WorldPay installation password?".'),
    '#size' => 16,
    '#maxlength' => 16,
    '#default_value' => $settings['payment_security']['password'],
    '#element_validate' => array(
      '_commerce_worldpay_bg_validate_password',
    ),
  );
  $form['payment_security']['md5_salt'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret key'),
    '#description' => t('This is the key used to hash some of the content for verification between Worldpay and this site".'),
    '#size' => 16,
    '#maxlength' => 30,
    '#default_value' => $settings['payment_security']['md5_salt'],
    '#required' => TRUE,
  );
  $form['payment_urls'] = array(
    '#type' => 'fieldset',
    '#title' => t('Payment URLs'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['payment_urls']['test'] = array(
    '#type' => 'textfield',
    '#title' => t('Test URL'),
    '#description' => t('The WorldPay test environment URL.'),
    '#default_value' => $settings['payment_urls']['test'],
    '#element_validate' => array(
      'commerce_worldpay_bg_valid_url',
    ),
    '#required' => TRUE,
  );
  $form['payment_urls']['live'] = array(
    '#type' => 'textfield',
    '#title' => t('Live URL'),
    '#description' => t('The WorldPay live environment URL.'),
    '#default_value' => $settings['payment_urls']['live'],
    '#element_validate' => array(
      'commerce_worldpay_bg_valid_url',
    ),
    '#required' => TRUE,
  );
  $form['payment_urls']['use_ssl'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use SSL for payment notifications'),
    '#description' => t('If checked, when WorldPay passes information, it will be done over SSL for greater security. Use in combination with callback password to prevent spoofing.'),
    '#default_value' => $settings['payment_urls']['use_ssl'],
  );
  $form['payment_urls']['force_non_ssl_links'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force http (non-ssl) return links'),
    '#description' => t('This is needed if "Use SSL" is checked and you want your buyers to return to the non-ssl site.'),
    '#default_value' => $settings['payment_urls']['force_non_ssl_links'],
  );

  // @todo what is the reason for not showing those fields?

  /*
  $form['txn_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Transaction mode'),
    '#description' => t('Adjust to live transactions when you are ready to start processing actual payments.'),
    '#options' => array(
      C_WORLDPAY_BG_TXN_MODE_LIVE => t('Live transactions in a live account'),
      C_WORLDPAY_BG_TXN_MODE_TEST => t('Test transactions in a test account'),
      WORLDPAY_TXN_MODE_SIMULATION => t('Simulation Account'),
    ),
    '#default_value' => $settings['txn_mode'],
  );

  $form['txn_type'] = array(
    '#type' => 'radios',
    '#title' => t('Default credit card transaction type'),
    '#description' => t('The default will be used to process transactions during checkout.'),
    '#options' => array(
      COMMERCE_CREDIT_AUTH_CAPTURE => t('Authorisation and capture'),
      COMMERCE_CREDIT_AUTH_ONLY => t('Authorisation only (requires manual or automated capture after checkout)'),
    ),
    '#default_value' => $settings['txn_type'],
  );

  $form['apply_avs_cv2'] = array(
    '#type' => 'radios',
    '#title' => t('AVS / CV2 Mode'),
    '#description' => t('CV2 validation mode used by default on all transactions.'),
    '#options' => array(
      '0' => t('If AVS/CV2 enabled then check them. If rules apply, use rules. (default)'),
      '1' => t('Force AVS/CV2 checks even if not enabled for the account. If rules apply, use rules.'),
      '2' => t('Force NO AVS/CV2 checks even if enabled on account.'),
      '3' => t('Force AVS/CV2 checks even if not enabled for the account but DO NOT apply any rules.'),
    ),
    '#default_value' => $settings['apply_avs_cv2'],
  );

  $form['apply_3d_secure'] = array(
    '#type' => 'radios',
    '#title' => t('3D Secure Mode'),
    '#description' => t('3D Secure mode used by default on all transactions.'),
    '#options' => array(
      '0' => t('If 3D-Secure checks are possible and rules allow, perform the checks and apply the authorisation rules. (default)'),
      '1' => t('Force 3D-Secure checks for this transaction if possible and apply rules for authorisation.'),
      '2' => t('Do not perform 3D-Secure checks for this transaction and always authorise.'),
      '3' => t('Force 3D-Secure checks for this transaction if possible but ALWAYS obtain an auth code, irrespective of rule base.'),
    ),
    '#default_value' => $settings['apply_3d_secure'],
  );
  */
  return $form;
}