M2_AuthorizeNetTD

A class to send a request to the Transaction Details XML API.

Defined (1)

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

/lib/authorize.net/lib/AuthorizeNetTD.php  
  1. class M2_AuthorizeNetTD extends M2_AuthorizeNetRequest 
  2.  
  3. const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; 
  4. const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; 
  5.  
  6. private $_xml; 
  7.  
  8. /** 
  9. * This function returns information about a settled batch: Batch ID, Settlement Time, &  
  10. * Settlement State. If you specify includeStatistics, you also receive batch statistics  
  11. * by payment type. 
  12. * The detault date range is one day (the previous 24 hour period). The maximum date range is 31  
  13. * days. The merchant time zone is taken into consideration when calculating the batch date range,  
  14. * unless the Z is specified in the first and last settlement date 
  15. * @param bool $includeStatistics 
  16. * @param string $firstSettlementDate // yyyy-mmddTHH:MM:SS 
  17. * @param string $lastSettlementDate // yyyy-mmddTHH:MM:SS 
  18. * @param bool $utc // Use UTC instead of merchant time zone setting 
  19. * @return AuthorizeNetTD_Response 
  20. */ 
  21. public function getSettledBatchList($includeStatistics = false, $firstSettlementDate = false, $lastSettlementDate = false, $utc = true) 
  22. $utc = ($utc ? "Z" : ""); 
  23. $this->_constructXml("getSettledBatchListRequest"); 
  24. ($includeStatistics ? 
  25. $this->_xml->addChild("includeStatistics", $includeStatistics) : null); 
  26. ($firstSettlementDate ? 
  27. $this->_xml->addChild("firstSettlementDate", $firstSettlementDate . $utc) : null); 
  28. ($lastSettlementDate ? 
  29. $this->_xml->addChild("lastSettlementDate", $lastSettlementDate . $utc) : null); 
  30. return $this->_sendRequest(); 
  31.  
  32. /** 
  33. * Return all settled batches for a certain month. 
  34. * @param int $month 
  35. * @param int $year 
  36. * @return AuthorizeNetTD_Response 
  37. */ 
  38. public function getSettledBatchListForMonth($month = false, $year = false) 
  39. $month = ($month ? $month : date('m')); 
  40. $year = ($year ? $year : date('Y')); 
  41. $firstSettlementDate = substr(date('c', mktime(0, 0, 0, $month, 1, $year)), 0, -6); 
  42. $lastSettlementDate = substr(date('c', mktime(0, 0, 0, $month+1, 0, $year)), 0, -6); 
  43. return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); 
  44.  
  45. /** 
  46. * This function returns limited transaction details for a specified batch ID 
  47. * @param int $batchId 
  48. * @return AuthorizeNetTD_Response 
  49. */ 
  50. public function getTransactionList($batchId) 
  51. $this->_constructXml("getTransactionListRequest"); 
  52. $this->_xml->addChild("batchId", $batchId); 
  53. return $this->_sendRequest(); 
  54.  
  55. /** 
  56. * Return all transactions for a certain day. 
  57. * @param int $month 
  58. * @param int $day 
  59. * @param int $year 
  60. * @return array Array of SimpleXMLElments 
  61. */ 
  62. public function getTransactionsForDay($month = false, $day = false, $year = false) 
  63. $transactions = array(); 
  64. $month = ($month ? $month : date('m')); 
  65. $day = ($day ? $day : date('d')); 
  66. $year = ($year ? $year : date('Y')); 
  67. $firstSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); 
  68. $lastSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); 
  69. $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); 
  70. $batches = $response->xpath("batchList/batch"); 
  71. foreach ($batches as $batch) { 
  72. $batch_id = (string)$batch->batchId; 
  73. $request = new M2_AuthorizeNetTD; 
  74. $tran_list = $request->getTransactionList($batch_id); 
  75. $transactions = array_merge($transactions, $tran_list->xpath("transactions/transaction")); 
  76. return $transactions; 
  77.  
  78. /** 
  79. * This function returns full transaction details for a specified transaction ID. 
  80. * @param int $transId 
  81. * @return AuthorizeNetTD_Response 
  82. */  
  83. public function getTransactionDetails($transId) 
  84. $this->_constructXml("getTransactionDetailsRequest"); 
  85. $this->_xml->addChild("transId", $transId); 
  86. return $this->_sendRequest(); 
  87.  
  88. /** 
  89. * This function returns statistics about the settled batch specified by $batchId. 
  90. * @param int $batchId 
  91. * @return AuthorizeNetTD_Response 
  92. */ 
  93. public function getBatchStatistics($batchId) 
  94. $this->_constructXml("getBatchStatisticsRequest"); 
  95. $this->_xml->addChild("batchId", $batchId); 
  96. return $this->_sendRequest(); 
  97.  
  98. /** 
  99. * This function returns the last 1000 unsettled transactions. 
  100. * @return AuthorizeNetTD_Response 
  101. */ 
  102. public function getUnsettledTransactionList() 
  103. $this->_constructXml("getUnsettledTransactionListRequest"); 
  104. return $this->_sendRequest(); 
  105.  
  106. /** 
  107. * @return string 
  108. */ 
  109. protected function _getPostUrl() 
  110. return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); 
  111.  
  112. /** 
  113. * @param string $response 
  114. *  
  115. * @return AuthorizeNetTransactionDetails_Response 
  116. */ 
  117. protected function _handleResponse($response) 
  118. return new M2_AuthorizeNetTD_Response($response); 
  119.  
  120. /** 
  121. * Prepare the XML post string. 
  122. */ 
  123. protected function _setPostString() 
  124. $this->_post_string = $this->_xml->asXML(); 
  125.  
  126.  
  127. /** 
  128. * Start the SimpleXMLElement that will be posted. 
  129. * @param string $request_type The action to be performed. 
  130. */ 
  131. private function _constructXml($request_type) 
  132. $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; 
  133. $this->_xml = @new SimpleXMLElement($string); 
  134. $merchant = $this->_xml->addChild('merchantAuthentication'); 
  135. $merchant->addChild('name', $this->_api_login); 
  136. $merchant->addChild('transactionKey', $this->_transaction_key); 
  137.