【发布时间】:2012-03-08 20:39:36
【问题描述】:
我在 CodeIgniter 2 上构建了一个网站,并且我正在使用 CodeIgniter PayPal Lib。我已经完成了所有必要的事情,现在我可以进行付款了。我收到一个 IPN 数据并将其发送到我的电子邮件。我已经阅读了 PayPal IPN 指南,但在那里找不到解决方案。
到目前为止一切正常,我对结果很满意,但我很担心,因为 PayPal IPN 验证失败,我无法理解问题出在哪里。
当我从沙盒测试站点发送 IPN 测试时,我会收到一个有效的 IPN, 但当我从我的网站付款时,IPN 验证失败。。 p>
我正在记录所有数据,在这两种情况下(有效或无效),付款都是成功的,我有一个“成功!”来自 PayPal 的消息。
我尝试过的事情
- 打开/关闭 CSRF 保护
- 更改编码 (utf-8 | windows-1252)
- 添加|从我的 PayPal 请求中删除字段
我正在使用的代码
我正在使用的字段
$this->paypal_lib->add_field('business', 'name_1321715512_biz@gmail.com');
$this->paypal_lib->add_field('return', site_url('paypal/success'));
$this->paypal_lib->add_field('cancel_return', site_url('paypal/cancel'));
$this->paypal_lib->add_field('notify_url', site_url('contest/receive_ipn'));
$this->paypal_lib->add_field('item_name', 'Contest Subscribtion Payment (Test)');
$this->paypal_lib->add_field('amount', '30');
$this->paypal_lib->add_field('item_number', Y11-1329469079-12); // Reference number
$this->paypal_lib->add_field('quantity', '1');
$this->paypal_lib->add_field('charset', 'utf8');
$this->paypal_lib->add_field('custom', 1723); //This is an id that I need.
发帖到 PayPal 进行验证
$post_string.="cmd=_notify-validate";
if (isset($_POST)){
foreach ($_POST as $field=>$value){
$value = str_replace("\n", "\r\n", $value);
$value = urlencode(stripslashes($value));
$post_string .= "&$field=$value";
$this->ipn_data[$field] = $value; //this is part of the library
}
}
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($post_string) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
验证IPN的代码
fputs ($fp, $header . $post_string);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// Send me e-mail - Verified
} else if (strcmp ($res, "INVALID") == 0) {
// Send me e-mail - Invalid
}
}
fclose($fp);
我还要发布收到的回复
这个是无效的(然后从我的网站发送)
cmd=_notify-validate&mc_gross=30.00&protection_eligibility=Ineligible&address_status=unconfirmed&payer_id=LD9UMUWHD44GY&tax=0.00&address_street=Via+Unit+d%27Italia%2C+5783296&payment_date=02%3A19%3A29+Feb+17%2C+2012+PST&payment_status=Completed&charset=windows-1252&address_zip=80127&first_name=Alexander&mc_fee=1.37&address_country_code=IT&address_name=Alexander+Videnov¬ify_version=3.4&custom=1721&payer_status=verified&business=aviden_1321715512_biz%40gmail.com&address_country=Italy&address_city=Napoli&quantity=1&verify_sign=AF1YwvTycK97c-VCwQnfsdzArWAcAqZjskElh-FsmZ0s9HqL9BjFUKVH&payer_email=aviden_1329133801_per%40gmail.com&txn_id=32Y96385XJ0686735&payment_type=instant&last_name=Videnov&address_state=Napoli&receiver_email=aviden_1321715512_biz%40gmail.com&payment_fee=&receiver_id=TQVQ3ASRDBW28&txn_type=web_accept&item_name=Yicca+Contest+Subscribtion+Payment+%28Test%29&mc_currency=EUR&item_number=Y11-1329473936-12&residence_country=IT&test_ipn=1&handling_amount=0.00&transaction_subject=1721&payment_gross=&shipping=0.00&ipn_track_id=35382e1887f00
这是已验证的(从 PayPal 测试站点发送时)
cmd=_notify-validate&test_ipn=1&payment_type=echeck&payment_date=02%3A28%3A24+Feb+17%2C+2012+PST&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123%2C+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=TESTSELLERID1&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&txn_type=web_accept&txn_id=242171028¬ify_version=2.1&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=An5ns1Kso7MWUdW4ErQKJJJ4qi4-Arge8MWjXZSo7fPSQf3xaqAOjrSH
我注意到的两件事
- 我的网站发送的 IPN 请求和沙盒测试站点发送的 IPN 请求之间的字段顺序(请求)不同。
-
notify_version字段存在差异。来自我的网站 (3.4) |来自 PayPal (2.1)
是否有人在验证过程中遇到过同样的问题。有什么我遗漏的东西,或者我可以调试更多的方法吗?
【问题讨论】:
标签: php validation codeigniter paypal-ipn