Welcome Guest, Not a member yet? Register   Sign In
paypal invalid ipn
#21

[eluser]jtotheb[/eluser]
Ah right okay, in understand now.

one final question!

"// Post the data back to paypal"

Why do you do this? Is this another level of security by checking with paypal that what you just received is from them and not someone else?
#22

[eluser]Khoa[/eluser]
Hi,

It took me about 2 hours and still couldn't figure out what is the problem here.

For some reason, the function ipn() inside the controller is just not called.

To test the data, I put in some debugging code that writes a file log as:

Code:
// Inside the controller, which can be accessed at http://localhost/testSite/product/ipn
function ipn()
{
    $fp = fopen('C:\\dbug_paypal.log', 'a');
    fwrite($fp, 'ipn gets called at: '.time().'\n');
    
    $this->load->library('paypal_lib');
    if ($this->paypal_lib->validate_ipn())
    {
        ...
    }
}

I double, triple checked the followings and they are all fine:
- the notify_url exists in the form with value = http://localhost/testSite/product/ipn. So, can be sure that the url is sent to paypal
- when copy the address http://localhost/testSite/product/ipn and paste it to the browser, it does write out the debug_paypal.log file. This ensures that url can be accessed and once accessed, it works.

So all I can see is that function does not get called at any stage at all. I'm testing on the sandbox, not try the live server yet. But I read in this forum that people say it still works with sandbox, right? So is there anything I missed? I can post the full code here if anyone is interested in.

BTW, at what stage do we expect the ipn() function to be called? Here are a couple of steps I see in the process:

1. User click on the "buy now" button which is the form with return url, cancel url, notify url and all other stuff
2. They are taken to paypal
3. Login to paypal
4. See the payment summary page, the page with title "Review your payment"
5. Then, user click on the "pay now" button
6. See the thank you page with the title "Thank you for your payment"
7. Then, there is a link saying "Return MY NAME's test store"

So, at what step is the function called?

My project due date is getting SOOOOO CLOSE now, I really really really need to solve this out urgently. Any help or experience to share would be very much appreciated!

Thanks,
Khoa
#23

[eluser]ray73864[/eluser]
ipn is called as soon as the person presses the 'pay now' button i believe, basically ipn is for validating the data instead of requiring a ssl connection, so the person clicks 'pay now' on paypal, paypal sends all the data to your server's ipn function, the ipn function packages it all up and sends it back to paypal exactly as it received it, if paypal receives it back correctly then it is assumed to be coming from your server.

if i remember correctly though, i believe the ipn stage can happen at any time after they press the paynow button, it will be whenever the paypal server has a free moment to do it.
#24

[eluser]Khoa[/eluser]
Thanks for the quick response ray,

So why is the function ipn not called then? I noticed one thing. After a payment is made, I double check in both the buyer and seller accounts in the sandbox, there is a list of transactions at the bottom. Sometimes the transaction is said to be "Completed", sometimes it says "Unclaimed". Do you have any idea about it? Can this be related to the fact that I do not receive the ipn?

You said "it will be whenever the paypal server has a free moment to do it.", what do you mean by this? It sounds like you have some experience with the fact that Paypal delays the transactions, can you share?

If paypal does not process it instantly, is there any case that ipn function will be called at some later stage in the future? Like I buy sth in the morning, but it won't be processed until midnight and that's when the ipn function is called?

Sorry to have so many question, but to be honest, at this time, I don't really care, or more correctly, don't have time to care about how paypal works, I just need to get this work asap. I will be in BIG BIG trouble if I cannot get this done by this christmas :-( Is there any way I can contact you directly to ask for your help on this? Like emailing you directly?

Thanks ray.
#25

[eluser]Khoa[/eluser]
I just tested it with the live server, and it doesn't work either!!! :-(
#26

[eluser]Unknown[/eluser]
Hi sph. could you help me please....??

i have a code for an IPN listener, and im working with sandbox. The response is always INVALID and I've tried diferrent things to prove that, thats the only problem....

Code:
<?php

// PHP 4.1
// read the post from PayPal system and add 'cmd'
  include('codigo.php');
  include('declararobjeto.php');
  $obj=declarar();
  $objinsertar=declarar();
$req = 'cmd=_notify-validate';
$objtexto=declarar();
$idx=0;
$linea="La hora es: ".horaactual();
$objtexto->ejecutar("INSERT into texto values('$idx','$linea')");

foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
//  $req .= '&'.http_build_query($_POST);
}
$lin="Lo que recibo en req = ".$req;
  $objtexto->ejecutar("INSERT into texto values('$idx','$lin')");
// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
//$cnx=mysql_connect("mysql1.000webhost.com","a6513996_doctorm","lumanbdluman000") or die(mysql_error());
//$cnx=mysql_connect("localhost","marc1ae_doctorm","lumanbdluman000") or die(mysql_error());
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$user_id=mysql_real_escape_string((int)$_POST['custom']);
$user_id=$_POST['custom'];
/*
//----------------------------------------------------------
$lin="ITEMNAME = ".$item_name." , ";
$lin.="ITEMNUMBER = ".$item_number." , ";
$lin.="PAYMENTSTATUS = ".$payment_status." , ";
$lin.="PAYMENTAMOUNT = ".$payment_amount." , ";
$lin.="PAYMENTCURRECY = ".$payment_currency." , ";
$lin.="TXNID = ".$txn_id." , ";
$lin.="RECEIVEREMAIL = ".$receiver_email." , ";
$lin.="PAYEREMAIL = ".$payer_email." , ";
$lin.="USERID = ".$user_id." , ";
$objtexto->ejecutar("INSERT into texto values('$idx','$lin')");
//----------------------------------------------------------
*/

//mysql_close($cnx);
if (!$fp)
{
// HTTP ERROR
$lin="ERROR FP";
$objtexto->ejecutar("INSERT into texto values('$idx','$lin')");
}
else
{  
  $lin="Lo que le envio a FP = ".$header.$req;
  $objtexto->ejecutar("INSERT into texto values('$idx','$lin')");
  fputs ($fp, $header . $req);  
  
  while (!feof($fp))
  {  
$res = fgets ($fp, 1024);   //ESTA ES LA ORIGINAL
//$res=stream_get_contents($fp, 1024);
$lin=$res;
    $objtexto->ejecutar("INSERT into texto values('$idx','$lin')");


if (strcmp ($res, "VERIFIED") == 0)
{
    // check the payment_status is Completed
    if($payment_status=="Completed")
    { // check that txn_id has not been previously processed
      $obj->ejecutar("SELECT * from log where txn_id='$txn_id'");
   if($fobj=$obj->obtfila())
   {
    //si entra aqui es porque esa transaccion ya fue hecha anteriormente. debemos evitar duplicaciones.
   }
   else
   { // check that receiver_email is your Primary PayPal email
     if(($receiver_email=="[email protected]")||($receiver_email=="[email protected]")||($receiver_email=="[email protected]"))
     {
        if(($payment_amount=="8.99")&&($payment_currency=="USD"))
     {
        //ahora inserto el txn_id en la base de datos
     $idx=0;
       $objinsertar->ejecutar("INSERT into log values('$idx','$txn_id','$payer_email')");
     //ahora actualizo premium a 1
     $objinsertar->ejecutar("UPDATE users set premium='1' where user_id='$user_id'");
    
     }
     }
   }
    }


// check that payment_amount/payment_currency are correct
// process payment
    }
    else
{
   if (strcmp ($res, "INVALID") == 0)
   {
    // log for manual investigation
   }
}
}
fclose ($fp);
}

?>

when I was debugging my code i found this at $res....
HTTP/1.1 200 OK
Date: Mon, 03 Jun 2013 19:36:31 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Set-Cookie: cwrClyrK4LoCV1fydGbAxiNL6iG=ZlLtTHhoH2...
Set-Cookie: cookie_check=yes; expires=Thu, 01-Jun-...
Set-Cookie: navcmd=_notify-validate; domain=.paypa...
Set-Cookie: navlns=0.0; expires=Sun, 29-May-2033 1...
Set-Cookie: Apache=10.74.8.69.1370288191671154; pa...
Vary: Accept-Encoding
Strict-Transport-Security: max-age=14400
Connection: close
Content-Type: text/html; charset=UTF-8

INVALID




Theme © iAndrew 2016 - Forum software by © MyBB