2015-12-23 3 views
0

Я пытаюсь внедрить приемник PayPal IPN. Проблема в том, что, что бы я ни пытался, я все еще получаю НЕВЕРНЫЙ ответ от IPN Simulator. Я просматривал многие форумы, но никто не помогал. Кто-нибудь знает, что может быть проблемой?PayPal IPN симулятор, возвращающий отрицательный ответ

См. Мой код ниже. YII_DEBUG is true USE_SANDBOX is true Я пробовал реализацию с или без cacert.pem, ничего не работает.

public function actionProcessPayment() 
{ 
    // Read POST data 
    // reading posted data directly from $_POST causes serialization 
    // issues with array data in POST. Reading raw POST data from input stream instead. 
    $raw_post_data = file_get_contents('php://input'); 
    if(YII_DEBUG == true) { 
     Yii::log(date('[Y-m-d H:i e] '). "Original data: " . $raw_post_data . PHP_EOL, 'warning'); 
    } 

    $req = 'cmd=_notify-validate&'.$raw_post_data; 


    // Post IPN data back to PayPal to validate the IPN data is genuine 
    // Without this step anyone can fake IPN data 
    if(self::USE_SANDBOX == true) { 
     $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; 
    } else { 
     $paypal_url = "https://www.paypal.com/cgi-bin/webscr"; 
    } 

    $ch = curl_init($paypal_url); 
    if ($ch == FALSE) { 
     return FALSE; 
    } 
    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); 
    if(YII_DEBUG == true) { 
     curl_setopt($ch, CURLOPT_HEADER, 1); 
     curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
    } 

    // Set TCP timeout to 30 seconds 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); 

    $cert = dirname(__FILE__).'/../components/cacert.pem'; 
    curl_setopt($ch, CURLOPT_CAINFO, $cert); 

    $res = curl_exec($ch); 
    if (curl_errno($ch) != 0) // cURL error 
    { 
     if(YII_DEBUG == true) { 
      Yii::log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 'warning'); 
     } 
     curl_close($ch); 
     exit; 
    } else { 
     // Log the entire HTTP response if debug is switched on. 
     if(YII_DEBUG == true) { 
      Yii::log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 'warning'); 
      Yii::log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 'warning'); 
     } 
     curl_close($ch); 
    } 

    // Inspect IPN validation result and act accordingly 
    // Split response headers and payload, a better way for strcmp 
    $tokens = explode("\r\n\r\n", trim($res)); 
    $res = trim(end($tokens)); 
    if (strcmp ($res, "VERIFIED") == 0) { 
     // check whether the payment_status is Completed 
     // check that txn_id has not been previously processed 
     // check that receiver_email is your PayPal email 
     // check that payment_amount/payment_currency are correct 
     // process payment and mark item as paid. 
     // 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']; 
     if(isset($_POST['custom'], $_POST['payment_status'])) 
      if($_POST['payment_status'] == 'Completed') 
       Order::processPayment($_POST['custom']); 

     if(YII_DEBUG == true) { 
      Yii::log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 'warning'); 
     } 
    } else if (strcmp ($res, "INVALID") == 0) { 
     // log for manual investigation 
     // Add business logic here which deals with invalid IPN messages 
     if(YII_DEBUG == true) { 
      Yii::log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 'warning'); 
     } 
    } 

    Yii::app()->end(); 
} 

ответ

0

Проблема была из-IPN Simulator автоматически заполняется поле PAYMENT_DATE с, локальной (чешский) отформатированные дату с (Střední Evropa (běžný čas) строки. Я заменил это IPN симулятор для (GMT Standard Time) и Everythink работ хорошо сейчас ...

Смежные вопросы