Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: Communicating with PayPal to update database

  1. #11
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by JasonDFR View Post

    The attached zip contains two files. paypal_ipn.php and paypal_ipn.sql .
    Hi JasonDFR,

    I have a website that sells some products and I want to change a field in the database from "Sale" to "Sold" when payment has been made through paypal.

    Do you think that the files above will suit me as to what I require. i have an okay knowledge php so hopefully I can get this to work.

    Thanks,
    John.

  2. #12
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Hi... Glad to find someone who knows well about paypal IPN...

    Initially I was using a script for processing paypal ipn which did not work, and I modified a little bit but don't know how to test it..

    I signed up for paypal sandbox to test my script but i didn't know what to URL i need to post the variables back...

    I am in a hurry to go and just saw this thread in the last minute.. Will post much details later today or tomorrow...Jason, pls help

  3. #13
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I wouldn't say I know it well, but I was able to get it to work. The sandbox works as well, though I remember it being a little complicated to get set up. I haven't used this stuff for about 6 months, so I couldn't tell you off the top of my head how to work it out, but if you get stuck somewhere I'm happy to try to help out.

    If I remember correctly,setting the sandbox correctly and changing the url in the pay_pal ipn script to reflect the sandbox's url, and correctly identiying the location of your paypal_ipn script when setting it up for your account, are the biggest things.

    You should also set up the default paypal mysql tables in your database,They posted the SQL to get it set up on thieir site somewhere, and use that at least while your testing.

  4. #14
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Hi I have two files, config.php and protect.php... config.php simply has variable assignments.

    protect.php has the actual code to receive the POST variables from paypal, send it back with the required appended text and check if the reply is INVALID or VERIFIED. If it is verified it will send an email to the customer with the download link for the product....

    Also, I have set the page protect.php as the page the customer's will be redirected to after a successful check out. If the customer gets to the page this way, then the page will simply inform the payment is successful and download link has been emailed..

    I have also enabled IPN in my paypal profile and entered the path for protect.php.... I now want to check it will work or not:

    This is the contents of my config.php where I have replaced the actual details with www.example.com:

    Code:
    <?php
    
    	$website = "http://www.example.com";
    
    	$msg = "Thanks for your purchase at www.example.com";
    
    	$email = "contact@example.com";
    
    	$yourname = "Example.com Sales";
    
    	$product = "Example product";
    
    
    	$paypal = "paypal@example.com";
    
    	$amount = 14.99;
    
    	$download = "http://www.example.com/files/example.pdf";
    
    
    global $website, $msg, $email, $yourname, $product, $paypal, $amount, $download;
    ?>


    Here is the code inside protect.php:

    Code:
    <?
    
    require("config.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";
    $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
    
    //These are all of the variables that paypal sends us:
    
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_gross = $_POST['payment_gross'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
    $invoice = $_POST['invoice'];
    $first_name = $_POST['first_name'];
    
    
    
    <html>
    <head>
    <title><?=$msg?></title>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    
    
    
    <?
    
    
    if (!$fp) {
    	echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> $errstr ($errno)<br><br>You may want to refresh your browser in a couple of minutes.</font></p>";
    
    	
    	$email_msg = "There has been an error on your Paypal Download Protection script: $errstr ($errno)";
    	mail("$email", "Invalid Purchase", $email_msg, "From: $email");
    	
    } else {
    	fputs ($fp, $header . $req);
    	while (!feof($fp)) {
    		$res = fgets ($fp, 1024);
    		if (strcmp ($res, "VERIFIED") == 0) {
    			
    			if ($payment_status != "Completed") {
    				echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> The status of the payment is not yet completed.</font></p>";
    			} elseif ($receiver_email != $paypal) {
    				echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You did not purchase this item from the correct seller.</font></p>";
    				
    			} elseif ($payment_gross == $amount) {
    				echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You have no paid the full amount.</font></p>";
    			} else {
    				
    
    				$headers = "From: $yourname <$email>\n";
    				$headers .= "X-Sender: <$email>\n"; 
    				$headers .= "X-Mailer: PHP\n";
    				$headers .= "X-Priority: 1\n";
    				$headers .= "Return-Path: <$email>\n";
    				
    		$email_send_msg = "
    
    Thank you for your purchase, $first_name
    
    To download your $product, please go to: $download
    
    Please feel free to email us at: $email
    
    $yourname
    $website
    $email
    
    ";
    				
    				mail($payer_email, $msg, $email_send_msg, $headers);
    				
    ?>
    
    <p align=center>The web site address containing the download link has been sent to <?=$payer_email?>
    <br><br>If you do not receive an email from us within 24 hours, please email <?=$email?>
    <br><br>Thank you, <?=$first_name?></p>
    
    <?
    				// And.. that's it!
    			}
    		} else if (strcmp ($res, "INVALID") == 0) {
    			echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You did not purchase this item from the correct seller.</font></p>";
    			
    			$email_msg = "There has been an invalid request from your Paypal Download Protection script. You may want to investiage this manually from your paypal account.";
    			mail("$email", "Invalid Purchase", $email_msg, "From: $email");
    			
    			$success = true;
    		}
    	}
    	fclose ($fp);
    }
    
    
    ?>
    <p><br>
    
    </center>
    </BODY>
    </HTML>

    Earlier I tried to use this with real time payments but it didn't work but I noticed then that in protect.php $HTTP_POST_VARS was used instead of $_POST.. So I changed it.. But haven't tested with this edited code.

  5. #15
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    can anyone please reply?

  6. #16
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    What isn't working exactly? Where do you think your error is at? Did you start out with the files I had attached in the .zip ?

  7. #17
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    110
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default

    This seems like the forum to ask my PayPal integration question.

    Currently I have a registration form with a couple of fields. The initial intention once a user pressed the submit button was to
    1) validate the form
    2) make the form action open a PHP file to send me an email with the form details

    I have now integrated the PayPal HTML code into the registration and replaced my submit button with theirs.

    The problem is that the form action has now changed to take me directly to PayPal, which defeats the purpose of collected information on the customer.

    I am thinking, is it possible that I can do this once a user clicks the submit button?

    1) validate the form
    2) make the form action open a PHP file
    3) Have PHP file send me an email with the form details
    4) Then have PHP file redirect me to PayPal for payments

    I am sure the PayPal form code fields can be embedded in PHP and used as a secondary action once the email action has been completed.

    I just need some validation from senior coders.

    Thanks in advance.

  8. #18
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    the only way I think that could be done is to separate the process out. so you would have to have form validated on page1.php that page1.php does your php file and email etc, then redirects to page2.php which has your paypal button on it.

    the other option would be to use paypal ipn (instant payment notification) which will call a url on your server, passing it all of the information regarding the transaction. In that code, do what you need with the file etc and email. You may find that that ipn trans has the info in it you are looking for.

    I tried a long time ago to update an order status when the paypal button was clicked and never was successful. Once you put that button on a page, its action is going to paypal

  9. #19
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    110
    Thanks
    15
    Thanked 1 Time in 1 Post

    Default

    i've already taken the code from PayPal's form and wrapped the form around my input tags.
    With the form action I've used whatever action PayPal gave. And it sends you to their servers you're right.
    But I'm sure PHP could serve me better if I redirected the action to a PHP file (like ASP) and had it perform some functions (and keep the PayPal variables) and then send those in a URL query for example, via PHP, to PayPal servers.

    Lots of sites I've come across have a similar form integration feature. I was just curious on the method so I could get a heads up before I made any attempts today.

    Will keep you all posted.

  10. #20
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by JasonDFR View Post
    PayPal IPN is the way to go. It works well once you get it set up right. Through trial and error I got mine working well. If anyone needs a hand with this issue, feel free to contact me and I'll help out.

    Also, a big thank you to Greg for replying to my post and exchanging emails with me while I worked through this; Thanks Greg!

    Jason
    Hi, I am trying out to setup paypal ipn, but facing issue, my database is not updating, got script from paypal.com/ipn website.. help please

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •