home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (uc_cybersource.install)

This example Drupal source code file (uc_cybersource.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, data, function, has_curl, has_dom, has_soap, href, if, like, method, php, post, sql, translate

The uc_cybersource.install Drupal example source code

<?php
// $Id: uc_cybersource.install,v 1.1.2.6 2010/07/12 01:57:43 tr Exp $

/**
 * @file
 * Handles installing, uninstalling, and updating CyberSource settings.
 */

/**
 * Implementation of hook_requirements().
 */
function uc_cybersource_requirements($phase) {
  $t = get_t();

  $has_curl = function_exists('curl_init');
  $has_dom = class_exists('DOMDocument');
  $has_soap = class_exists('SoapClient');
  $method = variable_get('uc_cybersource_method', 'post');

  // Using SOAP.
  if ($method == 'soap') {
    $requirements['uc_cybersource_soap_and_dom'] = array(
      'title' => $t('SOAP and DOM'),
      'value' => $has_soap && $has_dom ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_soap || !$has_dom) {
      $requirements['uc_cybersource_soap_and_dom']['severity'] = REQUIREMENT_ERROR;
      $requirements['uc_cybersource_soap_and_dom']['description'] = $t("Cybersource's SOAP Toolkit API requires the PHP <a href='!soap_url'>SOAP</a> and <a href='!dom_url'>DOM</a> libraries.", array('!soap_url' => 'http://php.net/manual/en/soap.setup.php', '!dom_url' => 'http://php.net/manual/en/dom.setup.php'));
    }
  }

  // Using POST with cURL.
  elseif ($method == 'post') {
    $requirements['uc_cybersource_curl'] = array(
      'title' => $t('cURL'),
      'value' => $has_curl ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_curl) {
      $requirements['uc_cybersource_curl']['severity'] = REQUIREMENT_ERROR;
      $requirements['uc_cybersource_curl']['description'] = $t("Cybersource's Silent Order POST requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
    }
  }

  return $requirements;
}

function uc_cybersource_uninstall() {
  // Delete related variables all at once.
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_cybersource_%%' OR name LIKE 'cs_ship_from_%%'");
}

function uc_cybersource_update_1() {
  // Change the variable used to define the default transaction type.
  if (variable_get('uc_cybersource_transaction_type', 'sale') == 'sale') {
    variable_set('uc_pg_cybersource_cc_txn_type', UC_CREDIT_AUTH_CAPTURE);
  }
  else {
    variable_set('uc_pg_cybersource_cc_txn_type', UC_CREDIT_AUTH_ONLY);
  }

  variable_del('uc_cybersource_transaction_type');

  // Convert the old subscription IDs to the new ones.
  $result = db_query("SELECT order_id, data FROM {uc_orders} WHERE data LIKE '%%cybersource%%soap%%'");
  while ($row = db_fetch_array($result)) {
    $data = unserialize($row['data']);
    uc_credit_log_reference($row['order_id'], $data['uc_cybersource']['soap']['subscription_id'], 'XXXX');
  }

  return array();
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal uc_cybersource.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.