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

Drupal example source code file (uc_authorizenet.install)

This example Drupal source code file (uc_authorizenet.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, auth_capture, else, function, has_curl, if, language, mode, phase, php, return, title, translate, true

The uc_authorizenet.install Drupal example source code

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

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

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

  $has_curl = function_exists('curl_init');

  $requirements['uc_authorizenet_curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['uc_authorizenet_curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['uc_authorizenet_curl']['description'] = $t("Authorize.net 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_authorizenet_uninstall() {
  // Delete related variables all at once.
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_authnet_%%'");
}

function uc_authorizenet_update_1() {
  // Update variable values to the new names that match the API documentation.
  variable_set('uc_authnet_api_login_id', variable_get('authnet_aim_login_id', ''));
  variable_del('authnet_aim_login_id');

  variable_set('uc_authnet_api_transaction_key', variable_get('authnet_aim_transaction_key', ''));
  variable_del('authnet_aim_transaction_key');

  $mode = variable_get('authnet_aim_transaction_mode', 'live_test');
  if ($mode == 'production') {
    $mode = 'live';
  }
  elseif ($mode == 'test') {
    $mode = 'developer_test';
  }
  variable_set('uc_authnet_aim_txn_mode', $mode);
  variable_del('authnet_aim_transaction_mode');

  if (variable_get('authnet_aim_transaction_type', 'capture') == 'capture') {
    variable_set('uc_authnet_aim_txn_type', 'AUTH_CAPTURE');
  }
  else {
    variable_set('uc_authnet_aim_txn_type', 'AUTH_ONLY');
  }
  variable_del('authnet_aim_transaction_type');

  variable_del('authnet_aim_delimiter');

  if (variable_get('authnet_aim_customer_notification', 'FALSE') == 'TRUE') {
    variable_set('uc_authnet_aim_customer_email', TRUE);
  }
  variable_del('authnet_aim_customer_notification');

  variable_del('authnet_aim_merchant_notification');

  return array();
}

function uc_authorizenet_update_2() {
  // Change the variable used to define the default transaction type.
  if (variable_get('uc_authnet_aim_txn_type', 'AUTH_CAPTURE') == 'AUTH_CAPTURE') {
    variable_set('uc_pg_authorizenet_cc_txn_type', UC_CREDIT_AUTH_CAPTURE);
  }
  else {
    variable_set('uc_pg_authorizenet_cc_txn_type', UC_CREDIT_AUTH_ONLY);
  }

  variable_del('uc_authnet_aim_txn_type');

  return array();
}

function uc_authorizenet_update_3() {
  // Update the name of the CIM transaction mode variable.
  variable_set('uc_authnet_cim_mode', variable_get('uc_authnet_cim_server', 'disabled'));
  variable_del('uc_authet_cim_server');

  return array();
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal uc_authorizenet.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.