You are here

public function WorldpayRedirect::buildConfigurationForm in Commerce Worldpay 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php \Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway\WorldpayRedirect::buildConfigurationForm()

Throws

\InvalidArgumentException

Overrides PaymentGatewayBase::buildConfigurationForm

File

src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php, line 181

Class

WorldpayRedirect
Provides the Worldpay Redirect payment gateway.

Namespace

Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $payment_url = \Drupal::request()
    ->getSchemeAndHttpHost() . '/payment/notify/MACHINE_NAME_OF_PAYMENT_GATEWAY';
  $help_url = Url::fromUri('http://www.worldpay.com/support/kb/bg/paymentresponse/pr5502.html');
  $form['help_text'] = [
    '#type' => 'fieldset',
    '#title' => t('Installation instructions'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['help_text']['worldpay_settings'] = [
    '#markup' => $this
      ->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>@shopper_link</em>. @link.</li>
        <li><strong>SignatureFields must be set to</strong>: <em>@sig</em></li>
        <li><strong>MD5 secret for transactions</strong>: The secret must be between 20 and 30 characters long with no white space and contain at least one upper case letter, one lower case letter, one number and one symbol.</li>
      </ul>', [
      '@response_url' => '<wpdisplay item=' . C_WORLDPAY_BG_RESPONSE_URL_TOKEN . '-ppe empty="' . $payment_url . '">',
      '@sig' => implode(':', static::md5signatureFields()),
      '@link' => $this->linkGenerator
        ->generate($this
        ->t('Worldpay help document'), $help_url),
      '@shopper_link' => '<wpdisplay item=MC_callback>',
    ]),
  ];
  $form['help_text']['confirmed_setup'] = [
    '#type' => 'checkbox',
    '#title' => t('I have completed the WorldPay installation setup (above).'),
    '#default_value' => $this->configuration['confirmed_setup'],
    '#required' => TRUE,
    '#tree' => TRUE,
  ];
  $form['installation_id'] = [
    '#type' => 'textfield',
    '#title' => t('Installation ID'),
    '#size' => 16,
    '#default_value' => $this->configuration['installation_id'],
    '#required' => TRUE,
  ];
  $form['debug'] = [
    '#type' => 'select',
    '#title' => t('Debug mode'),
    '#multiple' => FALSE,
    '#options' => [
      'log' => t('Log'),
      'screen' => t('Screen'),
      'both' => t('Both'),
      'none' => t('None'),
    ],
    '#default_value' => $this->configuration['debug'],
  ];
  $form['site_id'] = [
    '#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' => $this->configuration['site_id'],
    '#required' => FALSE,
  ];
  $form['payment_parameters'] = [
    '#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']['test_mode'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable test mode'),
    '#default_value' => $this->configuration['payment_parameters']['test_mode'],
  ];
  $form['payment_parameters']['test_result'] = [
    '#type' => 'select',
    '#title' => t('Test mode result'),
    '#description' => t('Specify the required transaction result when working in test mode.'),
    '#default_value' => $this->configuration['payment_parameters']['test_result'],
    '#options' => [
      'AUTHORISED' => 'Authorised',
      'REFUSED' => 'Refused',
      'ERROR' => 'Error',
      'CAPTURED' => 'Captured',
    ],
    '#disabled' => !$this->configuration['payment_parameters']['test_mode'] ? TRUE : FALSE,
  ];
  $form['payment_security'] = [
    '#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'] = [
    '#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' => $this->configuration['payment_security']['use_password'],
  ];
  $form['payment_security']['password'] = [
    '#type' => 'textfield',
    '#title' => t('Installation password'),
    '#description' => t('This will only be used if you have checked "Use WorldPay installation password?".'),
    '#size' => 20,
    '#maxlength' => 30,
    '#default_value' => $this->configuration['payment_security']['password'],
  ];
  $form['payment_security']['md5_salt'] = [
    '#type' => 'textfield',
    '#title' => t('MD5 secret for transactions'),
    '#description' => t('The secret is used to hash some of the content for verification between Worldpay and this site.'),
    '#size' => 20,
    '#maxlength' => 30,
    '#default_value' => $this->configuration['payment_security']['md5_salt'],
    '#required' => TRUE,
  ];
  $form['payment_urls'] = [
    '#type' => 'details',
    '#title' => t('Payment URLs'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['payment_urls']['test'] = [
    '#type' => 'textfield',
    '#title' => t('Test URL'),
    '#description' => t('The WorldPay test environment URL.'),
    '#default_value' => $this->configuration['payment_urls']['test'],
    '#required' => TRUE,
  ];
  $form['payment_urls']['live'] = [
    '#type' => 'textfield',
    '#title' => t('Live URL'),
    '#description' => t('The WorldPay live environment URL.'),
    '#default_value' => $this->configuration['payment_urls']['live'],
    '#required' => TRUE,
  ];
  $form['payment_urls']['use_ssl'] = [
    '#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' => $this->configuration['payment_urls']['use_ssl'],
  ];
  $form['payment_urls']['force_non_ssl_links'] = [
    '#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' => $this->configuration['payment_urls']['force_non_ssl_links'],
  ];
  return $form;
}