Php paypal未发送live的ipn详细信息

Php paypal未发送live的ipn详细信息,php,paypal,Php,Paypal,我在贝宝配置中使用了以下代码 ///Paypal Array/// $data=array( //merchant email for live //'merchant_email'=>'sumofish@yahoo.com', //merchant email for

我在贝宝配置中使用了以下代码

///Paypal Array///
                            $data=array(
                            //merchant email for live
                            //'merchant_email'=>'sumofish@yahoo.com',
                            //merchant email for test
                            'merchant_email'=>'uneebmir321-facilitator@yahoo.com',
                            'product_name'=>$bundleplan." Bundle Plan",
                            's_amount'=>$bundle_came_price,     // Second` Amount
                            's_cycle'=>'M',         //Second Period M=montrh,Y=year ,D=Days, W='week'
                            's_period'=>$period,    // Second Cycle
                            //see small_price fucntionality again
                            'small_price'=>$bundle_came_price,
                            ////see small_price fucntionality again
                            'currency_code'=>'USD',
                            'thanks_page'=>"https://".$_SERVER['HTTP_HOST'].'/puppy/puppy/thanks222.php',
                            'notify_url'=>"https://puppybundle.com/beta/ipn.php",
                            'cancel_url'=>"https://puppybundle.com/beta/index.php",
                            //true for sandbox false for live
                            'paypal_mode'=>true,
                            //true for sandbox false for live
                            'currency_symbole'=>'$'
                            );
                ///Paypal Array///
这是ipn类

<?php
session_start();
$unique_id=$_SESSION['unique_id'];
include("db.php");
file_put_contents("newfile.txt",var_export($_POST,true));
$status="not_completed";
                            $status2="paid";
                            $status3="remaining";
                            $zero=0;
                            $currency="CAD";
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp (trim($res), "VERIFIED") == 0) {
    // check whether the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment

    // assign posted variables to local variables


     $price = $_POST['mc_gross'];
     $currency = $_POST['mc_currency'];
     $payer_email = $_POST['payer_email'];
     $txn_id=$_POST['txn_id'];

    $item_name = $_POST['item_name'];
        if($item_name=="Small Bundle Plan"){

            $item_name="small";
        }

parse_str($_POST['custom'],$_MYVAR);

$custom =$_MYVAR['id'];
$unique_id =$_MYVAR['unique_id'];
trim($custom);
$txt =$custom;
    $currency_code= $_POST['currency_code'];
    $fulldate = gmdate('Y-m-d H:i:s');
    if($txn_id){

    $query="UPDATE `puppy_pending_transaction` SET `status`=? WHERE unique_id=?";
                            $stmt = $db->prepare($query);
                            if($stmt){
                                $stmt->bind_param("ss", $status2,$unique_id);
                                $stmt->execute();   
                                $stmt->close();         
                            } 


$query="INSERT INTO `puppy_transaction_confirmed`(`transaction_id`,`unique_id`, `user_id`, `payer_email`, `transaction_time`, `package`, `amount`, `currency`,`status_delivery`) VALUES (?,?,?,?,?,?,?,?,?)";
                            $stmt = $db->prepare($query);

                            if($stmt) 
                            {
                                $check=$stmt->bind_param("sssssssss",$txn_id,$unique_id,$custom,$payer_email,$fulldate,$item_name,$price,$currency,$status);
                                $stmt->execute();               
                                $stmt->close();
                            }

$query="INSERT INTO `puppy_paid_transaction_record`(`unique_id`, `month_delivered`, `total`,`status`) VALUES (?,?,?,?)";
                            $stmt = $db->prepare($query);
                            if($stmt){
                                $stmt->bind_param("ssss", $unique_id,$zero,$item_name,$status3);
                                $stmt->execute();   
                                $stmt->close();         
                            } 
    }   
} else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation 
}
?>
在ipn类中

`$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');`

对于实时模式,我已经使用ipn模拟器验证了我的文件,这是确定的更多,我确信我在paypal中为商家设置的ipn路径也是确定的,我确信,我不知道出了什么问题!有人能告诉我正确的方向吗?

根据下载的最新PHP。您可以将IPN类文件保存到需要的任何位置(以下示例与IPN文件位于同一文件夹中)

您还需要设置一个异常捕获例程,因为Paypal默认情况下没有实现一个异常捕获例程(这就是
try{…}catch{}
块所做的)


