Reply
Highlighted
Member
Posts: 1
Registered: ‎06-09-2011

Transaction APIs

Ok, here goes! The AuthNet phone support person could not help me so I will try this in the forums.

 

I am implementing the new Transaction APIs.

 

I downloaded the SDK from authnet and I am able to get one function working - the getSettledBatchList function.

 

Here is the code I am using as described in the Sample Code:

 

 

require_once "../code/classes/AuthorizeNet.php";
define("AUTHORIZENET_API_LOGIN_ID", "xxxxxxxx");
define("AUTHORIZENET_TRANSACTION_KEY", "yyyyyyy");
define("AUTHORIZENET_SANDBOX", false);
// Get Settled Batch List
$request = new AuthorizeNetTD;
//$includeStatistics = true;
//$firstSettlementDate = "2011-06-01T00:00:00";
//$lastSettlementDate = "2011-06-10T00:00:00";
//$response = $request->getSettledBatchList($includeStatistics,$firstSettlementDate,$lastSettlementDate);
$response = $request->getSettledBatchList();
echo count($response->xml->batchList->batch) . " batches<br>";
foreach ($response->xml->batchList->batch as $batch) {
    echo "Batch ID: " . $batch->batchId . "<br>";
}
This works fine, even when I add in the start and end date parameters.
However, when I try to implement getBatchDetails(), I get nothing. When I look thru the code in AuthorizeNetTD.php, I do not see this function - I do see the others.
So, I assume that this function does not exist (yet). Is this correct?
Then I read again the ReportingGuide_XML.pdf documentation (for the 5th time) and see that it indicates that the
function getBatchStatistics DOES exist, but in the XML world. (It appears as 'getBatchStatisticsRequest' appended to the function name).
So, now I want to try it via XML.
But there is no sample code on how to send an API transaction (or at least it is not
clear enough how to do it) using the XML method.
I am not smart enough to build this from scratch and there
seems to be no sample code for this. I can easily build the XML string as shown, but a) how to send? and b) where
to send?
So, does anyone know of any sample code to use to implement the XML way to do this. 
Thanks for any assistance.
Tom

 

Highlighted
Administrator
Posts: 591
Registered: ‎08-21-2009

Re: Transaction APIs

You are correct that not all of the Transaction Details API functions are available yet in the current versions of the SDK.  The only way to make use of these functions is directly via an XML request.

 

Here is a stripped down version of the code used in the PHP SDK to process a properly formatted XML request:

 

$post_string = "<xml />"; //This should be your properly structured XML request

$post_url = "https://apitest.authorize.net/xml/v1/request.api"; //switch 'apitest' to 'api' for production

 

$curl_request = curl_init($post_url);

curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_string);

curl_setopt($curl_request, CURLOPT_HEADER, 0);

curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);

curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/ssl/cert.pem'); //must be correct path to cert.pem from the SDK

curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));

$response = curl_exec($curl_request); //XML Response is stored here

curl_close($curl_request);

Highlighted
Member
Posts: 1
Registered: ‎06-15-2011

Re: Transaction APIs

<?php
$post_string=  '<?xml version="1.0" encoding="utf-8"?>
<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>XXXXXX</name>
<transactionKey>XXXXXXXXXXXXXXXXXXXXXXXXX</transactionKey>
</merchantAuthentication>
<transId>3679480912</transId>
</getTransactionDetailsRequest>';


 //This should be your properly structured XML request

$post_url = "https://api.authorize.net/xml/v1/request.api"; //switch 'apitest' to 'api' for production

 

$curl_request = curl_init($post_url);

curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_string);

curl_setopt($curl_request, CURLOPT_HEADER, 0);

curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);

curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname("./anet_php_sdk/lib/ssl/cert.pem"))); //must be correct path to cert.pem from the SDK

curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));

$response = curl_exec($curl_request); //XML Response is stored here
  if($response ==true) {
                    echo "The test passed <br/>";
                }
                if($response == false) {
               
                echo "no";
                }

curl_close($curl_request);


     $xmlData = new SimpleXMLElement($response);//it is used for accessing dom XML element
     print_r($xmlData); //just for testing

     foreach($xmlData->Response as $response) {
                        echo "$response->messages->resultCode";
              
                                                }
?>

 

I have 'XXX'ed the sensitive data . I have used the transaction id from the merchant interface under reports.

 

Output:no
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\test1\index.php:46 Stack trace: #0 C:\wamp\www\test1\index.php(46): SimpleXMLElement->__construct('') #1 {main} thrown in C:\wamp\www\test1\index.php on line 46

 

which means there is no response generated.

 

Where do I get batchId from.