php - IPN + mysql for paypal 未验证

标签 php mysql html paypal paypal-ipn

我处理这个文件已经有一段时间了,我真的很困惑。我不知道我做错了什么付款不更新用户的硬币并将交易插入 mySQL。

我用sandbox paypal上的测试工具测试IPN,返回成功。如果我遗漏了任何其他信息 - 让我知道。

我的 config.php(它只是连接到 mysql 数据库)

<?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);
}
?>  

最佳答案

HAHA 愚蠢的我,需要把 ssl://sandbox.paypal.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);

关于php - IPN + mysql for paypal 未验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9338583/

相关文章:

php - 将 session 存储为关联数组

javascript - php 中的 POST 和提交按钮问题

MySQL LIMIT 使用 SELECT COUNT(*) 作为 SELECT 中的值

mysql - Rails 跳过 ID,可能是数据库 MySQL 事务问题?

javascript - 如何以幻灯片形式显示 mysql 数据库中的图像

php - MySQL检查表是否已经存在

mysql - 如何使同一表中的一列作为自动增量其他列可以为主键

html - HR 未在页脚居中

html - 基于文本的浏览器中的水平导航

html - div 之间的差距很小,但我没有在 css 上设置边距