Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PayPal IPN

Hey there everyone, I'm a front end designer lost in this world of SQL and PHP and was wondering if anyone could help me out with the PayPal IPN. From a tutorial online I have this written so far (try not to laugh):

PHP Code

<?php
 
mysql_connect
("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("PP") or die(mysql_error());
 
// 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.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) {
 
$email = $_POST['payer_email'];
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$buyerid = $_POST['payer_id'];
$authid = $_POST['auth_id'];
    
$sql = "INSERT INTO clients (email, firstname, lastname, buyerid, authid) VALUES ($email, $firstname, $lastname, $buyerid, $authid)";
}
 
else if (
strcmp ($res, "INVALID") == 0) {
 
// INVALID!
 
}
}
fclose ($fp);
}
?>

So I guess my question is how do I get this code to work with my "Buy Now" button on my website? Also if you guys could look over the code I have because I have no clue what I'm doing with PHP 🤝 Thank you.
[Image: BQ6bF1l.png]
I don't wanna discourage you, but honestly, you're far from being ready to code anything PayPal related. Not only is that code terrible, it's vulnerable to SQL injection and using deprecated mysql_* functions.

So start with the basics. Read up on PHP, SQL and most importantly, PDO. You'll get there, but not by using that code. Throw that code away and never look back.
BTC: 1PQFRwoyRUTCWMC7anLdVxTp4t22MVoos2
(Feb 27, 2017 09:22 AM)Scy7e Wrote:  I don't wanna discourage you, but honestly, you're far from being ready to code anything PayPal related. Not only is that code terrible, it's vulnerable to SQL injection and using deprecated mysql_* functions.

So start with the basics. Read up on PHP, SQL and most importantly, PDO. You'll get there, but not by using that code. Throw that code away and never look back.

Yea I totally get that man, trust me. The thing is I don't have time to learn a totally different language, I wish I did. I have all of my other code worked out for PayPal checkout and I need to email clients after the transaction completes. The reason being is because I need a way to process payments asap!
[Image: BQ6bF1l.png]
That looks like a very old IPN, i would move away from using MySQL & switch over to MySQLi before anything. Also, this is just the IPN, which your PayPal account should be updated so it knows where to notify. You can do that in the "Sellers Preferences" section on PayPal.

Most commonly people use a html form which contains details about the payment before actually directed to PayPal. You can add the "notify_url" there & that is the URL where this IPN is located. This is what you will execute when your Buy button is pressed, or at least something similar.

(Feb 27, 2017 09:29 AM)Specs Wrote:  That looks like a very old IPN, i would move away from using MySQL & switch over to MySQLi before anything. Also, this is just the IPN, which your PayPal account should be updated so it knows where to notify. You can do that in the "Sellers Preferences" section on PayPal.

Most commonly people use a html form which contains details about the payment before actually directed to PayPal. You can add the "notify_url" there & that is the URL where this IPN is located. This is what you will execute when your Buy button is pressed, or at least something similar.


As of now I have my HTML form setup according to PayPal's documentation. I have pulled out details using the HTML "hidden" values. I just need to pull first name, last name, AUTH ID and a couple other key values and then email a confirmation after the payment completes. I noticed you posted about the "notify_url" value which is all well and fine but how would I save the values I need and then use something like PHP to email a confirmation?

The problem being with that is that I need to know when the payments go through and if they didn't go through, why and stuff like that provided by the IPN.
[Image: BQ6bF1l.png]
(Feb 27, 2017 09:28 AM)Rolex™ Wrote:  Yea I totally get that man, trust me. The thing is I don't have time to learn a totally different language, I wish I did. I have all of my other code worked out for PayPal checkout and I need to email clients after the transaction completes. The reason being is because I need a way to process payments asap!

You don't actually need to learn another language, luckily. Most mysql_* statements are just turned in to mysqli_* (with a few extra parameters here and there).

Also, look up prepared statements, at first you'll look at them and think WTF. But once you've written one or two, it all falls together.

That code you've written could very easily be turned in to mysqli.
aint my sig design skills sick?
(Feb 27, 2017 09:37 AM)Rolex™ Wrote:  As of now I have my HTML form setup according to PayPal's documentation. I have pulled out details using the HTML "hidden" values. I just need to pull first name, last name, AUTH ID and a couple other key values and then email a confirmation after the payment completes. I noticed you posted about the "notify_url" value which is all well and fine but how would I save the values I need and then use something like PHP to email a confirmation?

The problem being with that is that I need to know when the payments go through and if they didn't go through, why and stuff like that provided by the IPN.

This is what the IPN is for, if it returns VERIFIED then you can start sorting through all the data which is sent to it via POST. There is pretty much everything you need to know about the transaction supplied and you can access it like this for example: $_POST['payer_email']. This is the email you could send a mail to. To get names its something like "first_name" & "last_name".
(Feb 27, 2017 10:40 AM)Specs Wrote:  This is what the IPN is for, if it returns VERIFIED then you can start sorting through all the data which is sent to it via POST. There is pretty much everything you need to know about the transaction supplied and you can access it like this for example: $_POST['payer_email']. This is the email you could send a mail to. To get names its something like "first_name" & "last_name".

Yea and as you can see from the example code I posted I did that for a couple variables but how do I use it you know?
[Image: BQ6bF1l.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by citsejaMFeb 4, 2020 02:58 PM 6 290 Feb 4, 2020 02:58 PM
Last Post: citsejaM
[PHP] by d4neSep 21, 2017 01:21 AM 4 527 Sep 21, 2017 01:21 AM
Last Post: Eagle 95
[PHP] by тнe randoм dυтcн gυyJul 5, 2017 01:24 PM 3 780 Jul 5, 2017 01:24 PM
Last Post: тнe randoм dυтcн gυy