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:
- From my site send user to paypal, having set
returnurl
to be the url corresponding to what they purchased. - Paypal processes, then hits my
IPN listener
- User sees message in paypal window and button
Return to merchant
(I am in sandbox testing) - 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!