2014-09-03 6 views
-1

documentation에서 직접 IPN 예제를 사용하고 있습니다.IPN 게시물이 매번 비어 있음

PayPal은 문제없이 지불하지만 PayPal은 아무런 문제없이 내 리스너로 리디렉션되지만 항상 빈 $ _POST 변수가 있습니다. 누구든지 문제를 볼 수 있습니까?

<?php 
    // Send an empty HTTP 200 OK response to acknowledge receipt of the notification 
    header('HTTP/1.1 200 OK'); 

    // Assign payment notification values 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']; 

    // Build the required acknowledgement message out of the notification just received 
    $req = 'cmd=_notify-validate';    // Add 'cmd=_notify-validate' to beginning of the acknowledgement 

    echo '<pre>'; 
    var_dump($_POST); 
    echo '</pre><hr/>'; 

    foreach ($_POST as $key => $value) {   // Loop through the notification NV pairs 
     $value = urlencode(stripslashes($value)); // Encode these values 
     $req .= "&$key=$value";     // Add the NV pairs to the acknowledgement 
    } 

    // Set up the acknowledgement request headers 
    $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";     // HTTP POST request 
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 

    // Open a socket for the acknowledgement request 
    $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

    // Send the HTTP POST request back to PayPal for validation 
    fputs($fp, $header . $req); 

    while (!feof($fp)) {      // While not EOF 
     $res = fgets($fp, 1024);    // Get the acknowledgement response 

     if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification 
      // Authentication protocol is complete - OK to process notification contents 
      echo 'thanks for the payment, we are processing your request.'; 
     } else if (strcmp ($res, "INVALID") == 0) { 
      //Response contains INVALID - reject notification 
      echo 'something has gone wrong. please try again.'; 
     } 
    } 

    fclose($fp); // Close the file 

?> 

결과 : 버튼 코드를 추가로 업데이트

array(0) { 
} 
something has gone wrong. please try again. 

:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="upload" value="1"> 
<input type="hidden" name="no_shipping" value="1"> 
<input type="hidden" name="business" value="H7G2W8WN4XXXXX"> 

<input type="hidden" name="item_name_1" value="Item Name"> 
<input type="hidden" name="amount_1" value="0.25"> 

<input type="hidden" name="item_name_2" value="Item Name 2"> 
<input type="hidden" name="amount_2" value="0.25"> 

<input type="submit" value="Buy Now"/> 
</form> 
+0

당신이 여기에 버튼 코드를 게시 할 수 : 여기

이를 찾는 사람을위한 링크입니다? – Eshan

+0

@Eshan이 포함되었습니다. –

+0

[IPN Simulator] (https://developer.paypal.com/webapps/developer/applications/ipn_simulator)를 사용하여 테스트 요청을 보내 봤습니까? 방금 단순한 2 줄 스크립트 (헤더를 반환하고 $ _POST를 파일에 덤프)를 사용하여이 작업을 직접 수행했으며 예상대로 작동했습니다. – timclutton

답변

1

var_dump()가 브라우저에 출력 $_POST에 의미하기 때문에 당신은 아무것도 표시되지 않는 이유는 . 따라서 IPN URL을 방문하면 페이지에 아무 것도 게시하지 않으므로 아무 것도 게시하지 않습니다. 또한 나머지 스크립트는 여전히 실행되어 PayPal에 빈 응답을 보내 확인하지만 비어 있으므로 INVALID이 반환됩니다.

IPN이 청취자에게 게시되는 것을보고 싶다면 error_log()을 사용하여 IPN 로그에 기록하는 것이 좋습니다. 이렇게하면 PayPal이 청취자에게 게시 할 때 무슨 일이 일어나는지 보여줍니다.

또한 원래는 나를 괴롭힌 몇 가지 사실을 발견했습니다. 첫 번째는 헤더 정보입니다. PayPal은 더 많은 헤더 정보가 필요하도록 시스템을 업데이트했습니다. 업데이트에 대한 통지는 here을 참조하십시오. 당신이 변경 제안한다 Basicall이에

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";     // HTTP POST request 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 

을 :

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";     // HTTP POST request 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$header .= "Host: www.paypal.com:443\r\n";    //<---added this 
$header .= "Connection: close\r\n";      //<---and this 

마지막으로 내가 뒤에 공간 VERIFIED을 받고 이후, $res 주위에 trim() 기능을 추가해야한다고합니다.

희망 하시겠습니까?

+0

감사합니다. 실제로는 유리하게 보였지만 실제로는 이러한 변경으로 인해 스크립트가 제대로 작동하지 않았습니다. –