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

Drupal example source code file (uc_paypal.install)

This example Drupal source code file (uc_paypal.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, database, default, function, not, null, php, ret, sql, the, true, type, varchar

The uc_paypal.install Drupal example source code

<?php
// $Id: uc_paypal.install,v 1.6.2.7 2010/03/19 21:27:17 tr Exp $

/**
 * @file
 * Installation file for PayPal, primarily for the logging of IPNs.

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

  $has_curl = function_exists('curl_init');

  // PayPal WPP requires cURL.
  if (variable_get('uc_pg_paypal_wpp_enabled', TRUE)) {
    $requirements['uc_paypal_curl'] = array(
      'title' => $t('cURL'),
      'value' => $has_curl ? $t('Enabled') : $t('Not found'),
    );
    if (!$has_curl) {
      $requirements['uc_paypal_curl']['severity'] = REQUIREMENT_ERROR;
      $requirements['uc_paypal_curl']['description'] = $t("PayPal WPP requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
    }
  }

  return $requirements;
}

/**
 * Implementation of hook_schema().
 */
function uc_paypal_schema() {
  $schema = array();

  $schema['uc_payment_paypal_ipn'] = array(
    'description' => 'Logs PayPal Instant Payment Notifications.',
    'fields' => array(
      'order_id' => array(
        'description' => 'The order ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'txn_id' => array(
        'description' => 'The transaction ID from PayPal.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'txn_type' => array(
        'description' => 'The transaction type from PayPal.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'mc_gross' => array(
        'description' => 'The payment amount from PayPal.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'The IPN status from PayPal.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'receiver_email' => array(
        'description' => 'The e-mail address of the PayPal account.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'payer_email' => array(
        'description' => 'The e-mail address of the buyer.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'received' => array(
        'description' => 'The IPN receipt timestamp.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'order_id' => array('order_id'),
    ),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function uc_paypal_install() {
  drupal_install_schema('uc_paypal');

  $t = get_t();
  db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('paypal_pending', '%s', 'payment_received', 7, 1);", $t('PayPal pending'));
}

/**
 * Implementation of hook_uninstall().
 */
function uc_paypal_uninstall() {
  drupal_uninstall_schema('uc_paypal');
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_paypal_%%'");
}

function uc_paypal_update_1() {
  // Clean out the old order status table and redefine its structure.
  if ($_SESSION['statuses'] !== TRUE) {
    $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE order_status_id order_status_id VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
    $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE title title VARCHAR(48) CHARACTER SET utf8 NOT NULL default ''");
    $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE notify state VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
    $ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD weight MEDIUMINT(9) NOT NULL");
    $ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD locked TINYINT NOT NULL DEFAULT '0'");
    $ret[] = update_sql("DELETE FROM {uc_order_statuses} WHERE order_status_id LIKE '_'");
    $_SESSION['statuses'] = TRUE;
  }

  $t = get_t();
  $ret[] = update_sql("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('paypal_pending', '". $t('PayPal pending') ."', 'payment_received', 7, 1);");

  return $ret;
}

function uc_paypal_update_2() {
  // Change the variable used to define the default transaction type.
  if (variable_get('uc_paypal_wpp_payment_action', 'Sale') == 'Sale') {
    variable_set('uc_pg_paypal_wpp_cc_txn_type', UC_CREDIT_AUTH_CAPTURE);
  }
  else {
    variable_set('uc_pg_paypal_wpp_cc_txn_type', UC_CREDIT_AUTH_ONLY);
  }
  variable_del('uc_paypal_wpp_payment_action');

  // Fix a bug in a variable name.
  variable_set('uc_paypal_wps_submit_method', variable_get('uc_paypal_wbs_submit_method', 'single'));
  variable_del('uc_paypal_wbs_submit_method');

  return array();
}

function uc_paypal_update_6000() {
  $ret = array();

  db_drop_index($ret, 'uc_payment_paypal_ipn', 'order_id');
  db_change_field($ret, 'uc_payment_paypal_ipn', 'order_id', 'order_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), array('indexes' => array('order_id' => array('order_id'))));
  db_change_field($ret, 'uc_payment_paypal_ipn', 'received', 'received', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));

  return $ret;
}

Other Drupal examples (source code examples)

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