2012-02-18 4 views
0

私はこのファイルをしばらくは作業していました。私は、支払いがユーザーのコインを更新せず、トランザクションをmySQLに挿入しないように、私が間違っていることを知らない。PayPalのIPN + mysqlが検証されない

私はIPNをテストするためにサンドボックスpaypalのテストツールを使用しましたが、成功しています。私が他の情報を残しているなら、私に知らせてください。 //sandbox.paypal:(ちょうどMySQLデータベースに接続する)

私のconfig.phpここ

<?php 
session_start(); 
    include("database.php"); 
    if(!(@mysql_connect("$host","$user","$pass") && @mysql_select_db("$tablename"))) { 
?> 

は私のIPN.php

<?php 
require("config.php"); 

// read the post from PayPal system and add 'cmd' 
$req = 'cmd=_notify-validate'; 

foreach ($_POST as $key => $value) { 
$value = urlencode(stripslashes($value)); 
$req .= "&$key=$value"; 
} 

// post back to PayPal system to validate 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

// 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']; 
$custom = $_POST['custom']; 

if (!$fp) { 
// HTTP ERROR 
} else { 
fputs ($fp, $header . $req); 
while (!feof($fp)) { 
$res = fgets ($fp, 1024); 
if (strcmp ($res, "VERIFIED") == 0) { 
$pack = mysql_fetch_object(mysql_query("SELECT * FROM `c_pack` WHERE `name`='{$item_name}' AND `coins`='{$item_number}'")); 
$user = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `id`='{$custom}'")); 
if (
    ($receiver_email == $site->paypal) && 
    ($payment_amount == $pack->price) && 
    ($payment_status == 'Completed') 
    ) { 
mysql_query("UPDATE `users` SET `coins`=`coins`+'{$pack->coins}' WHERE `id`='{$custom}'");   
mysql_query("INSERT INTO `transactions` (user, points, pack, money, date) VALUES('{$user->login}', '{$pack->coins}', '{$item_name}', '{$payment_amount}', NOW())"); 
} 
} 
else if (strcmp ($res, "INVALID") == 0) { 
// log for manual investigation 
} 
} 
fclose ($fp); 
} 
?> 

答えて

1

HAHA愚かな私に、SSLを置くために必要です.com - これは他の誰かのための将来の参考用です。あなたのボタンとfpをサンドボックスにセットアップすることを忘れないでください。これを理解するのに5時間かかりました。

// post back to PayPal system to validate 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);