close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Regarding PayPal IPN listener page

Thread began 2/07/2023 7:16 am by Jared Lui | Last modified 2/10/2023 3:15 pm by Ray Borduin | 925 views | 14 replies |

Jared Lui

Regarding PayPal IPN listener page

Hi Ray,

I looked at the IPN details on the PayPal website and ended up with more questions than answers so instead found these two examples via Google search.

Obviously these are custom and will need to be edited for my DB needs and connection, etc. I get the main idea connecting to PayPal and confirming the connection with the back and forth in both versions. I know that one of these is very stripped down and the other includes some debugging and the ability to send a custom email response. I think I can figure out how to edit either one as needed.

My question is, do you see one as being better than the other code wise? I do have 'listener.php' uploaded and working now and I can send a payment live with no issues. So that I take it is a good thing.

However, I still have not added the ability to INSERT or UPDATE my DB.

If you read the comments in the 'listener.php' on LINES 66-72 he creates a record with the payment details with a "pending" status and then once the payment is verified, updates the record to "Paid"

Could you write an example code snippet using the attached table called 'dues' where the duesID could be the PayPal 'custom' parameter session id and maybe one or two of the other like duesAmtPaid and duesPaidDate?

I am sure I could figured it out after I had an example of the structure/format needed to post/update the the DB and where it goes in that page. I assume it will go in the space occupied by the comments between the {}.

And can you confirm this using the example below:
(the variables would be my table column names and they correspond to the PayPal variables - correct? and this is what I use to INSERT/UPDATE my DB?)

$lotNumber = $_POST['item_number'];
$duesStatus = $_POST['payment_status'];
$duesAmtPaid = $_POST['mc_gross'];
$duesID = $_POST['custom'];

I know I could probably figure it out on my own if I had the time and headspace to work on it but once again I have zero time. I will of course pay you for your time and appreciate as always your help and expertise!

Sign in to reply to this post

Ray BorduinWebAssist

It is really pretty simple, so either page would work. Just go with listener.php. To do an insert or update you would just apply the insert record server behavior with the "always" trigger on the page and move the code down to line 60 so it only runs on approved orders.

I'm not sure if you have to do the insert first and update to pending, or just do an insert on the ipn page directly. Usually if you are dealing with a single item, then you can just do an insert on the IPN page to decrease complexity.

If you don't have all the information you need for the insert on the IPN page returned from paypal (there are a lot of POSTED fields to choose from), then you can pass a few more using a hidden field named "custom" that will be passed through to the ipn page.

If you want direct help, give me a call and I can do it in a screen share. Should only take an hour or so.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

I really didn't expect it to be as simple as using only an insert or update.

That being said, I can still send a successful payment, however I am still unable to insert a new record. Could you see what I have missed or done wrong in the attached listener.php page. I am guessing that I can leave the rowID column blank and let the DB create a new one and treat the other columns like I normally would like the payment date could just be a timestamp.

I don't know what else I am missing or have wrong. I tried changing these lines to this thinking maybe I had it wrong:
$InsertQuery->bindColumn("lotNumber", "i", "lotNumber", "WA_DEFAULT");
$InsertQuery->bindColumn("duesAmtPaid", "i", "duesAmtPaid", "WA_DEFAULT");
$InsertQuery->bindColumn("duesStatus", "s", "duesStatus", "WA_DEFAULT");

But still no new records inserted.

Also, I left the InsertGoTo blank thinking that the PayPal would direct to the success page, it does, but the user has to click the return to merchant button. This shouldn't matter correct?

Hopefully you can spot it easily. otherwise we can plan a screen share soon.

Sign in to reply to this post

Ray BorduinWebAssist

$InsertQuery->bindColumn("lotNumber", "i", "item_number", "WA_DEFAULT");
$InsertQuery->bindColumn("duesAmtPaid", "i", "mc_gross", "WA_DEFAULT");
$InsertQuery->bindColumn("duesStatus", "s", "payment_status", "WA_DEFAULT");

should probably be:


$InsertQuery->bindColumn("lotNumber", "i", $_POST["item_number"], "WA_DEFAULT");
$InsertQuery->bindColumn("duesAmtPaid", "i", $_POST["mc_gross"], "WA_DEFAULT");
$InsertQuery->bindColumn("duesStatus", "s", $_POST["payment_status"], "WA_DEFAULT");

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

See private message..

Attached Files
listener.php
Sign in to reply to this post

Ray BorduinWebAssist

IPN won't stop payments from going through. Paypal posts to IPN after a payment goes through. So there is definitely a possibility you don't have it set up right. If you go to your paypal IPN settings you can see posted payments and any error results. It is possible your button is overriding the IPN page setting as well.

I'd put a call on the top of the page:
file_put_contents("test.txt","Hello World. Testing!")

That will write a file if something accesses the ipn page and tell you if it is getting hit or not.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

Originally Said By: Ray Borduin
  IPN won't stop payments from going through.  



Noted. Thanks!

I did get the test.txt file with the Hello World. Testing! message so learned something cool. Thanks for that too!

So I guess the page is at least loading.

I checked the PayPal settings for API Access, I used the SOAP settings when I created the button since it was the only version that used: USER/PASS/SIG. I beleave that was the version your software was based off right?

I'm guessing since the payments are going through that this is setup correctly?

Should Auto Return be set to on or off under the Website Payment Prefs? I've tried it under both with the same results. Also tried it with Payment Data Transfer set to on/off with same thing.

On the button from I tried removing the "success" return value link to see if that was confusing it. Didn't help.

I moved that Hello World test text to the very bottom of the file with new test text to see if it still worked and it did.

I removed the 3 bindColumn lines in case there was still an issue with the variables I'm using. I would think it should at least create a new empty row in the table shouldn't it?

Sign in to reply to this post

Ray BorduinWebAssist

Try moving the insert code above with the webassist connection and queryobj.php includes. See if the insert works. Maybe it is something in the downloaded code.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jared Lui

Okay, that worked. I got a row created. The only thing that came over correct was the 'duesStatus' column, the duesAmtPaid and lotNumber columns came up zeros but I can play with that to find out why now that I have something to work with.

I guess now I need to find out where the issue is in the rest of the code. I'll compare the basic part to the other set of code I got to see what the differences are (minus the extra stuff like email sending and debugging). I don't know how old either one of these are, i just know that there was not much out there as far as recent examples.

Sign in to reply to this post

Ray BorduinWebAssist

Here is a function i wrote a while ago...

php:
<?php

function WA_isValidPayPal()     {
  
$retVal false;
  
$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$errstr30);
  if (!
$fp) {
    
$retVal false;
  }
  else {
    
fputs ($fp$header $req);
    while (!
feof($fp)) {
      
$res fgets ($fp1024);
      if (
strcmp ($res"VERIFIED") == 0) {
        
$retVal true;
      }
      else if (
strcmp ($res"INVALID") == 0) {
        
$retVal false;
      }
    }
    
fclose ($fp);
  }
  return 
$retVal;
}
?>



You could add that and then just use the trigger:

if (WA_isValidPayPal()) {
// insert code here
}

But my code is similar to theirs so it might not work either. The missing field values are probably because you have your form values wrong for your POST. You can probably get those better with something like:

file_put_contents("test.txt",json_encode($_POST));

Then your test.txt file will have all of the form fields posted and their values so you can pick through and see what you need.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...