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

Source for file AuthorizeNet.php

Documentation is available at AuthorizeNet.php

  1. <?php
  2. require_once 'Payment/Process2/Result.php';
  3. require_once 'Payment/Process2/Result/Driver.php';
  4.  
  5. class Payment_Process2_Result_AuthorizeNet extends Payment_Process2_Result implements Payment_Process2_Result_Driver
  6. {
  7.  
  8.     var $_statusCodeMap = array('1' => Payment_Process2::RESULT_APPROVED,
  9.                                 '2' => Payment_Process2::RESULT_DECLINED,
  10.                                 '3' => Payment_Process2::RESULT_OTHER,
  11.                                 '4' => Payment_Process2::RESULT_REVIEW
  12.                                 );
  13.  
  14.     /**
  15.      * AuthorizeNet status codes
  16.      *
  17.      * This array holds many of the common response codes. There are over 200
  18.      * response codes - so check the AuthorizeNet manual if you get a status
  19.      * code that does not match (see "Response Reason Codes & Response
  20.      * Reason Text" in the AIM manual).
  21.      *
  22.      * @see getStatusText()
  23.      * @access private
  24.      */
  25.     var $_statusCodeMessages = array(
  26.           '1' => 'This transaction has been approved.',
  27.           '2' => 'This transaction has been declined.',
  28.           '3' => 'This transaction has been declined.',
  29.           '4' => 'This transaction has been declined.',
  30.           '5' => 'A valid amount is required.',
  31.           '6' => 'The credit card number is invalid.',
  32.           '7' => 'The credit card expiration date is invalid.',
  33.           '8' => 'The credit card has expired.',
  34.           '9' => 'The ABA code is invalid.',
  35.           '10' => 'The account number is invalid.',
  36.           '11' => 'A duplicate transaction has been submitted.',
  37.           '12' => 'An authorization code is required but not present.',
  38.           '13' => 'The merchant Login ID is invalid or the account is inactive.',
  39.           '14' => 'The Referrer or Relay Response URL is invalid.',
  40.           '15' => 'The transaction ID is invalid.',
  41.           '16' => 'The transaction was not found.',
  42.           '17' => 'The merchant does not accept this type of credit card.',
  43.           '18' => 'ACH transactions are not accepted by this merchant.',
  44.           '19' => 'An error occurred during processing. Please try again in 5 minutes.',
  45.           '20' => 'An error occurred during processing. Please try again in 5 minutes.',
  46.           '21' => 'An error occurred during processing. Please try again in 5 minutes.',
  47.           '22' => 'An error occurred during processing. Please try again in 5 minutes.',
  48.           '23' => 'An error occurred during processing. Please try again in 5 minutes.',
  49.           '24' => 'The Nova Bank Number or Terminal ID is incorrect. Call Merchant Service Provider.',
  50.           '25' => 'An error occurred during processing. Please try again in 5 minutes.',
  51.           '26' => 'An error occurred during processing. Please try again in 5 minutes.',
  52.           '27' => 'The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.',
  53.           '28' => 'The merchant does not accept this type of credit card.',
  54.           '29' => 'The PaymentTech identification numbers are incorrect. Call Merchant Service Provider.',
  55.           '30' => 'The configuration with the processor is invalid. Call Merchant Service Provider.',
  56.           '31' => 'The FDC Merchant ID or Terminal ID is incorrect. Call Merchant Service Provider.',
  57.           '32' => 'The merchant password is invalid or not present.',
  58.           '33' => 'Missing required field',
  59.           '34' => 'The VITAL identification numbers are incorrect. Call Merchant Service Provider.',
  60.           '35' => 'An error occurred during processing. Call Merchant Service Provider.',
  61.           '36' => 'The authorization was approved, but settlement failed.',
  62.           '37' => 'The credit card number is invalid.',
  63.           '38' => 'The Global Payment System identification numbers are incorrect. Call Merchant Service Provider.',
  64.           '39' => 'The supplied currency code is either invalid, not supported, not allowed for this merchant or doesn\'t have an exchange rate.',
  65.           '40' => 'This transaction must be encrypted.',
  66.           '41' => 'FraudScreen.net fraud score is higher than threshold set by merchant',
  67.           '42' => 'There is missing or invalid information in a required field.',
  68.           '43' => 'The merchant was incorrectly set up at the processor. Call your Merchant Service Provider.',
  69.           '44' => 'This transaction has been declined. Card Code filter error!',
  70.           '45' => 'This transaction has been declined. Card Code / AVS filter error!',
  71.           '46' => 'Your session has expired or does not exist. You must log in to continue working.',
  72.           '47' => 'The amount requested for settlement may not be greater than the original amount authorized.',
  73.           '48' => 'This processor does not accept partial reversals.',
  74.           '49' => 'A transaction amount greater than $99,999 will not be accepted.',
  75.           '50' => 'This transaction is awaiting settlement and cannot be refunded.',
  76.           '51' => 'The sum of all credits against this transaction is greater than the original transaction amount.',
  77.           '52' => 'The transaction was authorized, but the client could not be notified; the transaction will not be settled.',
  78.           '53' => 'The transaction type was invalid for ACH transactions.',
  79.           '54' => 'The referenced transaction does not meet the criteria for issuing a credit.',
  80.           '55' => 'The sum of credits against the referenced transaction would exceed the original debit amount.',
  81.           '56' => 'This merchant accepts ACH transactions only; no credit card transactions are accepted.',
  82.           '57' => 'An error occurred in processing. Please try again in 5 minutes.',
  83.           '58' => 'An error occurred in processing. Please try again in 5 minutes.',
  84.           '59' => 'An error occurred in processing. Please try again in 5 minutes.',
  85.           '60' => 'An error occurred in processing. Please try again in 5 minutes.',
  86.           '61' => 'An error occurred in processing. Please try again in 5 minutes.',
  87.           '62' => 'An error occurred in processing. Please try again in 5 minutes.',
  88.           '63' => 'An error occurred in processing. Please try again in 5 minutes.',
  89.           '64' => 'The referenced transaction was not approved.',
  90.           '65' => 'This transaction has been declined.',
  91.           '66' => 'The transaction did not meet gateway security guidelines.',
  92.           '67' => 'The given transaction type is not supported for this merchant.',
  93.           '68' => 'The version parameter is invalid.',
  94.           '69' => 'The transaction type is invalid. The value submitted in x_type was invalid.',
  95.           '70' => 'The transaction method is invalid.',
  96.           '71' => 'The bank account type is invalid.',
  97.           '72' => 'The authorization code is invalid.',
  98.           '73' => 'The driver\'s license date of birth is invalid.',
  99.           '74' => 'The duty amount is invalid.',
  100.           '75' => 'The freight amount is invalid.',
  101.           '76' => 'The tax amount is invalid.',
  102.           '77' => 'The SSN or tax ID is invalid.',
  103.           '78' => 'The Card Code (CVV2/CVC2/CID) is invalid.',
  104.           '79' => 'The driver\'s license number is invalid.',
  105.           '80' => 'The driver\'s license state is invalid.',
  106.           '81' => 'The merchant requested an integration method not compatible with the AIM API.',
  107.           '82' => 'The system no longer supports version 2.5; requests cannot be posted to scripts.',
  108.           '83' => 'The requested script is either invalid or no longer supported.',
  109.           '84' => 'This reason code is reserved or not applicable to this API.',
  110.           '85' => 'This reason code is reserved or not applicable to this API.',
  111.           '86' => 'This reason code is reserved or not applicable to this API.',
  112.           '87' => 'This reason code is reserved or not applicable to this API.',
  113.           '88' => 'This reason code is reserved or not applicable to this API.',
  114.           '89' => 'This reason code is reserved or not applicable to this API.',
  115.           '90' => 'This reason code is reserved or not applicable to this API.',
  116.           '91' => 'Version 2.5 is no longer supported.',
  117.           '92' => 'The gateway no longer supports the requested method of integration.',
  118.           '93' => 'A valid country is required.',
  119.           '94' => 'The shipping state or country is invalid.',
  120.           '95' => 'A valid state is required.',
  121.           '96' => 'This country is not authorized for buyers.',
  122.           '97' => 'This transaction cannot be accepted.',
  123.           '98' => 'This transaction cannot be accepted.',
  124.           '99' => 'This transaction cannot be accepted.',
  125.           '100' => 'The eCheck type is invalid.',
  126.           '101' => 'The given name on the account and/or the account type does not match the actual account.',
  127.           '102' => 'This request cannot be accepted.',
  128.           '103' => 'This transaction cannot be accepted.',
  129.           '104' => 'This transaction is currently under review.',
  130.           '105' => 'This transaction is currently under review.',
  131.           '106' => 'This transaction is currently under review.',
  132.           '107' => 'This transaction is currently under review.',
  133.           '108' => 'This transaction is currently under review.',
  134.           '109' => 'This transaction is currently under review.',
  135.           '110' => 'This transaction is currently under review.',
  136.           '111' => 'A valid billing country is required.',
  137.           '112' => 'A valid billing state/provice is required.',
  138.           '116' => 'The authentication indicator is invalid.',
  139.           '117' => 'The cardholder authentication value is invalid.',
  140.           '118' => 'The combination of authentication indicator and cardholder authentication value is invalid.',
  141.           '119' => 'Transactions having cardholder authentication values cannot be marked as recurring.',
  142.           '120' => 'An error occurred during processing. Please try again.',
  143.           '121' => 'An error occurred during processing. Please try again.',
  144.           '122' => 'An error occurred during processing. Please try again.',
  145.           '127' => 'The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.',
  146.           '141' => 'This transaction has been declined.',
  147.           '145' => 'This transaction has been declined.',
  148.           '152' => 'The transaction was authorized, but the client could not be notified; the transaction will not be settled.',
  149.           '165' => 'This transaction has been declined.',
  150.           '170' => 'An error occurred during processing. Please contact the merchant.',
  151.           '171' => 'An error occurred during processing. Please contact the merchant.',
  152.           '172' => 'An error occurred during processing. Please contact the merchant.',
  153.           '173' => 'An error occurred during processing. Please contact the merchant.',
  154.           '174' => 'The transaction type is invalid. Please contact the merchant.',
  155.           '175' => 'The processor does not allow voiding of credits.',
  156.           '180' => 'An error occurred during processing. Please try again.',
  157.           '181' => 'An error occurred during processing. Please try again.',
  158.           '200' => 'This transaction has been declined.',
  159.           '201' => 'This transaction has been declined.',
  160.           '202' => 'This transaction has been declined.',
  161.           '203' => 'This transaction has been declined.',
  162.           '204' => 'This transaction has been declined.',
  163.           '205' => 'This transaction has been declined.',
  164.           '206' => 'This transaction has been declined.',
  165.           '207' => 'This transaction has been declined.',
  166.           '208' => 'This transaction has been declined.',
  167.           '209' => 'This transaction has been declined.',
  168.           '210' => 'This transaction has been declined.',
  169.           '211' => 'This transaction has been declined.',
  170.           '212' => 'This transaction has been declined.',
  171.           '213' => 'This transaction has been declined.',
  172.           '214' => 'This transaction has been declined.',
  173.           '215' => 'This transaction has been declined.',
  174.           '216' => 'This transaction has been declined.',
  175.           '217' => 'This transaction has been declined.',
  176.           '218' => 'This transaction has been declined.',
  177.           '219' => 'This transaction has been declined.',
  178.           '220' => 'This transaction has been declined.',
  179.           '221' => 'This transaction has been declined.',
  180.           '222' => 'This transaction has been declined.',
  181.           '223' => 'This transaction has been declined.',
  182.           '224' => 'This transaction has been declined.',
  183.           '243' => 'Recurring billing is not allowed for this eCheck.Net type',
  184.           '244' => 'This eCheck.Net type is not allowed for this Bank Account Type.',
  185.           '245' => 'This eCheck.Net type is not allowed when using the payment gateway hosted payment form.',
  186.           '246' => 'This eCheck.Net type is not allowed.',
  187.           '247' => 'This eCheck.Net type is not allowed.',
  188.           '250' => 'This transaction has been declined.',
  189.           '251' => 'This transaction has been declined.',
  190.           '252' => 'Your order has been received. Thank you for your business!',
  191.           '253' => 'Your order has been received. Thank you for your business!',
  192.           '254' => 'This transaction has been declined.',
  193.           '261' => 'An error occurred during processing. Please try again'
  194.     );
  195.  
  196.     var $_avsCodeMap = array(
  197.         'A' => Payment_Process2::AVS_MISMATCH,
  198.         'B' => Payment_Process2::AVS_ERROR,
  199.         'E' => Payment_Process2::AVS_ERROR,
  200.         'G' => Payment_Process2::AVS_NOAPPLY,
  201.         'N' => Payment_Process2::AVS_MISMATCH,
  202.         'P' => Payment_Process2::AVS_NOAPPLY,
  203.         'R' => Payment_Process2::AVS_ERROR,
  204.         'S' => Payment_Process2::AVS_ERROR,
  205.         'U' => Payment_Process2::AVS_ERROR,
  206.         'W' => Payment_Process2::AVS_MISMATCH,
  207.         'X' => Payment_Process2::AVS_MATCH,
  208.         'Y' => Payment_Process2::AVS_MATCH,
  209.         'Z' => Payment_Process2::AVS_MISMATCH
  210.     );
  211.  
  212.     var $_avsCodeMessages = array(
  213.         'A' => 'Address matches, postal code does not',
  214.         'B' => 'Address information not provided',
  215.         'E' => 'Address Verification System Error',
  216.         'G' => 'Non-U.S. Card Issuing Bank',
  217.         'N' => 'No match on street address nor postal code',
  218.         'P' => 'Address Verification System not applicable',
  219.         'R' => 'Retry - System unavailable or timeout',
  220.         'S' => 'Service not supported by issuer',
  221.         'U' => 'Address information unavailable',
  222.         'W' => '9-digit postal code matches, street address does not',
  223.         'X' => 'Address and 9-digit postal code match',
  224.         'Y' => 'Address and 5-digit postal code match',
  225.         'Z' => '5-digit postal code matches, street address does not'
  226.     );
  227.  
  228.     var $_cvvCodeMap = array('M' => Payment_Process2::CVV_MATCH,
  229.                              'N' => Payment_Process2::CVV_MISMATCH,
  230.                              'P' => Payment_Process2::CVV_ERROR,
  231.                              'S' => Payment_Process2::CVV_ERROR,
  232.                              'U' => Payment_Process2::CVV_ERROR
  233.     );
  234.  
  235.     var $_cvvCodeMessages = array(
  236.         'M' => 'CVV code matches',
  237.         'N' => 'CVV code does not match',
  238.         'P' => 'CVV code was not processed',
  239.         'S' => 'CVV code should have been present',
  240.         'U' => 'Issuer unable to process request',
  241.     );
  242.  
  243.     var $_fieldMap = array('0'  => 'code',
  244.                            '2'  => 'messageCode',
  245.                            '3'  => 'message',
  246.                            '4'  => 'approvalCode',
  247.                            '5'  => 'avsCode',
  248.                            '6'  => 'transactionId',
  249.                            '7'  => 'invoiceNumber',
  250.                            '8'  => 'description',
  251.                            '9'  => 'amount',
  252.                            '12' => 'customerId',
  253.                            '37' => 'md5Hash',
  254.                            '38' => 'cvvCode'
  255.     );
  256.  
  257.     /**
  258.      * To hold the MD5 hash returned
  259.      *
  260.      * @var string 
  261.      * @access private
  262.      */
  263.     var $_md5Hash;
  264.  
  265.     /**
  266.      * Parses the data received from the payment gateway
  267.      *
  268.      * @access public
  269.      */
  270.     function parse()
  271.     {
  272.         if (empty($this->_rawResponse)) {
  273.             return array();
  274.         }
  275.  
  276.         $delim $this->_request->getOption('x_delim_char');
  277.         $encap $this->_request->getOption('x_encap_char');
  278.  
  279.         $responseArray explode($encap $delim $encap$this->_rawResponse);
  280.         if ($responseArray === false{
  281.             return array();
  282.         }
  283.  
  284.         $count count($responseArray- 1;
  285.         if ($responseArray[0]{0== $encap{
  286.             $responseArray[0substr($responseArray[0]1);
  287.         }
  288.         if (substr($responseArray[$count]-1== $encap{
  289.             $responseArray[$countsubstr($responseArray[$count]0-1);
  290.         }
  291.  
  292.         // Save some fields in private members
  293.         $map array_flip($this->_fieldMap);
  294.         if (!empty($responseArray[$map['md5Hash']])) {
  295.             $this->_md5Hash $responseArray[$map['md5Hash']];
  296.         }
  297.         if (!empty($responseArray[$map['amount']])) {
  298.             $this->_amount  $responseArray[$map['amount']];
  299.         }
  300.  
  301.         $this->_mapFields($responseArray);
  302.  
  303.         // Adjust result code/message if needed based on raw code
  304.         switch ($this->messageCode{
  305.             case 33:
  306.                 // Something is missing so we send the raw message back
  307.                 $this->_statusCodeMessages[33$this->message;
  308.                 break;
  309.             case 11:
  310.                 // Duplicate transactions
  311.                 $this->code = Payment_Process2::RESULT_DUPLICATE;
  312.                 break;
  313.             case 4:
  314.             case 41:
  315.             case 250:
  316.             case 251:
  317.                 // Fraud detected
  318.                 $this->code = Payment_Process2::RESULT_FRAUD;
  319.                 break;
  320.         }
  321.     }
  322.  
  323.     /**
  324.      * Parses the data received from the payment gateway callback
  325.      *
  326.      * @access public
  327.      * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
  328.      */
  329.     function parseCallback()
  330.     {
  331.         $this->code          = $this->_rawResponse['x_response_code'];
  332.         $this->messageCode   = $this->_rawResponse['x_response_reason_code'];
  333.         $this->message       = $this->_rawResponse['x_response_reason_text'];
  334.         $this->approvalCode  = $this->_rawResponse['x_auth_code'];
  335.         $this->avsCode       = $this->_rawResponse['x_avs_code'];
  336.         $this->transactionId = $this->_rawResponse['x_trans_id'];
  337.         $this->invoiceNumber = $this->_rawResponse['x_invoice_num'];
  338.         $this->description   $this->_rawResponse['x_description'];
  339.         $this->_amount       $this->_rawResponse['x_amount'];
  340.         $this->customerId    = $this->_rawResponse['x_cust_id'];
  341.         $this->_md5Hash      $this->_rawResponse['x_MD5_Hash'];
  342.         $this->cvvCode       = $this->_rawResponse['x_cvv2_resp_code'];
  343.  
  344.         /** @todo Fix this! */
  345.         $map array_flip($GLOBALS['_Payment_Process2_AuthorizeNet']);
  346.         $this->action        $map[strtoupper($this->_rawResponse['x_type'])];
  347.     }
  348.  
  349.     /**
  350.      * Validates the legitimacy of the response
  351.      *
  352.      * To be able to validate the response, the md5Value option
  353.      * must have been set in the processor. If the md5Value is not set this
  354.      * function will fail gracefully, but this MAY CHANGE IN THE FUTURE!
  355.      *
  356.      * Check if the response is legitimate by matching MD5 hashes.
  357.      * To avoid MD5 mismatch while the key is being renewed
  358.      * the md5Value can be an array with 2 indexes: "new" and "old"
  359.      * respectively holding the new and old MD5 values.
  360.      *
  361.      * Note: If you're having problem passing this check: be aware that
  362.      * the login name is CASE-SENSITIVE!!! (even though you can log in
  363.      * using it all lowered case...)
  364.      *
  365.      * @return mixed TRUE if response is legitimate, FALSE if not, PEAR_Error on error
  366.      * @access public
  367.      * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
  368.      */
  369.     function isLegitimate()
  370.     {
  371.         $md5Value $this->_request->getOption('md5Value');
  372.         if (!$md5Value{
  373.             // For now fail gracefully if it is not set.
  374.             return true;
  375.         }
  376.  
  377.         $fields $this->_request->login . $this->transactionId
  378.                     . $this->_amount;
  379.         if (is_array($md5Value)) {
  380.             if (strcasecmp($this->_md5Hashmd5($md5Value['new'$fields)) == 0 ||
  381.                 strcasecmp($this->_md5Hashmd5($md5Value['old'$fields)) == 0{
  382.  
  383.                 return true;
  384.             }
  385.         elseif (strcasecmp($this->_md5Hashmd5($md5Value $fields)) == 0{
  386.             return true;
  387.         }
  388.         return false;
  389.     }
  390. }

Documentation generated on Mon, 11 Mar 2019 15:40:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.