0

I'm trying to build a custom accounting report using the PayPal NVP API that will get all transactions for a specific date range.

My code:

$headers            = array(
    'USER'              => $production_user,
    'PWD'               => $production_pass,
    'SIGNATURE'         => $production_sig
);

$nvp                = array(
    'METHOD'            => 'TransactionSearch',
    'TRANSACTIONCLASS'  => 'RECEIVED',
    'STARTDATE'         => '2016-12-01T00:00:00Z',
    'ENDDATE'           => '2016-12-31T00:00:00Z'
);

$request_url        = "https://api-3t.paypal.com/nvp?".http_build_query($nvp);

$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);

$result = explode("&", $result);

foreach($result as $f=>$v){
    $t  = explode("=", $v);
    echo $t[0]." => ".urldecode($t[1]);
    echo "<br>";
}

Here is what gets printed:

HTTP/1.1 200 OK Date: Fri, 10 Feb 2017 19:51:20 GMT Server: Apache X-PAYPAL-OPERATION-NAME: X-PAYPAL-API-RC: 10001 Connection: close Cache-Control: max-age => 0, no-cache, no-store, must-revalidate Pragma: no-cache HTTP_X_PP_AZ_LOCATOR: slcb.slc Paypal-Debug-Id: 484a759b46e4a Set-Cookie: X-PP-SILOVER

CORRELATIONID => some_random_characters
ACK => Failure
L_ERRORCODE0 => 10001
L_SHORTMESSAGE0 => Internal Error
L_LONGMESSAGE0 => Timeout processing request

Any assistance with this issue would be greatly appreciated!

LukeSkywalker
  • 153
  • 1
  • 8

1 Answers1

0

You are using a post request and have not post data.

I do not know what PayPal wants to see but I'm guessing it's not what you are sending.

Some things to try:

If you need to pass the USER, PWD, and SIGNATURE in the Request Header do it like this:

$request = array();
$request[] = "USER: $production_user";
$request[] = "PWD: $production_pass";
$request[] = "SIGNATURE: $production_sig";

curl_setopt($ch, CURLOPT_HTTPHEADER, $request);

If the $nvp parameters need to be post data, try this:

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);

The $nvp can be passed as a query string in the post data also.

$query = http_build_query($nvp);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

The difference is the Content-Type.

The first method:

Content-Type: application/x-www-form-urlencoded 

The second method:

Content-Type: multipart/form-data

To help in trouble shooting it would be good to see both the request and response header.

Use these options to get the headers:

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

The Request Header will be in the 'curl_getinfo()'

curl_setopt($ch, CURLOPT_HEADER, true);


$result = curl_exec($ch);
$info = curl_getinfo($ch);
var_export($info);

The above gives lots of other details of the request. If you only want to see the header:

 $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);

To get the response header:

$result = curl_exec($ch);

$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
$response = substr($result ,0,$skip);
$result = substr($result ,$skip);
Misunderstood
  • 5,534
  • 1
  • 18
  • 25
  • Thank you for the thorough response @Misunderstood ! The issue was that I was not passing any post data. I added the USR, PWD, and SIG back into the post string, and everything started working. – LukeSkywalker Feb 19 '17 at 18:29