paypal - 如何解决在一次交易中收到多个IPN消息(相同内容)

标签 paypal paypal-ipn

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

下面是我的 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

最佳答案

即使发生这种情况也很烦人,但在 PayPal 最终解决该问题之前,您需要制定保护措施,以免您对同一笔付款进行两次处理。

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

关于paypal - 如何解决在一次交易中收到多个IPN消息(相同内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308611/

相关文章:

paypal - 不能使用多个字段来指定接收者

php - 向沙盒帐户付款时无法使用沙盒个人帐户登录

php - PayPal IPN - 发送到 ipn.php 的是什么?

paypal - 新的 PayPal 移动 SDK 中的 CustomID

paypal-sandbox - 支付测试期间 Paypal 沙箱帐户出错

PayPal 的自适应支付 API 和分期付款的链式支付

php - 我们可以通过在链接上传递订阅 ID 来取消订阅定期付款吗

php - 没有 Composer 的 Paypal 核心 SDK

php - 如何在 Paypal 中设置混合定期付款和一次性付款

html - PayPal 的 IPN 不会因购物车上传而触发