PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 21st, 2006, 10:01 AM
bombski bombski is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 264 bombski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 h 22 m 48 sec
Reputation Power: 0
PayPal IPN Grrrrr!!

Hi,

I finally found a IPN script that actually works and I can almost understand. One problem I currently have is it doens't echo anything what ever the result. Here is the code.

PHP Code:
<?
#1 = Live on PayPal Network 
#2 = Testing with www.BelaHost.com/pp
$verifymode "2"# be sure to change value for testing/live!
# Send notifications to here
$send_mail_to "info@designanet.co.uk";
# subject of messages
$sysname "Paypal IPN Transaction";
# Your primary PayPal e-mail address
$paypal_email "selleraccount@testdomain.com";

# MySQL Database Information set by Default to insert into paypal_ipn table.
# This can be changed after the IPN is VERIFIED.
$MyUser "root";
$MyPass "";
$MyHost "localhost";
$MyDatabase "paypal_database";

# Now we Read the Posted IPN
$postvars = array();

            foreach (
$_POST as $ipnvars => $ipnvalue$postvars[] = $ipnvars;
                
# Now we ADD "cmd=_notify-validate" for Post back Validation
                   
$postipn 'cmd=_notify-validate'
                   
$orgipn '<b>Posted IPN variables in order received:</b><br><br>';
                
# Prepare for validation
            
for ($x=0$x count($postvars); $x++) { $y=$x+1$postkey $postvars[$x]; $postval = $$postvars[$x]; $postipn.= "&" $postkey "=" urlencode($postval);  $orgipn.= "<b>#" $y "</b> Key: " $postkey " <b>=</b> " $postval "<br>";  }

            
## Verify Mode 1: This will post the IPN variables to the Paypal Network for Validation
            
if ($verifymode == 1) {
                
                
$port fsockopen ("paypal.com"80$errno$errstr30);
                
$header "POST /cgi-bin/webscr HTTP/1.0\r\n".
                
"Host: www.paypal.com\r\n".
                
"Content-Type: application/x-www-form-urlencoded\r\n".
                
"Content-Length: " strlen($postipn) . "\r\n\r\n";
            
            } elseif (
$verifymode == 2) {
                
                
$port fsockopen ("www.sandbox.paypal.com"80$errno$errstr30);
                
$header "POST /cgi-bin/webscr HTTP/1.0\r\n".
                
"Host: www.sandbox.paypal.com\r\n".
                
"Content-Type: application/x-www-form-urlencoded\r\n".
                
"Content-Length: " strlen($postipn) . "\r\n\r\n";
            
            } else { 
            
                
$error=1; echo "CheckMode: " $verifymode " is invalid!";  
                   exit; 
            
            }


            
# Error at this point: If at this point you need to check your Firewall or your Port restrictions?
            
if (!$port && !$error) {
            
                echo 
"Problem: Error Number: " $errno " Error String: " $errstr;
                
mail("$send_mail_to""$sysname""\nYour Paypal System failed due to $errno and string $errstr \n");            
                exit;

            
# If No Errors to this point then we proceed with the processing.
            # Open port to paypal or test site and post Varibles.
            
} else {
         
                
fputs ($port$header $postipn);
                while (!
feof($port)) {
                       
$reply fgets ($port1024);
                       
$reply trim ($reply);
                }

# Prepare a Debug Report
$ipnreport $orgipn "<br><b>" "IPN Reply: " $reply "</b>";


# Buyer Information
 // taken these out to fit

#There are certain variables that we will not store for cart since they are dynamic                    
#such as mc_gross_x as they will be forever changing/increasing your script must check these


# IPN was Confirmed as both Genuine and VERIFIED
            
if (!strcmp ($reply"VERIFIED"))
            {

/* Now that IPN was VERIFIED below are a few things which you may want to do at this point.
 1. Check that the "payment_status" variable is: "Completed"
 2. If it is Pending you may want to wait or inform your customer?
 3. You should Check your datebase to ensure this "txn_id" or "subscr_id" is not a duplicate. txn_id is not sent with subscriptions!
 4. Check "payment_gross" or "mc_gross" matches match your prices!
 5. You definately want to check the "receiver_email" or "business" is yours. 
 6. We have included an insert to database for table paypal_ipn
 */

# Remove Echo below when live
echo $ipnreport;
echo 
"VALID";
mail("$send_mail_to""$sysname""\n Verified IPN Transaction\n \n$ipnreport\n");
                                  }

# IPN was Not Validated as Genuine and is INVALID
            
elseif (!strcmp ($reply"INVALID"))
            {

/* Now that IPN was INVALID below are a few things which you may want to do at this point.
 1. Check your code for any post back Validation problems!
 2. Investigate the Fact that this Could be an attack on your script IPN!
 3. If updating your DB, Ensure this "txn_id" is Not a Duplicate!
*/

# Remove Echo line below when live
echo $ipnreport;
echo 
"INVALID";
mail("$send_mail_to""$sysname""\n IN Valid IPN Transaction\n \n$ipnreport\n");
                                  }

            else
            {

# If your script reaches this point there is a problem. Communication from your script to test/paypal pages could be 1 reason.
echo $ipnreport;
echo 
"ERROR";
mail("$send_mail_to""$sysname""\n FATAL ERROR No Reply at all\n \n$ipnreport\n");
            }


# Terminate the Socket connection and Exit
    
fclose ($port); exit;
      }

?>


Could you help me out? or has anyone got a IPN script they could share with me. I don't understand classes so please dont waste your time trying to explain them to me.

Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PayPal IPN Grrrrr!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek