/** * Post back to PayPal to check whether this request is a valid one * * @return void * @throws RemoteServiceUnavailableException * @throws \Exception */ protected function _postBack() { $httpAdapter = $this->_curlFactory->create(); $postbackQuery = http_build_query($this->getRequestData()) . '&cmd=_notify-validate'; $postbackUrl = $this->_config->getPayPalIpnUrl(); $this->_addDebugData('postback_to', $postbackUrl); $httpAdapter->setConfig(['verifypeer' => $this->_config->getValue('verifyPeer')]); $httpAdapter->write(\Zend_Http_Client::POST, $postbackUrl, '1.1', ['Connection: close'], $postbackQuery); try { $postbackResult = $httpAdapter->read(); } catch (\Exception $e) { $this->_addDebugData('http_error', ['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, ['500', '502', '503'])) { if (empty($postbackResult)) { $reason = 'Empty response.'; } else { $reason = 'Response code: ' . $responseCode . '.'; } $this->_debugData['exception'] = 'PayPal IPN postback failure. ' . $reason; throw new RemoteServiceUnavailableException(__($reason)); } $response = preg_split('/^\\r?$/m', $postbackResult, 2); $response = trim($response[1]); if ($response != 'VERIFIED') { $this->_addDebugData('postback', $postbackQuery); $this->_addDebugData('postback_result', $postbackResult); throw new \Exception('PayPal IPN postback failure. See system.log for details.'); } }