M2_AuthorizeNetSIM

Easily parse an AuthorizeNet SIM Response.

Defined (1)

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

/lib/authorize.net/lib/AuthorizeNetSIM.php  
  1. class M2_AuthorizeNetSIM extends M2_AuthorizeNetResponse 
  2.  
  3. // For ARB transactions 
  4. public $subscription_id; 
  5. public $subscription_paynum; 
  6.  
  7. /** 
  8. * Constructor. 
  9. * @param string $api_login_id 
  10. * @param string $md5_setting For verifying an Authorize.Net message. 
  11. */ 
  12. public function __construct($api_login_id = false, $md5_setting = false) 
  13. $this->api_login_id = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); 
  14. $this->md5_setting = ($md5_setting ? $md5_setting : (defined('AUTHORIZENET_MD5_SETTING') ? AUTHORIZENET_MD5_SETTING : "")); 
  15. $this->response = $_POST; 
  16.  
  17. // Set fields without x_ prefix 
  18. foreach ($_POST as $key => $value) { 
  19. $name = substr($key, 2); 
  20. $this->$name = $value; 
  21.  
  22. // Set some human readable fields 
  23. $map = array( 
  24. 'invoice_number' => 'x_invoice_num',  
  25. 'transaction_type' => 'x_type',  
  26. 'zip_code' => 'x_zip',  
  27. 'email_address' => 'x_email',  
  28. 'ship_to_zip_code' => 'x_ship_to_zip',  
  29. 'account_number' => 'x_account_number',  
  30. 'avs_response' => 'x_avs_code',  
  31. 'authorization_code' => 'x_auth_code',  
  32. 'transaction_id' => 'x_trans_id',  
  33. 'customer_id' => 'x_cust_id',  
  34. 'md5_hash' => 'x_MD5_Hash',  
  35. 'card_code_response' => 'x_cvv2_resp_code',  
  36. 'cavv_response' => 'x_cavv_response',  
  37. ); 
  38. foreach ($map as $key => $value) { 
  39. $this->$key = (isset($_POST[$value]) ? $_POST[$value] : ""); 
  40.  
  41. $this->approved = ($this->response_code == self::APPROVED); 
  42. $this->declined = ($this->response_code == self::DECLINED); 
  43. $this->error = ($this->response_code == self::ERROR); 
  44. $this->held = ($this->response_code == self::HELD); 
  45.  
  46. /** 
  47. * Verify the request is AuthorizeNet. 
  48. * @return bool 
  49. */ 
  50. public function isAuthorizeNet() 
  51. return count($_POST) && $this->md5_hash && ($this->generateHash() == $this->md5_hash); 
  52.  
  53. /** 
  54. * Generates an Md5 hash to compare against Authorize.Net's. 
  55. * @return string Hash 
  56. */ 
  57. public function generateHash() 
  58. $amount = ($this->amount ? $this->amount : "0.00"); 
  59. return strtoupper(md5($this->md5_setting . $this->api_login_id . $this->transaction_id . $amount)); 
  60.