IPN无效,但不在沙盒中

时间:2015-09-12 23:47:44

标签: paypal paypal-ipn paypal-sandbox

我知道这个问题被问了很多,我看过可能与这个问题有关的每个问题,但似乎没有一个问题可以解决我的问题。基本上,当我在沙箱中运行我的代码时,它可以工作,但不是在实时。这是:

<?php

class Paypal_IPN
{

    /** @var string $_url The paypal url to go through cURL
    $private $_url;
    /**
    * @param string $mode 'live' or 'sandbox'
    */

    public function __construct($mode = 'live') 
    {
        if ($mode == 'live')
        $this->_url = 'https://www.paypal.com/cgi-bin/webscr';

        else 
        $this->_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    }

    public function run()
    {
        $postFields = 'cmd=_notify-validate';

        foreach ($_POST as $key => $value) {

            if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){  
                $varvalue = urlencode(stripslashes($varvalue)); 
            }
            else { 
                $value = urlencode($value); 
            } 
            $postFields .= "&$key=$varvalue"; 
        }

        $ch = curl_init();

        curl_setopt_array($ch, array(
            CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $postFields
            ));

        $result = curl_exec($ch);
        curl_close($ch); 

        $price = $_POST['mc_gross'];


         if ($result == 'VERIFIED') {

            try 
                            {
                                $bdd = new PDO('mysql:host=HOST;dbname=DBNAME', 'LOGIN', 'PASS');

                            } catch(PDOexception $e)
                            {
                                echo "erreur";
                            }   



                            $bdd->exec("UPDATE users SET price='$price' WHERE pseudo='CUSTOMER'");

         } else {
    // IPN invalid, log for manual investigation
    echo "The response from IPN was: <b>" .$result ."</b>";

         }

    }
}

 ?>

所以是的,每次我进入运行此代码的确认页面:

<?php
    require 'ipn.php';
    $paypal = new Paypal_IPN();
    $paypal->run();
?>

我收到此错误:来自IPN的回复是:INVALID

我将IPN文件的正确URL输入到我的paypal帐户中。我真的看不出我做错了什么。你能帮助我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

在公共函数中,运行else语句:

$value = urlencode($value);

应阅读:

$varvalue = urlencode($value);