|
Rank: Starting Member
Groups: Registered
Joined: 1/6/2010 Posts: 1 Location: UK
|
Hi guys I'm having problems with PayPals IPN. It seems very temperamental, some times it works and other times not. Basically all the script does is updates my database and sends an email once the payment is taken. I'm using Fasthost to host the IPN script. I copied the IPN code from another site, and entered my own code after the #### Payment complete enter code here #### comment and before the #### END #### comment. What makes it hard to trouble shot is the fact it's a intermittent error. Is there a more reliable way to code this script? Code below: Code:<?php $req = 'cmd=_notify-validate'; foreach($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; }
$header.= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header.= "Content-Type: application/x-www-form-urlencoded\r\n"; $header.= "Content-Length: " . strlen($req) . "\r\n\r\n";
//Change the URL to www.sandbox.paypal.com when you are testing using the sandbox //$fp = @fsockopen("www.sandbox.paypal.com", 80, $errno, $errstr, 30); $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) { echo "$errstr ($errno)"; //could not connect to PayPal. Log this error. //IT NEEDS TO BE FIXED ASAP!! } else { fputs($fp, $header . $req); while (!feof($fp)) { //Loop untill we reach the last line (which is where the treasure lies ;)) $tx_status = fgets($fp); } //Values sent by paypal $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $first_name = $_POST['first_name'];
if (strcmp($tx_status, "VERIFIED") == 0) { if (strcmp($payment_status, "Completed") == 0) { #### Payment complete enter code here ####
$connection = mysql_connect("***", "***", "****"); mysql_select_db("roissyonline", $connection);
$result = mysql_query("SELECT * FROM users WHERE email='$payer_email'", $connection) or die("error querying database"); $display = mysql_fetch_assoc($result);
$email = $display['email']; $to = $email; $subject = "Welcome to Roissy People"; $message = "Dear " . $display['first_name'] .",
Welcome to Roissy People.
Thank you for choosing Roissy People as your online training provider. Your new online training account has been activated and is ready to use. Follow the steps below to get your training started right away.
Use the details below to access your new account.
Remember to keep this information safe.
Visit the http://roissyonlinetraining.com/ home page and click Login. Enter your username and password:
Username: " . $display['user'] . "\n Password: " . $display['password_temp'] . "
GET STARTED NOW – Follow our quick-start guide
Quick-Start Guide:
1. Visit the http://www.roissyonlinetraining.com/ and click the Login button
2. At the Login page enter your username and password (see above)
3. Follow the on-screen guide to access you course content.
You are will be able to access the course training content and, if applicable, any end of course examinations for 90 days from the date you first enrolled. During this time you can access the course training content as many times as you wish until you have understood and memorized the content.
End of course examinations - if applicable:
1. You can access to the end of course examination at any time. However, you will not be able to return any of the course content once you start the examination.
2. We recommend you do the examination in a quite area away from any other distractions.
3. Each examination is made of a series of multiple-choice questions, to pass it you must achieve 75 percent.
4. Upon passing you will automatically be given access to your unique certificate, which you can print off once only. Please ensure you keep your certificate in a safe place, whilst duplicates can be issued there is an additional administration fee for this duplicate certificate service.
5. Should you fail, you can retake the examination as many times as you need to at no additional cost within 90 days from the date you first enrolled.
6. If you have to retake the examination you will still have access to the course content prior to the examination for as long as you need to enable you to refine your knowledge. However, as before, once you begin the examination you will not have access to the course content.
Remember, if you need any additional help, our UK-based experts are on hand.
We are committed to providing first-class customer service and feature-rich solutions to help you get the most from your business and your training. We always welcome feedback; so if you have any comments or suggestions at any time, please feel free to contact us.
Best regards,
The Roissy People Team
"; mysql_query("UPDATE `users` SET password_temp='none', op='$item_number' WHERE email='$email'"); // Headers $from = "no_reply@roissyonlinetraining.com"; $headers = "From: $from";
mail($to, $subject, $message, $headers, "-f". $from);
#### END #### } else { //Payment is PENDING. Funds will be released later. } } elseif (strcmp($tx_status, "INVALID") == 0) { //Payment Failed!! //This is most probably a hacking attempt. //Send an email to yourself so you can investigate. }
}
fclose($fp); ?> Many thanks for your help. Best wishes Clive
|