2014-10-13 2 views
0

이 IPN 리스너 스크립트가 있습니다. 나는 이것을 페이팔에서 복사하고 약간 수정한다.IPN이 유효하지 않은 샌드 박스를 반환합니다.

function ipn_listener() 
    { 

     $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 IPN message sent from PayPal and prepend 'cmd=_notify-validate' 
     $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'); 
     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 [link removed] 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"); 
      echo "Got " . curl_error($ch) . " when processing IPN data"; 
     curl_close($ch); 
     exit; 
     } 
     curl_close($ch); 
     // STEP 3: Inspect IPN validation result and act accordingly 
     switch($res){ 
      case "VERIFIED": 
      echo 'verified'; 
       break; 
      case "INVALID": 
       echo 'invalid'; 
       break; 
      default: 
       // any other case (such as no response, connection timeout...) 
     } 
    } 

항상 그 리스너를 호출하면 항상 유효하지 않습니다. 나는 그 문제를 이해하지 못한다. 그것은 단지 IPN을 사용하는 제 1 시간입니다. IPN 메시지를 표시하고 싶습니다.

고마워,

답변

1

당신은 그 청취자 또는 페이팔을 부르는 중입니까? 이 스크립트는 전송이 수행 된 후에 실행되어야합니다.

내가 맞다면 PayPal 프로필에서이 파일/기능에 대한 URL을 지정하고 html 코드를 다시 확인하여 POST 작업이 올바른지 확인해야합니다. 더 자세한 내용은 여기 여기 IPN 리스너은`에코 "있어"listener..about를 호출 https://developer.paypal.com/webapps/developer/docs/classic/products/instant-payment-notification/

+0

메신저에 대한 https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/buynow_buttons/

확인이 검사에 대해. curl_error ($ ch). "IPN 데이터를 처리 할 때"; "컬에 오류가있을 때만 출력한다고 생각합니다. – Zurreal

+1

모두 괜찮 으면 IPN 기록을 확인하십시오. 내 계정 -> 기록 -> IPN 기록 또한 실제로 샌드 박스를 사용하고 있는지 확인하십시오. –

+0

나는 이미 확인하고 모든 것이 잘되었다 ... 배달 상태가 '전송 됨'입니다. 심지어 시뮬레이션 IPN을 시도해도 성공적으로 전송됩니다. 내가 이해할 수없는 유일한 이유는 내가 항상 무효가되는 이유입니다. – Zurreal

관련 문제