Jump to content

paypal IPN help please


cherimartin

Recommended Posts

Hi, I am new here, so hello everyone.

 

I really need some help with getting Paypal IPN working correctly.

 

This is what I am trying to do.  I have a user database, when the user logs in, they have the option to upgrade/subscribe to our website.

 

So when they subscribe and payment is validated, I want a specific field in a specific table updated based on the user's unique ID, not based on [payer_email], so how do I pass on that parameter using IPN?

 

right now I added the "userId" to a hidden field in the Paypal subscription form named "on1"....

 

I hope this isn't confusing - would really appreciate your help -  I added code below.

<?php

DB info --


// 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 ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);


if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

$email = $_POST['payer_email'];
$userId=$_POST['on1'];
$membership = '2';

mysql_query("UPDATE users SET membership=".$membership." WHERE userId=".$userId) or die(mysql_error()); 

$to      = $email;
$subject = 'subject line';
$message = '
message here
';

mail($to, $subject, $message, $headers);



}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

$to      = 'my_email';
$subject = 'subject lin';
$message = '

Dear Administrator,

A payment has been made but is flagged as INVALID.
Please verify the payment manualy and contact the buyer.

Buyer Email: '.$email.'
';
$headers = 'From:my_email' . "\r\n";

mail($to, $subject, $message, $headers);

}
}
fclose ($fp);
}
?>

 

Link to comment
Share on other sites

Hi cherimartin,

 

funny, i am at the exact same stage in my own website. I am creating the IPN script to update the membership of a member.

 

If you are using the "buy now" button, there is a "custom" input you can add to the button form.

 

Create the button on the paypal site,

encrypt the form script from the paypal site,

then simply copy it into you html page somewhere.

If you want to add a specific ID; simply add another hidden field to the button form named custom in which you can add any value you wish up to 256characters

 

This field is then passed back in the IPN which you can get and do what ever with. If you want to add a membership duration, you may want to encrypt it, this can be done with the "item number", an optional extra to the item name on the paypal site.

 

______________________________________________________________________________________

 

 

That is as far as i have got at the moment... I am currently stuck on the verifying the response...

https://cms.paypal.com/cms_content/US/en_US/files/developer/IPNGuide.pdf

 

The above link is to a pdf guide on it all.

 

Chapter 2, page 19, point 5... says "5. Verify that the response status is 200."

This is confusing me as i thought the response was either valid or invalid? Would you be able to shed any light?

 

 

Link to comment
Share on other sites

Not sure yet, i'm just finishing it off.

 

I've got the following done:

1. Check VERIFIED, then continue, if not send email to the debug email reporting the error

2. Check payment status == completed, if not send email to debug email reporting error

3. Check the txnid isn't already in the paypal payments table, if it is then send the duplicate error to the debug email

4. If the data insertion into the paypal_payment table wasn't succefull send error to debug email (this should not stop the membership later though as i recieved confirmation of payment from paypal)

5. Close the connection with PayPal. and paypal DB connection

6. Open the new std db connection

7. Update the members table with the new expiration unix timestamp according to what was purchased and the encrypted ID sent.

 

 

The only thing i am still stuck on though is, what point 5. is on about in the guide i mentioned above. Further reading led me to:

http://tools.ietf.org/html/rfc2616#section-10

But i am still non the wiser. Is this an old version of VERIFIED or INVALID? I sent the question to paypal email help and waiting on the response.

 

Also on page 49 of the pdf guide: https://cms.paypal.com/cms_content/US/en_US/files/developer/IPNGuide.pdf

it lists the possible values of the "payment_status" variable. What is the difference between "Completed" and "Processed"?? Their descriptions are pretty much the same.

Link to comment
Share on other sites

Hey guys, sorry to be ALMOST completely unhelpful, but there is a sample IPN communication sample somewhere within PayPal's www.x.com developer site. If you use their sample you will have a fully functional IPN hand shake script. If i can find it again i will post it here for future use.

Link to comment
Share on other sites

Also on page 49 of the pdf guide: https://cms.paypal.com/cms_content/US/en_US/files/developer/IPNGuide.pdf

it lists the possible values of the "payment_status" variable. What is the difference between "Completed" and "Processed"?? Their descriptions are pretty much the same.

 

"completed" means the single payment has completed and this message of completed will be sent in the IPN. This is used on single payments like the "buynow" button.

 

"processed" is used if you are doing multiple payments and when all the payments have been done (processed) then this message is sent back in the IPN. This option is not used on single payments like buy now.

 

____________________________________________________

 

 

The other point was additional security to confirm if the IPN listener is talking to paypal. However it usually isn't required as VERIFIED will suffice. You can simply set the listener to send an email so you know to investigate otherwise

 

 

Link to comment
Share on other sites

I found developing for PayPal somewhat difficult. They have a couple different guides, some of which contradict themselves. A lot of the documentation is hard to find. There are also hidden "features/bugs" that you get to find out first hand on things that don't work like the documentation says it should. Best thing to do is contact PayPal MTS with any debug info. They are usually pretty good at telling you what the issue is even though you might rip your hair out at the insanity of the issue.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.