4

我正在使用 Codeigniter 测试我的购物车结账paypal_lib。我从沙盒消息中获得的结果:“VERIFIED”以及函数“validate_ipn”返回 true。但我在这里面临的麻烦是我的日志文件和订单数据不时包含来自贝宝的相同数据。

下面是我的ipn验证:

function validate_ipn(){

    $url_parsed = parse_url($this->paypal_url);       
    $post_string="cmd=_notify-validate";     
    if ($this->CI->input->post())
    {
        foreach ($this->CI->input->post() as $field=>$value)
        { 
            $this->ipn_data[$field] = $value;
            $post_string .= '&' . $field.'='.urlencode(stripslashes($value));
        }
    }

    //$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30); 
            $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $err_num, $err_str, 30);
    if(!$fp)
    {
        $this->last_error = "fsockopen error no. $errnum: $errstr";
        $this->log_ipn_results(false);       
        return false;
    } 
    else
    { 
        fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); 
        fputs($fp, "Host: $url_parsed[host]\r\n"); 
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
        fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); 
        fputs($fp, "Connection: close\r\n\r\n"); 
        fputs($fp, $post_string . "\r\n\r\n"); 

        // loop through the response from the server and append to variable
        while(!feof($fp))
            $this->ipn_response .= fgets($fp, 1024); 

        fclose($fp); // close connection
    }

    if (eregi("VERIFIED",$this->ipn_response))
    {
        // Valid IPN transaction.
        $this->log_ipn_results(true);
        return true;         
    } 
    else 
    {
        $this->last_error = 'IPN Validation Failed.';
        $this->log_ipn_results(false);  
        return false;
    }
}

这是我在日志中得到的(没有什么不同)。有很多这样的消息:

[04/24/2012 9:31 AM] - SUCCESS!
IPN POST Vars from Paypal:
mc_gross=11.00, protection_eligibility=Eligible, address_status=confirmed
, item_number1=3, tax=0.00, item_number2=5, payer_id=T4WYEY49NUK4Y, item_number3=6, address_street=1 Maire-Victorin, payment_date=00:28:18 Apr 24, 
2012 PDT, payment_status=Pending, charset=windows-1252, address_zip=M5A 1E1, mc_shipping=0.00, mc_handling=0.00, first_name=Test, address_country_code=CA, 
address_name=Test User, notify_version=3.4, custom=292aaf2e76b586a80c20f13c5b1d6997, payer_status=verified, business=tham21_1297141093_biz@yahoo.com, 
address_country=Canada, num_cart_items=3, mc_handling1=0.00, mc_handling2=0.00, mc_handling3=0.00, address_city=Toronto, verify_sign=AQwZI3e5UUeRN1fFRRAZwba0SCKvAK5Jh7SdLhAZdWaitG4t3SzIzk6D,
payer_email=tham21_1297133813_per@yahoo.com, mc_shipping1=0.00, mc_shipping2=0.00, mc_shipping3=0.00, tax1=0.00, tax2=0.00, tax3=0.00, txn_id=19366377KU1661939, 
payment_type=instant, last_name=User, address_state=Ontario, item_name1=Test 003 Product, receiver_email=tham21_1297141093_biz@yahoo.com, item_name2=Test 005 Product, 
item_name3=Test 006 Product, quantity1=1, quantity2=1, receiver_id=C7F8469MV6QVN, pending_reason=multi_currency, quantity3=1, txn_type=cart, mc_gross_1=2.00, mc_currency=EUR, 
mc_gross_2=4.00, mc_gross_3=5.00, residence_country=CA, test_ipn=1, transaction_subject=292aaf2e76b586a80c20f13c5b1d6997, payment_gross=, ipn_track_id=95d4aa9eb8b34, 

IPN Response from Paypal Server:
 HTTP/1.1 200 OK

8
VERIFIED
0



[04/24/2012 9:33 AM] - SUCCESS!
IPN POST Vars from Paypal:
mc_gross=11.00, protection_eligibility=Eligible, address_status=confirmed
, item_number1=3, tax=0.00, item_number2=5, payer_id=T4WYEY49NUK4Y, item_number3=6, address_street=1 Maire-Victorin, payment_date=00:28:18 Apr 24, 
2012 PDT, payment_status=Pending, charset=windows-1252, address_zip=M5A 1E1, mc_shipping=0.00, mc_handling=0.00, first_name=Test, address_country_code=CA, 
address_name=Test User, notify_version=3.4, custom=292aaf2e76b586a80c20f13c5b1d6997, payer_status=verified, business=tham21_1297141093_biz@yahoo.com, 
address_country=Canada, num_cart_items=3, mc_handling1=0.00, mc_handling2=0.00, mc_handling3=0.00, address_city=Toronto, verify_sign=AQwZI3e5UUeRN1fFRRAZwba0SCKvAK5Jh7SdLhAZdWaitG4t3SzIzk6D, 
payer_email=tham21_1297133813_per@yahoo.com, mc_shipping1=0.00, mc_shipping2=0.00, mc_shipping3=0.00, tax1=0.00, tax2=0.00, tax3=0.00, txn_id=19366377KU1661939, 
payment_type=instant, last_name=User, address_state=Ontario, item_name1=Test 003 Product, receiver_email=tham21_1297141093_biz@yahoo.com, item_name2=Test 005 Product, 
item_name3=Test 006 Product, quantity1=1, quantity2=1, receiver_id=C7F8469MV6QVN, pending_reason=multi_currency, quantity3=1, txn_type=cart, mc_gross_1=2.00, mc_currency=EUR, 
mc_gross_2=4.00, mc_gross_3=5.00, residence_country=CA, test_ipn=1, transaction_subject=292aaf2e76b586a80c20f13c5b1d6997, payment_gross=, ipn_track_id=95d4aa9eb8b34, 

IPN Response from Paypal Server:
 HTTP/1.1 200 OK
Date: Tue, 24 Apr 2012 07:33:44 GMT

8
VERIFIED
0
4

1 回答 1

0

甚至会发生这种情况很烦人,但是在 PayPal 最终解决问题之前,您需要开发一种保护措施,这样您就不会两次处理相同的付款。

最常见的解决方案是将数据库中的事务标记为已处理,更改状态字段或添加日期。然后检查每个 IPN 消息上的这个值,如果它已经设置,则忽略 IPN(但记录它)。

于 2013-12-16T15:45:11.673 回答