trappedatuf Posted September 18, 2008 Share Posted September 18, 2008 We use Paypal Website Payments Pro for our merchant processing. We thought it would be nice to have the Paypal balance displayed on the admin homepage, for easy reference! Just download the zip file, follow the instructions and you're all set paypalBalance.zip 0 Quote Link to comment Share on other sites More sharing options...
jmanuel Posted September 18, 2008 Share Posted September 18, 2008 Thanks! for you script 0 Quote Link to comment Share on other sites More sharing options...
trappedatuf Posted September 18, 2008 Author Share Posted September 18, 2008 No prob! I really like this software so I'm just trying to help out where I can 0 Quote Link to comment Share on other sites More sharing options...
KayoteX Posted September 18, 2008 Share Posted September 18, 2008 Does it require real PP login info? If yes, it's very insecure. 0 Quote Link to comment Share on other sites More sharing options...
trappedatuf Posted September 18, 2008 Author Share Posted September 18, 2008 No, it uses your PP API_USERNAME, API_PASSWORD and API_SIGNATURE... it is based on code Paypal provides as the proper way to access their API system to get things like your balance and transactions, etc. 0 Quote Link to comment Share on other sites More sharing options...
arhost Posted September 18, 2008 Share Posted September 18, 2008 Great work Thanks! 0 Quote Link to comment Share on other sites More sharing options...
Zorro67 Posted September 19, 2008 Share Posted September 19, 2008 Thought I'd drop the recent paypal transaction data into the bottom of the home page. It would appear that the functionality is there to list recent paypal transactions. However, not being a coder, I'm not sure how to call the function transSearch. Anybody done this from the code above? 0 Quote Link to comment Share on other sites More sharing options...
bigsean Posted September 24, 2008 Share Posted September 24, 2008 Hey this is a great module however I could not get it to work. I inserted the user/pass/signature then pasted the code in the TPL but the balance shows $0.00. I have a Business PayPal account, will this only work with a Paypal Website Payments Pro account? cheers (sorry this has been resolved, I had to change the Primary currency on my paypal account, thanks for the great module) 0 Quote Link to comment Share on other sites More sharing options...
keliix06 Posted September 26, 2008 Share Posted September 26, 2008 Thought I'd drop the recent paypal transaction data into the bottom of the home page.It would appear that the functionality is there to list recent paypal transactions. However, not being a coder, I'm not sure how to call the function transSearch. Anybody done this from the code above? I did this, it's actually pretty simple. I also modified the code to fit the WHMCS layout. Here's the new paypalBalance.php file: <?php /**************************************************** CallerService.php This file uses the constants.php to get parameters needed to make an API call and calls the server.if you want use your own credentials, you have to change the constants.php Called by TransactionDetails.php, ReviewOrder.php, DoDirectPaymentReceipt.php and DoExpressCheckoutPayment.php. ****************************************************/ /** * hash_call: Function to perform the API call to PayPal using API signature * @methodName is name of API method. * @nvpStr is nvp string. * returns an associtive array containing the response from the server. */ // FOR WHMCS WE WANT TO CALL THE CHECK_BALANCE FUNCTION SO IT GETS DISPLAYED! require_once 'paypalConstants.php'; $API_UserName=API_USERNAME; $API_Password=API_PASSWORD; $API_Signature=API_SIGNATURE; $API_Endpoint =API_ENDPOINT; $version=VERSION; //session_start(); //declaring of global variables //global $API_UserName, $API_Password, $API_Signature, $API_Endpoint, $version, $nvp_Header; //$sslcertpath = "C:/Apache/htdocs/cert_key_pemlive.txt"; $SOAPrequest = <<< End_Of_Quote <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="1"> <ebl:Credentials xmlns:ebl="urn:ebay:apis:eBLBaseComponents"> <ebl:Username>$API_UserName</ebl:Username> <ebl:Password>$API_Password</ebl:Password> <ebl:Signature>$API_Signature</ebl:Signature> </ebl:Credentials> </RequesterCredentials> </soapenv:Header> <soapenv:Body> <GetBalanceReq xmlns="urn:ebay:api:PayPalAPI"> <GetBalanceRequest> <Version xmlns="urn:ebay:apis:eBLBaseComponents">2.3</Version> </GetBalanceRequest> </GetBalanceReq> </soapenv:Body> </soapenv:Envelope> End_Of_Quote; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://api-3t.paypal.com/2.0/"); //curl_setopt($ch, CURLOPT_SSLCERT, $sslcertpath); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $SOAPrequest); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Without this then $response will just be a true or false, this causes $response to be the actual returned XML code which is what we want $response = curl_exec ($ch); preg_match('/([0-9]*\.[0-9]*)(<\/Balance>)/i', $response, $matches); // This pulls out the balance from the response: <Balance xsi:type="cc:BasicAmountType" currencyID="USD">16457.62</Balance> $data['PAYPALBALANCE'] = "$".number_format($matches[0], 2); function hash_call($methodName,$nvpStr) { //declaring of global variables //global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header; require_once 'paypalConstants.php'; $API_UserName=API_USERNAME; $API_Password=API_PASSWORD; $API_Signature=API_SIGNATURE; $API_Endpoint =API_ENDPOINT; $version=VERSION; session_start(); //setting the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$API_Endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1); //turning off the server and peer verification(TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled. //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php if(USE_PROXY) curl_setopt ($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT); //NVPRequest for submitting to server $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($version)."&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature).$nvpStr; //setting the nvpreq as POST FIELD to curl curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq); //getting response from server $response = curl_exec($ch); //convrting NVPResponse to an Associative Array $nvpResArray=deformatNVP($response); $nvpReqArray=deformatNVP($nvpreq); $_SESSION['nvpReqArray']=$nvpReqArray; if (curl_errno($ch)) { // moving to display page to display curl errors $_SESSION['curl_error_no']=curl_errno($ch) ; $_SESSION['curl_error_msg']=curl_error($ch); $location = "APIError.php"; header("Location: $location"); } else { //closing the curl curl_close($ch); } return $nvpResArray; } /** This function will take NVPString and convert it to an Associative Array and it will decode the response. * It is usefull to search for a particular key and displaying arrays. * @nvpstr is NVPString. * @nvpArray is Associative Array. */ function deformatNVP($nvpstr) { $intial=0; $nvpArray = array(); while(strlen($nvpstr)){ //postion of Key $keypos= strpos($nvpstr,'='); //position of value $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr); /*getting the Key and Value values and storing in a Associative Array*/ $keyval=substr($nvpstr,$intial,$keypos); $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1); //decoding the respose $nvpArray[urldecode($keyval)] =urldecode( $valval); $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr)); } return $nvpArray; } function transSearch($startDateStr, $endDateStr, $transID) { //session_unset(); // clearing the session before starting new API Call //session_start(); /* Construct the request string that will be sent to PayPal. The variable $nvpstr contains all the variables and is a name value pair string with & as a delimiter */ $nvpStr; $transactionID=urlencode($transID); if(isset($startDateStr)) { $start_time = strtotime($startDateStr); $iso_start = date('Y-m-d\T00:00:00\Z', $start_time); $nvpStr="&STARTDATE=$iso_start"; } if(isset($endDateStr)&&$endDateStr!='') { $end_time = strtotime($endDateStr); $iso_end = date('Y-m-d\T24:00:00\Z', $end_time); $nvpStr.="&ENDDATE=$iso_end"; } if($transactionID!='') $nvpStr=$nvpStr."&TRANSACTIONID=$transactionID"; /* Make the API call to PayPal, using API signature. The API response is stored in an associative array called $resArray */ $resArray=hash_call("TransactionSearch",$nvpStr); /* Next, collect the API request in the associative array $reqArray as well to display back to the browser. Normally you wouldnt not need to do this, but its shown for testing */ $reqArray=$_SESSION['nvpReqArray']; /* Display the API response back to the browser. If the response from PayPal was a success, display the response parameters' If the response was an error, display the errors received using APIError.php. */ $ack = strtoupper($resArray["ACK"]); if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING"){ //$_SESSION['reshash']=$resArray; $location = "ppnvp/APIError.php"; header("Location: $location"); } ?> <h1>Paypal Transactions Last 5 Days</h1> <p><table width=100% cellspacing=1 bgcolor="#cccccc"> <?php //checking for Transaction ID in NVP response if(!isset($resArray["L_TRANSACTIONID0"])){ ?> <tr> <td colspan="6"> No Transaction Selected </td> </tr> <?php } else { $count=0; //counting num of transaction IDs present in NVP response arrray. while (isset($resArray["L_TRANSACTIONID".$count])) $count++; ?> <tr bgcolor=#efefef style="text-align:center;font-weight:bold;"> <td></td> <td>ID</td> <td>Time</td> <td>Status</td> <td>Payer Name</td> <td>Gross Amount</td> <td>Net Amount</td> </tr> <?php $ID=0; while ($count>0) { $transactionID = $resArray["L_TRANSACTIONID".$ID]; $timeStamp = $resArray["L_TIMESTAMP".$ID]; $tsarray = array("T","Z"); $timeStamp = str_replace($tsarray, " ", $timeStamp); $payerName = $resArray["L_NAME".$ID]; $amount = $resArray["L_AMT".$ID]; $net = $resArray["L_NETAMT".$ID]; $status = $resArray["L_STATUS".$ID]; $count--; $ID++; ?> <tr bgcolor="#ffffff"> <td><?=$ID ?></td> <td><?=$transactionID ?></td> <td><?=$timeStamp?> <!--12/7/2005 9:57:58 AM--></td> <td><?=$status?></td> <td><?=$payerName?></td> <td>$<?=$amount?></td> <td>$<?=$net?></td> </tr> <?php } } ?> </TABLE> <? } ?> Then in your homepage.tpl file just add: {php} $date = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-5,date("Y"))); transSearch($date,'',''); {/php} The paypalBalance.php file has to have been included already. I put the balance in the top area where it shows pending orders etc. and the transactions just above the to-do list. This code shows transactions from the last 5 days, I also have that coded as the h1 in the code I posted. Modify as needed. 0 Quote Link to comment Share on other sites More sharing options...
AndrewMKP Posted September 29, 2008 Share Posted September 29, 2008 Looks good! Well done =) 0 Quote Link to comment Share on other sites More sharing options...
mediademon Posted October 1, 2008 Share Posted October 1, 2008 Works great... thanks! A few tweaks for localization... 0 Quote Link to comment Share on other sites More sharing options...
stevewilliams Posted November 17, 2008 Share Posted November 17, 2008 Is this just for PPL Payments Pro, or can this be modified to work with a regular Business acct???? 0 Quote Link to comment Share on other sites More sharing options...
JLHC Posted November 17, 2008 Share Posted November 17, 2008 Is this just for PPL Payments Pro, or can this be modified to work with a regular Business acct???? Yes this can also be used for the normal/regular PayPal account. 0 Quote Link to comment Share on other sites More sharing options...
stevewilliams Posted November 17, 2008 Share Posted November 17, 2008 Yes this can also be used for the normal/regular PayPal account. Thanks for the quick answer. I downloaded your plugin, and I was wondering what I would have to change in paypal_constants in orfer to get it to work with the business accounts. Thanks a ton! 0 Quote Link to comment Share on other sites More sharing options...
trappedatuf Posted November 18, 2008 Author Share Posted November 18, 2008 Steve, It should work right off the bat. I coded this thing and it reads the balance from my Paypal Business account just fine. 0 Quote Link to comment Share on other sites More sharing options...
keliix06 Posted November 18, 2008 Share Posted November 18, 2008 I also use it with a normal business account with only the modifications I listed, but none of those were to get it to work. 0 Quote Link to comment Share on other sites More sharing options...
hightekhosting Posted November 18, 2008 Share Posted November 18, 2008 We cannot seem to get this to report. I have made the changes in the constants as mentioned, but it is continously showing $0.00. Any ideas? Our currency is AUD. 0 Quote Link to comment Share on other sites More sharing options...
SnakeDiver Posted November 19, 2008 Share Posted November 19, 2008 Great mod, and good idea. Just curious why you chose to go with the SOAP method over the NVP ? hightekhosting, there may be an extra value that has to be appended to the output to paypal which asks for AUD back instead of USD. I see a "ReturnAllCurrencies" value, but what it says is that by default PayPal will return the default currency. Make sure AUD is the default currency on your account. Cheers, 0 Quote Link to comment Share on other sites More sharing options...
Phile Posted December 22, 2008 Share Posted December 22, 2008 We use 3 seperate paypal accounts for different services. Can this be modified to show balances for all 3? 0 Quote Link to comment Share on other sites More sharing options...
HiDef-Laws Posted January 1, 2009 Share Posted January 1, 2009 This is pretty neat. Would be nice to list, say, the past 5-10 transactions new subscriptions (not just payments) instead of by days. When I first put 5 days up I had to scroll a long way to get to my main homepage modules (same for the past 24 hours). Time to investigate API search calls I can use. 0 Quote Link to comment Share on other sites More sharing options...
zoilodiaz Posted January 1, 2009 Share Posted January 1, 2009 this work excellent whit us thanks so much, Matt maybe need think in add this featured in the next release.. this featured is perfect, make our sales easy 0 Quote Link to comment Share on other sites More sharing options...
HiDef-Laws Posted January 2, 2009 Share Posted January 2, 2009 I updated mine to show the past 24 hours only and edited the title for the printout to state as much. When I have more time I will play with different search functions. I started reading it tonight but New Years Day is not the day to be doing such work. 0 Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 3, 2009 Share Posted January 3, 2009 I have never seen a signature in a paypal business account? Where is that info? 0 Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 3, 2009 Share Posted January 3, 2009 nvm... Found it. Must be fairly new, or at least I am blind and never looked. lol 0 Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted January 5, 2009 Share Posted January 5, 2009 just wondering.. Mine doesn't show balance either.. always says $0 with the developer account. Maybe that is a problem with paypal developer API? It is work with a live account though.. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.