IPN paypal(PHP)插入数据库的麻烦

时间:2015-09-18 14:08:52

标签: php paypal paypal-ipn

我想在数据库中插入一些从paypal发送到我的IPN的数据。目前我只是在测试,所以我想在我的付款表中添加几个数据片段。

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 PayPal email
        // check that payment_amount/payment_currency are correct
        // process payment and mark item as paid.

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

        try 
        {
        $sql = "INSERT INTO payment(transaction_id,payment_status)
        VALUES('$txn_id','$payment_status')";
            mysql_query($sql);
        }

        catch(Exception $e)
        {
            echo "Caught Exception: " . $e->getMessage(); 
        }       


        /*if($payment_status == "completed")
        {
            mysql_query('UPDATE `users` SET `is_member`= 1 WHERE `username` == $username')
        }
        else
        {
           mysql_query('UPDATE `users` SET `is_member`= 0 WHERE `username` == $username')
        }*/


        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
        }
    } else if (strcmp ($res, "INVALID") == 0) {
        // log for manual investigation
        // Add business logic here which deals with invalid IPN messages
        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
        }
    }

另一个问题是,这是我应该按原样存储数据的方式,当它被发送到IPN接收器时?我目前正在向页面发送虚拟IPN消息以进行测试。它说消息已经收到,但数据库中没有证据

0 个答案:

没有答案