Source for file TrustCommerce.php
Documentation is available at TrustCommerce.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Joe Stump <joe@joestump.net> |
// | Robert Peake <robert.peake@trustcommerce.com> |
// +----------------------------------------------------------------------+
// $Id: TrustCommerce.php,v 1.5 2005/07/08 00:13:25 jstump Exp $
require_once('Payment/Process.php');
require_once('Payment/Process/Common.php');
require_once('Net/Curl.php');
$GLOBALS['_Payment_Process_TrustCommerce'] = array (
* Payment_Process_TrustCommerce
* This is a processor for TrustCommerce's merchant payment gateway.
* (http://www.trustcommerce.com/)
* This is ALPHA code, and has not been fully tested. It is not recommended
* that you use it in a production envorinment without further testing.
* @package Payment_Process
* @author Robert Peake <robert.peake@trustcommerce.com>
* Front-end -> back-end field map.
* This array contains the mapping from front-end fields (defined in
* the Payment_Process class) to the field names TrustCommerce requires.
'password' => 'password',
'transactionId' => 'transid',
'currency' => 'currency',
* @author Robert Peake <robert.peake@trustcommerce.com>
'routingCode' => 'routing',
'accountNumber' => 'account',
* Default options for this processor.
* @see Payment_Process::setOptions()
var $_defaultOptions = array ();
* Has the transaction been processed?
* The response body sent back from the gateway.
* @param array $options Class options to set.
* @see Payment_Process::setOptions()
$this->_driver = 'TrustCommerce';
* Process the transaction.
* @return mixed Payment_Process_Result on success, PEAR_Error on failure
if(PEAR ::isError ($result)) {
$result = $this->_prepare ();
if (PEAR ::isError ($result)) {
// Don't die partway through
PEAR ::pushErrorHandling (PEAR_ERROR_RETURN );
$fields = $this->_prepareQueryString ();
$result = tclink_send ($fields);
for($i=0; $i< sizeof($r_keys); $i++ ) {
$result_string .= $key. '='. $value. "\n";
if (PEAR ::isError ($result_string)) {
PEAR ::popErrorHandling ();
$result = $result_string;
$curl = & new Net_Curl ('https://vault.trustcommerce.com/trans/');
if (PEAR ::isError ($curl)) {
PEAR ::popErrorHandling ();
$curl->userAgent = 'PEAR Payment_Process_TrustCommerce 0.1a';
$result = &$curl->execute ();
if (PEAR ::isError ($result)) {
PEAR ::popErrorHandling ();
/** END TCLINK/CURL CASE STATEMENT **/
$this->_responseBody = trim($result);
$this->_processed = true;
// Restore error handling
PEAR ::popErrorHandling ();
if (!PEAR ::isError ($response)) {
* Get (completed) transaction status.
* @return boolean status.
* Prepare the POST query string.
* @return string The query string
function _prepareQueryString ()
/* expiration is expressed as mmyy */
$fulldate = $data['exp'];
$month = strtok($fulldate,'/');
$exp = $month. substr($year,2 ,2 );
/* end expiration mangle */
/* amount is expressed in cents with leading zeroes */
$data['amount'] = $data['amount']*100;
if (strlen($data['amount']) == 1 ) {
$data['amount'] = "00". $data['amount'];
} else if(strlen($data['amount']) < 3 ) {
$data['amount'] = "0". $data['amount'];
} else if(strlen($data['amount']) > 8 ) {
$amount_message = 'Amount: '. $data['amount']. ' too large.';
PEAR ::pushErrorHandling (PEAR_ERROR_RETURN );
PEAR ::raiseError ($amount_message);
PEAR ::popErrorHandling ();
if ($this->_payment->getType () == 'CreditCard' &&
if ($this->_payment->getType () == 'eCheck') {
foreach ($data as $key => $val) {
$this->_options['authorizeUri'] = 'https://vault.trustcommerce.com/trans/?'. implode('&',$sets);
var $_statusCodeMap = array ('approved' => PAYMENT_PROCESS_RESULT_APPROVED ,
'accepted' => PAYMENT_PROCESS_RESULT_APPROVED ,
'declined' => PAYMENT_PROCESS_RESULT_DECLINED ,
'baddata' => PAYMENT_PROCESS_RESULT_OTHER ,
'error' => PAYMENT_PROCESS_RESULT_OTHER );
* TrustCommerce status codes
* This array holds response codes.
var $_statusCodeMessages = array (
'approved' => 'The transaction was successfully authorized.',
'accepted' => 'The transaction has been successfully accepted into the system.',
'decline' => 'The transaction was declined, see declinetype for further details.',
'baddata' => 'Invalid parameters passed, see error for further details.',
'error' => 'System error when processing the transaction, see errortype for details.',
var $_avsCodeMap = array (
'N' => PAYMENT_PROCESS_AVS_MISMATCH ,
'U' => PAYMENT_PROCESS_AVS_NOAPPLY ,
'G' => PAYMENT_PROCESS_AVS_NOAPPLY ,
'R' => PAYMENT_PROCESS_AVS_ERROR ,
'E' => PAYMENT_PROCESS_AVS_ERROR ,
'S' => PAYMENT_PROCESS_AVS_ERROR ,
'O' => PAYMENT_PROCESS_AVS_ERROR
var $_avsCodeMessages = array (
'X' => 'Exact match, 9 digit zipcode.',
'Y' => 'Exact match, 5 digit zipcode.',
'A' => 'Street address match only.',
'W' => '9 digit zipcode match only.',
'Z' => '5 digit zipcode match only.',
'N' => 'No mtach on street address or zipcode.',
'U' => 'AVS unavailable on this card.',
'G' => 'Non-US card issuer, AVS unavailable.',
'R' => 'Card issuer system currently down, try again later.',
'E' => 'Error, ineligible - not a mail/phone order.',
'S' => 'Service not supported.',
'O' => 'General decline or other error'
var $_cvvCodeMap = array ('cvv' => PAYMENT_PROCESS_CVV_MISMATCH
var $_cvvCodeMessages = array ( 'cvv' => 'The CVV number is not valid.'
var $_fieldMap = array ('status' => 'code',
'transid' => 'transactionId'
$this->Payment_Process_Response ($rawResponse);
for($i=0; $i< sizeof($array); $i++ )
$response_line = $array[$i];
$response_array = preg_split("/=/",$response_line);
$key = $response_array[0 ];
$value = $response_array[1 ];
$responseArray[$key] = $value;
$this->_mapFields ($responseArray);
function _mapFields ($responseArray)
foreach($this->_fieldMap as $key => $val) {
$this->$val = $responseArray[$key];
if (!isset ($this->_statusCodeMessages[$this->messageCode]))
$message = $this->_statusCodeMessages[$responseArray['status']];
if($responseArray['error'])
$message .= "\nError type: ". $responseArray['error']. '.';
if($responseArray['offenders'])
$message .= "\nOffending fields: ". $responseArray['offenders']. '.';
$this->_statusCodeMessages[$this->messageCode] = $message;
Documentation generated on Mon, 11 Mar 2019 14:00:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|