Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Paypal Problem.


PHP Paypal Problem.

Reply
  #1 (permalink)  
Old 04-13-05, 01:00 PM
897236489 897236489 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Paypal Problem.

OK I have a script on my site which uses PayPal for members to sign up. When the user has paid PayPal is suposed to use IPN to send the user information to this file named "paypal.php" and for some reason unknown to me it is not working. Could it be that PayPal has upgraded and the file is no longer compatable anymore, if so can this file be updated to work once again?

The code is as follows:
PHP Code:

<?PHP


// read the post from PayPal system and add 'cmd'
$req 'cmd=_notify-validate';
foreach (
$_POST as $key => $value) {
$value urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$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";
$fp fsockopen ('www.paypal.com'80$errno$errstr30);
// assign posted variables to local variables
$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'];
$payment_date date("Y-m-d");
if (!
$fp) {
// HTTP ERROR
} else {
fputs ($fp$header $req);
while (!
feof($fp)) {
$res fgets ($fp1024);

if (
strcmp ($res"VERIFIED") == && ($payment_status=="Completed" || $payment_status=="Pending") && $receiver_email==$mailer && $payment_amount=="10.00" && $payment_currency=="USD") { // process payment
//////CREATE RANDOM PASSWORD///////
function makeRandomPassword() {
  
$salt "abchefghjkmnpqrstuvwxyz0123456789";
  
srand((double)microtime()*1000000); 
      
$i 0;
      while (
$i <= 7) {
            
$num rand() % 33;
            
$tmp substr($salt$num1);
            
$pass $pass $tmp;
            
$i++;
      }
      return 
$pass;
}

$random_password makeRandomPassword();
$db_password md5($random_password);
////////////INSERT INTO DB//////////
$query "INSERT INTO members (item_name,item_number,payment_status,payment_amount,txn_id,email,payment_date,password) VALUES ('$item_name','$item_number','$payment_status','$payment_amount','$txn_id','$payer_email','$payment_date','$db_password')";
$result mysql_query($query);
if (
$result){
//////////EMAIL ADMIN ////////
$asubject "Membership Payment PROCESSED";
$amessage "Another Membership Payment has been processed.

PAYMENT INFO:
    
Item Name:
$item_name
Item Num:
$item_number
   Status:
$payment_status
   Amount:
$payment_amount
 Currency:
$payment_currency
   TXN Id:
$txn_id
    Buyer:
$payer_email
     Date:
$payment_date
"
;
mail($business$asubject$amessage"From: $emailfrom\nX-Mailer: PHP/" phpversion());
////////END EMAIL ADMIN//////

//////////EMAIL BUYER ////////
$bsubject "Your Membership Information";
$bmessage "Thank you for purchasing a Membership!

You now have access to our Members area.

ACCESS INFO:
Members Url: 
$membersurl
Username: 
$payer_email
Password: 
$random_password 

Thanks for your purchase!

"
;
mail($payer_email$bsubject$bmessage"From: $emailfrom\nX-Mailer: PHP/" phpversion());
////////END EMAIL BUYER//////

    
}else{
$esubject "Membership Payment ERROR";
$emessage "Another Membership Payment has been processed, but there was an error inserting the info into the database.

PAYMENT INFO:
    
Item Name:
$item_name
 Item Num:
$item_number
   Status:
$payment_status
   Amount:
$payment_amount
 Currency:
$payment_currency
   TXN Id:
$txn_id
    Buyer:
$payer_email
     Date:
$payment_date
"
;
mail($business$esubject$emessage"From: $emailfrom\nX-Mailer: PHP/" phpversion());
    }
}
else if (
strcmp ($res"INVALID") == 0) {
$subject "Membership Payment INVALID";
$message "A payment attempt was made but the status was marked INVALID.

PAYMENT INFO:
    
Item Name:
$item_name
 Item Num:
$item_number
   Status:
$payment_status
   Amount:
$payment_amount
 Currency:
$payment_currency
   TXN Id:
$txn_id
    Buyer:
$payer_email
"
;
mail(business$subject$message"From: $emailfrom\nX-Mailer: PHP/" phpversion());
// log for manual investigation
}
}
fclose ($fp);
}
?>
Please get back to me as soon as possible.

Last edited by MadDog; 04-18-05 at 09:46 AM. Reason: Tag your code!
Reply With Quote
  #2 (permalink)  
Old 04-13-05, 07:07 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
my note:
1. you miss the return url (post field name: return).
2. you forgot to concatenate text response from paypal
PHP Code:

$res fgets ($fp1024); 

3. your validation is inappropriate
PHP Code:

if (strcmp ($res"VERIFIED") == && ($payment_status=="Completed" || $payment_status=="Pending") && $receiver_email==$mailer && $payment_amount=="10.00" && $payment_currency=="USD") { // process payment 

__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #3 (permalink)  
Old 04-17-05, 04:27 AM
897236489 897236489 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I don't understand what you meen I'm relitivley new to PHP. how would I fix this?
Reply With Quote
  #4 (permalink)  
Old 04-18-05, 09:15 AM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
there's so called pointer. i've pointed out the cause for the script malfunction. maybe you're new to php, but believe me, you only need some hours/days to read the manual and solve this problem (if you want to solve it yourself).
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #5 (permalink)  
Old 04-22-05, 10:20 AM
Tomp Tomp is offline
New Member
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Ive been trying to use the above code also, I have absolutly no idea about PHP etc, so would be very usefull if you could post up the code that you tihnk is correct
Reply With Quote
  #6 (permalink)  
Old 04-26-05, 11:36 AM
897236489 897236489 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Can somebody hurry and PLEASE help me with this?
Reply With Quote
  #7 (permalink)  
Old 08-08-05, 05:05 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
This looks like a pretty good IPN script. I can understand most of it but would like if someone correct the problem as I cannot see what the errors are.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help with htaccess and php problem tigherrdk PHP 6 03-09-09 02:28 AM
PHP Sessions problem dannyallen PHP 1 06-26-04 10:43 AM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 11:19 AM
php in linux problem usman PHP 6 05-15-04 11:57 AM


All times are GMT -5. The time now is 06:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.