我发现我的实时IPN回调失败的原因是由于字符%0A将辅助自定义地址行放在新行上。
现在我发现了一篇关于这句话的论坛帖子,在urlencode()之后使用preg_replace()来修复它。
虽然我的日志不再显示新行的地址的第二部分,但我仍然收到失败的回复。
Sandbox IPN测试100%精细btw!
这是我最近的失败回复:
[04/06/2011 9:50 PM] - FAIL: IPN Validation Failed.
IPN POST Vars from Paypal:
mc_gross=0.01, protection_eligibility=Partially+Eligible+-+INR+Only, address_status=unconfirmed, payer_id=9K77MVZTDM594, tax=0.00, address_street=XXX+XXXXXX+XXXX%0D%0AXXXXXXXXX, payment_date=14%3A49%3A54+Apr+06%2C+2011+PDT, payment_status=Completed, charset=windows-1252, address_zip=XXX+XXX, first_name=XXXX, mc_fee=0.01, address_country_code=GB, address_name=XXXX+XXXXXXX, notify_version=3.1, custom=1234567890, payer_status=verified, business=XXXX%40XXXXXXXXXX.org.uk, address_country=United+Kingdom, address_city=XXXXXXXXX, quantity=1, verify_sign=ApKghSivOFtm6Gk7Iqy6QZvljWTIAYIpfc-Ew7d1VnZBDsFqcj5EugKu, payer_email=XXXXXXXX%40gmail.com, txn_id=4P917406R68516736, payment_type=instant, last_name=XXXXXXX, address_state=XXXXXXXXXX, receiver_email=XXXX%40XXXXXXXXXX.org.uk, payment_fee=, receiver_id=V4BXQHT3VGZNA, txn_type=web_accept, item_name=Property+Name+Here, mc_currency=GBP, item_number=1234, residence_country=GB, handling_amount=0.00, transaction_subject=1234567890, payment_gross=, shipping=0.00,
IPN Response from Paypal Server:
HTTP/1.1 200 OK
Date: Wed, 06 Apr 2011 21:50:05 GMT
Server: Apache
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=JxDUosn1BGy-BGZ8_loF9qdJB8p0zaq4ygql2vv-wr6gZhUyoUobb_raRpEtxg2Lt2_AIAFJO0HTQnbcKkUfv4baA1xeGgPSvAIPqRmviBEpCrtoMjQpxXdVXiOau5FloCtrn0%7cg-VIk7zlxsbY7FvV2g4tHq21VEFKmgQkvHlx7GybNRPg0IZ7rqEa0EjIj1J80sJxIxtqVm%7c_M2zQAKDYSInX-d1c_mggK-Q3a9OM9NjrmWB77K3EL2gTV6y1NwnlSiFczF6HT64jNSV8G%7c1302126606; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Sat, 03-Apr-2021 21:50:06 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Tue, 01-Apr-2031 21:50:06 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.191.196.11.50971302126605524; path=/; expires=Tue, 21-Feb-05 15:21:49 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
7
INVALID
0
(X只是替换敏感信息)
注意@s现在显示为%04?
为什么Sandbox IPN会起作用,而不是这个? (也许是因为沙箱根本没有辅助地址线?)
这是我使用preg_replace()
的更新代码$value = str_replace("\n", "\r\n", $value);
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$this->ipn_data[$field] = $value;
$post_string .= $field.'='.$value.'&';