You are here

function commerce_sermepa_redirect_form in Commerce sermepa 7

Payment method callback: redirect form to sermepa gateway.

Parameters

commerce_order $order: The fully loaded order being paid for.

array $payment_method: An array of the current settings.

Return value

array Form elements that should be submitted to the redirected payment service.

File

./commerce_sermepa.module, line 343
Provides a payment method for Drupal Commerce using Sermepa/Redsys gateway.

Code

function commerce_sermepa_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']['Ds_MerchantCode'])) {
    drupal_set_message(t('Sermepa is not configured for use. Merchant code has not been specified.'), 'error');
    return array();
  }
  if (empty($payment_method['settings']['Ds_MerchantPassword'])) {
    drupal_set_message(t('SHA256 Sermepa password is not set for use. Merchant password has not been specified.'), 'error');
    return array();
  }
  if (empty($payment_method['settings']['Ds_Merchant_Terminal'])) {
    drupal_set_message(t('Sermepa is not configured for use. Merchant terminal has not been specified.'), 'error');
    return array();
  }
  $settings = array(
    // Return to the previous page when payment is canceled.
    'cancel_return' => url('checkout/' . $order->order_id . '/payment/back/' . $order->data['payment_redirect_key'], array(
      'absolute' => TRUE,
    )),
    // Return to the payment redirect page for processing successful payments.
    'return' => url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array(
      'absolute' => TRUE,
    )),
    // Url to get POST result of payment.
    'merchant_url' => url('sermepa/callback/' . $order->order_id, array(
      'absolute' => TRUE,
    )),
    // Specify the current payment method instance ID in the notify_url.
    'payment_method' => $payment_method['instance_id'],
  );
  return commerce_sermepa_order_form($form, $form_state, $order, $payment_method['settings'] + $settings);
}