解决Opencart paypal ipn 返回 INVALID

系统出现个别订单状态是Pending,但Paypal已经收到钱,按照下面步骤逐一排查

1.打开Paypal的设置,修改Debug Mode为Enabled

2.后台System 》 Tools 》Error Logs,查看日志,发现出现问题的订单返回PP_STANDARD :: IPN RESPONSE: INVALID

3.通过在Paypal官网查询,发现以下文字:

To ensure that symbols and special characters in the date or other fields are processed correctly, use rawurlencode and rawurldecode instead of urlencode and decode.

查询Error Logs,出现问题的订单返回PP_STANDARD :: IPN REQUEST记录里invoice的后面,会有两个++号,导致链接不完整,从而导致IPN返回INVALID

查询 pp_standard.php代码,发现Opencart官方使用的是urlencode,修改为rawurlencode。

附上Paypal传送门 Receiving an INVALID message from PayPal

4.修改paypal的字符编码

go to your Paypal profile

click My selling tools in the sidebar

scroll to the bottom and click PayPal button language encoding

click More options and set the encoding to UTF-8

 
 

P.S.urlencode与rawurlencode区别

urlencode:返回字符串,此字符串中除了-_.之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与application/x-www-form-urlencoded的媒体类型编码方式一样。由于历史原因,此编码在将空格编码为加号(+)方面与 RFC1738 编码不同。

rawurlencode:返回字符串,此字符串中除了-_.之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数。这是在 RFC 1738 中描述的编码,是为了保护原义字符以免其被解释为特殊的 URL 定界符,同时保护 URL 格式以免其被传输媒体(像一些邮件系统)使用字符转换时弄乱。

原文地址:https://www.cnblogs.com/chixiaobai/p/9504786.html