Source for file Process.php
Documentation is available at Process.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: Ian Eure <ieure@php.net> |
// | Joe Stump <joe@joestump.net> |
// +----------------------------------------------------------------------+
// $Id: Process.php,v 1.30 2004/05/03 16:35:40 jstump Exp $
require_once 'Validate.php';
require_once 'Payment/Process/Type.php';
define('PAYMENT_PROCESS_ERROR_NOTIMPLEMENTED', -100 );
define('PAYMENT_PROCESS_ERROR_NOFIELD', -101 );
define('PAYMENT_PROCESS_ERROR_NOPROCESSOR', -102 );
define('PAYMENT_PROCESS_ERROR_INCOMPLETE', -1 );
define('PAYMENT_PROCESS_ERROR_INVAILD', -2 );
define('PAYMENT_PROCESS_ERROR_AVS',-3 );
define('PAYMENT_PROCESS_ERROR_CVV',-4 );
define('PAYMENT_PROCESS_ACTION_NORMAL', 200 );
// Authorize only. No funds are transferred.
define('PAYMENT_PROCESS_ACTION_AUTHONLY', 201 );
// Credit funds back from a previously-charged transaction.
define('PAYMENT_PROCESS_ACTION_CREDIT', 202 );
// Post-authorize an AUTHONLY transaction.
define('PAYMENT_PROCESS_ACTION_POSTAUTH', 203 );
define('PAYMENT_PROCESS_SOURCE_POS', 300 );
define('PAYMENT_PROCESS_SOURCE_ONLINE', 301 );
define('PAYMENT_PROCESS_RESULT_APPROVED', 400 );
define('PAYMENT_PROCESS_RESULT_DECLINED', 401 );
define('PAYMENT_PROCESS_RESULT_OTHER', 402 );
define('PAYMENT_PROCESS_RESULT_FRAUD', 403 );
define('PAYMENT_PROCESS_RESULT_DUPLICATE',404 );
define('PAYMENT_PROCESS_AVS_MATCH',500 );
define('PAYMENT_PROCESS_AVS_MISMATCH',501 );
define('PAYMENT_PROCESS_AVS_ERROR',502 );
define('PAYMENT_PROCESS_AVS_NOAPPLY',503 );
define('PAYMENT_PROCESS_CVV_MATCH',600 );
define('PAYMENT_PROCESS_CVV_MISMATCH',601 );
define('PAYMENT_PROCESS_CVV_ERROR',602 );
define('PAYMENT_PROCESS_CVV_NOAPPLY',603 );
* @author Ian Eure <ieure@php.net>
* @package Payment_Process
* Your login name to use for authentication to the online processor.
* Your password to use for authentication to the online processor.
* This should be set to one of the PAYMENT_PROCESS_ACTION_* constants.
* A description of the transaction (used by some processors to send
* information to the client, normally not a required field).
* The transaction amount.
* This should be set to one of the PAYMENT_PROCESS_SOURCE_* constants.
* Array of fields which are required.
var $_required = array ();
* Processor-specific data.
* @author Joe Stump <joe@joestump.net>
* Return an instance of a specific processor.
* @param string $type Name of the processor
* @param array $options Options for the processor
* @return mixed Instance of the processor object, or a PEAR_Error object.
function &factory($type, $options = false )
$class = "Payment_Process_". $type;
if (include_once " Payment/Process/{$type}.php" ) {
$object = & new $class($options);
$object->_driver = $type;
return PEAR ::raiseError ('"'. $type. '" processor does not exist',
* @param array $where Associative array of data to set, in the format
if (isset ($where[$field])) {
$this->$field = $where[$field];
* This will set a value, such as the credit card number. If the requested
* field is not part of the basic set of supported fields, it is set in
* @param string $field The field to set
* @param string $value The value to set
function set($field, $value)
return PEAR ::raiseError (" Field \"$field\" does not exist." , PAYMENT_PROCESS_ERROR_INVALID );
* Mark a field as being required.
* @param $field Field name
* @return boolean always true.
$this->_required[$field] = true;
* Mark a field as being optional.
* @param $field Field name
* @return boolean always true.
unset ($this->_required[$field]);
* Determine if a field is required.
* @param string $field Field to check
* @return boolean true if required, false if optional.
return (isset ($this->_required[$field]));
* Determines if a field exists.
* @author Ian Eure <ieure@php.net>
* @param string $field Field to check
* @return boolean true if field exists, false otherwise
* This function returns an array containing all the possible fields which
* @author Ian Eure <ieure@php.net>
* @return array Array of valid fields.
foreach ($vars as $idx => $field) {
if (ereg('^_+', $field)) {
* @author Ian Eure <ieure@php.net>
* @param Array $options Options to set
* @param Array $defaultOptions Default options
function setOptions($options = false , $defaultOptions = false )
$defaultOptions = $defaultOptions ? $defaultOptions : $this->_defaultOptions;
$this->_options = @array_merge($defaultOptions, $options);
* @author Ian Eure <ieure@php.net>
* @param string $option Option to get
* @return mixed Option value
return @$this->_options[$option];
* @author Joe Stump <joe@joestump.net>
* @param string $option Option name to set
* @param mixed $value Value to set
return ($this->_options[$option] = $value);
* See if a value is a defined constant.
* This function checks to see if $value is defined in one of
* PAYMENT_PROCESS_{$class}_*. It's used to verify that e.g. $object->action is one of
* PAYMENT_PROCESS_ACTION_NORMAL, PAYMENT_PROCESS_ACTION_AUTHONLY etc.
* @param mixed $value Value to check
* @param mixed $class Constant class to check
* @return boolean true if it is defined, false otherwise.
function _isDefinedConst ($value, $class)
$re = '^PAYMENT_PROCESS_'. strtoupper($class). '_.*';
foreach ($consts as $constant => $constVal) {
if (ereg($re, $constant)) {
* Statically check a Payment_Result class for success
* @author Joe Stump <joe@joestump.net>
if (is_a($obj,'Payment_Process_Result')) {
* Statically check a Payment_Result class for error
* @author Joe Stump <joe@joestump.net>
if (PEAR ::isError ($obj)) {
if (is_a($obj,'Payment_Process_Result')) {
* The core result class that should be returned from each driver's process()
* function. This should be extended as Payment_Process_Result_DriverName and
* then have the appropriate fields mapped out accordingly.
* Take special care to appropriately create a parse() function in your result
* class. You can then call _mapFields() with a resultArray (ie. exploded
* result) to map your results from parse() into the member variables.
* Please note that this class keeps your original codes intact so they can
* be accessed directly and then uses the function wrappers to return uniform
* @author Joe Stump <joe@joestump.net>
* @package Payment_Process
* Processor instance which this result was instantiated from.
* This should contain a reference to the requesting Processor.
* @author Ian Eure <ieure@php.net>
* The raw response (ie. from cURL)
* @author Joe Stump <joe@joestump.net>
* @var string $_rawResponse
* The approval/decline code
* The value returned by your gateway as approved/declined should be mapped
* into this variable. Valid results should then be mapped into the
* appropriate PAYMENT_PROCESS_RESULT_* code using the $_statusCodeMap
* array. Values returned into $code should be mapped as keys in the map
* with PAYMENT_PROCESS_RESULT_* as the values.
* @author Joe Stump <joe@joestump.net>
* @see PAYMENT_PROCESS_RESULT_APPROVED, PAYMENT_PROCESS_RESULT_DECLINED
* @see PAYMENT_PROCESS_RESULT_OTHER, $_statusCodeMap
* Along with the response (yes/no) you usually get a response/message
* code that translates into why it was approved/declined. This is where
* you map that code into. Your $_statusCodeMessages would then be keyed by
* valid messageCode values.
* @author Joe Stump <joe@joestump.net>
* @var mixed $messageCode
* @see $_statusCodeMessages
* Map the textual message from the gateway into this variable. It is not
* currently returned or used (in favor of the $_statusCodeMessages map, but
* can be accessed directly for debugging purposes.
* @author Joe Stump <joe@joestump.net>
* @see $_statusCodeMessages
var $message = 'No message from gateway';
* Authorization/Approval code
* @author Joe Stump <joe@joestump.net>
* @var string $approvalCode
* Address verification code
* The AVS code returned from your gateway. This should then be mapped to
* the appropriate PAYMENT_PROCESS_AVS_* code using $_avsCodeMap. This value
* should also be mapped to the appropriate textual message via the
* $_avsCodeMessages array.
* @author Joe Stump <joe@joestump.net>
* @see PAYMENT_PROCESS_AVS_MISMATCH, PAYMENT_PROCESS_AVS_ERROR
* @see PAYMENT_PROCESS_AVS_MATCH, PAYMENT_PROCESS_AVS_NOAPPLY, $_avsCodeMap
* This is the unique transaction ID, which is used by gateways to modify
* transactions (credit, update, etc.). Map the appropriate value into this
* @author Joe Stump <joe@joestump.net>
* @var string $transactionId
* Unique internal invoiceNumber (ie. your company's order/invoice number
* that you assign each order as it is processed). It is always a good idea
* to pass this to the gateway (which is usually then echo'd back).
* @author Joe Stump <joe@joestump.net>
* @var string $invoiceNumber
* Unique internall customer ID (ie. your company's customer ID used to
* track individual customers).
* @author Joe Stump <joe@joestump.net>
* @var string $customerId
* The CVV code is the 3-4 digit number on the back of most credit cards.
* This value should be mapped via the $_cvvCodeMap variable to the
* appropriate PAYMENT_PROCESS_CVV_* values.
* @author Joe Stump <joe@joestump.net>
var $cvvCode = PAYMENT_PROCESS_CVV_NOAPPLY;
* Your cvvCode value should be mapped to appropriate messages via the
* $_cvvCodeMessage array. This value is merely here to hold the value
* returned from the gateway (if any).
* @author Joe Stump <joe@joestump.net>
* @var string $cvvMessage
function &factory($type,$rawResponse)
$class = 'Payment_Process_Result_'. $type;
return new $class($rawResponse);
return PEAR ::raiseError ('Invalid response type: '. $type. '('. $class. ')');
* @author Joe Stump <joe@joestump.net>
if ($this->_request->getOption ('avsCheck') === true ) {
return PEAR ::raiseError ('AVS check failed',
$paymentType = $this->_request->_payment ->_driver;
if ($this->_request->getOption ('cvvCheck') === true &&
$paymentType == PAYMENT_PROCESS_TYPE_CREDITCARD ) {
return PEAR ::raiseError ('CVV check failed',
* @author Joe Stump <joe@joestump.net>
return PEAR ::raiseError ('parse() not implemented',
* @author Joe Stump <joe@joestump.net>
if (isset ($this->_statusCodeMap[$this->code])) {
return $this->_statusCodeMap[$this->code];
* Return the message from the code map, or return the raw message if
* there is one. Otherwise, return a worthless message.
* @author Joe Stump <joe@joestump.net>
if (isset ($this->_statusCodeMessages[$this->messageCode])) {
return 'No message reported';
return $this->_avsCodeMap[$this->avsCode];
return $this->_avsCodeMessages[$this->avsCode];
return $this->_cvvCodeMap[$this->cvvCode];
return $this->_cvvCodeMessages[$this->cvvCode];
* @author Joe Stump <joe@joestump.net>
* @param mixed $responseArray
function _mapFields ($responseArray) {
foreach($this->_fieldMap as $key => $val) {
$this->$val = $responseArray[$key];
Documentation generated on Mon, 11 Mar 2019 13:51:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|