drogon982007 2014-09-15 13:52
浏览 28

PayPal IPN没有发送到mysql

My paypal ipn is not sending data to mysql. It does work with sandbox mode. I have filled in the password in the real code, thats not the problem.

This is the code that i use for the IPN script:

<?php
   //Change these with your information
$paypalmode = ''; //Sandbox for testing or empty ''
$dbusername     = 'jeffrfj13_jdv'; //db username
$dbpassword     = ''; //db password
$dbhost     = 'localhost'; //db host
$dbname     = 'jeffrfj13_paypal'; //db name

if($_POST)
{   
if($paypalmode=='sandbox')
        {
              $paypalmode     =   '.sandbox';
         }
       $req = 'cmd=' . urlencode('_notify-validate');
       foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    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_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
    $res = curl_exec($ch);
    curl_close($ch);

    if (strcmp ($res, "VERIFIED") == 0)
    {
        $transaction_id = $_POST['txn_id'];
        $username = $_POST['txn_id'];
        $itemname = $_POST['item_name'];
        $firstname = $_POST['first_name'];
        $lastname = $_POST['last_name'];
        $payeremail = $_POST['payer_email'];
        $paymentdate = $_POST['payment_date'];
        $paymentstatus = $_POST['payment_status'];
        $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
        $mcgross = $_POST['mc_gross'];
        $otherstuff = json_encode($_POST);

        $conn = mysql_connect($dbhost,$dbusername,$dbpassword);
        if (!$conn)
        {
         die('Could not connect: ' . mysql_error());
        }

        mysql_select_db($dbname, $conn);

        // insert in our IPN record table
        $query = "INSERT INTO paypal
        (transactie_id,programma,naam,email,transactie_datum,status,totaal_bedrag,username,ieverything_else)
        VALUES
        ('$transaction_id','$itemname','$firstname $lastname','$payeremail','$mdate','$paymentstatus','$mcgross','$username','$otherstuff')";

        if(!mysql_query($query))
        {
            //mysql error..!
        }
        mysql_close($conn);

    }

} ?>

If somebody can help me that would be very nice! Kind regards, Jeffrey

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)