2017-12-08 9 views
0

メンバーのプレミアムを更新する方法を見つけることができません。 ユーザーが支払って支払いが完了したときに、プレミアムをYESに更新したい支払いが完了したときにデータベースを更新する

支払いが完了すると何も起こりません。また、ユーザーにプレミアムアクセスがある場合でもNOと表示されます。

ここに任意のアイデアはありますか?ペイパルIPN

を使用してイムは、ここに私のlistener.phpある

<?php require('includes/config.php'); 



header('HTTP/1.1 200 OK'); 

// 
// STEP 2 - create the response we need to send back to PayPal for them to confirm that it's legit 
// 

$resp = 'cmd=_notify-validate'; 
foreach ($_POST as $parm => $var) 
    { 
    $var = urlencode(stripslashes($var)); 
    $resp .= "&$parm=$var"; 
    } 

// STEP 3 - Extract the data PayPal IPN has sent us, into 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']; 
    $record_id  = $_POST['custom']; 


// Right.. we've pre-pended "cmd=_notify-validate" to the same data that PayPal sent us (I've just shown some of the data PayPal gives us. A complete list 
// is on their developer site. Now we need to send it back to PayPal via HTTP. To do that, we create a file with the right HTTP headers followed by 
// the data block we just createdand then send the whole bally lot back to PayPal using fsockopen 


// STEP 4 - Get the HTTP header into a variable and send back the data we received so that PayPal can confirm it's genuine 

$httphead = "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$httphead .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$httphead .= "Content-Length: " . strlen($resp) . "\r\n\r\n"; 

// Now create a ="file handle" for writing to a URL to paypal.com on Port 443 (the IPN port) 

$errno =''; 
$errstr=''; 

$fh = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

// STEP 5 - Nearly done. Now send the data back to PayPal so it can tell us if the IPN notification was genuine 

if (!$fh) { 

// Uh oh. This means that we have not been able to get thru to the PayPal server. It's an HTTP failure 
// 
// You need to handle this here according to your preferred business logic. An email, a log message, a trip to the pub.. 
      } 

// Connection opened, so spit back the response and get PayPal's view whether it was an authentic notification   

else { 
      fputs ($fh, $httphead . $resp); 
      while (!feof($fh)) 
       { 
       $readresp = fgets ($fh, 1024); 
       if (strcmp ($readresp, "VERIFIED") == 0) 
        { 





    $stmt = $db->prepare("UPDATE members SET Premium = 'YES' WHERE memberID = :memberID"); 
$stmt->execute(array(
     ':memberID' => $memberID 

    )); 


} 







} 

       else if (strcmp ($readresp, "INVALID") == 0) 
        { 

//    Man alive! A hacking attempt? 

        } 
       } 
fclose ($fh); 
     } 
// 
// 
// STEP 6 - Pour yourself a cold one. 
// 
// 

?> 

私は今しばらくの間闘争を持っている、と私はまだカントはそれを動作させます。助けてくれてありがとう!

+0

デバッグコードを挿入しましたか? $ test = $ stmt-> execute($ foo); if(!$ test)echo "ステートメントが実行されませんでした!" $ db->エラー。 –

+0

@Kevin_Kinseyいいえ、それはlistener.phpでもうまくいきますか?私は10秒前にリダイレクトされるので、 – kibrobro

+0

ダイ()を追加してください。 ...? –

答えて

0

PayPal IPNはローカルマシン上では動作しませんPayPalシミュレータを使用して検証することができます。「notify_url」またはセットアップIPNハンドラurlを使用してpaypalアカウントに送信する必要があります。

$url_parsed = parse_url($paypal_url); 
    $post_string = ''; 
    foreach ($_REQUEST as $field => $value) { 
     $post_string .= $field . '=' . urlencode(stripslashes($value)) . '&'; 
    } 
    $post_string.="cmd=_notify-validate"; // append ipn command 
    // get the correct paypal url to post request to 
    $paypal_mode_status = $ipn_data; //get_option('im_sabdbox_mode'); 
    if ($paypal_mode_status == true) 
    $fp = fsockopen('ssl://www.sandbox.paypal.com', "443", $err_num, $err_str, 60); 
    else 
    $fp = fsockopen('ssl://www.paypal.com', "443", $err_num, $err_str, 60); 
    $ipn_response = ''; 

    if (!$fp) { 
    // could not open the connection. If loggin is on, the error message 
    // will be in the log. 
     $ipn_status = "fsockopen error no. $err_num: $err_str"; 
     if ($ipn_data == true) { 
     echo 'fsockopen fail'; 
     } 
     return false; 
    } else { 
    // Post the data back to paypal 
     fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); 
     fputs($fp, "Host: $url_parsed[host]\r\n"); 
     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
     fputs($fp, "Content-length: " . strlen($post_string) . "\r\n"); 
     fputs($fp, "Connection: close\r\n\r\n"); 
     fputs($fp, $post_string . "\r\n\r\n"); 

     // loop through the response from the server and append to variable 
     while (!feof($fp)) { 
     $ipn_response .= fgets($fp, 1024); 
     } 
     fclose($fp); // close connection 
    } 
    // Invalid IPN transaction. Check the $ipn_status and log for details. 
    if (!preg_match("/VERIFIED/s", $ipn_response)) { 
     $ipn_status = 'IPN Validation Failed'; 

     if ($ipn_data == true) { 
     echo 'Validation fail'; 
     print_r($_REQUEST); 
     } 
     return false; 
    } else { 
     $ipn_status = "IPN VERIFIED"; 
     if ($ipn_data == true) { 
     echo 'SUCCESS'; 
     } 
     return true; 
    } 
+0

これをlistener.phpの代わりに使うべきでしょうか? – kibrobro

+0

はい、これをあなたのlistener.php(あなたのIPN)ファイルに使うことができます – Vivek

関連する問題