cancel
Showing results for 
Search instead for 
Did you mean: 

Custom PHP cURL receives NULL Response

Hey everybody!

 

This is probably a very simple problem, but I don't know how to fix it.  My client wants a custom report of transaction data generated with the system and I don't have access to the server to be able to load up the SDK.  I think this is going to be no problem, but for some reason all I can get back from the sandbox is "NULL." 

 

Could someone please tell me what I'm doing wrong here?

 

<?php
$cert_path 	= dirname(__FILE__).'/ssl/cert.pem';

$test_url 	= "https://apitest.authorize.net/xml/v1/request.api";
$prod_url 	= "https://api.authorize.net/xml/v1/request.api";
$url 		= $test_url;

$api_id 	= "MY_LOGIN_ID";
$account_key 	= "MY_TRANSACTION_ID";
$request_type 	= "getSettledBatchListRequest";

$string 	= '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>';
$xml 		= @new SimpleXMLElement($string);
$merchant 	= $xml->addChild('merchantAuthentication');
$merchant->addChild('name', $api_id);
$merchant->addChild('transactionKey', $account_key);
$as_xml 		= $xml->asXML();

$ch 		= curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $as_xml);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 45);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if( file_exists($cert_path) ){ 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, $cert_path); 
}
$result 	= curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
$result 	= json_decode($result, true);
var_dump($result);
?>

 

I'm guessing it might be that I can't find the .xsd file in the SDK.  

 

Thank you in advance!

phpjayhawk
Member
3 REPLIES 3

Hello @phpjayhawk


It doesn't look like anyone has responded yet, but someone still may have feedback on what you're looking for. I'd recommend subscribing to this topic so that you'll be alerted via email if anyone else from the community is able to respond with any comments. To subscribe, click Topic Options at the top of this thread and then select Subscribe. You'll then receive an email once anyone replies to your post.

Thanks,

Richard

RichardH
Administrator Administrator
Administrator

Thanks, @RichardH .

 

I will leave this up in the hopes that someone knows the answer, but I did resort to using the SDK and an answer to this issue is no longer neccesary for me.

Hi,

 

I realize you have resorted to using the SDK, but for anyone who may be interested, below is what works for this particular API call and language:

<?php

$xmlContent = '<getSettledBatchListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>YOUR_API_LOGIN</name>
    <transactionKey>YOUR_TRANSACION_KEY</transactionKey>
  </merchantAuthentication>
  <includeStatistics>true</includeStatistics>
  <firstSettlementDate>2017-05-01T16:00:00Z</firstSettlementDate>
  <lastSettlementDate>2017-05-31T16:00:00Z</lastSettlementDate>
</getSettledBatchListRequest>';

  $url = 'https://apitest.authorize.net/xml/v1/request.api';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlContent);
  $result = curl_exec($ch);
  echo $result;
  curl_close($ch);
Powered by NexWebSites.com -
Certified Authorize.net developers