0

I can't seem to figure out proper way to handle the return url from a paypal purchase and display an alert message.

Here is how I understand process:

  1. From my site send user to paypal, having set returnurl to be the url corresponding to what they purchased.
  2. Paypal processes, then hits my IPN listener
  3. User sees message in paypal window and button Return to merchant (I am in sandbox testing)
  4. User hits Return to Merchant and is back to the page where they made purchase from

Ok, so in my IPN listener I do this:

if( ! session_id() ) {
    session_start();
}

then a bunch of checks, then

$_SESSION['alert-success'] = 'Thank you for your purchase!';

or

$_SESSION['alert-danger'] = 'There was a problem processing your order';

Now in this IPN listener I can set more fine tuned messages, but for now trying to get something basic working.

Then in the product page they are returned to I have this

     <div class="flash-message">
         <?php
         foreach (['danger', 'warning', 'success', 'info'] as $msg) {
             $msgtype = 'alert-' . $msg;
             $issession=0;
             if(isset($_SESSION[$msgtype])) {
                 $p = "<p class=\"alert " . $msgtype. "\">" . $_SESSION[$msgtype] . "</p>";
                 echo $p;
                 $issession=1;
             }
         }
         if ($issession) {
             session_destroy();
         }
         ?>
     </div>

Now, this isn't doing anything. So it seems whatever session variable is being set in IPN listener is not available when user gets back to the return url.

I have in my paypal form this

<input type="hidden" name="rm" value="2">

in order to have the $_POST data and I confirmed that when user hits Return to Merchant the post data is there with 'payer_status' => string 'VERIFIED'

So what gives? What is the point of having an IPN listener do a bunch of work, if the return url is only coming back with minimal info? It is the status info I get in IPN listener that I want to be able to display in my flash message area, and I thought my using session variables would achieve that but was wrong.

All above said, what is the proper way to do this?

Thanks!

1 Answer 1

0

The reason using sessions doesn't work because paypal is the one sending data to the IPN listener. The session wouldn't be stored on the user's browser since they aren't the one sending data to the IPN listener. Can you not store the information gathered from the IPN listener into a database? That's what I did for my paypal purchases. When the payment successfully went through, I stored the payment data gathered from the IPN listener and stored it with their user ID in the database. When they were redirected to a success page, I grabbed the information from the database and displayed it.

1
  • I thought about that, but that means I would have to auto log them in. Or I guess I can just use the $_POST data and show a generic message about failure or success.
    – Brian
    Oct 24, 2019 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.