Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a little php help needed to finish paypal pdt intergration please! 1

Status
Not open for further replies.

lukefred76

Technical User
Apr 29, 2008
11
GB
Hi,

I need help to finish this pdt intergration.

I've been working with the following code which is fab but i need it to do one final thing. The code is this...

Code:
$this_url   = $_SERVER["REQUEST_URI"];
	$var_set    = explode("?", $this_url);
	$paypal_transaction_token = '';
	$payment_status           = '';
	                $payment_amount           = '';
	                $payment_currency         = '';
	                $payment_item             = '';
	  
	        if(count($var_set) > 1) {
	            $paras = explode("&",$var_set[1]);
	            for($i = 0; $i < count($paras); $i++) {
	                $tmp_vals = explode('=', $paras[$i]);
	                if($tmp_vals[0] == 'tx') {
	                    $paypal_transaction_token = $tmp_vals[1];
	                }
	                if($tmp_vals[0] == 'st') {
	                    $payment_status = $tmp_vals[1];
	                }
	                                if($tmp_vals[0] == 'amt') {
	                    $payment_amount  = $tmp_vals[1];
	                }
	                                if($tmp_vals[0] == 'cc') {
	                    $payment_currency = $tmp_vals[1];
	                }
	                                if($tmp_vals[0] == 'item_number') {
	                    $payment_item = $tmp_vals[1];
	                }
	            }
	        }
	  
	  /*         Part - 1 */
	                $req = 'cmd=_notify-synch';
	        $req .= "&tx=$paypal_transaction_token&at=dAU7Pab_oaiVwQTep9ha8l8ZJRnNG_ss50f69zT8a-iDU91uX-wFN2ROaDu";  // test key
	  
	 /*         Part - 2 */
	        $ipnexec = curl_init();
	        curl_setopt($ipnexec, CURLOPT_URL, "[URL unfurl="true"]https://www.sandbox.paypal.com/webscr&");[/URL] // test url
	        //curl_setopt($ipnexec, CURLOPT_URL, '[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr');[/URL] // live url
	        curl_setopt($ipnexec, CURLOPT_HEADER, 0);
	        curl_setopt($ipnexec, CURLOPT_USERAGENT, 'Server Software: '.@$_SERVER['SERVER_SOFTWARE'].' PHP Version: '.phpversion());
	        curl_setopt($ipnexec, CURLOPT_REFERER, $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']);
	        curl_setopt($ipnexec, CURLOPT_SSL_VERIFYHOST, 0);
	        curl_setopt($ipnexec, CURLOPT_SSL_VERIFYPEER, 0);
	        curl_setopt($ipnexec, CURLOPT_POST, 1);
	        curl_setopt($ipnexec, CURLOPT_POSTFIELDS, $req);
	        curl_setopt($ipnexec, CURLOPT_FOLLOWLOCATION, 0);
	        curl_setopt($ipnexec, CURLOPT_RETURNTRANSFER, 1);
	        curl_setopt($ipnexec, CURLOPT_TIMEOUT, 30);
	        $ipnresult = trim(curl_exec($ipnexec));
	        $ipnresult = "status=".$ipnresult;
	        curl_close($ipnexec);
	  
	                /*         Part - 3 */
	        $parameter_value_array = explode("\n", $ipnresult);
	        $value_array =array();
	        foreach ($parameter_value_array as $key=>$value) {
	            $key_values = explode("=", $value);
	            $value_array[$key_values[0]] = $key_values[1];
	        }
	        if(array_key_exists("status", $value_array) && $value_array['status'] == 'SUCCESS') {
	            print_r($value_array);
				
				
				
			
		foreach($value_array as $key => $value) {
    $$key = $value;
}


echo "Thank you your order is complete<br />";
echo "Invoice Number $invoice";
echo "<br /><br /><br /><br /><br />";


This is great but i would like to know how I can display the name of each item that was included in the order.

PP returns [item_name1] => A shoe, [item_name2] => A Sock
etc etc

How would count and display the name of each item that was in the basket.

Thank you for any help you can provide

bl
 
Code:
foreach($returnArray as $key=>$item):
 echo $item . '<br/>';
endforeach;
 
Hi Jpadie,

Thanks for coming back to me so quick.

I tried your code but it gives me a "Invalid argument supplied for foreach() "


bl
 
ok i probably should have included everything that pp returns..

Code:
Array ( [status] => SUCCESS [mc_gross] => 537.99 [invoice] => WP81724869 [protection_eligibility] => Eligible [address_status] => confirmed [item_number1] => SKU001 [tax] => 0.00 [item_number2] => SKU040 [payer_id] => G4YFLWDHUQCUW [address_street] => 1+Main+Terrace [payment_date] => 15%3A17%3A46+Feb+09%2C+2012+PST [payment_status] => Completed [charset] => windows-1252 [address_zip] => W12+4LQ [mc_shipping] => 0.00 [mc_handling] => 2.99 [first_name] => Test [mc_fee] => 18.49 [address_country_code] => GB [address_name] => Test+User [custom] => [payer_status] => verified [business] => seller_1280148364_biz%40ddd.co.uk [address_country] => United+Kingdom [num_cart_items] => 2 [mc_handling1] => 0.00 [mc_handling2] => 0.00 [address_city] => Wolverhampton [payer_email] => buyer_1280148301_per%40dfd.co.uk [mc_shipping1] => 0.00 [mc_shipping2] => 0.00 [txn_id] => 2KM609114H039380U [payment_type] => instant [last_name] => User [address_state] => West+Midlands [item_name1] => A Shoe [receiver_email] => seller_1280148364_biz%40ddd.co.uk [item_name2] => A Sock [payment_fee] => [quantity1] => 1 [quantity2] => 1 [receiver_id] => RGYHU6SUZEAF2 [txn_type] => cart [mc_gross_1] => 85.00 [mc_currency] => GBP [mc_gross_2] => 450.00 [residence_country] => GB [transaction_subject] => Shopping+CartBasic+A+ShoeA+Sock [payment_gross] => ) SUCCESS

Does this help?
thanks

bl
 
assume the array returned by paypal is called $returnArray

Code:
<?php
$fields = array(
			'item_name',
			'quantity',
			'mc_gross_');
			
$numItems = $returnArray['num_cart_items'];
?>

<table>
<?php for($i=1; $i<=$numItems; $i++): ?>
<tr>
	<?php foreach($fields as $f): ?>
	<td><?php echo ${$f . $i};?> </td>
	<?php endforeach; ?>
</tr>
<?php endfor;?>
</table>
 
Hi jpadie,

Sorry for the delay in replying.

Thank you very much for your help with this.

truly appreciated.

bl
 
Hi jpadie,

Sorry, this will be the last question

I've been trying to use your code...

Code:
<?php for($i=1; $i<=$numItems; $i++): ?>

    <?php foreach($fields as $f): ?>
    <?php echo preg_replace('/\+/',' ', ${$f . $i});?> 
    <?php endforeach; ?>
    <?php echo"<br />";?>
<?php endfor;?>


and put into an email to send the user...


Code:
$payer_email = preg_replace('/\%40/','@',$payer_email);
$from="orders@me.co.uk";
$subject="Your order";


$body = $body . "\r\nDate: "  . date('l j F Y') ."\r\n";
$body = $body . "\r\n======================================\r\n";	
	
$body = $body . "Order Information:\r\n";
$body = $body . "===========================================\r\n";				
	
$fields = array(
            'item_name',
            'mc_gross_');
$numItems = $value_array['num_cart_items'];

for($i=1; $i<=$numItems; $i++):

foreach($fields as $f): 
$body = $body . " .  preg_replace('/\+/',' ', ${$f . $i}); . ";
endforeach; 
$body = $body . "<br />";
endfor;
			
$body = $body ."\r\nDelivery:  £2.99";
		
mail($payer_email, $subject, $body,"From: $from\nX-Mailer: PHP/" . phpversion());


With my ltd knowledge i cant get it to work.

Any ideas??

You've prob guess php isn't one of my strongest attributes.

Thanks for your help

bl
 
please ignore - there was a small error - all fixed

thanx

bl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top