【问题标题】:Unable to communicate with the PayPal error无法与 PayPal 错误通信
【发布时间】:2016-01-26 12:55:16
【问题描述】:

我正在使用 Magento 版本。 1.8.1.0

我无法与 PayPal 网关通信。在这两种情况下,paypal express checkout 或 paypal Payments Pro 都会出错。

我已经启用 SSL 验证:- 否

你能解释一下这个错误吗?

谢谢

【问题讨论】:

    标签: magento magento-1.8


    【解决方案1】:

    Paypal 最近在沙盒上推出了一些安全更新(生产将在 6 月更新)https://devblog.paypal.com/upcoming-security-changes-notice/

    最重要的是,沙盒不再接受 TLS 1.0 和 1.1,Magento Paypal 模块默认不使用 1.2。我们可以期待官方补丁很快解决这个问题,但与此同时,您可以通过使用以下 call 函数覆盖 Mage/Paypal/Model/Api/Nvp.php(在您的本地代码池中或通过重写)来解决它:

    public function call($methodName, array $request)
    {
        $request = $this->_addMethodToRequest($methodName, $request);
        $eachCallRequest = $this->_prepareEachCallRequest($methodName);
        if ($this->getUseCertAuthentication()) {
            if ($key = array_search('SIGNATURE', $eachCallRequest)) {
                unset($eachCallRequest[$key]);
            }
        }
        $request = $this->_exportToRequest($eachCallRequest, $request);
        $debugData = array('url' => $this->getApiEndpoint(), $methodName => $request);
    
        try {
            $http = new Varien_Http_Adapter_Curl();
            $http->addOption(CURLOPT_SSLVERSION,6);//CURL_SSLVERSION_TLSv1_2
            $config = array(
                'timeout'    => 60,
                'verifypeer' => $this->_config->verifyPeer
            );
    
            if ($this->getUseProxy()) {
                $config['proxy'] = $this->getProxyHost(). ':' . $this->getProxyPort();
            }
            if ($this->getUseCertAuthentication()) {
                $config['ssl_cert'] = $this->getApiCertificate();
            }
            $http->setConfig($config);
            $http->write(
                Zend_Http_Client::POST,
                $this->getApiEndpoint(),
                '1.1',
                $this->_headers,
                $this->_buildQuery($request)
            );
            $response = $http->read();
        } catch (Exception $e) {
            $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
            $this->_debug($debugData);
            throw $e;
        }
    
        $response = preg_split('/^\r?$/m', $response, 2);
        $response = trim($response[1]);
        $response = $this->_deformatNVP($response);
    
        $debugData['response'] = $response;
        $this->_debug($debugData);
        $response = $this->_postProcessResponse($response);
    
        // handle transport error
        if ($http->getErrno()) {
            Mage::logException(new Exception(
                sprintf('PayPal NVP CURL connection error #%s: %s', $http->getErrno(), $http->getError())
            ));
            $http->close();
    
            Mage::throwException(Mage::helper('paypal')->__('Unable to communicate with the PayPal gateway.'));
        }
    
        // cUrl resource must be closed after checking it for errors
        $http->close();
    
        if (!$this->_validateResponse($methodName, $response)) {
            Mage::logException(new Exception(
                Mage::helper('paypal')->__("PayPal response hasn't required fields.")
            ));
            Mage::throwException(Mage::helper('paypal')->__('There was an error processing your order. Please contact us or try again later.'));
        }
    
        $this->_callErrors = array();
        if ($this->_isCallSuccessful($response)) {
            if ($this->_rawResponseNeeded) {
                $this->setRawSuccessResponseData($response);
            }
            return $response;
        }
        $this->_handleCallErrors($response);
        return $response;
    }
    

    重要的一行是$http->addOption(CURLOPT_SSLVERSION,6);//CURL_SSLVERSION_TLSv1_2

    【讨论】:

    • 应用此代码但同样的错误...你能解释一下吗?谢谢
    • 您还需要 OpenSSL 版本 1.0.1+。尝试在命令行中运行“openssl 版本”来检查。
    猜你喜欢
    • 2016-01-24
    • 2014-03-07
    • 2013-08-29
    • 2015-07-01
    • 2022-01-07
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 2023-01-05
    相关资源
    最近更新 更多