server-webapi-code-10-ipn.php / php
<?php //I haven't changed this file from it's original state to make it easier for you // to skim code, please change the email addreses, I don't really want notification // from your test system when stuff fails... :) //Process the IPN //Step 0. Record the transaction ob_start(); echo date("D M j G:i:s T Y") . "\n"; print_r(_POST); body, FILE_APPEND); //Step 1. Verify IPN With PayPal _POST); if (subject = "FAKE IPN RECEIVED"; headers = "From: ipn_processor@example.com\r\n" . "Reply-To: donotreply@example.com\r\n" . "X-Mailer: PHP/" . phpversion(); mail(subject, headers); exit; }else if(subject = "Unable to validate IPN"; result\n address = "paul@preinheimer.com"; address, body, //Step 1.5 Check payment status switch (_POST['payment_status']) { case "Completed": break; case "Pending": paymentPendingThankYou(body = "Hi, an IPN was received that wasn't a completed payment or a pending payment. Please confirm this transaction against our records."; post; address = "paul@preinheimer.com"; address, body, //Step 2. Confirm Product Information result = confirmProduct(_POST['item_name'],result == false) { address = "paul@preinheimer.com"; address, body, //Step 3. Process the order subject = "VALID IPN Received"; headers = "From: ipn_processor@example.com\r\n" . "Reply-To: donotreply@example.com\r\n" . "X-Mailer: PHP/" . phpversion(); mail(subject, headers); file_put_contents("/tmp/IPN.txt", "\ngood ipn\n", FILE_APPEND); exit; function verifyIPN(postdata = ""; data as v) { i . "=" . urlencode(postdata.="cmd=_notify-validate"; //www.sandbox.paypal.com" ,"443",errnum, if(!fp) { return "errstr"; } else { fputs(fp, "Host: www.sandbox.paypal.com\r\n"); fputs(fp, "Content-length: ".strlen(fp, "Connection: close\r\n\r\n"); fputs(postdata . "\r\n\r\n"); while(!feof(response[]=@fgets(fp); } response); if(eregi("VERIFIED",//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(name, id) && is_numeric(name = mysql_escape_string(query = "SELECT id FROM products WHERE `id` = 'name' AND `cost` = 'query) == 1) { return true; }else { return false; } } function processOrder(address) { 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!"; address, body, post) { body .= subject = "IPN Received"; headers = "From: ipn_processor@example.com\r\n" . "Reply-To: donotreply@example.com\r\n" . "X-Mailer: PHP/" . phpversion(); mail(subject, headers); exit; } function rowCount(
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.