Revision: 33076
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 5, 2010 23:17 by mikael12
Initial Code
define('PAYPAL_TOKEN', '123456981723dasdas_paypal_token'); define('PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr'); $tx = (isset($_GET['tx'])) ? $_GET['tx'] : ''; // Send POST for data response $ch = curl_init(PAYPAL_URL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,'cmd=_notify-synch&tx='.$tx.'&at='.PAYPAL_TOKEN); curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL $res = curl_exec($ch); // Log response $fp = fopen(PATH.'/log/paypal.log', 'a'); fwrite($fp, "\n".date('d.m.Y H:i')."\n"); fwrite($fp, $res); fclose($fp); // Parse response $lines = explode("\n", $res); $processed = (strcmp($lines[0], "SUCCESS") == 0) ? true : false; unset($lines[0]); unset($lines[30]); $keyarray = array(); foreach ($lines as $line) { list($key,$val) = explode("=", $line); $keyarray[urldecode($key)] = urldecode($val); } if ($processed && $keyarray['payment_status'] == 'Completed') { echo "OK"; } else { echo "Something went wrong.<br /> PayPal response: <br />".$res; }
Initial URL
Initial Description
Initial Title
Process paypal response
Initial Tags
Initial Language
PHP