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

Drupal example source code file (test_gateway.module)

This example Drupal source code file (test_gateway.module) 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

admin, amount, array, card, charged, context, failed, function, message, order_id, php, return, success, test_gateway_charge

The test_gateway.module Drupal example source code

<?php
// $Id: test_gateway.module,v 1.1.2.7 2009/08/17 21:27:56 islandusurper Exp $

/**
 * @file
 * A test module used as an example for a payment gateway.
 *
 * Development sponsored by the Ubercart project.  http://www.ubercart.org
 */

/*******************************************************************************
 * Hook Functions (Ubercart)
 ******************************************************************************/

function test_gateway_payment_gateway() {
  $gateways[] = array(
    'id' => 'test_gateway',
    'title' => t('Test Gateway'),
    'description' => t('Process credit card payments through the Test Gateway.'),
    'credit' => 'test_gateway_charge',
  );

  return $gateways;
}


/*******************************************************************************
 * Module and Helper Functions
 ******************************************************************************/

function test_gateway_charge($order_id, $amount, $data) {
  global $user;
  $order = uc_order_load($order_id);

  // Use 0000000000000000 to test a failed payment, anything else for a good one.
  if ($order->payment_details['cc_number'] == '0000000000000000') {
    $success = FALSE;
  }
  else {
    $success = TRUE;
  }

  // Uncomment this lines to see the order object.  The information for the
  // payment is in the $order->payment_details array.
  // drupal_set_message('<pre>'. print_r($order->payment_details, TRUE) .'</pre>');

  if ($success) {
    $context = array(
      'revision' => 'formatted-original',
      'type' => 'amount',
    );
    $message = t('Credit card charged: !amount', array('!amount' => uc_price($amount, $context)));
    uc_order_comment_save($order_id, $user->uid, $message, 'admin');
  }
  else {
    $message = t('Credit card charge failed.');
    uc_order_comment_save($order_id, $user->uid, $message, 'admin');
  }

  $result = array(
    'success' => $success,
    'comment' => t('Card charged, resolution code: 0022548315'),
    'message' => $success ? t('Credit card payment processed successfully.') : t('Credit card charge failed.'),
    'uid' => $user->uid,
    // 'data' => $data,
  );

  return $result;
}

Other Drupal examples (source code examples)

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