2011-08-05 117 views
1

我已经包括了我想在这里测试,但因为我是新来的贝宝,我不知道如何调试贝宝为例,沙箱,则帮助我,所以尽管:(贝宝噩梦

它看起来像付款已经被处理和接受,我现在要做的就是更新mysql表格,就在"if($payment_amount==10.00&&$payment_currency=='GBP'){"之下的标记下面的行上。我已经在phpmyadmin上测试了我的mysql,它的作用就像一个魅力,它只是其他的东西可能是错误的这里:(

PayPal按钮

<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"> 
    <input type="hidden" name="cmd" value="_xclick-subscriptions" /> 
    <input type="hidden" name="business" value="[email]" /> 
    <input type="hidden" name="item_name" value="New Subscription" /> 
    <input type="hidden" name="first_name" value="<?php echo $arr['user']['fname']; ?>" /> 
    <input type="hidden" name="last_name" value="<?php echo $arr['user']['lname']; ?>" /> 
    <input type="hidden" name="address1" value="<?php echo $arr['user']['add1']; ?>" /> 
    <input type="hidden" name="address2" value="<?php echo $arr['user']['add2']; ?>" /> 
    <input type="hidden" name="city" value="<?php echo $arr['user']['town']; ?>" /> 
    <input type="hidden" name="zip" value="<?php echo $arr['user']['postcode']; ?>" /> 
    <input type="hidden" name="email" value="[client_email]" /> 
    <input type="hidden" name="currency_code" value="GBP" /> 
    <input type="hidden" name="no_shipping" value="1" /> 
    <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" /> 
    <input type="hidden" name="recurring" value="1" /> 
    <input type="hidden" name="a3" value="10.00" /> 
    <input type="hidden" name="p3" value="1" /> 
    <input type="hidden" name="t3" value="Y" /> 
    <input type="hidden" name="src" value="1" /> 
    <input type="hidden" name="sra" value="1" /> 
    <input type="hidden" name="item_number" value="<?php echo $arr['user']['id'] ?>" /> 
    <input type="hidden" name="return" value="<?php echo site_url.'account/' ?>" /> 
    <input type="hidden" name="cancel_return" value="<?php echo site_url.'account/' ?>" /> 
    <input type="hidden" name="notify_url" value="<?php echo site_url.'account/ipn.php' ?>" /> 
</form> 

贝宝IPN处理程序

<?php 
// UPDATED LINE BELOW 
mail("[myemail]", "PP",'initiated', "From:sup[email protected]"); 
// read the post from PayPal system and add 'cmd' 
$req = 'cmd=_notify-validate'; 

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

// 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.paypal.com', 443, $errno, $errstr, 30); 
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

$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']; 
$business    = $_POST['business']; 
$payer_email   = $_POST['payer_email']; 
// $payer_email    = $_POST['payer_email']; 


if (!$fp) { 
    // echo 'Error 101 23'; 
    // die(); 
} else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
     $res = fgets ($fp, 1024); 
     if (strcmp ($res, "VERIFIED") == 0) { 
      $data['paypal_receivers_email']  = '[email]'; 
      if($payment_status=='Completed' && $receiver_email == $data['paypal_receivers_email'] &&$receiver_email){ 
       if($payment_amount==10.00&&$payment_currency=='GBP'){ 
        //successfully// now update db :)// <== this is where im strugling it does not seem to come down here at all. 
       } 
      } 
     // check 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 
     } 
     else if (strcmp ($res, "INVALID") == 0) { 
     // log for manual investigation 

     } 
    } 
    fclose ($fp); 
} 

?> 
+0

我认为沙盒包含一个日志/调试功能,我记得在那里看到,但不是很确定,你可以检查。还要检查要调试的电子邮件是否在另一个页面上工作,甚至可能更好地尝试使用file_put_contents登录文件,然后检查日志,有时电子邮件会转到批量文件夹,您不希望被旁边的问题分散注意力。 –

回答

2

尝试调试,像我一样:

在每一步中,把电子邮件()与来自PayPal(邮寄)的详细信息等。记录(邮件自己)每个成功,错误,它会给你你的问题来源。例如,把

mail("[email protected]", "PP", $res, "From:[email protected]"); 

刚刚宣布后您的变量

+0

当我使用IPN沙箱时,我试过用https://www.paypaltech.com/sg2提供的脚本,它不会工作:(我收不到任何电子邮件whats so so :( – Val

+0

正如我所说的,使调试器对于你自己来说,记录IPN处理程序的每一步以及PayPal的行为和他们的响应,你就会更容易地得到你的问题的来源 – genesis

+0

我不认为你了解我,我可以把'mail(“[email protected]” “PP”,$ res,“From:[email protected]”)'在ipn处理程序页面的最顶端,即使如此,如果我直接访问相同的url,它也可以工作, – Val

0

SITE_URL是一个常数?

<input type="hidden" name="return" value="<?php echo site_url.'account/' ?>" /> 
<input type="hidden" name="cancel_return" value="<?php echo site_url.'account/' ?>" /> 
<input type="hidden" name="notify_url" value="<?php echo site_url.'account/ipn.php' ?>" /> 

如果不是你缺少$或a()(如果它是一个函数)。

你有没有仔细检查完整的url是以html源代码形式返回的?如果它在浏览器中工作,似乎PayPal可能无法获得IPN的正确返回URL。

+0

site_url是一个定义常量,如'define('sitE_url','www .....');' – Val

+0

只需www或它包含http://? – Josh