开发者

php paypal ipn weird callback values

开发者 https://www.devze.com 2023-03-19 12:41 出处:网络
I am trying to use paypal ipn to have members on my site buy a premium membership using the buy now button. When I first tried it it didn\'t work at all. After some changes I was able to successfully

I am trying to use paypal ipn to have members on my site buy a premium membership using the buy now button. When I first tried it it didn't work at all. After some changes I was able to successfully receive payments. The only problem was the data that was suppose to go into my database through the ipn was... somehow not right. The email address was right, but the txn_id was wrong, and no date was inserted. The transaction id given at the end of a transaction does not match the one inserted into my database.

Also even though a transaction is complete, it still sends me to the return_cancel url.

Table columns- id(auto incremented), txn_id (paypal transaction ID), email (of buyer)

// assign posted variables to local variables
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$user_id = mss($_POST['custom']); //user id
$curdate = date("Y-m-d H:i:s");

if (!$fp) {
    // HTTP ERROR
} else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0) {
            $update_prem = mysql_query("UPDATE `users` SET `accountype` = '2' WHERE `users`.`id` ='".$user_id."'");
            $log_query=mysql_query("INSERT INTO `log` (`id`, `txn_id`, `date`, `email`) VALUES ('','".$txn_id."', '".$curdate."','1".$payer_email."')");
        }
        else if (strcmp ($res, "INVALID") == 0) {
        开发者_如何学JAVA    // log for manual investigation
            $log_query=mysql_query("INSERT INTO `pplog` (`lid`, `txn_id`, `date`, `email`) VALUES ('','".$txn_id."', '".$curdate."','000".$payer_email."')");
        }
    }
    fclose ($fp);
}

Also in the code where it says '1".$payer_email."' and '000".$payer_email."', I used to let me know if the logged value was a VALID or INVALID log. The first few times, it was logged twice, then I figured out why it did that, but now it logges it once but just '".$payer_email."'???

I got the email problem working now. the only thing left is why does paypal return INVALID when the transaction was complete? Is it because its a paypal sandbox thing?

Does anyone know what could be the cause of this, or has anyone had this problem themselves??


Alternatively there are a few PHP Paypal IPN Integration Class available on internet, have you tried any of those? I have linked 2 of them, see if that helps.

http://www.micahcarrick.com/php-paypal-ipn-integration-class.html

http://www.geniegate.com/other/paypal/

I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消