M2_AuthorizeNetCP_Response

Parses an AuthorizeNet Card Present Response.

Defined (1)

The class is defined in the following location(s).

/lib/authorize.net/lib/AuthorizeNetCP.php  
  1. class M2_AuthorizeNetCP_Response extends M2_AuthorizeNetResponse 
  2. private $_response_array = array(); // An array with the split response. 
  3.  
  4. /** 
  5. * Constructor. Parses the AuthorizeNet response string. 
  6. * @param string $response The response from the AuthNet server. 
  7. * @param string $delimiter The delimiter used (default is ", ") 
  8. * @param string $encap_char The encap_char used (default is "|") 
  9. * @param array $custom_fields Any custom fields set in the request. 
  10. */ 
  11. public function __construct($response, $delimiter, $encap_char, $custom_fields) 
  12. if ($response) { 
  13.  
  14. // If it's an XML response 
  15. if (substr($response, 0, 5) == "<?xml") { 
  16.  
  17. $this->xml = @simplexml_load_string($response); 
  18. // Set all fields 
  19. $this->version = array_pop(array_slice(explode('"', $response), 1, 1)); 
  20. $this->response_code = (string)$this->xml->ResponseCode; 
  21.  
  22. if ($this->response_code == 1) { 
  23. $this->response_reason_code = (string)$this->xml->Messages->Message->Code; 
  24. $this->response_reason_text = (string)$this->xml->Messages->Message->Description; 
  25. } else { 
  26. $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode; 
  27. $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText; 
  28.  
  29. $this->authorization_code = (string)$this->xml->AuthCode; 
  30. $this->avs_code = (string)$this->xml->AVSResultCode; 
  31. $this->card_code_response = (string)$this->xml->CVVResultCode; 
  32. $this->transaction_id = (string)$this->xml->TransID; 
  33. $this->md5_hash = (string)$this->xml->TransHash; 
  34. $this->user_ref = (string)$this->xml->UserRef; 
  35. $this->card_num = (string)$this->xml->AccountNumber; 
  36. $this->card_type = (string)$this->xml->AccountType; 
  37. $this->test_mode = (string)$this->xml->TestMode; 
  38. $this->ref_trans_id = (string)$this->xml->RefTransID; 
  39.  
  40.  
  41. } else { // If it's an NVP response 
  42.  
  43. // Split Array 
  44. $this->response = $response; 
  45. if ($encap_char) { 
  46. $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); 
  47. } else { 
  48. $this->_response_array = explode($delimiter, $response); 
  49.  
  50. /** 
  51. * If AuthorizeNet doesn't return a delimited response. 
  52. */ 
  53. if (count($this->_response_array) < 10) { 
  54. $this->approved = false; 
  55. $this->error = true; 
  56. $this->error_message = "Unrecognized response from AuthorizeNet: $response"; 
  57. return; 
  58.  
  59.  
  60.  
  61. // Set all fields 
  62. $this->version = $this->_response_array[0]; 
  63. $this->response_code = $this->_response_array[1]; 
  64. $this->response_reason_code = $this->_response_array[2]; 
  65. $this->response_reason_text = $this->_response_array[3]; 
  66. $this->authorization_code = $this->_response_array[4]; 
  67. $this->avs_code = $this->_response_array[5]; 
  68. $this->card_code_response = $this->_response_array[6]; 
  69. $this->transaction_id = $this->_response_array[7]; 
  70. $this->md5_hash = $this->_response_array[8]; 
  71. $this->user_ref = $this->_response_array[9]; 
  72. $this->card_num = $this->_response_array[20]; 
  73. $this->card_type = $this->_response_array[21]; 
  74. $this->split_tender_id = isset($this->_response_array[22]) ? $this->_response_array[22] : NULL; 
  75. $this->requested_amount = isset($this->_response_array[23]) ? $this->_response_array[23] : NULL; 
  76. $this->approved_amount = isset($this->_response_array[24]) ? $this->_response_array[24] : NULL; 
  77. $this->card_balance = isset($this->_response_array[25]) ? $this->_response_array[25] : NULL; 
  78.  
  79.  
  80.  
  81. $this->approved = ($this->response_code == self::APPROVED); 
  82. $this->declined = ($this->response_code == self::DECLINED); 
  83. $this->error = ($this->response_code == self::ERROR); 
  84. $this->held = ($this->response_code == self::HELD); 
  85.  
  86.  
  87. if ($this->error) { 
  88. $this->error_message = "AuthorizeNet Error: 
  89. Response Code: ".$this->response_code." 
  90. Response Reason Code: ".$this->response_reason_code." 
  91. Response Reason Text: ".$this->response_reason_text." 
  92. "; 
  93.  
  94. } else { 
  95. $this->approved = false; 
  96. $this->error = true; 
  97. $this->error_message = "Error connecting to AuthorizeNet"; 
  98.  
  99. /** 
  100. * Is the MD5 provided correct? 
  101. * @param string $api_login_id 
  102. * @param string $md5_setting 
  103. * @return bool 
  104. */ 
  105. public function isAuthorizeNet($api_login_id = false, $md5_setting = false) 
  106. $amount = ($this->amount ? $this->amount : '0.00'); 
  107. $api_login_id = ($api_login_id ? $api_login_id : AUTHORIZENET_API_LOGIN_ID); 
  108. $md5_setting = ($md5_setting ? $md5_setting : AUTHORIZENET_MD5_SETTING); 
  109. return ($this->md5_hash == strtoupper(md5($md5_setting . $api_login_id . $this->transaction_id . $amount))); 
  110.