【问题标题】:Paypal IPN works in sandbox but not livePaypal IPN 在沙盒中工作,但不是实时的
【发布时间】:2014-06-07 12:36:18
【问题描述】:

我从这里http://www.sanwebe.com/2012/07/paypal-instant-payment-notification-ipn/comment-page-1#comment-6871获得并改编了以下代码

<?php
include 'dbdata.php';
//Change these with your information
$paypalmode = 'sandbox'; //Sandbox for testing or empty ''
$paypalmode = '';
if($_POST)
{
    if($paypalmode=='sandbox')
    {
        $paypalmode     =   '.sandbox';
    }
    $req = 'cmd=' . urlencode('_notify-validate');
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    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_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
    $res = curl_exec($ch);
    curl_close($ch);

    if (strcmp ($res, "VERIFIED") == 0)
    {
        $transactionID = $_POST['txn_id'];
        $payerEmail = $_POST['payer_email'];
        $paymentStatus = $_POST['payment_status'];
        $firstName = $_POST['first_name'];
        $surname = $_POST['last_name'];
        $payerID = $_POST['payer_id'];
        $addressName = $_POST['address_name'];         
        $addressCountry = $_POST['address_country'];
        $addressCountryCode = $_POST['address_country_code'];
        $addressZip = $_POST['address_zip'];
        $addressState = $_POST['address_state'];
        $addressCity = $_POST['address_city'];
        $addressStreet = $_POST['address_street'];
        $mcGross = $_POST['mc_gross'];
        $mcShipping = $_POST['mc_shipping'];
        $mcCurrency = $_POST['mc_currency'];
        $paymentDate = $_POST['payment_date'];


        $mdate= date('Y-m-d H:i:s',strtotime($paymentDate));
        $otherStuff = json_encode($_POST);

          $query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus,firstName,surname,paymentDate,payerID,addressName,addressCountry,addressCountryCode,addressZip, addressState,addressCity,addressStreet,mcGross,mcShipping,mcCurrency,allData) VALUES  ('".$transactionID."','".$payerEmail."','".$paymentStatus."','".$firstName."','".$surname."','".$mdate."','".$payerID."','".$addressName."','".$addressCountry."','".$addressCountryCode."','".$addressZip."','".$addressState."','".$addressCity."','".$addressStreet."','".$mcGross."','".$mcShipping."','".$mcCurrency."','".$otherStuff."')";


     mysql_query($query5); 
  $mail_From    = "xxx@googlemail.com";
  $mail_To      = "xxx@googlemail.com";
  $mail_Subject = "VERIFIED IPN";
  $mail_Body    = $otherStuff;
  //mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

    }

    if (strcmp ($res, "INVALID") == 0)
    {
        $transaction_id = $_POST['txn_id'];
        $payerid = $_POST['payer_id'];
        $firstname = $_POST['first_name'];
        $lastname = $_POST['last_name'];
        $payeremail = $_POST['payer_email'];
        $paymentdate = $_POST['payment_date'];
        $paymentstatus = $_POST['payment_status'];
        $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
        $otherStuff = json_encode($_POST);

         $query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus) VALUES  ('".$transaction_id."','".$payeremail."','".$paymentstatus."')";
     mysql_query($query5); 

    }
}
?>

如果我使用沙盒模式和 IPN 模拟器,我可以将数据正确插入到表中。我现在已将客户 paypal 帐户的 IPN 设置设置为指向我的脚本并打开 IPN,但我没有发生任何事情。

该网站正在使用快速结帐。 该网站位于美国。 php 脚本托管在我们的服务器(英国)上。

Paypal 显示已发送,如果我重新发送 IPN,它们会重新显示为已发送。谁能看到这里出了什么问题?

  • 更新。我使用了我在英国的 paypal 帐户,并将 IPN 通知设置为相同的 URL,并从我妻子的 paypal 帐户发送了一笔付款,我得到了一个进入数据库的条目。

我也没有从 IPN 获得我妻子的客户详细信息,但我从模拟器获得。

沃比先生

【问题讨论】:

标签: php paypal


【解决方案1】:

只需替换

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

与

foreach ($_POST as $key => $value){
    $value = urlencode(stripslashes($value));
    $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
    $req .= "&$key=$value";         
}

【讨论】:

    猜你喜欢
    • 2019-01-09
    • 2012-06-25
    • 2013-07-04
    • 2013-12-15
    • 2013-12-06
    • 2012-04-09
    • 2016-10-02
    • 2015-11-25
    • 2018-08-14
    相关资源
    最近更新 更多