$v) { $postdata .= $i . "=" . urlencode($v) . "&"; } $postdata.="cmd=_notify-validate"; $fp=@fsockopen("ssl://www.sandbox.paypal.com" ,"443",$errnum,$errstr,30); if(!$fp) { return "$errnum: $errstr"; } else { fputs($fp, "POST /cgi-bin/webscr HTTP/1.1\r\n"); fputs($fp, "Host: www.sandbox.paypal.com\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ".strlen($postdata)."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $postdata . "\r\n\r\n"); while(!feof($fp)) { $response[]=@fgets($fp, 1024); } fclose($fp); } $response = implode("\n", $response); if(eregi("VERIFIED",$response)) { return true; }else { //Remember, You're likely going to want to set this to a real location file_put_contents("/tmp/IPN.txt", "Failed, $response", FILE_APPEND); return false; } } function confirmProduct($id, $name, $amount) { if (!(ctype_digit($id) && is_numeric($amount))) { return false; }else { $name = mysql_escape_string($name); } $query = "SELECT id FROM products WHERE `id` = '$id' AND `p_name` = '$name' AND `cost` = '$amount' LIMIT 1"; if (rowCount($query) == 1) { return true; }else { return false; } } function processOrder($data) { } function paymentPendingThankYou($address) { $subject = "Order Received"; $body = "Thanks for your order with Example.com!\n This message confirms that we have received notification from PayPal regarding your order. However, PayPal is still processing your payment at this time. Once PayPal confirms that they have completed processing your payment we will contact you again to confirm payment and include shipping details.\n\n If you have any questions please do not hesitate to contact us at support@example.com.\n\n We apreciate your business!"; $headers = "From: OrderConfirmation@example.com\r\n" . "Reply-To: support@example.com\r\n" . "X-Mailer: PHP/" . phpversion(); mail($address, $subject, $body, $headers); exit; } function unknownIPNReceived($post) { $body = "Hi, an IPN was received that wasn't a completed payment or a pending payment. Please confirm this transaction against our records."; $body .= $post; $subject = "IPN Received"; $address = "paul@preinheimer.com"; $headers = "From: ipn_processor@example.com\r\n" . "Reply-To: donotreply@example.com\r\n" . "X-Mailer: PHP/" . phpversion(); mail($address, $subject, $body, $headers); exit; } function rowCount($query) { return 1; } ?>