【发布时间】:2018-05-12 00:38:02
【问题描述】:
下午好,
今天一大早,我们的一位客户收到了一封电子邮件通知:
请检查您处理 PayPal 即时付款通知 (IPN) 的服务器。发送到以下 URL 的即时付款通知失败:
https://www.domain1.com/paypal/ipn
https://www.domain2.com/paypal/ipn
我查看了处理这些端点的代码,发现由于来自以下端点的空响应而引发了异常:
https://www.paypal.com/cgi-bin/webscr
app/code/core/Mage/Paypal/Model/Ipn.php(133)中的代码:
protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
{
$postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate';
$postbackUrl = $this->_config->getPaypalUrl();
$this->_debugData['postback_to'] = $postbackUrl;
$httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer));
$httpAdapter->write(
Zend_Http_Client::POST,
$postbackUrl,
'1.1',
array('Connection: close'),
$postbackQuery
);
try {
$postbackResult = $httpAdapter->read();
} catch (Exception $e) {
$this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
throw $e;
}
/*
* Handle errors on PayPal side.
*/
$responseCode = Zend_Http_Response::extractCode($postbackResult);
if (empty($postbackResult) || in_array($responseCode, array('500', '502', '503'))) {
if (empty($postbackResult)) {
$reason = 'Empty response.';
} else {
$reason = 'Response code: ' . $responseCode . '.';
}
$this->_debugData['exception'] = 'PayPal IPN postback failure. ' . $reason;
throw new Mage_Paypal_UnavailableException($reason);
}
$response = preg_split('/^\r?$/m', $postbackResult, 2);
$response = trim($response[1]);
if ($response != 'VERIFIED') {
$this->_debugData['postback'] = $postbackQuery;
$this->_debugData['postback_result'] = $postbackResult;
throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
}
}
我设置了同一站点的沙盒版本,在处理付款时,我仍然收到来自 https://www.sandbox.paypal.com/cgi-bin/webscr 的空回复
由于响应为空,因此引发了异常,并且响应标头被设置为 503 Service Unavailable,我认为这触发了我们的客户收到的电子邮件。
我在这里看到了一些类似的问题,但对于实际导致响应为空的原因尚无定论?这是 Paypal 的问题,还是我们的结果出了问题?为了完整起见,我们最近迁移到了一个新服务器(尽管这个问题似乎只是在最后一天左右出现)。
【问题讨论】: