Jump to content

Display Paypal Balance on Homepage


Recommended Posts

  • Replies 116
  • Created
  • Last Reply

Top Posters In This Topic

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?

Link to comment
Share on other sites

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?




(sorry this has been resolved, I had to change the Primary currency on my paypal account, thanks for the great module)

Link to comment
Share on other sites

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:


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.

require_once 'paypalConstants.php';


//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">
<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">
<GetBalanceReq xmlns="urn:ebay:api:PayPalAPI">
<Version xmlns="urn:ebay:apis:eBLBaseComponents">2.3</Version>

$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';

//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_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 
curl_setopt ($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT); 

//NVPRequest for submitting to server

//setting the nvpreq as POST FIELD to curl

//getting response from server
$response = curl_exec($ch);

//convrting NVPResponse to an Associative Array

if (curl_errno($ch)) {
	// moving to display page to display curl errors
	  $_SESSION['curl_error_no']=curl_errno($ch) ;
	  $location = "APIError.php";
	  header("Location: $location");
 } else {
	 //closing the curl

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)

	$nvpArray = array();

	//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*/
	//decoding the respose
	$nvpArray[urldecode($keyval)] =urldecode( $valval);
return $nvpArray;

function transSearch($startDateStr, $endDateStr, $transID) {
//session_unset(); // clearing the session before starting new API Call

/* 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 */


if(isset($startDateStr)) {
	$start_time = strtotime($startDateStr);
	$iso_start = date('Y-m-d\T00:00:00\Z',  $start_time);

if(isset($endDateStr)&&$endDateStr!='') {
	$end_time = strtotime($endDateStr);
	$iso_end = date('Y-m-d\T24:00:00\Z', $end_time);

	/* Make the API call to PayPal, using API signature.
  		The API response is stored in an associative array called $resArray */


	/* 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 */


	/* 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"){
		$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
			<td colspan="6">
			No Transaction Selected
	} else {
		//counting num of  transaction IDs present in NVP response arrray.
		while (isset($resArray["L_TRANSACTIONID".$count])) 

			<tr bgcolor=#efefef style="text-align:center;font-weight:bold;">
				<td>Payer Name</td>
				<td>Gross Amount</td>
				<td>Net Amount</td>


		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>






Then in your homepage.tpl file just add:


$date = date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-5,date("Y")));


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.

Link to comment
Share on other sites

  • 1 month later...

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.



Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

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. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated