2012-12-18 2 views
1

저는 페이팔 IPN을했는데 데이터베이스에 아무것도 표시되지 않았습니다. 여기 내 단추가 (나는 그것을 reoccuring 기반으로 만들었습니다) 내 코드, 아무도 내가 잘못 갔는지 보지? 누구는 나에게이 문제Paypal 샌드 박스 IPN이 내 데이터베이스 테이블을 업데이트하지 않습니다

<?php 
$conn = mysql_connect('localhost', 'USERNAME', 'PASSWORD'); 
if(!$conn) { die("Could not connect: ".mysql_error()); } 

$database = mysql_select_db('fbkidsonlinedb', $conn); 
if(!$database) { die("Can't use database: ".mysql_error()); } 


// 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"; 
} 

// If testing on Sandbox use: 
$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n"; 
//$header .= "Host: <!-- w --><a class="postlink" href="http://www.paypal.com:443">www.paypal.com:443</a><!-- w -->\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 

// If testing on Sandbox use: 
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

// assign posted variables to local variables 
$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"]; 
$payer_email = $_POST["payer_email"]; 
$user_id = mysql_real_escape_string($_POST["custom"]); 

if (!$fp) { 
    // HTTP ERROR 
} else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
     $res = fgets ($fp, 1024); 
     if (strcmp ($res, "VERIFIED") == 0) { 
      if ($payment_status=='Completed') { 
       $txn_id_check = mysql_query("SELECT txn_id FROM log WHERE txn_id =".$txn_id.""); 
       if (mysql_num_rows($txn_id_check) !=1) { 
        if ($payment_amount=='29.95' && $payment_currency=='USD') { 
         $log_query = mysql_query("INSERT INTO log VALUES ('', '".$txn_id."', '".$payer_email."')"); 
         $update_premium = mysql_query("UPDATE users SET authLevel='1' where fbID='".$user_id."'"); 
        } 
       } 
      } 
     } 
     else if (strcmp ($res, "INVALID") == 0) { 
      // log for manual investigation 
     } 
    } 
    fclose ($fp); 
} 
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_xclick-subscriptions"> 
<input type="hidden" name="business" value="hiddenForStackQuestion"> 
<input type="hidden" name="lc" value="US"> 
<input type="hidden" name="item_name" value="hiddenForStackQuestion"> 
<input type="hidden" name="no_note" value="1"> 
<input type="hidden" name="no_shipping" value="2"> 
<input type="hidden" name="rm" value="1"> 
<input type="hidden" name="return" value="hiddenForStackQuestion"> 
<input type="hidden" name="cancel_return" value="hiddenForStackQuestion"> 
<input type="hidden" name="src" value="1"> 
<input type="hidden" name="a3" value="29.95"> 
<input type="hidden" name="p3" value="1"> 
<input type="hidden" name="t3" value="Y"> 
<input type="hidden" name="notify_url" value="hiddenForStackQuestion" /> 
<input type="hidden" name="custom" value="<?php echo $userId ?>" /> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHosted"> 
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="border:none;"> 
</form> 
+1

실제로 들어오는 데이터가 있는지 확인해야하므로'print_r ($ _ POST)'에 표시된 내용을 참조하십시오. – MrCode

+1

오류 검사를하지 않고도 많은 양의 쿼리를 실행하기 때문에 잘못된 점이 나타나지 않습니다. 처음에 정확한 스크립트가 호출되고 있습니까? –

+0

@sindu - 우선 IPN을 받고 있습니까? –

답변

1

왜 호스트에 대한 링크를 할당 할를 해결하는 데 도움이 될 수 : 어쨌든

$header .= "Host:http://www.sandbox.paypal.com:443\r\n"; 

:

$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n"; 

그게 있어야한다 생각 PayPal에 익숙하지 않은 분, 실수라면 미안 해요

관련 문제