M2_AuthorizeNetAIM_Response

Parses an AuthorizeNet AIM Response.

Defined (1)

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

/lib/authorize.net/lib/AuthorizeNetAIM.php  
  1. class M2_AuthorizeNetAIM_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. // Split Array 
  15. $this->response = $response; 
  16. if ($encap_char) { 
  17. $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); 
  18. } else { 
  19. $this->_response_array = explode($delimiter, $response); 
  20.  
  21. /** 
  22. * If AuthorizeNet doesn't return a delimited response. 
  23. */ 
  24. if (count($this->_response_array) < 10) { 
  25. $this->approved = false; 
  26. $this->error = true; 
  27. $this->error_message = "Unrecognized response from AuthorizeNet: $response"; 
  28. return; 
  29.  
  30.  
  31.  
  32. // Set all fields 
  33. $this->response_code = $this->_response_array[0]; 
  34. $this->response_subcode = $this->_response_array[1]; 
  35. $this->response_reason_code = $this->_response_array[2]; 
  36. $this->response_reason_text = $this->_response_array[3]; 
  37. $this->authorization_code = $this->_response_array[4]; 
  38. $this->avs_response = $this->_response_array[5]; 
  39. $this->transaction_id = $this->_response_array[6]; 
  40. $this->invoice_number = $this->_response_array[7]; 
  41. $this->description = $this->_response_array[8]; 
  42. $this->amount = $this->_response_array[9]; 
  43. $this->method = $this->_response_array[10]; 
  44. $this->transaction_type = $this->_response_array[11]; 
  45. $this->customer_id = $this->_response_array[12]; 
  46. $this->first_name = $this->_response_array[13]; 
  47. $this->last_name = $this->_response_array[14]; 
  48. $this->company = $this->_response_array[15]; 
  49. $this->address = $this->_response_array[16]; 
  50. $this->city = $this->_response_array[17]; 
  51. $this->state = $this->_response_array[18]; 
  52. $this->zip_code = $this->_response_array[19]; 
  53. $this->country = $this->_response_array[20]; 
  54. $this->phone = $this->_response_array[21]; 
  55. $this->fax = $this->_response_array[22]; 
  56. $this->email_address = $this->_response_array[23]; 
  57. $this->ship_to_first_name = $this->_response_array[24]; 
  58. $this->ship_to_last_name = $this->_response_array[25]; 
  59. $this->ship_to_company = $this->_response_array[26]; 
  60. $this->ship_to_address = $this->_response_array[27]; 
  61. $this->ship_to_city = $this->_response_array[28]; 
  62. $this->ship_to_state = $this->_response_array[29]; 
  63. $this->ship_to_zip_code = $this->_response_array[30]; 
  64. $this->ship_to_country = $this->_response_array[31]; 
  65. $this->tax = $this->_response_array[32]; 
  66. $this->duty = $this->_response_array[33]; 
  67. $this->freight = $this->_response_array[34]; 
  68. $this->tax_exempt = $this->_response_array[35]; 
  69. $this->purchase_order_number= $this->_response_array[36]; 
  70. $this->md5_hash = $this->_response_array[37]; 
  71. $this->card_code_response = $this->_response_array[38]; 
  72. $this->cavv_response = $this->_response_array[39]; 
  73. $this->account_number = $this->_response_array[50]; 
  74. $this->card_type = $this->_response_array[51]; 
  75. $this->split_tender_id = $this->_response_array[52]; 
  76. $this->requested_amount = $this->_response_array[53]; 
  77. $this->balance_on_card = $this->_response_array[54]; 
  78.  
  79. $this->approved = ($this->response_code == self::APPROVED); 
  80. $this->declined = ($this->response_code == self::DECLINED); 
  81. $this->error = ($this->response_code == self::ERROR); 
  82. $this->held = ($this->response_code == self::HELD); 
  83.  
  84. // Set custom fields 
  85. if ($count = count($custom_fields)) { 
  86. $custom_fields_response = array_slice($this->_response_array, -$count, $count); 
  87. $i = 0; 
  88. foreach ($custom_fields as $key => $value) { 
  89. $this->$key = $custom_fields_response[$i]; 
  90. $i++; 
  91.  
  92. if ($this->error) { 
  93. $this->error_message = "AuthorizeNet Error: 
  94. Response Code: ".$this->response_code." 
  95. Response Subcode: ".$this->response_subcode." 
  96. Response Reason Code: ".$this->response_reason_code." 
  97. Response Reason Text: ".$this->response_reason_text." 
  98. "; 
  99. } else { 
  100. $this->approved = false; 
  101. $this->error = true; 
  102. $this->error_message = "Error connecting to AuthorizeNet"; 
  103.