You are here

function commerce_worldpay_bg_redirect_form in Commerce Worldpay 7

Implements hook_redirect_form().

Returns form elements that should be submitted to the redirected payment service; because of the array merge that happens upon return, the service's URL that should receive the POST variables should be set in the #action property of the returned form array

See also

http://www.drupalcommerce.org/specification/info-hooks/payment

File

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

Code

function commerce_worldpay_bg_redirect_form($form, &$form_state, $order, $payment_method) {

  // Return an error if the enabling action's settings haven't been configured.
  if (empty($payment_method['settings']['installation_id'])) {
    drupal_set_message(t('WorldPay Integration is not configured for use. Installation ID has not been specified.'), 'error');
    return array();
  }
  if (empty($payment_method['settings']['confirmed_setup'])) {
    drupal_set_message(t('Please complete the setup steps on Worldpay then check <em>I have completed the WorldPay installation setup</em>.'), 'error');
    return array();
  }
  if (empty($payment_method['settings']['payment_security']['md5_salt'])) {
    drupal_set_message(t('WorldPay Business Gateway Integration is not configured for use. Encryption salt key has not been specified.'), 'error');
    return array();
  }

  // Disable redirect if debugging.
  // @todo This is a bit of a HACK, find a better way for that.
  if ($payment_method['settings']['debug'] == 'screen' || $payment_method['settings']['debug'] == 'both') {
    drupal_add_js(';(function($) {Drupal.behaviors.commercePayment = {attach: function (context, settings) {}}})(jQuery);', array(
      'type' => 'inline',
      'weight' => 5,
    ));
  }
  $settings = array(
    // Specify the current payment method instance ID in the MC_callback URL
    'payment_method' => $payment_method['instance_id'],
  );
  return commerce_worldpay_bg_order_form($form, $form_state, $order, $payment_method['settings'] + $settings);
}