Here's the setup:
I have a site setup for a client. The customer:
- Visits the site
- Enters in basic information for our records
- Proceeds to PayPal via a "Buy Now" button
- Makes the payment through PayPal
- Returns to the site
What I am wanting to know is how do I get a list of all the transactions? I have the PayPal login as well as the API username, password, and signature, but for the life of me I cannot find a single place on the internet that gives an example of how to pull a list of transactions from PayPal either via PHP or jQuery/Javascript/Ajax.
Does anyone have any ideas? examples?
Thanks in advance.
UPDATE:
I was able to develop a solution to this question. See my answer below with code and comments.
Here's the setup:
I have a site setup for a client. The customer:
- Visits the site
- Enters in basic information for our records
- Proceeds to PayPal via a "Buy Now" button
- Makes the payment through PayPal
- Returns to the site
What I am wanting to know is how do I get a list of all the transactions? I have the PayPal login as well as the API username, password, and signature, but for the life of me I cannot find a single place on the internet that gives an example of how to pull a list of transactions from PayPal either via PHP or jQuery/Javascript/Ajax.
Does anyone have any ideas? examples?
Thanks in advance.
UPDATE:
I was able to develop a solution to this question. See my answer below with code and comments.
Share Improve this question edited Jul 12, 2013 at 20:54 The Duke Of Marshall שלום asked Jul 12, 2013 at 15:47 The Duke Of Marshall שלוםThe Duke Of Marshall שלום 1,6595 gold badges18 silver badges36 bronze badges3 Answers
Reset to default 18Ok, so I finally was able to develop something that works. The code is posted below with a link to the TransactionSearch API options from PayPal
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/
<?php
$info = 'USER=[API_USERNAME]'
.'&PWD=[API_PASSWORD]'
.'&SIGNATURE=[API_SIGNATURE]'
.'&METHOD=TransactionSearch'
.'&TRANSACTIONCLASS=RECEIVED'
.'&STARTDATE=2013-01-08T05:38:48Z'
.'&ENDDATE=2013-07-14T05:38:48Z'
.'&VERSION=94';
$curl = curl_init('https://api-3t.paypal.com/nvp');
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_POSTFIELDS, $info);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
# Bust the string up into an array by the ampersand (&)
# You could also use parse_str(), but it would most likely limit out
$result = explode("&", $result);
# Loop through the new array and further bust up each element by the equal sign (=)
# and then create a new array with the left side of the equal sign as the key and the right side of the equal sign as the value
foreach($result as $value){
$value = explode("=", $value);
$temp[$value[0]] = $value[1];
}
# At the time of writing this code, there were 11 different types of responses that were returned for each record
# There may only be 10 records returned, but there will be 110 keys in our array which contain all the different pieces of information for each record
# Now create a 2 dimensional array with all the information for each record together
for($i=0; $i<count($temp)/11; $i++){
$returned_array[$i] = array(
"timestamp" => urldecode($temp["L_TIMESTAMP".$i]),
"timezone" => urldecode($temp["L_TIMEZONE".$i]),
"type" => urldecode($temp["L_TYPE".$i]),
"email" => urldecode($temp["L_EMAIL".$i]),
"name" => urldecode($temp["L_NAME".$i]),
"transaction_id" => urldecode($temp["L_TRANSACTIONID".$i]),
"status" => urldecode($temp["L_STATUS".$i]),
"amt" => urldecode($temp["L_AMT".$i]),
"currency_code" => urldecode($temp["L_CURRENCYCODE".$i]),
"fee_amount" => urldecode($temp["L_FEEAMT".$i]),
"net_amount" => urldecode($temp["L_NETAMT".$i]));
}
?>
Also, I came up with this nifty little, simple script to get more details about a particular transaction:
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/
<?php
$info = 'USER=[API_USERNAME]'
.'&PWD=[API_PASSWORD]'
.'&SIGNATURE=[API_SIGNATURE]'
.'&VERSION=94'
.'&METHOD=GetTransactionDetails'
.'&TRANSACTIONID=[TRANSACTION_ID]'
.'&STARTDATE=2013-07-08T05:38:48Z'
.'&ENDDATE=2013-07-12T05:38:48Z';
$curl = curl_init('https://api-3t.paypal.com/nvp');
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_POSTFIELDS, $info);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
parse_str($result, $result);
foreach($result as $key => $value){
echo $key.' => '.$value."<BR>";
}
?>
They have a TransactionSearch API:
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/
I use mine pull by invoice number to retrieve transaction ids for refunding.
<script
data-env="sandbox"
data-tax="0.00"
data-shipping="0.00"
data-currency="USD"
data-amount="0.00"
data-quantity="0"
data-name="No Item Selected"
data-button="buynow" src="https://www.paypalobjects.com/js/external/[email protected]" async="async"></script>
This is a html element that hooks up to the paypal API to make a transaction when the button is clicked. Do not change the data-button
, src
, or async
properties. Completly remove the data-env
node after you are finished testing (the data-env
node prevents an actual charge from being made while you are testing). Change all of the other properties according to their names (e.g you would change data-name
to the name of the product you are selling). Insert the element as you would any other html element (e.g. <p>
).