M2_AuthorizeNetRequest

Sends requests to the Authorize.Net gateways.

Defined (1)

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

/lib/authorize.net/lib/shared/AuthorizeNetRequest.php  
  1. abstract class M2_AuthorizeNetRequest 
  2.  
  3. protected $_api_login; 
  4. protected $_transaction_key; 
  5. protected $_post_string;  
  6. public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections. 
  7. protected $_sandbox = true; 
  8. protected $_log_file = false; 
  9.  
  10. /** 
  11. * Set the _post_string 
  12. */ 
  13. abstract protected function _setPostString(); 
  14.  
  15. /** 
  16. * Handle the response string 
  17. */ 
  18. abstract protected function _handleResponse($string); 
  19.  
  20. /** 
  21. * Get the post url. We need this because until 5.3 you 
  22. * you could not access child constants in a parent class. 
  23. */ 
  24. abstract protected function _getPostUrl(); 
  25.  
  26. /** 
  27. * Constructor. 
  28. * @param string $api_login_id The Merchant's API Login ID. 
  29. * @param string $transaction_key The Merchant's Transaction Key. 
  30. */ 
  31. public function __construct($api_login_id = false, $transaction_key = false) 
  32. $this->_api_login = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); 
  33. $this->_transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : "")); 
  34. $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true); 
  35. $this->_log_file = (defined('AUTHORIZENET_LOG_FILE') ? AUTHORIZENET_LOG_FILE : false); 
  36.  
  37. /** 
  38. * Alter the gateway url. 
  39. * @param bool $bool Use the Sandbox. 
  40. */ 
  41. public function setSandbox($bool) 
  42. $this->_sandbox = $bool; 
  43.  
  44. /** 
  45. * Set a log file. 
  46. * @param string $filepath Path to log file. 
  47. */ 
  48. public function setLogFile($filepath) 
  49. $this->_log_file = $filepath; 
  50.  
  51. /** 
  52. * Return the post string. 
  53. * @return string 
  54. */ 
  55. public function getPostString() 
  56. return $this->_post_string; 
  57.  
  58. /** 
  59. * Posts the request to AuthorizeNet & returns response. 
  60. * @return AuthorizeNetARB_Response The response. 
  61. */ 
  62. protected function _sendRequest() 
  63. $this->_setPostString(); 
  64. $post_url = $this->_getPostUrl(); 
  65. $curl_request = curl_init($post_url); 
  66. curl_setopt($curl_request, CURLOPT_POSTFIELDS, $this->_post_string); 
  67. curl_setopt($curl_request, CURLOPT_HEADER, 0); 
  68. curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); 
  69. curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); 
  70. curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); 
  71.  
  72. if ($this->VERIFY_PEER) { 
  73. curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/ssl/cert.pem'); 
  74. } else { 
  75. if ($this->_log_file) { 
  76. file_put_contents($this->_log_file, "----Request----\nInvalid SSL option\n", FILE_APPEND); 
  77. return false; 
  78.  
  79. if (preg_match('/xml/', $post_url)) { 
  80. curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); 
  81.  
  82. $response = curl_exec($curl_request); 
  83.  
  84. if ($this->_log_file) { 
  85.  
  86. if ($curl_error = curl_error($curl_request)) { 
  87. file_put_contents($this->_log_file, "----CURL ERROR----\n$curl_error\n\n", FILE_APPEND); 
  88. // Do not log requests that could contain CC info. 
  89. file_put_contents($this->_log_file, "----Request----\n{$this->_post_string}\n", FILE_APPEND); 
  90.  
  91. file_put_contents($this->_log_file, "----Response----\n$response\n\n", FILE_APPEND); 
  92. curl_close($curl_request); 
  93.  
  94. return $this->_handleResponse($response); 
  95.