【问题标题】:Original Transaction Id of Paypal is not storing in databasePaypal 的原始交易 ID 未存储在数据库中
【发布时间】:2014-08-30 07:16:06
【问题描述】:

我正在使用以下代码将信息存储在 php 中的数据库中。

   if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){

    // Firstly Append paypal account to querystring
    @$querystring .= "?business=".urlencode($paypal_email)."&"; 

    // Append amount& currency (£) to quersytring so it cannot be edited in html

    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

    //loop for posted values and append to querystring
    foreach($_POST as $key => $value){
        $value = urlencode(stripslashes($value));
        $querystring .= "$key=$value&";
    }

    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);

    // Append querystring with custom field
    //$querystring .= "&custom=".USERID;

    // Redirect to paypal IPN
    header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
    exit();

 } else{

    // Response from Paypal

    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
        $req .= "&$key=$value";
    }


    // assign posted variables to local variables
    $data['userid']         = $_POST['userid'];
    $data['quantity']       = $_POST['quantity'];
    $data['item_name']      = $_POST['item_name'];
    $data['item_number']        = $_POST['item_number'];
    $data['payment_status']     = $_POST['payment_status'];
    $data['payment_amount']     = $_POST['mc_gross'];
    $data['payment_currency']   = $_POST['mc_currency'];
    $data['txn_id']         = $_POST['txn_id'];
    $data['receiver_email']     = $_POST['receiver_email'];
    $data['payer_email']        = $_POST['payer_email'];
    $data['custom']         = $_POST['custom'];


    // 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); 

    if (!$fp) {
        // HTTP ERROR
    } else {    

        fputs ($fp, $header . $req);
        while (!feof($fp)) {
            $res = fgets ($fp, 1024); 

                $valid_txnid = check_txnid($data['txn_id']);
                $valid_price = check_price($data['payment_amount'], $data['item_number']);


        if($valid_txnid && $valid_price){

    $sql = "INSERT INTO payments (txnid, payment_amount, payment_status, packageID, createdtime,UserID) VALUES (
                '".$_POST['txn_id']."' ,
                '".$_POST['mc_gross']."' ,
                '".$_POST['payment_status']."' ,
                '".$_POST['item_number']."' ,
                '".date("Y-m-d H:i:s")."' ,
        '".$userid."' )";
     $paymentQueryResult= mysql_query($sql,$link);              

            if($paymentQueryResult){

                echo "Payment has been made & successfully inserted into the  Database";        
                        // Payment has been made & successfully inserted into the Database          

            }
            else{   
                echo "Payment has been made but not recorded in system database. Please contact administrator ";                            
                        // Error inserting into DB
                        // E-mail admin or alert user

                    }
                }else{  
                    echo "Payment made but data has been changed";              
                    // Payment made but data has been changed
                    // E-mail admin or alert user

                }                       

        }       
    fclose ($fp);
    }   
}

但在我的情况下,从贝宝交易后显示的交易 ID 与上述代码存储在数据库中的交易 ID 不同。表示数据库中不同的事务 id 存储或两个事务 id 不同。

我已经寻找解决方案,但没有成功。

请给我正确的解决方案。

提前致谢!

【问题讨论】:

    标签: paypal


    【解决方案1】:

    PayPal 为单笔交易向买家和卖家分配不同的交易 ID。听起来您正在结帐并在屏幕上看到交易 ID,这是 PayPal 向买家展示的内容。您的 IPN 解决方案正在接收他们提供给卖家的交易 ID。

    您应该能够在您的 PayPal 帐户中搜索任一交易 ID 以找到交易详情,但同样,您会看到买家和卖家的不同 ID。这是正常的。

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 2020-03-15
      • 2020-08-27
      • 2012-09-30
      • 2011-09-12
      • 2021-09-16
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多