You are here

commerce_sagepay_paypal.module in Drupal Commerce SagePay Integration 7

File

modules/commerce_sagepay_paypal/commerce_sagepay_paypal.module
View source
<?php

/**
 * Implements hook_commerce_payment_method_info().
 */
function commerce_sagepay_paypal_commerce_payment_method_info() {
  $payment_methods = array();
  $payment_methods['commerce_sagepay_paypal'] = array(
    'base' => 'commerce_sagepay_paypal',
    'title' => t('SagePay PayPal Integration'),
    'display_title' => t('PayPal'),
    'short_title' => t('PayPal'),
    'description' => t('Integration with PayPal using Sage Pay Direct.'),
    'active' => FALSE,
    'terminal' => FALSE,
    'offsite' => TRUE,
    'offsite_autoredirect' => TRUE,
    'callbacks' => array(),
    'file' => 'includes/commerce_sagepay_paypal.inc',
  );
  return $payment_methods;
}

/**
 * Implements hook_menu().
 */
function commerce_sagepay_paypal_menu() {
  $items = array();

  // Define a path to receive PayPal Callback).
  $items['commerce-sagepay/paypal-callback/%'] = array(
    'page callback' => 'commerce_sagepay_paypal_handle_callback',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'includes/commerce_sagepay_paypal.inc',
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
function commerce_sagepay_paypal_theme($existing, $type, $theme, $path) {
  return array(
    'commerce_sagepay_paypal_card_logo' => array(
      'variables' => array(
        'name' => NULL,
        'img' => NULL,
        'href' => NULL,
      ),
    ),
  );
}

/**
 * Theme how the Paypal logo is displayed
 *
 * @param string $name
 *    Optionally override the name
 *
 * @param string $img
 *    Optionally override the img url
 *
 * @param string $href
 *    Optional href to link the image too
 *
 * @return string
 *   A themed output of card logo.
 */
function theme_commerce_sagepay_paypal_card_logo($variables) {
  $output = '';
  if (!empty($variables['img'])) {
    $src = $variables['img'];
  }
  else {
    $src = '/' . drupal_get_path('module', 'commerce_sagepay_paypal');
    $src .= '/img/paypal.gif';
  }
  $img = '<img src="' . $src . '" />';
  if (!empty($variables['href'])) {
    $output .= l($img, $variables['href'], array(
      'html' => TRUE,
    ));
  }
  else {
    $output .= $img;
  }
  return $output;
}