Payment_Process
[ class tree: Payment_Process ] [ index: Payment_Process ] [ all elements ]

Source for file AuthorizeNet.php

Documentation is available at AuthorizeNet.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Joe Stump <joe@joestump.net>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: AuthorizeNet.php,v 1.17 2004/04/30 15:27:14 jstump Exp $
  20.  
  21. require_once 'Payment/Process.php';
  22. require_once 'Payment/Process/Common.php';
  23. require_once 'Net/Curl.php';
  24.  
  25. $GLOBALS['_Payment_Process_AuthorizeNet'= array(
  26.     PAYMENT_PROCESS_ACTION_NORMAL   => 'AUTH_CAPTURE',
  27.     PAYMENT_PROCESS_ACTION_AUTHONLY => 'AUTH_ONLY',
  28.     PAYMENT_PROCESS_ACTION_POSTAUTH => 'PRIOR_AUTH_CAPTURE'
  29. );
  30.  
  31. /**
  32.  * Payment_Process_AuthorizeNet
  33.  *
  34.  * This is a processor for Authorize.net's merchant payment gateway.
  35.  * (http://www.authorize.net/)
  36.  *
  37.  * *** WARNING ***
  38.  * This is BETA code, and has not been fully tested. It is not recommended
  39.  * that you use it in a production envorinment without further testing.
  40.  *
  41.  * @package Payment_Process
  42.  * @author Joe Stump <joe@joestump.net>
  43.  * @version @version@
  44.  */
  45.     /**
  46.      * Front-end -> back-end field map.
  47.      *
  48.      * This array contains the mapping from front-end fields (defined in
  49.      * the Payment_Process class) to the field names DPILink requires.
  50.      *
  51.      * @see _prepare()
  52.      * @access private
  53.      */
  54.     var $_fieldMap = array(
  55.         // Required
  56.         'login' => 'x_login',
  57.         'password' => 'x_password',
  58.         'action' => 'x_type',
  59.         'invoiceNumber' => 'x_invoice_num',
  60.         'customerId' => 'x_cust_id',
  61.         'amount' => 'x_amount',
  62.         'name' => '',
  63.         'zip' => 'x_zip',
  64.         // Optional
  65.         'company' => 'x_company',
  66.         'address' => 'x_address',
  67.         'city' => 'x_city',
  68.         'state' => 'x_state',
  69.         'country' => 'x_country',
  70.         'phone' => 'x_phone',
  71.         'email' => 'x_email',
  72.         'ip' => 'x_customer_ip',
  73.     );
  74.  
  75.     /**
  76.     * $_typeFieldMap
  77.     *
  78.     * @author Joe Stump <joe@joestump.net>
  79.     * @access protected
  80.     */
  81.     var $_typeFieldMap = array(
  82.  
  83.            'CreditCard' => array(
  84.  
  85.                     'cardNumber' => 'x_card_num',
  86.                     'cvv' => 'x_card_code',
  87.                     'expDate' => 'x_exp_date'
  88.  
  89.            ),
  90.  
  91.            'eCheck' => array(
  92.  
  93.                     'routingCode' => 'x_bank_aba_code',
  94.                     'accountNumber' => 'x_bank_acct_num',
  95.                     'type' => 'x_bank_acct_type',
  96.                     'bankName' => 'x_bank_name',
  97.                     'name' => 'x_bank_acct_name'
  98.  
  99.            )
  100.     );
  101.  
  102.     /**
  103.      * Default options for this processor.
  104.      *
  105.      * @see Payment_Process::setOptions()
  106.      * @access private
  107.      */
  108.     var $_defaultOptions = array(
  109.          'authorizeUri' => 'https://secure.authorize.net/gateway/transact.dll',
  110.          'x_delim_data' => 'TRUE',
  111.          'x_relay' => 'FALSE',
  112.          'x_email_customer' => 'FALSE',
  113.          'x_test_request' => 'FALSE',
  114.          'x_currency_code' => 'USD',
  115.          'x_version' => '3.1'
  116.     );
  117.  
  118.     /**
  119.      * Has the transaction been processed?
  120.      *
  121.      * @type boolean
  122.      * @access private
  123.      */
  124.     var $_processed = false;
  125.  
  126.     /**
  127.      * The response body sent back from the gateway.
  128.      *
  129.      * @access private
  130.      */
  131.     var $_responseBody '';
  132.  
  133.     /**
  134.      * Constructor.
  135.      *
  136.      * @param  array  $options  Class options to set.
  137.      * @see Payment_Process::setOptions()
  138.      * @return void 
  139.      */
  140.     function Payment_Process_AuthorizeNet($options = false)
  141.     {
  142.         $this->setOptions($options);
  143.     }
  144.  
  145.     /**
  146.      * Process the transaction.
  147.      *
  148.      * @return mixed Payment_Process_Result on success, PEAR_Error on failure
  149.      */
  150.     function &process()
  151.     {
  152.         if($this->_options['debug'=== true{
  153.             echo "----------- DATA -----------\n";
  154.             print_r($this->_data);
  155.             echo "----------- DATA -----------\n";
  156.         }
  157.  
  158.         // Sanity check
  159.         $result $this->validate();
  160.         if(PEAR::isError($result)) {
  161.             return $result;
  162.         }
  163.  
  164.         // Prepare the data
  165.         $result $this->_prepare();
  166.         if (PEAR::isError($result)) {
  167.             return $result
  168.         }
  169.  
  170.         // Don't die partway through
  171.         PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  172.  
  173.         if($this->_options['debug'=== true{
  174.             print_r($this->_options);
  175.         }
  176.  
  177.         $fields $this->_prepareQueryString();
  178.         $curl new Net_Curl($this->_options['authorizeUri']);
  179.         if (PEAR::isError($curl)) {
  180.             PEAR::popErrorHandling();
  181.             return $curl;
  182.         }
  183.  
  184.         $curl->type = 'PUT';
  185.         $curl->fields = $fields;
  186.         if($this->_options['debug'=== true{
  187.             echo "------------ CURL FIELDS -------------\n";
  188.             print_r($curl->fields)
  189.             echo "------------ CURL FIELDS -------------\n";
  190.         }
  191.  
  192.         $curl->userAgent = 'PEAR Payment_Process_AuthorizeNet 0.1';
  193.  
  194.         $result &$curl->execute();
  195.         if (PEAR::isError($result)) {
  196.             PEAR::popErrorHandling();
  197.             return $result;
  198.         else {
  199.             $curl->close();
  200.         }
  201.  
  202.  
  203.         $this->_responseBody trim($result);
  204.         $this->_processed = true;
  205.  
  206.         // Restore error handling
  207.         PEAR::popErrorHandling();
  208.  
  209.         $response &Payment_Process_Result::factory($this->_driver,$this->_responseBody);
  210.         if(!PEAR::isError($response))
  211.         {
  212.           $response->_request = $this;
  213.           $response->parse();
  214.         }
  215.  
  216.         return $response;
  217.  
  218.     }
  219.  
  220.     /**
  221.      * Get (completed) transaction status.
  222.      *
  223.      * @return string Two-digit status returned from gateway.
  224.      */
  225.     function getStatus()
  226.     {
  227.         return false;
  228.     }
  229.  
  230.     /**
  231.      * Prepare the POST query string.
  232.      *
  233.      * @access private
  234.      * @return string The query string
  235.      */
  236.     function _prepareQueryString()
  237.     {
  238.  
  239.         $data array_merge($this->_options,$this->_data);
  240.  
  241.         // Set payment method to eCheck if our payment type is eCheck.
  242.         // Default is Credit Card.
  243.         $data['x_method''CC';
  244.         if($this->_payment->getType(== 'eCheck')
  245.         {
  246.           $data['x_method''ECHECK';
  247.           switch($this->_payment->type)
  248.           {
  249.             case PAYMENT_PROCESS_CK_CHECKING:
  250.               $data['x_bank_acct_type''CHECKING';
  251.               break;
  252.             case PAYMENT_PROCESS_CK_SAVINGS:
  253.               $data['x_bank_acct_type''SAVINGS';
  254.               break;
  255.           }
  256.         }
  257.  
  258.         if($this->_options['debug'=== true{
  259.             echo "--------- PREPARE QS DATA -----------\n";
  260.             print_r($this->_data);
  261.             print_r($data);
  262.             echo "--------- PREPARE QS DATA -----------\n";
  263.         }
  264.         $return = array();
  265.         $sets = array();
  266.         foreach ($data as $key => $val{
  267.             if (eregi('^x_',$key&& strlen($val)) {
  268.                 $return[$key$val;
  269.                 $sets[$key.'='.urlencode($val);
  270.             }
  271.         }
  272.  
  273.         $this->_options['authorizeUri'.= '?'.implode('&',$sets);
  274.  
  275.         return $return;
  276.     }
  277.  
  278.     /**
  279.     * _handleName
  280.     *
  281.     * @author Joe Stump <joe@joestump.net>
  282.     * @access private
  283.     */
  284.     function _handleName()
  285.     {
  286.       $parts explode(' ',$this->_payment->name);
  287.       $this->_data['x_first_name'array_shift($parts);
  288.       $this->_data['x_last_name'implode(' ',$parts)
  289.     }
  290. }
  291.  
  292.  
  293.     var $_statusCodeMap = array('1' => PAYMENT_PROCESS_RESULT_APPROVED,
  294.                                 '2' => PAYMENT_PROCESS_RESULT_DECLINED,
  295.                                 '3' => PAYMENT_PROCESS_RESULT_OTHER);
  296.  
  297.     /**
  298.      * AuthorizeNet status codes
  299.      *
  300.      * This array holds many of the common response codes. There are over 200
  301.      * response codes - so check the AuthorizeNet manual if you get a status
  302.      * code that does not match (see "Response Reason Codes & Response
  303.      * Reason Text" in the AIM manual).
  304.      *
  305.      * @see getStatusText()
  306.      * @access private
  307.      */
  308.     var $_statusCodeMessages = array(
  309.           '1' => 'This transaction has been approved.',
  310.           '2' => 'This transaction has been declined.',
  311.           '3' => 'This transaction has been declined.',
  312.           '4' => 'This transaction has been declined.',
  313.           '5' => 'A valid amount is required.',
  314.           '6' => 'The credit card number is invalid.',
  315.           '7' => 'The credit card expiration date is invalid.',
  316.           '8' => 'The credit card has expired.',
  317.           '9' => 'The ABA code is invalid.',
  318.           '10' => 'The account number is invalid.',
  319.           '11' => 'A duplicate transaction has been submitted.',
  320.           '12' => 'An authorization code is required but not present.',
  321.           '13' => 'The merchant Login ID is invalid or the account is inactive.',
  322.           '14' => 'The Referrer or Relay Response URL is invalid.',
  323.           '15' => 'The transaction ID is invalid.',
  324.           '16' => 'The transaction was not found.',
  325.           '17' => 'The merchant does not accept this type of credit card.',
  326.           '18' => 'ACH transactions are not accepted by this merchant.',
  327.           '19' => 'An error occurred during processing. Please try again in 5 minutes.',
  328.           '20' => 'An error occurred during processing. Please try again in 5 minutes.',
  329.           '21' => 'An error occurred during processing. Please try again in 5 minutes.',
  330.           '22' => 'An error occurred during processing. Please try again in 5 minutes.',
  331.           '23' => 'An error occurred during processing. Please try again in 5 minutes.',
  332.           '24' => 'The Nova Bank Number or Terminal ID is incorrect. Call Merchant Service Provider.',
  333.           '25' => 'An error occurred during processing. Please try again in 5 minutes.',
  334.           '26' => 'An error occurred during processing. Please try again in 5 minutes.',
  335.           '27' => 'The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.',
  336.           '28' => 'The merchant does not accept this type of credit card.',
  337.           '29' => 'The PaymentTech identification numbers are incorrect. Call Merchant Service Provider.',
  338.           '30' => 'The configuration with the processor is invalid. Call Merchant Service Provider.',
  339.           '31' => 'The FDC Merchant ID or Terminal ID is incorrect. Call Merchant Service Provider.',
  340.           '32' => 'The merchant password is invalid or not present.',
  341.           '33' => 'Missing required field',
  342.           '34' => 'The VITAL identification numbers are incorrect. Call Merchant Service Provider.',
  343.           '35' => 'An error occurred during processing. Call Merchant Service Provider.',
  344.           '36' => 'The authorization was approved, but settlement failed.',
  345.           '37' => 'The credit card number is invalid.',
  346.           '38' => 'The Global Payment System identification numbers are incorrect. Call Merchant Service Provider.',
  347.           '39' => 'The supplied currency code is either invalid, not supported, not allowed for this merchant or doesn\'t have an exchange rate.',
  348.           '40' => 'This transaction must be encrypted.',
  349.           '41' => 'FraudScreen.net fraud score is higher than threshold set by merchant',
  350.           '42' => 'There is missing or invalid information in a required field.',
  351.           '43' => 'The merchant was incorrectly set up at the processor. Call your Merchant Service Provider.',
  352.           '44' => 'This transaction has been declined. Card Code filter error!',
  353.           '45' => 'This transaction has been declined. Card Code / AVS filter error!',
  354.           '46' => 'Your session has expired or does not exist. You must log in to continue working.',
  355.           '47' => 'The amount requested for settlement may not be greater than the original amount authorized.',
  356.           '48' => 'This processor does not accept partial reversals.',
  357.           '49' => 'A transaction amount greater than $99,999 will not be accepted.',
  358.           '50' => 'This transaction is awaiting settlement and cannot be refunded.',
  359.           '51' => 'The sum of all credits against this transaction is greater than the original transaction amount.',
  360.           '52' => 'The transaction was authorized, but the client could not be notified; the transaction will not be settled.',
  361.           '53' => 'The transaction type was invalid for ACH transactions.',
  362.           '54' => 'The referenced transaction does not meet the criteria for issuing a credit.',
  363.           '55' => 'The sum of credits against the referenced transaction would exceed the original debit amount.',
  364.           '56' => 'This merchant accepts ACH transactions only; no credit card transactions are accepted.',
  365.           '57' => 'An error occurred in processing. Please try again in 5 minutes.',
  366.           '58' => 'An error occurred in processing. Please try again in 5 minutes.',
  367.           '59' => 'An error occurred in processing. Please try again in 5 minutes.',
  368.           '60' => 'An error occurred in processing. Please try again in 5 minutes.',
  369.           '61' => 'An error occurred in processing. Please try again in 5 minutes.',
  370.           '62' => 'An error occurred in processing. Please try again in 5 minutes.',
  371.           '63' => 'An error occurred in processing. Please try again in 5 minutes.',
  372.           '64' => 'The referenced transaction was not approved.',
  373.           '65' => 'This transaction has been declined.',
  374.           '66' => 'The transaction did not meet gateway security guidelines.',
  375.           '67' => 'The given transaction type is not supported for this merchant.',
  376.           '68' => 'The version parameter is invalid.',
  377.           '69' => 'The transaction type is invalid. The value submitted in x_type was invalid.',
  378.           '70' => 'The transaction method is invalid.',
  379.           '71' => 'The bank account type is invalid.',
  380.           '72' => 'The authorization code is invalid.',
  381.           '73' => 'The driver\'s license date of birth is invalid.',
  382.           '74' => 'The duty amount is invalid.',
  383.           '75' => 'The freight amount is invalid.',
  384.           '76' => 'The tax amount is invalid.',
  385.           '77' => 'The SSN or tax ID is invalid.',
  386.           '78' => 'The Card Code (CVV2/CVC2/CID) is invalid.',
  387.           '79' => 'The driver\'s license number is invalid.',
  388.           '80' => 'The driver\'s license state is invalid.',
  389.           '81' => 'The merchant requested an integration method not compatible with the AIM API.',
  390.           '82' => 'The system no longer supports version 2.5; requests cannot be posted to scripts.',
  391.           '83' => 'The requested script is either invalid or no longer supported.',
  392.           '84' => 'This reason code is reserved or not applicable to this API.',
  393.           '85' => 'This reason code is reserved or not applicable to this API.',
  394.           '86' => 'This reason code is reserved or not applicable to this API.',
  395.           '87' => 'This reason code is reserved or not applicable to this API.',
  396.           '88' => 'This reason code is reserved or not applicable to this API.',
  397.           '89' => 'This reason code is reserved or not applicable to this API.',
  398.           '90' => 'This reason code is reserved or not applicable to this API.',
  399.           '91' => 'Version 2.5 is no longer supported.',
  400.           '92' => 'The gateway no longer supports the requested method of integration.',
  401.           '93' => 'A valid country is required.',
  402.           '94' => 'The shipping state or country is invalid.',
  403.           '95' => 'A valid state is required.',
  404.           '96' => 'This country is not authorized for buyers.',
  405.           '97' => 'This transaction cannot be accepted.',
  406.           '98' => 'This transaction cannot be accepted.',
  407.           '99' => 'This transaction cannot be accepted.',
  408.           '100' => 'The eCheck type is invalid.',
  409.           '101' => 'The given name on the account and/or the account type does not match the actual account.',
  410.           '102' => 'This request cannot be accepted.',
  411.           '103' => 'This transaction cannot be accepted.',
  412.           '104' => 'This transaction is currently under review.',
  413.           '105' => 'This transaction is currently under review.',
  414.           '106' => 'This transaction is currently under review.',
  415.           '107' => 'This transaction is currently under review.',
  416.           '108' => 'This transaction is currently under review.',
  417.           '109' => 'This transaction is currently under review.',
  418.           '110' => 'This transaction is currently under review.',
  419.           '111' => 'A valid billing country is required.',
  420.           '112' => 'A valid billing state/provice is required.',
  421.           '116' => 'The authentication indicator is invalid.',
  422.           '117' => 'The cardholder authentication value is invalid.',
  423.           '118' => 'The combination of authentication indicator and cardholder authentication value is invalid.',
  424.           '119' => 'Transactions having cardholder authentication values cannot be marked as recurring.',
  425.           '120' => 'An error occurred during processing. Please try again.',
  426.           '121' => 'An error occurred during processing. Please try again.',
  427.           '122' => 'An error occurred during processing. Please try again.',
  428.           '127' => 'The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.',
  429.           '141' => 'This transaction has been declined.',
  430.           '145' => 'This transaction has been declined.',
  431.           '152' => 'The transaction was authorized, but the client could not be notified; the transaction will not be settled.',
  432.           '165' => 'This transaction has been declined.',
  433.           '170' => 'An error occurred during processing. Please contact the merchant.',
  434.           '171' => 'An error occurred during processing. Please contact the merchant.',
  435.           '172' => 'An error occurred during processing. Please contact the merchant.',
  436.           '173' => 'An error occurred during processing. Please contact the merchant.',
  437.           '174' => 'The transaction type is invalid. Please contact the merchant.',
  438.           '175' => 'The processor does not allow voiding of credits.',
  439.           '180' => 'An error occurred during processing. Please try again.',
  440.           '181' => 'An error occurred during processing. Please try again.',
  441.           '200' => 'This transaction has been declined.',
  442.           '201' => 'This transaction has been declined.',
  443.           '202' => 'This transaction has been declined.',
  444.           '203' => 'This transaction has been declined.',
  445.           '204' => 'This transaction has been declined.',
  446.           '205' => 'This transaction has been declined.',
  447.           '206' => 'This transaction has been declined.',
  448.           '207' => 'This transaction has been declined.',
  449.           '208' => 'This transaction has been declined.',
  450.           '209' => 'This transaction has been declined.',
  451.           '210' => 'This transaction has been declined.',
  452.           '211' => 'This transaction has been declined.',
  453.           '212' => 'This transaction has been declined.',
  454.           '213' => 'This transaction has been declined.',
  455.           '214' => 'This transaction has been declined.',
  456.           '215' => 'This transaction has been declined.',
  457.           '216' => 'This transaction has been declined.',
  458.           '217' => 'This transaction has been declined.',
  459.           '218' => 'This transaction has been declined.',
  460.           '219' => 'This transaction has been declined.',
  461.           '220' => 'This transaction has been declined.',
  462.           '221' => 'This transaction has been declined.',
  463.           '222' => 'This transaction has been declined.',
  464.           '223' => 'This transaction has been declined.',
  465.           '224' => 'This transaction has been declined.'
  466.     );
  467.  
  468.     var $_avsCodeMap = array(
  469.         'A' => PAYMENT_PROCESS_AVS_MISMATCH,
  470.         'B' => PAYMENT_PROCESS_AVS_ERROR,
  471.         'E' => PAYMENT_PROCESS_AVS_ERROR,
  472.         'G' => PAYMENT_PROCESS_AVS_NOAPPLY,
  473.         'N' => PAYMENT_PROCESS_AVS_MISMATCH,
  474.         'P' => PAYMENT_PROCESS_AVS_NOAPPLY,
  475.         'R' => PAYMENT_PROCESS_AVS_ERROR,
  476.         'S' => PAYMENT_PROCESS_AVS_ERROR,
  477.         'U' => PAYMENT_PROCESS_AVS_ERROR,
  478.         'W' => PAYMENT_PROCESS_AVS_MISMATCH,
  479.         'X' => PAYMENT_PROCESS_AVS_MATCH,
  480.         'Y' => PAYMENT_PROCESS_AVS_MATCH,
  481.         'Z' => PAYMENT_PROCESS_AVS_MISMATCH
  482.     );
  483.  
  484.     var $_avsCodeMessages = array(
  485.         'A' => 'Address matches, ZIP does not',
  486.         'B' => 'Address information not provided',
  487.         'E' => 'AVS Error',
  488.         'G' => 'Non-U.S. Card Issuing Bank',
  489.         'N' => 'No match',
  490.         'P' => 'AVS not applicable',
  491.         'R' => 'Retry - System unavailable or timeout',
  492.         'S' => 'Service not supported by issuer',
  493.         'U' => 'Address information unavailable',
  494.         'W' => '9-digit zip matches, Address (street) does not',
  495.         'X' => 'Address and 9-digit zip match',
  496.         'Y' => 'Address and 5-digit zip match',
  497.         'Z' => '5-digit zip matches, Address (street) does not'
  498.     );
  499.  
  500.     var $_cvvCodeMap = array('M' => PAYMENT_PROCESS_CVV_MATCH,
  501.                              'N' => PAYMENT_PROCESS_CVV_MISMATCH,
  502.                              'P' => PAYMENT_PROCESS_CVV_ERROR,
  503.                              'S' => PAYMENT_PROCESS_CVV_ERROR,
  504.                              'U' => PAYMENT_PROCESS_CVV_ERROR
  505.     );
  506.  
  507.     var $_cvvCodeMessages = array(
  508.         'M' => 'CVV codes match',
  509.         'N' => 'CVV codes do not match',
  510.         'P' => 'CVV code was not processed',
  511.         'S' => 'CVV code should have been present',
  512.         'U' => 'Issuer unable to process request',
  513.     );
  514.  
  515.     var $_fieldMap = array('0'  => 'code',
  516.                            '2'  => 'messageCode',
  517.                            '3'  => 'message',
  518.                            '4'  => 'approvalCode',
  519.                            '5'  => 'avsCode',
  520.                            '6'  => 'transactionId',
  521.                            '7'  => 'invoiceNumber',
  522.                            '12' => 'customerId',
  523.                            '39' => 'cvvCode'
  524.     );
  525.  
  526.     function Payment_Process_Response_AuthorizeNet($rawResponse
  527.     {
  528.         $this->Payment_Process_Response($rawResponse);
  529.     }
  530.  
  531.     function parse()
  532.     {
  533.       $responseArray explode(',',$this->_rawResponse);
  534.       $this->_mapFields($responseArray);
  535.     }
  536. }
  537.  
  538. ?>

Documentation generated on Mon, 11 Mar 2019 13:51:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.