简体   繁体   English

IPN + MySQL for Paypal无法验证

[英]IPN + mysql for paypal not verifying

I've been working on this file for awhile and I'm just really baffled. 我已经在这个文件上工作了一段时间了,我真的很困惑。 I don't know what I'm doing wrong for the payment to not update user's coins and insert transactions into mySQL. 我不知道我在为不更新用户代币并将交易插入MySQL中的付款做错什么。

I've used the test tools on sandbox paypal to test the IPN and it returns successful. 我已经使用了沙盒paypal上的测试工具来测试IPN,它会成功返回。 If I'm leaving out any other information - let me know. 如果我没有其他信息,请告诉我。

my config.php (which just connects to mysql database) 我的config.php(仅连接到mysql数据库)

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

here is my IPN.php 这是我的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 stupid me, needed to put ssl://sandbox.paypal.com - this is for future reference for anyone else.. remember to setup your button and fp to sandbox. 哈哈愚蠢的我,需要把ssl://sandbox.paypal.com-这是供其他人以后参考。.记得设置您的按钮和fp到沙盒。 Took me 5 hours to figure this out. 花了我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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM