2017-07-14 5 views
0

私はサンドボックスモードでPayPal IPNを使用していますが、何らかの理由でこのコードが動作しません。PayPal IPNがカスタムストアで動作しません

私が何をしたいのかは、角カッコで囲んでいることを確認するために "VERIFIED"と書いてあります。しかし、私はPhPを知らないのですが、私はお金のために働くためにこれが必要です。ここで

私の店のindex.phpを

<head> 
    <title>Donation Store | EndersoulsRH</title> 
</head> 
<body> 
    <center> 
     <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> 
     <input type="text" name="username" placeholder="Your Minecraft Username"> <br> 
     <input type="hidden" name="itemname" value="VIP"> 
     <input type="hidden" name="cmd" value="_s-xclick"> 
     <input type="hidden" name="hosted_button_id" value="SHW4WRJBFNDQA"> 
     <input type="image" src="http://www.endersouls.us/img/buynow.png" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!" width="200px;"> 
     <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"> 
     </form> 

     <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> 
     <input type="text" name="username" placeholder="Your Minecraft Username"> <br> 
     <input type="hidden" name="itemname" value="VIP"> 
     <input type="hidden" name="command" value="warp Ranks Hayno"> 
     <input type="hidden" name="cmd" value="_s-xclick"> 
     <input type="hidden" name="hosted_button_id" value="XU8NQN8EVPMYG"> 
     <input type="image" src="https://www.endersouls.us/img/buynow.png" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!" width="200px"> 
     <img alt="" border="0" src="https://www.sandbox.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"> 
     </form> 

    </center> 
</body> 
</html> 

は、ここで私はあなたのURLが間違っていると思う

<?php 
    header('HTTP/1.1 200 OK'); 

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

    $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']; 

    $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"; 

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

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

    if (!$fh) { 
     die("Connection to and from PayPal has bee lost"); 
    } else { 
     fputs ($fh, $httphead . $resp); 

     while (!feof($fh)) { 
      $readresp = fgets ($fh, 1024); 

      if (strcmp ($readresp, "VERIFIED") == 0) { 
       $command = "warp ranks Hayno"; 

       require_once("WebsenderAPI.php"); // Load Library 

       $wsr = new WebsenderAPI("*****","*****","*****"); // HOST , PASSWORD , PORT 

       if($wsr->connect()){ //Open Connect 

        $wsr->sendCommand($command); 

       } 

       $wsr->disconnect(); //Close connection. 
      } else if (strcmp ($readresp, "INVALID") == 0) { 

      } 

     fclose ($fh); 
     } 
    } 
?> 
+0

あなたのサーバのパブリックIPとパスワードを投稿しました... –

+0

そのIPとパスワードはパスワードとは関係ありませんXD –

答えて

0

ipn.php私のPayPalのです。代わりに、 `$ FH = fsockopenの( 'SSL://www.paypal.com'、443、$ errnoには、$ errstrは、30)の

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

を入れてみてください。

もsandbox.paypal.com/blahglah`

置く今ボタンテスト賃金

のでsandbox.paypal.comを入れて.....代わりにpaypal.comの....

// STEP 1: Read POST data 

// reading posted data from 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'); 
$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 post from PayPal system and add 'cmd' 
$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.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test 
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 "http://curl.haxx.se/docs/caextract.html" 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"); 
    curl_close($ch); 
    exit; 
} 
curl_close($ch); 


// STEP 3: Inspect IPN validation result and act accordinglyq 

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 Primary PayPal email 
    // check that payment_amount/payment_currency are correct 
    // process payment 

    // assign posted variables to local variablesq 
    $item_name = $_POST['item_name']; 
    $item_number = $_POST['item_number']; 
    $payment_status = $_POST['payment_status']; 
    if ($_POST['mc_gross'] != NULL) 
     $payment_amount = $_POST['mc_gross']; 
    else 
     $payment_amount = $_POST['mc_gross1']; 
    $payment_currency = $_POST['mc_currency']; 
    $txn_id = $_POST['txn_id']; 
    $receiver_email = $_POST['receiver_email']; 
    $payer_email = $_POST['payer_email']; 
    $custom = $_POST['custom']; 

$servername = "*****"; 
$username = "*****"; 
$password = "*****"; 
$dbname = "*****"; 

$nizz = (explode('|', $custom)); 
$var1 = $nizz[0]; 
$var2 = $nizz[1]; 
$var3 = $nizz[2]; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 
// DO YOUR QUERY HERE OR WHATEVER YOU WANT 


// -------------------- 



if ($conn->query($sql) === TRUE) { 


$email_from = '[email protected]'; 
//send mail from here to notify yourself 

} else { 
    echo "Error: " . $sql . "<br>" . $conn->error; 
} 
$conn->close(); 

} else if (strcmp ($res, "INVALID") == 0) { 
    // log for manual investigation 
} 
+0

それでも動作しませんでした。 –

+0

ステップバイステップで行くことができます。 1. sandbox paypal口座を開き、IPNを有効にします。 2.あなたのPHPページにURLを設定する3.私のコードを見て私は私の答えで私のコードを貼り付けコピーを行います。 PAY NOWボタンにもsandbox.paypal.comのURLがあることを確認してください。 – magma

+0

そのコードをコピーして貼り付けたが、それでも機能しませんでした。私は何が間違っているのか分かりません。 –

関連する問題