并确保Paypal最终能够使用类并(模糊地)构建一个正确的支付IPN类。下载它,特别是使用新的
.pem
文件,因为它正确地包含了他们的服务器安全证书,这导致了无休止的二次问题,到目前为止。那太好了!但是我在哪里做我的自定义编码呢?打开他们的PHP文件,将他们更新的代码复制到页面a上的代码上nd根据需要更新详细信息。好的,我正在给它一个goi我得到这个错误!未捕获的异常“异常”,在/home/mike7860/public_html/puppybundle.com/beta/PaypalIPN.php:98中显示消息“PayPal以http代码0响应”,我真的很感谢您对我的问题的关注Martin,但我们仍然在那里,实际上它仍然没有出现在条件是否已验证($verified)更新是,我没有收到任何错误,因为我之前有任何PHP错误?任何错误日志错误?你有没有在帐户部分告诉Paypal IPN的URL?你有没有添加
.pem
文件?是的,添加了pem文件IPN很好,没有PHP错误。我的证书文件路径是'root/cert/cacert.pem',在我的PaypalIPN文件中是我定义的路径作为curl_setopt($ch,CURLOPT_CAINFO,DIR./cert/cacert.pem”);是否正确?将pem文件放在与PHP文件相同的目录中可能是最简单的方法,我怀疑您的curl是否能够访问根文件夹。
`$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');`
<?php
define("LOG_FILE", "paypal_ipn.log");
////edit
error_log("Log File Started:\n",3,LOG_FILE);

require('PaypalIPN.php'); //check path is correct. 
$ipn = new PayPalIPN();    
try {
    // Use the sandbox endpoint during testing.
    $ipn->useSandbox(); //comment this line out to use live version.
    $verified = $ipn->verifyIPN(); //returns true or false. 
    if ($verified) {
        /*****
         * Process IPN
         * A list of variables is available here:
         * https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
         *
         * Here is where you add your data from your current setup, your own custom data to take the values from Paypal and process them.
         ****/
        // check whether the payment_status is Completed
        // check that txn_id has not been previously processed
        // check that receiver_email is your Primary PayPal email
        // check that payment_amount/payment_currency are correct
        // process payment

        // assign posted variables to local variables


        $price       = $_POST['mc_gross'];
        $currency    = $_POST['mc_currency'];
        $payer_email = $_POST['payer_email'];
        $txn_id      = $_POST['txn_id'];

        $item_name = $_POST['item_name'];
        if ($item_name == "Small Bundle Plan") {

            $item_name = "small";
        }

        parse_str($_POST['custom'], $_MYVAR);

        $custom    = $_MYVAR['id'];
        $unique_id = $_MYVAR['unique_id'];
        trim($custom);
        $txt           = $custom;
        $currency_code = $_POST['currency_code'];
        $fulldate      = gmdate('Y-m-d H:i:s');
        if ($txn_id) {

            $query = "UPDATE `puppy_pending_transaction` SET `status`=? WHERE unique_id=?";
            $stmt  = $db->prepare($query);
            if ($stmt) {
                $stmt->bind_param("ss", $status2, $unique_id);
                $stmt->execute();
                $stmt->close();
            }


            $query = "INSERT INTO `puppy_transaction_confirmed`(`transaction_id`,`unique_id`, `user_id`, `payer_email`, `transaction_time`, `package`, `amount`, `currency`,`status_delivery`) VALUES (?,?,?,?,?,?,?,?,?)";
            $stmt  = $db->prepare($query);

            if ($stmt) {
                $check = $stmt->bind_param("sssssssss", $txn_id, $unique_id, $custom, $payer_email, $fulldate, $item_name, $price, $currency, $status);
                $stmt->execute();
                $stmt->close();
            }

            $query = "INSERT INTO `puppy_paid_transaction_record`(`unique_id`, `month_delivered`, `total`,`status`) VALUES (?,?,?,?)";
            $stmt  = $db->prepare($query);
            if ($stmt) {
                $stmt->bind_param("ssss", $unique_id, $zero, $item_name, $status3);
                $stmt->execute();
                $stmt->close();
            }

            /***
             * End OP code
             ***/
        }
        // Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
        header("HTTP/1.1 200 OK");
    }

}
catch (Exception $e) {
    error_log("There was a problem: ".$e->getMessage(),3,LOG_FILE);
}
    if ($this->use_local_certs) {
        curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem");
    }